diff --git a/src/tests/access/test_ownable_twostep.cairo b/src/tests/access/test_ownable_twostep.cairo index 9708fc033..ed7c1ccde 100644 --- a/src/tests/access/test_ownable_twostep.cairo +++ b/src/tests/access/test_ownable_twostep.cairo @@ -34,17 +34,16 @@ fn setup() -> ComponentState { // #[test] -#[available_gas(2000000)] fn test_initializer_owner_pending_owner() { let mut state = COMPONENT_STATE(); - assert(state.Ownable_owner.read() == ZERO(), 'Owner should be ZERO'); - assert(state.Ownable_pending_owner.read() == ZERO(), 'Pending owner should be ZERO'); + assert!(state.Ownable_owner.read().is_zero()); + assert!(state.Ownable_pending_owner.read().is_zero()); state.initializer(OWNER()); assert_event_ownership_transferred(ZERO(), OWNER()); - assert(state.Ownable_owner.read() == OWNER(), 'Owner should be set'); - assert(state.Ownable_pending_owner.read() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.Ownable_owner.read(), OWNER()); + assert!(state.Ownable_pending_owner.read().is_zero()); } // @@ -52,7 +51,6 @@ fn test_initializer_owner_pending_owner() { // #[test] -#[available_gas(2000000)] fn test__accept_ownership() { let mut state = setup(); state.Ownable_pending_owner.write(OTHER()); @@ -60,8 +58,8 @@ fn test__accept_ownership() { state._accept_ownership(); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.owner() == OTHER(), 'Owner should be OTHER'); - assert(state.pending_owner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OTHER()); + assert!(state.pending_owner().is_zero()); } // @@ -69,52 +67,48 @@ fn test__accept_ownership() { // #[test] -#[available_gas(2000000)] fn test__propose_owner() { let mut state = setup(); state._propose_owner(OTHER()); assert_event_ownership_transfer_started(OWNER(), OTHER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pending_owner() == OTHER(), 'Pending owner should be OTHER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pending_owner(), OTHER()); } // transfer_ownership & transferOwnership #[test] -#[available_gas(2000000)] fn test_transfer_ownership() { let mut state = setup(); testing::set_caller_address(OWNER()); state.transfer_ownership(OTHER()); assert_event_ownership_transfer_started(OWNER(), OTHER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pending_owner() == OTHER(), 'Pending owner should be OTHER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pending_owner(), OTHER()); // Transferring to yet another owner while pending is set should work state.transfer_ownership(NEW_OWNER()); assert_event_ownership_transfer_started(OWNER(), NEW_OWNER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pending_owner() == NEW_OWNER(), 'Pending should be NEW_OWNER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pending_owner(), NEW_OWNER()); } #[test] -#[available_gas(2000000)] fn test_transfer_ownership_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); state.transfer_ownership(ZERO()); assert_event_ownership_transfer_started(OWNER(), ZERO()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pending_owner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pending_owner(), ZERO()); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_transfer_ownership_from_zero() { let mut state = setup(); @@ -122,7 +116,6 @@ fn test_transfer_ownership_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_transfer_ownership_from_nonowner() { let mut state = setup(); @@ -131,38 +124,35 @@ fn test_transfer_ownership_from_nonowner() { } #[test] -#[available_gas(2000000)] fn test_transferOwnership() { let mut state = setup(); testing::set_caller_address(OWNER()); state.transferOwnership(OTHER()); assert_event_ownership_transfer_started(OWNER(), OTHER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pendingOwner() == OTHER(), 'Pending owner should be OTHER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pendingOwner(), OTHER()); // Transferring to yet another owner while pending is set should work state.transferOwnership(NEW_OWNER()); assert_event_ownership_transfer_started(OWNER(), NEW_OWNER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pendingOwner() == NEW_OWNER(), 'Pending should be NEW_OWNER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pendingOwner(), NEW_OWNER()); } #[test] -#[available_gas(2000000)] fn test_transferOwnership_to_zero() { let mut state = setup(); testing::set_caller_address(OWNER()); state.transferOwnership(ZERO()); assert_event_ownership_transfer_started(OWNER(), ZERO()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pendingOwner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OWNER()); + assert!(state.pendingOwner().is_zero()); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_transferOwnership_from_zero() { let mut state = setup(); @@ -170,7 +160,6 @@ fn test_transferOwnership_from_zero() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_transferOwnership_from_nonowner() { let mut state = setup(); @@ -183,7 +172,6 @@ fn test_transferOwnership_from_nonowner() { // #[test] -#[available_gas(2000000)] fn test_accept_ownership() { let mut state = setup(); state.Ownable_pending_owner.write(OTHER()); @@ -192,12 +180,11 @@ fn test_accept_ownership() { state.accept_ownership(); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.owner() == OTHER(), 'Owner should be OTHER'); - assert(state.pending_owner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OTHER()); + assert!(state.pending_owner().is_zero()); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the pending owner',))] fn test_accept_ownership_from_nonpending() { let mut state = setup(); @@ -207,7 +194,6 @@ fn test_accept_ownership_from_nonpending() { } #[test] -#[available_gas(2000000)] fn test_acceptOwnership() { let mut state = setup(); state.Ownable_pending_owner.write(OTHER()); @@ -216,12 +202,11 @@ fn test_acceptOwnership() { state.acceptOwnership(); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.owner() == OTHER(), 'Owner should be OTHER'); - assert(state.pendingOwner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OTHER()); + assert!(state.pendingOwner().is_zero()); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the pending owner',))] fn test_acceptOwnership_from_nonpending() { let mut state = setup(); @@ -235,7 +220,6 @@ fn test_acceptOwnership_from_nonpending() { // #[test] -#[available_gas(2000000)] fn test_renounce_ownership() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -243,11 +227,10 @@ fn test_renounce_ownership() { assert_event_ownership_transferred(OWNER(), ZERO()); - assert(state.owner() == ZERO(), 'Should renounce ownership'); + assert!(state.owner().is_zero()); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_renounce_ownership_from_zero_address() { let mut state = setup(); @@ -255,7 +238,6 @@ fn test_renounce_ownership_from_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounce_ownership_from_nonowner() { let mut state = setup(); @@ -264,7 +246,6 @@ fn test_renounce_ownership_from_nonowner() { } #[test] -#[available_gas(2000000)] fn test_renounceOwnership() { let mut state = setup(); testing::set_caller_address(OWNER()); @@ -272,11 +253,10 @@ fn test_renounceOwnership() { assert_event_ownership_transferred(OWNER(), ZERO()); - assert(state.owner() == ZERO(), 'Should renounce ownership'); + assert!(state.owner().is_zero()); } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is the zero address',))] fn test_renounceOwnership_from_zero_address() { let mut state = setup(); @@ -284,7 +264,6 @@ fn test_renounceOwnership_from_zero_address() { } #[test] -#[available_gas(2000000)] #[should_panic(expected: ('Caller is not the owner',))] fn test_renounceOwnership_from_nonowner() { let mut state = setup(); @@ -293,46 +272,44 @@ fn test_renounceOwnership_from_nonowner() { } #[test] -#[available_gas(2000000)] fn test_full_two_step_transfer() { let mut state = setup(); testing::set_caller_address(OWNER()); state.transfer_ownership(OTHER()); assert_event_ownership_transfer_started(OWNER(), OTHER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pending_owner() == OTHER(), 'Pending owner should be OTHER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pending_owner(), OTHER()); testing::set_caller_address(OTHER()); state.accept_ownership(); assert_event_ownership_transferred(OWNER(), OTHER()); - assert(state.owner() == OTHER(), 'Owner should be OTHER'); - assert(state.pending_owner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OTHER()); + assert!(state.pending_owner().is_zero()); } #[test] -#[available_gas(2000000)] fn test_pending_accept_after_owner_renounce() { let mut state = setup(); testing::set_caller_address(OWNER()); state.transfer_ownership(OTHER()); assert_event_ownership_transfer_started(OWNER(), OTHER()); - assert(state.owner() == OWNER(), 'Owner should be OWNER'); - assert(state.pending_owner() == OTHER(), 'Pending owner should be OTHER'); + assert_eq!(state.owner(), OWNER()); + assert_eq!(state.pending_owner(), OTHER()); state.renounce_ownership(); assert_event_ownership_transferred(OWNER(), ZERO()); - assert(state.owner() == ZERO(), 'Should renounce ownership'); + assert!(state.owner().is_zero()); testing::set_caller_address(OTHER()); state.accept_ownership(); assert_event_ownership_transferred(ZERO(), OTHER()); - assert(state.owner() == OTHER(), 'Owner should be OTHER'); - assert(state.pending_owner() == ZERO(), 'Pending owner should be ZERO'); + assert_eq!(state.owner(), OTHER()); + assert!(state.pending_owner().is_zero()); } // @@ -343,8 +320,8 @@ fn assert_event_ownership_transfer_started( previous_owner: ContractAddress, new_owner: ContractAddress ) { let event = utils::pop_log::(ZERO()).unwrap(); - assert(event.previous_owner == previous_owner, 'Invalid `previous_owner`'); - assert(event.new_owner == new_owner, 'Invalid `new_owner`'); + assert_eq!(event.previous_owner, previous_owner); + assert_eq!(event.new_owner, new_owner); utils::assert_no_events_left(ZERO()); let mut indexed_keys = array![]; diff --git a/src/tests/presets/test_account.cairo b/src/tests/presets/test_account.cairo index 9b9cd3db7..c92b2c98e 100644 --- a/src/tests/presets/test_account.cairo +++ b/src/tests/presets/test_account.cairo @@ -182,10 +182,10 @@ fn test_isValidSignature_bad_sig() { fn test_supports_interface() { let dispatcher = setup_dispatcher(); let supports_isrc5 = dispatcher.supports_interface(ISRC5_ID); - let supports_isrc6 = dispatcher.supports_interface(ISRC6_ID); - let doesnt_support_0x123 = !dispatcher.supports_interface(0x123); assert!(supports_isrc5); + let supports_isrc6 = dispatcher.supports_interface(ISRC6_ID); assert!(supports_isrc6); + let doesnt_support_0x123 = !dispatcher.supports_interface(0x123); assert!(doesnt_support_0x123); } diff --git a/src/tests/presets/test_eth_account.cairo b/src/tests/presets/test_eth_account.cairo index 144f9739d..ae25f5f8a 100644 --- a/src/tests/presets/test_eth_account.cairo +++ b/src/tests/presets/test_eth_account.cairo @@ -90,23 +90,19 @@ fn setup_upgradeable() -> IUpgradeableDispatcher { #[test] fn test_constructor() { let mut state = EthAccountUpgradeable::contract_state_for_testing(); - let public_key = ETH_PUBKEY(); - EthAccountUpgradeable::constructor(ref state, public_key); + EthAccountUpgradeable::constructor(ref state, ETH_PUBKEY()); - assert_only_event_owner_added(ZERO(), public_key); - assert( - EthAccountUpgradeable::PublicKeyImpl::get_public_key(@state) == public_key, - 'Should return public_key' - ); - assert( - EthAccountUpgradeable::SRC5Impl::supports_interface(@state, ISRC5_ID), - 'Should implement ISRC5' - ); - assert( - EthAccountUpgradeable::SRC5Impl::supports_interface(@state, ISRC6_ID), - 'Should implement ISRC6' - ); + assert_only_event_owner_added(ZERO(), ETH_PUBKEY()); + + let public_key = EthAccountUpgradeable::PublicKeyImpl::get_public_key(@state); + assert_eq!(public_key, ETH_PUBKEY()); + + let supports_isrc5 = EthAccountUpgradeable::SRC5Impl::supports_interface(@state, ISRC5_ID); + assert!(supports_isrc5); + + let supports_isrc6 = EthAccountUpgradeable::SRC5Impl::supports_interface(@state, ISRC6_ID); + assert!(supports_isrc6); } // @@ -121,7 +117,7 @@ fn test_public_key_setter_and_getter() { testing::set_contract_address(dispatcher.contract_address); dispatcher.set_public_key(new_public_key); - assert(dispatcher.get_public_key() == new_public_key, 'Should return new_public_key'); + assert_eq!(dispatcher.get_public_key(), new_public_key); assert_event_owner_removed(dispatcher.contract_address, ETH_PUBKEY()); assert_only_event_owner_added(dispatcher.contract_address, new_public_key); @@ -135,7 +131,7 @@ fn test_public_key_setter_and_getter_camel() { testing::set_contract_address(dispatcher.contract_address); dispatcher.setPublicKey(new_public_key); - assert(dispatcher.getPublicKey() == new_public_key, 'Should return new_public_key'); + assert_eq!(dispatcher.getPublicKey(), new_public_key); assert_event_owner_removed(dispatcher.contract_address, ETH_PUBKEY()); assert_only_event_owner_added(dispatcher.contract_address, new_public_key); @@ -178,7 +174,7 @@ fn test_is_valid_signature() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); let is_valid = dispatcher.is_valid_signature(hash, signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -186,7 +182,7 @@ fn test_is_valid_signature_bad_sig() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); let is_valid = dispatcher.is_valid_signature(hash + 1, signature); - assert(is_valid == 0, 'Should reject invalid signature'); + assert!(is_valid.is_zero(), "Should reject invalid signature"); } #[test] @@ -194,7 +190,7 @@ fn test_isValidSignature() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); let is_valid = dispatcher.isValidSignature(hash, signature); - assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -202,7 +198,7 @@ fn test_isValidSignature_bad_sig() { let (dispatcher, hash, signature) = is_valid_sig_dispatcher(); let is_valid = dispatcher.isValidSignature(hash + 1, signature); - assert(is_valid == 0, 'Should reject invalid signature'); + assert!(is_valid.is_zero(), "Should reject invalid signature"); } // @@ -212,9 +208,13 @@ fn test_isValidSignature_bad_sig() { #[test] fn test_supports_interface() { let dispatcher = setup_dispatcher(); - assert(dispatcher.supports_interface(ISRC5_ID), 'Should implement ISRC5'); - assert(dispatcher.supports_interface(ISRC6_ID), 'Should implement ISRC6'); - assert(!dispatcher.supports_interface(0x123), 'Should not implement 0x123'); + + let supports_isrc5 = dispatcher.supports_interface(ISRC5_ID); + assert!(supports_isrc5); + let supports_isrc6 = dispatcher.supports_interface(ISRC6_ID); + assert!(supports_isrc6); + let doesnt_support_0x123 = !dispatcher.supports_interface(0x123); + assert!(doesnt_support_0x123); } // @@ -228,10 +228,8 @@ fn test_validate_deploy() { // `__validate_deploy__` does not directly use the passed arguments. Their // values are already integrated in the tx hash. The passed arguments in this // testing context are decoupled from the signature and have no effect on the test. - assert( - account.__validate_deploy__(CLASS_HASH(), SALT, ETH_PUBKEY()) == starknet::VALIDATED, - 'Should validate correctly' - ); + let is_valid = account.__validate_deploy__(CLASS_HASH(), SALT, ETH_PUBKEY()); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -272,10 +270,8 @@ fn test_validate_declare() { // `__validate_declare__` does not directly use the class_hash argument. Its // value is already integrated in the tx hash. The class_hash argument in this // testing context is decoupled from the signature and has no effect on the test. - assert( - account.__validate_declare__(CLASS_HASH()) == starknet::VALIDATED, - 'Should validate correctly' - ); + let is_valid = account.__validate_declare__(CLASS_HASH()); + assert_eq!(is_valid, starknet::VALIDATED,); } #[test] @@ -333,12 +329,12 @@ fn test_execute_with_version(version: Option) { let ret = account.__execute__(calls); - assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); - assert(erc20.balance_of(RECIPIENT()) == amount, 'Should have transferred'); + assert_eq!(erc20.balance_of(account.contract_address), 800, "Should have remainder"); + assert_eq!(erc20.balance_of(RECIPIENT()), amount, "Should have transferred"); let mut call_serialized_retval = *ret.at(0); let call_retval = Serde::::deserialize(ref call_serialized_retval); - assert(call_retval.unwrap(), 'Should have succeeded'); + assert!(call_retval.unwrap()); } #[test] @@ -362,7 +358,8 @@ fn test_validate() { let calls = array![]; let account = setup_dispatcher_with_data(Option::Some(@SIGNED_TX_DATA())); - assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); + let is_valid = account.__validate__(calls); + assert_eq!(is_valid, starknet::VALIDATED); } #[test] @@ -404,16 +401,16 @@ fn test_multicall() { calls.append(call2); let ret = account.__execute__(calls); - assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); - assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); - assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); + assert_eq!(erc20.balance_of(account.contract_address), 200, "Should have remainder"); + assert_eq!(erc20.balance_of(recipient1), 300, "Should have transferred"); + assert_eq!(erc20.balance_of(recipient2), 500, "Should have transferred"); let mut call1_serialized_retval = *ret.at(0); let mut call2_serialized_retval = *ret.at(1); let call1_retval = Serde::::deserialize(ref call1_serialized_retval); let call2_retval = Serde::::deserialize(ref call2_serialized_retval); - assert(call1_retval.unwrap(), 'Should have succeeded'); - assert(call2_retval.unwrap(), 'Should have succeeded'); + assert!(call1_retval.unwrap()); + assert!(call2_retval.unwrap()); } #[test] @@ -423,7 +420,7 @@ fn test_multicall_zero_calls() { let ret = account.__execute__(calls); - assert(ret.len() == 0, 'Should have an empty response'); + assert!(ret.len().is_zero(), "Should have an empty response"); } #[test]