diff --git a/contracts/src/access/control/mod.rs b/contracts/src/access/control/mod.rs index f6823fb0a..ace6e6f01 100644 --- a/contracts/src/access/control/mod.rs +++ b/contracts/src/access/control/mod.rs @@ -449,7 +449,7 @@ mod tests { unsafe impl TopLevelStorage for AccessControl {} #[motsu::test] - fn default_role_is_default_admin( + fn get_role_admin_returns_default_admin_for_standard_role( contract: Contract, alice: Address, ) { @@ -458,7 +458,7 @@ mod tests { } #[motsu::test] - fn default_admin_roles_admin_is_itself( + fn get_role_admin_returns_default_admin_for_default_admin_role( contract: Contract, alice: Address, ) { @@ -468,7 +468,7 @@ mod tests { } #[motsu::test] - fn non_admin_cannot_grant_role_to_others( + fn grant_role_reverts_when_not_admin( contract: Contract, alice: Address, bob: Address, @@ -479,7 +479,7 @@ mod tests { } #[motsu::test] - fn accounts_can_be_granted_roles_multiple_times( + fn grant_role_succeeds_assigning_role_multiple_times( contract: Contract, alice: Address, bob: Address, @@ -493,7 +493,7 @@ mod tests { } #[motsu::test] - fn not_granted_roles_can_be_revoked( + fn revoke_role_succeeds_removing_ungranted_role( contract: Contract, alice: Address, bob: Address, @@ -508,7 +508,7 @@ mod tests { } #[motsu::test] - fn admin_can_revoke_role( + fn revoke_role_succeeds_removing_granted_role( contract: Contract, alice: Address, bob: Address, @@ -524,7 +524,7 @@ mod tests { } #[motsu::test] - fn non_admin_cannot_revoke_role( + fn revoke_role_reverts_when_not_admin( contract: Contract, alice: Address, bob: Address, @@ -539,7 +539,7 @@ mod tests { } #[motsu::test] - fn roles_can_be_revoked_multiple_times( + fn revoke_role_succeeds_removing_role_multiple_times( contract: Contract, alice: Address, bob: Address, @@ -553,7 +553,7 @@ mod tests { } #[motsu::test] - fn bearer_can_renounce_role( + fn renounce_role_succeeds_removing_own_role( contract: Contract, alice: Address, ) { @@ -567,7 +567,7 @@ mod tests { } #[motsu::test] - fn only_sender_can_renounce( + fn renounce_role_reverts_when_not_sender( contract: Contract, alice: Address, bob: Address, @@ -579,7 +579,7 @@ mod tests { } #[motsu::test] - fn roles_can_be_renounced_multiple_times( + fn renounce_role_succeeds_removing_role_multiple_times( contract: Contract, alice: Address, bob: Address, @@ -593,7 +593,7 @@ mod tests { } #[motsu::test] - fn a_roles_admin_role_can_change( + fn _set_role_admin_succeeds_updating_admin_role( contract: Contract, alice: Address, ) { @@ -605,7 +605,7 @@ mod tests { } #[motsu::test] - fn the_new_admin_can_grant_roles( + fn grant_role_succeeds_assigning_role_with_new_admin( contract: Contract, alice: Address, bob: Address, @@ -619,7 +619,7 @@ mod tests { } #[motsu::test] - fn the_new_admin_can_revoke_roles( + fn revoke_role_succeeds_removing_role_with_new_admins( contract: Contract, alice: Address, bob: Address, @@ -634,7 +634,7 @@ mod tests { } #[motsu::test] - fn previous_admins_no_longer_grant_roles( + fn grant_role_reverts_when_called_by_old_admin( contract: Contract, alice: Address, bob: Address, @@ -648,7 +648,7 @@ mod tests { } #[motsu::test] - fn previous_admins_no_longer_revoke_roles( + fn revoke_role_reverts_when_called_by_old_admin( contract: Contract, alice: Address, bob: Address, @@ -662,7 +662,7 @@ mod tests { } #[motsu::test] - fn does_not_revert_if_sender_has_role( + fn _check_role_succeeds_verifying_granted_role( contract: Contract, alice: Address, ) { @@ -687,7 +687,7 @@ mod tests { } #[motsu::test] - fn internal_grant_role_true_if_no_role( + fn _grant_role_true_if_no_role( contract: Contract, alice: Address, bob: Address, @@ -697,7 +697,7 @@ mod tests { } #[motsu::test] - fn internal_grant_role_false_if_role( + fn _grant_role_succeeds_with_existing_role( contract: Contract, alice: Address, bob: Address, @@ -709,7 +709,7 @@ mod tests { } #[motsu::test] - fn internal_revoke_role_true_if_role( + fn _revoke_role_succeeds_removing_existing_role( contract: Contract, alice: Address, bob: Address, @@ -722,7 +722,7 @@ mod tests { } #[motsu::test] - fn internal_revoke_role_false_if_no_role( + fn _revoke_role_succeeds_with_nonexistent_role( contract: Contract, alice: Address, bob: Address, diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index a44a7d53c..3e16d0cfe 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -294,7 +294,6 @@ mod tests { #[motsu::test] fn constructor(contract: Contract, alice: Address) { contract.sender(alice).constructor(alice).unwrap(); - let owner = contract.sender(alice).owner(); assert_eq!(owner, alice); @@ -319,7 +318,7 @@ mod tests { } #[motsu::test] - fn transfers_ownership( + fn transfer_ownership_updates_owner_address( contract: Contract, alice: Address, bob: Address, @@ -340,7 +339,7 @@ mod tests { } #[motsu::test] - fn prevents_non_owners_from_transferring( + fn transfer_ownership_reverts_when_not_owner( contract: Contract, alice: Address, bob: Address, @@ -352,7 +351,7 @@ mod tests { } #[motsu::test] - fn prevents_reaching_stuck_state( + fn transfer_ownership_reverts_when_transferring_to_zero_address( contract: Contract, alice: Address, ) { @@ -367,7 +366,7 @@ mod tests { } #[motsu::test] - fn loses_ownership_after_renouncing( + fn renounce_ownership_sets_zero_address( contract: Contract, alice: Address, ) { @@ -387,7 +386,7 @@ mod tests { } #[motsu::test] - fn prevents_non_owners_from_renouncing( + fn renounce_ownership_reverts_when_not_owner( contract: Contract, alice: Address, bob: Address, @@ -398,19 +397,6 @@ mod tests { assert!(matches!(err, Error::UnauthorizedAccount(_))); } - #[motsu::test] - fn recovers_access_using_internal_transfer( - contract: Contract, - alice: Address, - bob: Address, - ) { - contract.sender(alice).constructor(bob).unwrap(); - - contract.sender(alice)._transfer_ownership(bob); - let owner = contract.sender(alice).owner(); - assert_eq!(owner, bob); - } - #[motsu::test] fn interface_id() { let actual = ::interface_id(); diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index 04d1f35c1..ef430aa60 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -251,7 +251,7 @@ mod tests { } #[motsu::test] - fn reads_pending_owner( + fn pending_owner_returns_current_address( contract: Contract, alice: Address, bob: Address, @@ -263,7 +263,7 @@ mod tests { } #[motsu::test] - fn initiates_ownership_transfer( + fn transfer_ownership_succeeds_updating_pending_owner( contract: Contract, alice: Address, bob: Address, @@ -276,10 +276,11 @@ mod tests { .expect("should initiate ownership transfer"); assert_eq!(contract.sender(alice).owner(), alice); + assert_eq!(contract.sender(alice).pending_owner(), bob); } #[motsu::test] - fn prevents_non_owners_from_initiating_transfer( + fn transfer_ownership_reverts_when_not_owner( contract: Contract, alice: Address, bob: Address, @@ -297,7 +298,7 @@ mod tests { } #[motsu::test] - fn accepts_ownership( + fn accept_ownership_succeeds_completing_transfer( contract: Contract, alice: Address, bob: Address, @@ -314,7 +315,7 @@ mod tests { } #[motsu::test] - fn prevents_non_pending_owner_from_accepting( + fn accept_ownership_reverts_when_not_pending_owner( contract: Contract, alice: Address, bob: Address, @@ -333,7 +334,7 @@ mod tests { } #[motsu::test] - fn completes_two_step_ownership_transfer( + fn transfer_ownership_succeeds_with_complete_flow( contract: Contract, alice: Address, bob: Address, @@ -356,9 +357,11 @@ mod tests { } #[motsu::test] - fn renounces_ownership(contract: Contract, alice: Address) { + fn renounce_ownership_succeeds_clearing_owner( + contract: Contract, + alice: Address, + ) { contract.sender(alice).constructor(alice).unwrap(); - contract .sender(alice) .renounce_ownership() @@ -367,7 +370,7 @@ mod tests { } #[motsu::test] - fn prevents_non_owners_from_renouncing( + fn renounce_ownership_reverts_when_not_owner( contract: Contract, alice: Address, bob: Address, @@ -384,7 +387,7 @@ mod tests { } #[motsu::test] - fn cancels_transfer_on_renounce( + fn renounce_ownership_succeeds_clearing_pending_transfer( contract: Contract, alice: Address, bob: Address, @@ -401,7 +404,7 @@ mod tests { } #[motsu::test] - fn allows_owner_to_cancel_transfer( + fn transfer_ownership_succeeds_canceling_transfer( contract: Contract, alice: Address, bob: Address, @@ -418,7 +421,7 @@ mod tests { } #[motsu::test] - fn allows_owner_to_overwrite_transfer( + fn transfer_ownership_succeeds_overwriting_pending_owner( contract: Contract, alice: Address, bob: Address, diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index a36bb1521..c39a9f41d 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -646,26 +646,38 @@ mod tests { } #[motsu::test] - fn reads_start(contract: Contract, alice: Address) { + fn start_returns_configured_timestamp( + contract: Contract, + alice: Address, + ) { let (start, _) = contract.sender(alice).init(start(), DURATION); assert_eq!(U256::from(start), contract.sender(alice).start()); } #[motsu::test] - fn reads_duration(contract: Contract, alice: Address) { + fn duration_returns_configured_period( + contract: Contract, + alice: Address, + ) { let (_, duration) = contract.sender(alice).init(0, DURATION); assert_eq!(U256::from(duration), contract.sender(alice).duration()); } #[motsu::test] - fn reads_end(contract: Contract, alice: Address) { + fn end_returns_start_plus_duration( + contract: Contract, + alice: Address, + ) { let (start, duration) = contract.sender(alice).init(start(), DURATION); assert_eq!(U256::from(start + duration), contract.sender(alice).end()); } #[motsu::test] - fn reads_max_end(contract: Contract, alice: Address) { + fn end_returns_sum_with_max_values( + contract: Contract, + alice: Address, + ) { contract.sender(alice).init(u64::MAX, u64::MAX); assert_eq!( U256::from(U64::MAX) + U256::from(U64::MAX), @@ -674,7 +686,7 @@ mod tests { } #[motsu::test] - fn gets_vesting_schedule( + fn vesting_schedule_calculates_linear_vesting( contract: Contract, alice: Address, ) { @@ -706,7 +718,7 @@ mod tests { } #[motsu::test] - fn gets_vesting_schedule_zero_duration( + fn vesting_schedule_calculates_immediate_release( contract: Contract, alice: Address, ) { @@ -756,13 +768,6 @@ mod tests { } } - #[motsu::test] - fn interface_id() { - let actual = ::interface_id(); - let expected: B32 = 0x23a2649d_u32.into(); - assert_ne!(actual, expected); - } - #[motsu::test] fn supports_interface(contract: Contract, alice: Address) { assert!(contract.sender(alice).supports_interface( diff --git a/contracts/src/token/erc1155/extensions/burnable.rs b/contracts/src/token/erc1155/extensions/burnable.rs index d4a396077..0a2778f0b 100644 --- a/contracts/src/token/erc1155/extensions/burnable.rs +++ b/contracts/src/token/erc1155/extensions/burnable.rs @@ -152,7 +152,7 @@ mod tests { } #[motsu::test] - fn burns(contract: Contract, alice: Address) { + fn burn_destroys_owned_tokens(contract: Contract, alice: Address) { let (token_ids, values) = contract.sender(alice).init(alice, 1); let initial_balance = @@ -169,7 +169,7 @@ mod tests { } #[motsu::test] - fn burns_with_approval( + fn burn_destroys_approved_tokens( contract: Contract, alice: Address, bob: Address, @@ -195,7 +195,7 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_burns( + fn burn_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -217,7 +217,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_burns( + fn burn_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -245,7 +245,7 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_burn( + fn burn_reverts_when_balance_insufficient( contract: Contract, alice: Address, ) { @@ -272,7 +272,10 @@ mod tests { } #[motsu::test] - fn burns_batch(contract: Contract, alice: Address) { + fn burn_batch_destroys_multiple_owned_tokens( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.sender(alice).init(alice, 4); for (&token_id, &value) in token_ids.iter().zip(values.iter()) { @@ -292,7 +295,7 @@ mod tests { } #[motsu::test] - fn burns_batch_with_approval( + fn burn_batch_destroys_multiple_approved_tokens( contract: Contract, alice: Address, bob: Address, @@ -321,7 +324,7 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_burn_batch( + fn burn_batch_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -345,7 +348,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_burn_batch( + fn burn_batch_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -373,7 +376,7 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_burn_batch( + fn burn_batch_reverts_when_balance_insufficient( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index 55ac9868e..e63364a4a 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -99,7 +99,7 @@ mod tests { unsafe impl TopLevelStorage for Erc1155MetadataUri {} #[motsu::test] - fn uri_ignores_token_id( + fn uri_returns_constant_for_different_ids( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index e0f752cc2..7b4309c76 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -408,7 +408,10 @@ mod tests { } #[motsu::test] - fn before_mint(contract: Contract, alice: Address) { + fn total_supply_returns_zero_for_unminted_token( + contract: Contract, + alice: Address, + ) { let token_id = random_token_ids(1)[0]; assert_eq!(U256::ZERO, contract.sender(alice).total_supply(token_id)); assert_eq!(U256::ZERO, contract.sender(alice).total_supply_all()); @@ -416,7 +419,7 @@ mod tests { } #[motsu::test] - fn after_mint_single( + fn total_supply_returns_amount_after_single_mint( contract: Contract, alice: Address, bob: Address, @@ -435,7 +438,7 @@ mod tests { } #[motsu::test] - fn after_mint_batch( + fn total_supply_returns_amounts_after_batch_mint( contract: Contract, alice: Address, bob: Address, @@ -451,7 +454,7 @@ mod tests { } #[motsu::test] - fn mint_reverts_on_invalid_receiver( + fn mint_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -474,7 +477,7 @@ mod tests { #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `total_supply`"] - fn mint_panics_on_total_supply_overflow( + fn mint_reverts_when_total_supply_overflows( contract: Contract, alice: Address, bob: Address, @@ -497,7 +500,7 @@ mod tests { #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `total_supply_all`"] - fn mint_panics_on_total_supply_all_overflow( + fn mint_reverts_when_total_supply_all_overflows( contract: Contract, alice: Address, bob: Address, @@ -517,7 +520,7 @@ mod tests { } #[motsu::test] - fn after_burn_single( + fn total_supply_returns_zero_after_single_burn( contract: Contract, alice: Address, bob: Address, @@ -537,7 +540,7 @@ mod tests { } #[motsu::test] - fn after_burn_batch( + fn total_supply_returns_zero_after_batch_burn( contract: Contract, alice: Address, bob: Address, @@ -563,7 +566,7 @@ mod tests { } #[motsu::test] - fn burn_reverts_when_invalid_sender( + fn burn_reverts_when_sender_invalid( contract: Contract, alice: Address, bob: Address, @@ -585,7 +588,7 @@ mod tests { } #[motsu::test] - fn supply_unaffected_by_no_op( + fn total_supply_returns_zero_for_zero_addresses( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc1155/extensions/uri_storage.rs b/contracts/src/token/erc1155/extensions/uri_storage.rs index e12a56c13..b76b90287 100644 --- a/contracts/src/token/erc1155/extensions/uri_storage.rs +++ b/contracts/src/token/erc1155/extensions/uri_storage.rs @@ -116,7 +116,7 @@ mod tests { const TOKEN_ID: U256 = uint!(1_U256); #[motsu::test] - fn uri_returns_metadata_uri_when_token_uri_is_not_set( + fn uri_returns_metadata_uri_when_only_metadata_set( contract: Contract, alice: Address, ) { @@ -128,7 +128,7 @@ mod tests { } #[motsu::test] - fn uri_returns_empty_string_when_no_uri_is_set( + fn uri_returns_empty_when_no_uri_set( contract: Contract, alice: Address, ) { @@ -136,7 +136,7 @@ mod tests { } #[motsu::test] - fn uri_returns_token_uri_when_base_uri_is_empty( + fn uri_returns_token_uri_when_only_token_set( contract: Contract, alice: Address, ) { @@ -153,7 +153,7 @@ mod tests { } #[motsu::test] - fn uri_returns_concatenated_base_uri_and_token_uri( + fn uri_returns_concatenated_base_and_token_uri( contract: Contract, alice: Address, ) { @@ -179,7 +179,7 @@ mod tests { } #[motsu::test] - fn uri_ignores_metadata_uri_when_token_uri_is_set( + fn uri_returns_token_uri_over_metadata_uri( contract: Contract, alice: Address, ) { @@ -197,7 +197,7 @@ mod tests { assert_eq!(token_uri, contract.sender(alice).uri(TOKEN_ID)); } #[motsu::test] - fn test_set_uri( + fn set_token_uri_updates_token_specific_uri( contract: Contract, alice: Address, ) { @@ -214,7 +214,7 @@ mod tests { assert_eq!(token_uri, contract.sender(alice).uri(TOKEN_ID)); } #[motsu::test] - fn test_set_base_uri( + fn set_base_uri_updates_base_uri_value( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index 2ccde233f..218f896ac 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -1173,7 +1173,7 @@ mod tests { } #[test] - fn should_create_transfer_single() { + fn create_transfer_single_returns_valid_data() { let id = uint!(1_U256); let value = uint!(10_U256); let details = Erc1155ReceiverData::new(vec![id], vec![value]); @@ -1182,7 +1182,7 @@ mod tests { } #[test] - fn should_create_transfer_batch() { + fn create_transfer_batch_returns_valid_data() { let ids = random_token_ids(5); let values = random_values(5); let details = Erc1155ReceiverData::new(ids.clone(), values.clone()); @@ -1191,7 +1191,10 @@ mod tests { } #[motsu::test] - fn balance_of_zero_balance(contract: Contract, alice: Address) { + fn balance_of_returns_zero_for_new_token( + contract: Contract, + alice: Address, + ) { let owner = alice; let token_id = random_token_ids(1)[0]; let balance = contract.sender(alice).balance_of(owner, token_id); @@ -1199,7 +1202,7 @@ mod tests { } #[motsu::test] - fn error_when_array_length_mismatch( + fn balance_of_batch_reverts_when_array_length_mismatch( contract: Contract, alice: Address, bob: Address, @@ -1226,7 +1229,7 @@ mod tests { } #[motsu::test] - fn balance_of_batch_zero_balance( + fn balance_of_batch_returns_zeros_for_new_tokens( contract: Contract, alice: Address, bob: Address, @@ -1245,7 +1248,7 @@ mod tests { } #[motsu::test] - fn set_approval_for_all( + fn set_approval_for_all_updates_operator_status( contract: Contract, alice: Address, bob: Address, @@ -1269,7 +1272,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_operator_set_approval_for_all( + fn set_approval_for_all_reverts_when_operator_invalid( contract: Contract, alice: Address, ) { @@ -1291,7 +1294,10 @@ mod tests { } #[motsu::test] - fn mints(contract: Contract, alice: Address) { + fn mint_creates_new_token_balance( + contract: Contract, + alice: Address, + ) { let token_id = random_token_ids(1)[0]; let value = random_values(1)[0]; @@ -1306,7 +1312,7 @@ mod tests { } #[motsu::test] - fn error_when_mints_to_invalid_receiver( + fn mint_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1328,7 +1334,10 @@ mod tests { } #[motsu::test] - fn mints_batch(contract: Contract, alice: Address) { + fn mint_batch_creates_multiple_token_balances( + contract: Contract, + alice: Address, + ) { let token_ids = random_token_ids(4); let values = random_values(4); @@ -1358,7 +1367,10 @@ mod tests { } #[motsu::test] - fn mints_batch_same_token(contract: Contract, alice: Address) { + fn mint_batch_accumulates_same_token_balance( + contract: Contract, + alice: Address, + ) { let token_id = uint!(1_U256); let values = random_values(4); let expected_balance: U256 = values.iter().sum(); @@ -1387,7 +1399,7 @@ mod tests { } #[motsu::test] - fn error_when_batch_mints_to_invalid_receiver( + fn mint_batch_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1416,7 +1428,7 @@ mod tests { } #[motsu::test] - fn error_when_batch_mints_not_equal_arrays( + fn mint_batch_reverts_when_arrays_length_mismatch( contract: Contract, alice: Address, ) { @@ -1439,7 +1451,10 @@ mod tests { } #[motsu::test] - fn burns(contract: Contract, alice: Address) { + fn burn_decreases_token_balance( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.sender(alice).init(alice, 1); let token_id = token_ids[0]; @@ -1456,7 +1471,7 @@ mod tests { } #[motsu::test] - fn error_when_burns_from_invalid_sender( + fn burn_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -1477,7 +1492,7 @@ mod tests { } #[motsu::test] - fn error_when_burns_with_insufficient_balance( + fn burn_reverts_when_balance_insufficient( contract: Contract, alice: Address, ) { @@ -1502,7 +1517,10 @@ mod tests { } #[motsu::test] - fn burns_batch(contract: Contract, alice: Address) { + fn burn_batch_decreases_multiple_balances( + contract: Contract, + alice: Address, + ) { let (token_ids, values) = contract.sender(alice).init(alice, 4); contract @@ -1519,7 +1537,10 @@ mod tests { } #[motsu::test] - fn burns_batch_same_token(contract: Contract, alice: Address) { + fn burn_batch_decreases_accumulated_balance( + contract: Contract, + alice: Address, + ) { let token_id = uint!(1_U256); let value = uint!(80_U256); @@ -1549,7 +1570,7 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_from_invalid_sender( + fn burn_batch_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -1572,7 +1593,7 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_with_insufficient_balance( + fn burn_batch_reverts_when_balance_insufficient( contract: Contract, alice: Address, ) { @@ -1601,7 +1622,7 @@ mod tests { } #[motsu::test] - fn error_when_batch_burns_not_equal_arrays( + fn burn_batch_reverts_when_arrays_length_mismatch( contract: Contract, alice: Address, ) { @@ -1623,7 +1644,7 @@ mod tests { } #[motsu::test] - fn safe_transfer_from( + fn safe_transfer_from_moves_token_between_accounts( contract: Contract, alice: Address, bob: Address, @@ -1669,7 +1690,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_receiver_safe_transfer_from( + fn safe_transfer_from_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1698,7 +1719,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_safe_transfer_from( + fn safe_transfer_from_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -1732,7 +1753,7 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_safe_transfer_from( + fn safe_transfer_from_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -1760,7 +1781,7 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_safe_transfer_from( + fn safe_transfer_from_reverts_when_balance_insufficient( contract: Contract, alice: Address, bob: Address, @@ -1797,7 +1818,7 @@ mod tests { } #[motsu::test] - fn safe_transfer_from_with_data( + fn safe_transfer_from_moves_token_with_data( contract: Contract, alice: Address, dave: Address, @@ -1827,7 +1848,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_receiver_safe_transfer_from_with_data( + fn safe_transfer_from_with_data_reverts_when_receiver_invalid( contract: Contract, alice: Address, dave: Address, @@ -1835,18 +1856,21 @@ mod tests { let (token_ids, values) = contract.sender(alice).init(dave, 1); let invalid_receiver = Address::ZERO; + contract + .sender(dave) + .set_approval_for_all(alice, true) + .expect("should approve Dave's tokens to Alice"); + let err = contract .sender(alice) - .do_safe_transfer_from( + .safe_transfer_from( dave, invalid_receiver, - token_ids, - values, - &vec![0, 1, 2, 3].into(), + token_ids[0], + values[0], + vec![0, 1, 2, 3].into(), ) - .motsu_expect_err( - "should not transfer tokens to the `Address::ZERO`", - ); + .expect_err("should not transfer tokens to the `Address::ZERO`"); assert!(matches!( err, @@ -1857,7 +1881,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_safe_transfer_from_with_data( + fn safe_transfer_from_with_data_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -1891,7 +1915,7 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_safe_transfer_from_with_data( + fn safe_transfer_from_with_data_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -1919,7 +1943,7 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_safe_transfer_from_with_data( + fn safe_transfer_from_with_data_reverts_when_balance_insufficient( contract: Contract, alice: Address, bob: Address, @@ -1957,7 +1981,7 @@ mod tests { } #[motsu::test] - fn safe_batch_transfer_from( + fn safe_batch_transfer_from_success( contract: Contract, alice: Address, bob: Address, @@ -1993,7 +2017,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_receiver_safe_batch_transfer_from( + fn safe_batch_transfer_from_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -2022,7 +2046,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_safe_batch_transfer_from( + fn safe_batch_transfer_from_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -2056,7 +2080,7 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_safe_batch_transfer_from( + fn safe_batch_transfer_from_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -2084,7 +2108,7 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_safe_batch_transfer_from( + fn safe_batch_transfer_from_reverts_when_balance_insufficient( contract: Contract, alice: Address, bob: Address, @@ -2122,7 +2146,7 @@ mod tests { } #[motsu::test] - fn error_when_not_equal_arrays_safe_batch_transfer_from( + fn safe_batch_transfer_from_reverts_when_arrays_length_mismatch( contract: Contract, alice: Address, dave: Address, @@ -2157,7 +2181,7 @@ mod tests { } #[motsu::test] - fn safe_batch_transfer_from_with_data( + fn safe_batch_transfer_from_success_with_data( contract: Contract, alice: Address, bob: Address, @@ -2191,7 +2215,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_receiver_safe_batch_transfer_from_with_data( + fn safe_batch_transfer_from_with_data_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -2220,7 +2244,7 @@ mod tests { } #[motsu::test] - fn error_when_invalid_sender_safe_batch_transfer_from_with_data( + fn safe_batch_transfer_from_with_data_reverts_when_sender_invalid( contract: Contract, alice: Address, ) { @@ -2254,7 +2278,7 @@ mod tests { } #[motsu::test] - fn error_when_missing_approval_safe_batch_transfer_from_with_data( + fn safe_batch_transfer_from_with_data_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -2282,7 +2306,7 @@ mod tests { } #[motsu::test] - fn error_when_insufficient_balance_safe_batch_transfer_from_with_data( + fn safe_batch_transfer_from_with_data_reverts_when_balance_insufficient( contract: Contract, alice: Address, bob: Address, @@ -2320,7 +2344,7 @@ mod tests { } #[motsu::test] - fn error_when_not_equal_arrays_safe_batch_transfer_from_with_data( + fn safe_batch_transfer_from_with_data_reverts_when_arrays_length_mismatch( contract: Contract, alice: Address, dave: Address, diff --git a/contracts/src/token/erc20/extensions/burnable.rs b/contracts/src/token/erc20/extensions/burnable.rs index ad08d4998..06a1a724a 100644 --- a/contracts/src/token/erc20/extensions/burnable.rs +++ b/contracts/src/token/erc20/extensions/burnable.rs @@ -84,7 +84,10 @@ mod tests { use crate::token::erc20::{Erc20, Error, IErc20}; #[motsu::test] - fn burns(contract: Contract, alice: Address) { + fn burn_decreases_balance_and_total_supply( + contract: Contract, + alice: Address, + ) { let zero = U256::ZERO; let one = uint!(1_U256); @@ -107,7 +110,7 @@ mod tests { } #[motsu::test] - fn burns_errors_when_insufficient_balance( + fn burn_reverts_when_balance_insufficient( contract: Contract, alice: Address, ) { @@ -121,29 +124,31 @@ mod tests { } #[motsu::test] - fn burn_from(contract: Contract, alice: Address, bob: Address) { - // Alice approves `msg::sender`. + fn burn_from_decreases_balance_and_allowance_and_total_supply( + contract: Contract, + alice: Address, + bob: Address, + ) { let one = uint!(1_U256); - contract.sender(alice).approve(bob, one).motsu_unwrap(); + let two = uint!(2_U256); // Mint some tokens for Alice. - let two = uint!(2_U256); - contract - .sender(alice) - ._update(Address::ZERO, alice, two) - .motsu_unwrap(); + contract.sender(alice)._mint(alice, two).motsu_unwrap(); assert_eq!(two, contract.sender(alice).balance_of(alice)); assert_eq!(two, contract.sender(alice).total_supply()); + // Alice approves Bob. + contract.sender(alice).approve(bob, one).motsu_unwrap(); + contract.sender(bob).burn_from(alice, one).motsu_unwrap(); assert_eq!(one, contract.sender(alice).balance_of(alice)); assert_eq!(one, contract.sender(alice).total_supply()); - assert_eq!(U256::ZERO, contract.sender(alice).allowance(bob, alice)); + assert_eq!(U256::ZERO, contract.sender(alice).allowance(alice, bob)); } #[motsu::test] - fn burns_from_errors_when_insufficient_balance( + fn burn_from_reverts_when_balance_insufficient( contract: Contract, alice: Address, bob: Address, @@ -162,7 +167,7 @@ mod tests { } #[motsu::test] - fn burns_from_errors_when_insufficient_allowance( + fn burn_from_reverts_when_allowance_insufficient( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc20/extensions/capped.rs b/contracts/src/token/erc20/extensions/capped.rs index e424d48c2..638870e56 100644 --- a/contracts/src/token/erc20/extensions/capped.rs +++ b/contracts/src/token/erc20/extensions/capped.rs @@ -105,7 +105,10 @@ mod tests { unsafe impl TopLevelStorage for Capped {} #[motsu::test] - fn cap_works(contract: Contract, alice: Address) { + fn constructor_sets_cap_and_rejects_zero( + contract: Contract, + alice: Address, + ) { let value = uint!(2024_U256); contract.sender(alice).constructor(value).expect("should set cap"); assert_eq!(contract.sender(alice).cap(), value); diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index 15c0da4de..8378b4fb7 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1375,6 +1375,24 @@ mod tests { } } + #[motsu::test] + fn get_max_deposit_amount( + contract: Contract, + alice: Address, + ) { + let max_deposit = contract.sender(alice).max_deposit(alice); + assert_eq!(max_deposit, U256::MAX); + } + + #[motsu::test] + fn get_max_mint_amount( + contract: Contract, + alice: Address, + ) { + let max_mint = contract.sender(alice).max_mint(alice); + assert_eq!(max_mint, U256::MAX); + } + #[motsu::test] fn total_assets_returns_invalid_asset_err( vault: Contract, diff --git a/contracts/src/token/erc20/extensions/flash_mint.rs b/contracts/src/token/erc20/extensions/flash_mint.rs index c9d373075..18d884de5 100644 --- a/contracts/src/token/erc20/extensions/flash_mint.rs +++ b/contracts/src/token/erc20/extensions/flash_mint.rs @@ -424,7 +424,7 @@ mod tests { unsafe impl TopLevelStorage for Erc20FlashMintTestExample {} #[motsu::test] - fn max_flash_loan_token_match( + fn max_flash_loan_returns_max_when_no_supply( contract: Contract, alice: Address, ) { @@ -434,7 +434,7 @@ mod tests { } #[motsu::test] - fn max_flash_loan_token_mismatch( + fn max_flash_loan_returns_zero_for_mismatched_token( contract: Contract, alice: Address, ) { @@ -443,7 +443,7 @@ mod tests { } #[motsu::test] - fn max_flash_loan_when_token_minted( + fn max_flash_loan_returns_remaining_capacity( contract: Contract, alice: Address, ) { @@ -462,7 +462,7 @@ mod tests { } #[motsu::test] - fn flash_fee( + fn flash_fee_succeeds_returning_configured_amount( contract: Contract, alice: Address, ) { @@ -482,7 +482,7 @@ mod tests { } #[motsu::test] - fn flash_fee_reverts_when_invalid_token( + fn flash_fee_reverts_when_token_invalid( contract: Contract, alice: Address, ) { @@ -501,7 +501,7 @@ mod tests { } #[motsu::test] - fn flash_loan_reverts_when_exceeded_max_loan( + fn flash_loan_reverts_when_max_loan_exceeded( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 18568d81f..f2acc9b64 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -627,7 +627,7 @@ mod tests { #[motsu::test] #[should_panic = "should not exceed `U256::MAX` for `total_supply`"] - fn update_mint_errors_arithmetic_overflow( + fn mint_panics_with_arithmetic_overflow( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc721/extensions/burnable.rs b/contracts/src/token/erc721/extensions/burnable.rs index 19fe568b8..02e3d3142 100644 --- a/contracts/src/token/erc721/extensions/burnable.rs +++ b/contracts/src/token/erc721/extensions/burnable.rs @@ -61,7 +61,10 @@ mod tests { const TOKEN_ID: U256 = uint!(1_U256); #[motsu::test] - fn burns(contract: Contract, alice: Address) { + fn burn_succeeds_destroying_owned_token( + contract: Contract, + alice: Address, + ) { let one = uint!(1_U256); contract @@ -98,7 +101,7 @@ mod tests { } #[motsu::test] - fn burns_with_approval( + fn burn_succeeds_destroying_approved_token( contract: Contract, alice: Address, bob: Address, @@ -142,7 +145,7 @@ mod tests { } #[motsu::test] - fn burns_with_approval_for_all( + fn burn_succeeds_destroying_operator_approved_token( contract: Contract, alice: Address, bob: Address, @@ -187,7 +190,7 @@ mod tests { } #[motsu::test] - fn error_when_get_approved_of_previous_approval_burned( + fn get_approved_reverts_when_token_burned( contract: Contract, alice: Address, bob: Address, @@ -220,7 +223,7 @@ mod tests { } #[motsu::test] - fn error_when_burn_without_approval( + fn burn_reverts_when_approval_missing( contract: Contract, alice: Address, bob: Address, @@ -245,7 +248,7 @@ mod tests { } #[motsu::test] - fn error_when_burn_nonexistent_token( + fn burn_reverts_when_token_nonexistent( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index ed805ce20..19ff5b2cf 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -863,7 +863,10 @@ mod tests { } #[motsu::test] - fn mints(contract: Contract, alice: Address) { + fn mint_succeeds_with_consecutive_and_standard_tokens( + contract: Contract, + alice: Address, + ) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -899,7 +902,7 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_id_twice( + fn mint_reverts_when_token_id_exists( contract: Contract, alice: Address, ) { @@ -919,7 +922,7 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_invalid_receiver( + fn mint_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -939,7 +942,7 @@ mod tests { } #[motsu::test] - fn error_when_to_is_zero( + fn mint_consecutive_reverts_when_receiver_zero( contract: Contract, alice: Address, ) { @@ -956,7 +959,7 @@ mod tests { } #[motsu::test] - fn error_when_exceed_batch_size( + fn mint_consecutive_reverts_when_batch_size_exceeded( contract: Contract, alice: Address, ) { @@ -977,7 +980,7 @@ mod tests { } #[motsu::test] - fn transfers_from( + fn transfer_from_succeeds_with_consecutive_tokens( contract: Contract, alice: Address, bob: Address, @@ -1035,7 +1038,10 @@ mod tests { } #[motsu::test] - fn burns(contract: Contract, alice: Address) { + fn burn_succeeds_with_consecutive_and_standard_tokens( + contract: Contract, + alice: Address, + ) { // Mint batch of 1000 tokens to Alice. contract.sender(alice).init(vec![alice], vec![uint!(1000_U96)]); @@ -1111,7 +1117,7 @@ mod tests { } #[motsu::test] - fn safe_transfer_from( + fn safe_transfer_from_succeeds_moving_owned_token( contract: Contract, alice: Address, bob: Address, @@ -1135,7 +1141,7 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_approved_token( + fn safe_transfer_from_succeeds_moving_approved_token( contract: Contract, alice: Address, bob: Address, @@ -1160,7 +1166,7 @@ mod tests { } #[motsu::test] - fn error_when_safe_transfer_from_incorrect_owner( + fn safe_transfer_from_reverts_when_owner_incorrect( contract: Contract, alice: Address, bob: Address, @@ -1187,7 +1193,7 @@ mod tests { } #[motsu::test] - fn error_when_internal_safe_transfer_nonexistent_token( + fn safe_transfer_reverts_when_token_nonexistent( contract: Contract, alice: Address, bob: Address, @@ -1206,7 +1212,7 @@ mod tests { } #[motsu::test] - fn error_when_safe_transfer_to_invalid_receiver( + fn safe_transfer_from_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1239,7 +1245,7 @@ mod tests { } #[motsu::test] - fn safe_transfers_from_with_data( + fn safe_transfer_from_succeeds_with_additional_data( contract: Contract, alice: Address, bob: Address, @@ -1268,7 +1274,7 @@ mod tests { } #[motsu::test] - fn error_when_internal_safe_transfer_to_invalid_receiver( + fn safe_transfer_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1306,7 +1312,7 @@ mod tests { } #[motsu::test] - fn error_when_internal_safe_transfer_from_incorrect_owner( + fn safe_transfer_reverts_when_owner_incorrect( contract: Contract, alice: Address, bob: Address, @@ -1334,7 +1340,10 @@ mod tests { } #[motsu::test] - fn safe_mints(contract: Contract, alice: Address) { + fn safe_mint_succeeds_creating_owned_token( + contract: Contract, + alice: Address, + ) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1360,7 +1369,7 @@ mod tests { } #[motsu::test] - fn error_when_approve_for_nonexistent_token( + fn approve_reverts_when_token_nonexistent( contract: Contract, alice: Address, bob: Address, @@ -1379,7 +1388,7 @@ mod tests { } #[motsu::test] - fn error_when_approve_by_invalid_approver( + fn approve_reverts_when_approver_invalid( contract: Contract, alice: Address, bob: Address, @@ -1404,7 +1413,7 @@ mod tests { } #[motsu::test] - fn approval_for_all( + fn set_approval_for_all_succeeds_toggling_operator_status( contract: Contract, alice: Address, bob: Address, @@ -1421,7 +1430,7 @@ mod tests { } #[motsu::test] - fn error_when_get_approved_of_nonexistent_token( + fn get_approved_reverts_when_token_nonexistent( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index 59344acd1..128d7a47a 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -399,7 +399,7 @@ mod tests { unsafe impl TopLevelStorage for Erc721EnumerableTestExample {} #[motsu::test] - fn total_supply_no_tokens( + fn total_supply_returns_zero_when_empty( contract: Contract, alice: Address, ) { @@ -407,7 +407,7 @@ mod tests { } #[motsu::test] - fn reverts_when_token_by_index_is_out_of_bound( + fn token_by_index_reverts_when_index_out_of_bounds( contract: Contract, alice: Address, ) { @@ -428,7 +428,7 @@ mod tests { } #[motsu::test] - fn add_token_to_all_tokens_enumeration_works( + fn _add_token_to_all_tokens_enumeration_updates_supply_and_indices( contract: Contract, alice: Address, ) { @@ -473,7 +473,7 @@ mod tests { } #[motsu::test] - fn remove_token_from_all_tokens_enumeration_works( + fn _remove_token_from_all_tokens_enumeration_updates_remaining_indices( contract: Contract, alice: Address, ) { @@ -552,7 +552,7 @@ mod tests { } #[motsu::test] - fn check_increase_balance() { + fn _check_increase_balance_validates_amount_constraints() { assert!(Erc721Enumerable::_check_increase_balance(0).is_ok()); let err = Erc721Enumerable::_check_increase_balance(1) @@ -567,7 +567,7 @@ mod tests { } #[motsu::test] - fn token_of_owner_by_index_works( + fn token_of_owner_by_index_returns_correct_token( contract: Contract, alice: Address, ) { @@ -604,7 +604,7 @@ mod tests { } #[motsu::test] - fn reverts_when_token_of_owner_for_index_out_of_bound( + fn token_of_owner_by_index_reverts_when_index_out_of_bounds( contract: Contract, alice: Address, ) { @@ -648,7 +648,7 @@ mod tests { } #[motsu::test] - fn reverts_when_token_of_owner_does_not_own_any_token( + fn token_of_owner_by_index_reverts_when_no_tokens( contract: Contract, alice: Address, ) { @@ -667,7 +667,7 @@ mod tests { } #[motsu::test] - fn token_of_owner_by_index_after_transfer_works( + fn token_of_owner_by_index_returns_token_after_ownership_change( contract: Contract, alice: Address, bob: Address, diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index 5717b1508..c91f273c7 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -182,7 +182,7 @@ mod tests { assert!(!contract.sender(alice).supports_interface(fake_interface_id)); } #[motsu::test] - fn token_uri_works( + fn token_uri_returns_configured_metadata( contract: Contract, alice: Address, ) { diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index 64bdeecce..286de67c7 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -1073,7 +1073,7 @@ mod tests { const TOKEN_ID: U256 = uint!(1_U256); #[motsu::test] - fn error_when_checking_balance_of_invalid_owner( + fn balance_of_reverts_when_owner_is_zero( contract: Contract, alice: Address, ) { @@ -1089,7 +1089,10 @@ mod tests { } #[motsu::test] - fn balance_of_zero_balance(contract: Contract, owner: Address) { + fn balance_of_returns_zero_for_new_address( + contract: Contract, + owner: Address, + ) { let balance = contract .sender(owner) .balance_of(owner) @@ -1098,7 +1101,7 @@ mod tests { } #[motsu::test] - fn error_when_checking_owner_of_nonexistent_token( + fn owner_of_reverts_when_token_nonexistent( contract: Contract, alice: Address, ) { @@ -1116,7 +1119,10 @@ mod tests { } #[motsu::test] - fn mints(contract: Contract, alice: Address) { + fn _mint_succeeds_for_valid_recipient( + contract: Contract, + alice: Address, + ) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1141,7 +1147,7 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_id_twice( + fn _mint_reverts_when_token_already_exists( contract: Contract, alice: Address, ) { @@ -1161,7 +1167,7 @@ mod tests { } #[motsu::test] - fn error_when_minting_token_invalid_receiver( + fn _mint_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1181,7 +1187,10 @@ mod tests { } #[motsu::test] - fn safe_mints(contract: Contract, alice: Address) { + fn _safe_mint_creates_token_successfully( + contract: Contract, + alice: Address, + ) { let initial_balance = contract .sender(alice) .balance_of(alice) @@ -1207,7 +1216,7 @@ mod tests { } #[motsu::test] - fn error_when_safe_mint_token_id_twice( + fn _safe_mint_reverts_when_token_already_exists( contract: Contract, alice: Address, ) { @@ -1228,7 +1237,7 @@ mod tests { } #[motsu::test] - fn error_when_safe_mint_invalid_receiver( + fn _safe_mint_reverts_when_receiver_invalid( contract: Contract, alice: Address, ) { @@ -1248,7 +1257,7 @@ mod tests { } #[motsu::test] - fn transfers_from( + fn transfer_from_moves_token_successfully( contract: Contract, alice: Address, bob: Address, diff --git a/contracts/src/utils/cryptography/ecdsa.rs b/contracts/src/utils/cryptography/ecdsa.rs index e7ca4cacf..86e2e49c6 100644 --- a/contracts/src/utils/cryptography/ecdsa.rs +++ b/contracts/src/utils/cryptography/ecdsa.rs @@ -221,14 +221,14 @@ mod tests { ); #[test] - fn prepares_calldata() { + fn encode_calldata_creates_correct_abi_encoded_data() { let expected = alloy_primitives::bytes!("a1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2000000000000000000000000000000000000000000000000000000000000001c65e72b1cf8e189569963750e10ccb88fe89389daeeb8b735277d59cd6885ee823eb5a6982b540f185703492dab77b863a88ce01f27e21ade8b2879c10fc9e653"); let calldata = encode_calldata(MSG_HASH, V, R, S); assert_eq!(expected, calldata); } #[test] - fn rejects_invalid_s() { + fn check_if_malleable_returns_error_when_s_exceeds_upper_bound() { let invalid_s = SIGNATURE_S_UPPER_BOUND + uint!(1_U256); let invalid_s = B256::from_slice(&invalid_s.to_be_bytes_vec()); let err = check_if_malleable(&invalid_s) @@ -242,7 +242,7 @@ mod tests { } #[test] - fn validates_s() { + fn check_if_malleable_succeeds_with_s_below_upper_bound() { let valid_s = SIGNATURE_S_UPPER_BOUND - uint!(1_U256); let invalid_s = B256::from_slice(&valid_s.to_be_bytes_vec()); let result = check_if_malleable(&invalid_s); diff --git a/contracts/src/utils/cryptography/eip712.rs b/contracts/src/utils/cryptography/eip712.rs index 5b727828d..2c0a1cd93 100644 --- a/contracts/src/utils/cryptography/eip712.rs +++ b/contracts/src/utils/cryptography/eip712.rs @@ -163,7 +163,7 @@ mod tests { } #[test] - fn domain_test() { + fn eip712_domain_returns_correct_domain_fields() { let contract = TestEIP712::default(); let domain = contract.eip712_domain(); assert_eq!(FIELDS, domain.0); @@ -176,7 +176,7 @@ mod tests { } #[test] - fn test_to_typed_data_hash() { + fn to_typed_data_hash_creates_correct_eip712_hash() { // TYPE_HASH let domain_separator = b256!( "8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f" diff --git a/contracts/src/utils/math/alloy.rs b/contracts/src/utils/math/alloy.rs index e538253f3..d51c0e74e 100644 --- a/contracts/src/utils/math/alloy.rs +++ b/contracts/src/utils/math/alloy.rs @@ -206,7 +206,7 @@ mod tests { use crate::utils::math::alloy::{Math, Rounding}; #[test] - fn check_sqrt() { + fn sqrt_returns_correct_square_root() { proptest!(|(value: U256)| { // U256::root(..) method requires std. Can only be used in tests. assert_eq!(value.sqrt(), value.root(2)); @@ -214,7 +214,7 @@ mod tests { } #[test] - fn check_average() { + fn average_calculates_correct_midpoint() { proptest!(|(left: U256, right: U256)| { // compute average in straight forward way with overflow and downcast. let expected = (U512::from(left) + U512::from(right)) / uint!(2_U512); diff --git a/contracts/src/utils/nonces.rs b/contracts/src/utils/nonces.rs index d8a6f22c3..64cbfbb50 100644 --- a/contracts/src/utils/nonces.rs +++ b/contracts/src/utils/nonces.rs @@ -141,12 +141,18 @@ mod tests { unsafe impl TopLevelStorage for Nonces {} #[motsu::test] - fn initiate_nonce(contract: Contract, alice: Address) { + fn nonces_returns_zero_for_new_address( + contract: Contract, + alice: Address, + ) { assert_eq!(contract.sender(alice).nonces(alice), U256::ZERO); } #[motsu::test] - fn use_nonce(contract: Contract, alice: Address) { + fn use_nonce_increments_nonce_correctly( + contract: Contract, + alice: Address, + ) { let use_nonce = contract.sender(alice).use_nonce(alice); assert_eq!(use_nonce, U256::ZERO); @@ -155,7 +161,10 @@ mod tests { } #[motsu::test] - fn use_checked_nonce(contract: Contract, alice: Address) { + fn use_checked_nonce_succeeds_with_valid_nonce( + contract: Contract, + alice: Address, + ) { let use_checked_nonce = contract.sender(alice).use_checked_nonce(alice, U256::ZERO); assert!(use_checked_nonce.is_ok()); @@ -165,7 +174,7 @@ mod tests { } #[motsu::test] - fn use_checked_nonce_invalid_nonce( + fn use_checked_nonce_reverts_when_nonce_invalid( contract: Contract, alice: Address, ) { diff --git a/contracts/src/utils/pausable.rs b/contracts/src/utils/pausable.rs index c2ca40e1f..581f0af83 100644 --- a/contracts/src/utils/pausable.rs +++ b/contracts/src/utils/pausable.rs @@ -177,7 +177,10 @@ mod tests { unsafe impl TopLevelStorage for Pausable {} #[motsu::test] - fn paused_works(contract: Contract, alice: Address) { + fn paused_returns_correct_contract_state( + contract: Contract, + alice: Address, + ) { contract.sender(alice).paused.set(true); assert!(contract.sender(alice).paused()); @@ -186,15 +189,17 @@ mod tests { } #[motsu::test] - fn when_not_paused_works(contract: Contract, alice: Address) { + fn when_not_paused_succeeds_when_contract_not_paused( + contract: Contract, + alice: Address, + ) { contract.sender(alice).paused.set(false); - let result = contract.sender(alice).when_not_paused(); assert!(result.is_ok()); } #[motsu::test] - fn when_not_paused_errors_when_paused( + fn when_not_paused_reverts_when_contract_is_paused( contract: Contract, alice: Address, ) { @@ -206,7 +211,10 @@ mod tests { } #[motsu::test] - fn when_paused_works(contract: Contract, alice: Address) { + fn when_paused_succeeds_when_contract_is_paused( + contract: Contract, + alice: Address, + ) { contract.sender(alice).pause().unwrap(); assert!(contract.sender(alice).paused()); @@ -215,7 +223,7 @@ mod tests { } #[motsu::test] - fn when_paused_errors_when_not_paused( + fn when_paused_reverts_when_contract_not_paused( contract: Contract, alice: Address, ) { @@ -227,7 +235,10 @@ mod tests { } #[motsu::test] - fn pause_works(contract: Contract, alice: Address) { + fn pause_succeeds_when_contract_not_paused( + contract: Contract, + alice: Address, + ) { contract.sender(alice).paused.set(false); assert!(!contract.sender(alice).paused()); @@ -238,7 +249,7 @@ mod tests { } #[motsu::test] - fn pause_errors_when_already_paused( + fn pause_reverts_when_contract_already_paused( contract: Contract, alice: Address, ) { @@ -251,7 +262,10 @@ mod tests { } #[motsu::test] - fn unpause_works(contract: Contract, alice: Address) { + fn unpause_succeeds_when_contract_is_paused( + contract: Contract, + alice: Address, + ) { contract.sender(alice).paused.set(true); assert!(contract.sender(alice).paused()); @@ -262,7 +276,7 @@ mod tests { } #[motsu::test] - fn unpause_errors_when_already_unpaused( + fn unpause_reverts_when_contract_already_unpaused( contract: Contract, alice: Address, ) { diff --git a/contracts/src/utils/structs/bitmap.rs b/contracts/src/utils/structs/bitmap.rs index c5b909988..73e1ab226 100644 --- a/contracts/src/utils/structs/bitmap.rs +++ b/contracts/src/utils/structs/bitmap.rs @@ -112,7 +112,7 @@ mod tests { impl BitMap {} #[motsu::test] - fn set_value() { + fn set_sets_bit_correctly() { proptest!(|(value: U256, alice: Address)| { let bit_map = Contract::::new(); let mut bit_map = bit_map.sender(alice); @@ -123,7 +123,7 @@ mod tests { } #[motsu::test] - fn unset_value() { + fn unset_clears_bit_correctly() { proptest!(|(value: U256, alice: Address)| { let bit_map = Contract::::new(); let mut bit_map = bit_map.sender(alice); @@ -135,7 +135,7 @@ mod tests { } #[motsu::test] - fn set_to_value() { + fn set_to_changes_bit_state_correctly() { proptest!(|(value: U256, alice: Address)| { let bit_map = Contract::::new(); let mut bit_map = bit_map.sender(alice); diff --git a/contracts/src/utils/structs/checkpoints/mod.rs b/contracts/src/utils/structs/checkpoints/mod.rs index c1f9537f8..e4b74e89f 100644 --- a/contracts/src/utils/structs/checkpoints/mod.rs +++ b/contracts/src/utils/structs/checkpoints/mod.rs @@ -391,7 +391,10 @@ mod tests { use motsu::prelude::Contract; #[motsu::test] - fn push(checkpoint: Contract>, alice: Address) { + fn push_adds_sequential_checkpoints_correctly( + checkpoint: Contract>, + alice: Address, + ) { let first_key = uint!(1_U96); let first_value = uint!(11_U160); @@ -431,7 +434,10 @@ mod tests { } #[motsu::test] - fn push_same_value(checkpoint: Contract>, alice: Address) { + fn push_updates_checkpoint_with_same_key( + checkpoint: Contract>, + alice: Address, + ) { let first_key = uint!(1_U96); let first_value = uint!(11_U160); @@ -470,7 +476,10 @@ mod tests { ); } #[motsu::test] - fn lower_lookup(checkpoint: Contract>, alice: Address) { + fn lower_lookup_returns_correct_checkpoint_value( + checkpoint: Contract>, + alice: Address, + ) { checkpoint .sender(alice) .push(uint!(1_U96), uint!(11_U160)) @@ -503,7 +512,10 @@ mod tests { } #[motsu::test] - fn upper_lookup(checkpoint: Contract>, alice: Address) { + fn upper_lookup_returns_correct_checkpoint_value( + checkpoint: Contract>, + alice: Address, + ) { checkpoint .sender(alice) .push(uint!(1_U96), uint!(11_U160)) @@ -536,7 +548,10 @@ mod tests { } #[motsu::test] - fn upper_lookup_recent(checkpoint: Contract>, alice: Address) { + fn upper_lookup_recent_returns_correct_checkpoint_value( + checkpoint: Contract>, + alice: Address, + ) { // `upper_lookup_recent` has different optimizations for "short" (<=5) // and "long" (>5) checkpoint arrays. // @@ -601,7 +616,10 @@ mod tests { } #[motsu::test] - fn latest(checkpoint: Contract>, alice: Address) { + fn latest_returns_most_recent_checkpoint_value( + checkpoint: Contract>, + alice: Address, + ) { assert_eq!(checkpoint.sender(alice).latest(), uint!(0_U160)); checkpoint .sender(alice) @@ -619,7 +637,10 @@ mod tests { } #[motsu::test] - fn latest_checkpoint(checkpoint: Contract>, alice: Address) { + fn latest_checkpoint_returns_most_recent_checkpoint( + checkpoint: Contract>, + alice: Address, + ) { assert_eq!(checkpoint.sender(alice).latest_checkpoint(), None); checkpoint .sender(alice) @@ -640,7 +661,7 @@ mod tests { } #[motsu::test] - fn error_when_unordered_insertion( + fn push_reverts_when_inserting_checkpoint_with_lower_key( checkpoint: Contract>, alice: Address, ) { diff --git a/examples/access-control/tests/access_control.rs b/examples/access-control/tests/access_control.rs index 0be7978f5..32980aadc 100644 --- a/examples/access-control/tests/access_control.rs +++ b/examples/access-control/tests/access_control.rs @@ -29,7 +29,9 @@ fn ctr(admin: Address) -> Constructor { // ============================================================================ #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { +async fn constructor_succeeds_with_default_admin_role( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let receipt = alice .as_deployer() @@ -70,7 +72,7 @@ async fn constructs(alice: Account) -> Result<()> { } #[e2e::test] -async fn other_roles_admin_is_the_default_admin_role( +async fn get_role_admin_returns_default_admin_role( alice: Account, ) -> Result<()> { let contract_addr = alice @@ -89,7 +91,9 @@ async fn other_roles_admin_is_the_default_admin_role( } #[e2e::test] -async fn default_role_is_default_admin(alice: Account) -> Result<()> { +async fn get_role_admin_handles_both_regular_and_default_admin_roles( + alice: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr(alice.address())) @@ -110,7 +114,7 @@ async fn default_role_is_default_admin(alice: Account) -> Result<()> { } #[e2e::test] -async fn error_when_non_admin_grants_role( +async fn grant_role_reverts_when_caller_lacks_admin_permission( alice: Account, bob: Account, ) -> Result<()> { @@ -135,10 +139,7 @@ async fn error_when_non_admin_grants_role( } #[e2e::test] -async fn accounts_can_be_granted_roles_multiple_times( - alice: Account, - bob: Account, -) -> Result<()> { +async fn grant_role_is_idempotent(alice: Account, bob: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr(alice.address())) @@ -179,7 +180,9 @@ async fn accounts_can_be_granted_roles_multiple_times( } #[e2e::test] -async fn not_granted_roles_can_be_revoked(alice: Account) -> Result<()> { +async fn revoke_role_succeeds_when_role_not_previously_granted( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let contract_addr = alice .as_deployer() @@ -204,7 +207,7 @@ async fn not_granted_roles_can_be_revoked(alice: Account) -> Result<()> { } #[e2e::test] -async fn admin_can_revoke_role(alice: Account, bob: Account) -> Result<()> { +async fn revoke_role_is_idempotent(alice: Account, bob: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr(alice.address())) @@ -237,7 +240,7 @@ async fn admin_can_revoke_role(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn error_when_non_admin_revokes_role( +async fn revoke_role_reverts_when_caller_lacks_admin_permission( alice: Account, bob: Account, ) -> Result<()> { @@ -266,7 +269,7 @@ async fn error_when_non_admin_revokes_role( } #[e2e::test] -async fn roles_can_be_revoked_multiple_times( +async fn revoke_role_succeeds_with_multiple_identical_revokes( alice: Account, bob: Account, ) -> Result<()> { @@ -301,7 +304,9 @@ async fn roles_can_be_revoked_multiple_times( } #[e2e::test] -async fn not_granted_roles_can_be_renounced(alice: Account) -> Result<()> { +async fn renounce_role_succeeds_when_role_not_previously_granted( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let contract_addr = alice .as_deployer() @@ -322,7 +327,10 @@ async fn not_granted_roles_can_be_renounced(alice: Account) -> Result<()> { } #[e2e::test] -async fn bearer_can_renounce_role(alice: Account, bob: Account) -> Result<()> { +async fn renounce_role_is_idempotent( + alice: Account, + bob: Account, +) -> Result<()> { let bob_addr = bob.address(); let contract_addr = alice .as_deployer() @@ -353,7 +361,7 @@ async fn bearer_can_renounce_role(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn error_when_the_one_renouncing_is_not_the_sender( +async fn renounce_role_reverts_when_not_role_holder( alice: Account, bob: Account, ) -> Result<()> { @@ -379,7 +387,9 @@ async fn error_when_the_one_renouncing_is_not_the_sender( } #[e2e::test] -async fn roles_can_be_renounced_multiple_times(alice: Account) -> Result<()> { +async fn renounce_role_succeeds_with_multiple_identical_renounces( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let contract_addr = alice .as_deployer() @@ -401,7 +411,9 @@ async fn roles_can_be_renounced_multiple_times(alice: Account) -> Result<()> { } #[e2e::test] -async fn a_roles_admin_role_can_change(alice: Account) -> Result<()> { +async fn set_role_admin_succeeds_with_new_admin_role( + alice: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr(alice.address())) @@ -426,7 +438,7 @@ async fn a_roles_admin_role_can_change(alice: Account) -> Result<()> { } #[e2e::test] -async fn the_new_admin_can_grant_roles( +async fn role_admin_change_succeeds_with_new_admin_granting_role( alice: Account, bob: Account, ) -> Result<()> { @@ -475,7 +487,7 @@ async fn the_new_admin_can_grant_roles( } #[e2e::test] -async fn the_new_admin_can_revoke_roles( +async fn role_admin_change_succeeds_with_new_admin_revoking_role( alice: Account, bob: Account, ) -> Result<()> { @@ -521,7 +533,7 @@ async fn the_new_admin_can_revoke_roles( } #[e2e::test] -async fn error_when_previous_admin_grants_roles( +async fn role_admin_change_reverts_when_previous_admin_attempts_to_grant_role( alice: Account, bob: Account, ) -> Result<()> { @@ -555,7 +567,7 @@ async fn error_when_previous_admin_grants_roles( } #[e2e::test] -async fn error_when_previous_admin_revokes_roles( +async fn role_admin_change_reverts_when_previous_admin_attempts_to_revoke_role( alice: Account, bob: Account, ) -> Result<()> { diff --git a/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs b/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs index 1002e2602..7c025a4bc 100644 --- a/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs +++ b/examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs @@ -18,9 +18,7 @@ fn ctr(uri: &str) -> Constructor { // ============================================================================ #[e2e::test] -async fn uri_returns_metadata_uri_when_token_uri_is_not_set( - alice: Account, -) -> eyre::Result<()> { +async fn uri_returns_correct_metadata_uri(alice: Account) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr(URI)) @@ -39,7 +37,7 @@ async fn uri_returns_metadata_uri_when_token_uri_is_not_set( } #[e2e::test] -async fn uri_returns_empty_string_when_no_uri_is_set( +async fn uri_returns_empty_string_when_no_uri_set( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice @@ -61,7 +59,7 @@ async fn uri_returns_empty_string_when_no_uri_is_set( } #[e2e::test] -async fn uri_returns_concatenated_base_uri_and_token_uri( +async fn uri_returns_combined_base_and_token_uri( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice @@ -93,9 +91,7 @@ async fn uri_returns_concatenated_base_uri_and_token_uri( } #[e2e::test] -async fn uri_returns_token_uri_when_base_uri_is_empty( - alice: Account, -) -> eyre::Result<()> { +async fn uri_returns_specific_token_uri(alice: Account) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr("")) @@ -122,7 +118,7 @@ async fn uri_returns_token_uri_when_base_uri_is_empty( } #[e2e::test] -async fn uri_ignores_metadata_uri_when_token_uri_is_set( +async fn uri_returns_token_uri_overriding_metadata_uri( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice diff --git a/examples/erc1155-supply/tests/erc1155-supply.rs b/examples/erc1155-supply/tests/erc1155-supply.rs index 3440381e4..1c392fc78 100644 --- a/examples/erc1155-supply/tests/erc1155-supply.rs +++ b/examples/erc1155-supply/tests/erc1155-supply.rs @@ -21,7 +21,9 @@ fn random_values(size: usize) -> Vec { // ============================================================================ #[e2e::test] -async fn constructs(alice: Account) -> eyre::Result<()> { +async fn constructor_initializes_supply_to_zero( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -39,7 +41,9 @@ async fn constructs(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mint(alice: Account) -> eyre::Result<()> { +async fn mint_succeeds_and_updates_supply_correctly( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -73,7 +77,9 @@ async fn mint(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mint_to_receiver_contract(alice: Account) -> eyre::Result<()> { +async fn mint_succeeds_for_receiver_contract_with_correct_supply( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -122,7 +128,10 @@ async fn mint_to_receiver_contract(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mint_batch(alice: Account, bob: Account) -> eyre::Result<()> { +async fn mint_batch_succeeds_and_updates_supply_correctly( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -175,7 +184,7 @@ async fn mint_batch(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mint_batch_transfer_to_receiver_contract( +async fn mint_batch_succeeds_for_receiver_contract_with_correct_supply( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -245,7 +254,7 @@ async fn mint_batch_transfer_to_receiver_contract( } #[e2e::test] -async fn mint_panics_on_total_supply_overflow( +async fn mint_reverts_when_total_supply_overflows( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -275,7 +284,7 @@ async fn mint_panics_on_total_supply_overflow( } #[e2e::test] -async fn mint_panics_on_total_supply_all_overflow( +async fn mint_reverts_when_cumulative_total_supply_would_exceed_maximum( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -300,7 +309,9 @@ async fn mint_panics_on_total_supply_all_overflow( } #[e2e::test] -async fn burn(alice: Account) -> eyre::Result<()> { +async fn burn_succeeds_and_updates_supply_correctly( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -335,7 +346,10 @@ async fn burn(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn burn_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { +async fn burn_succeeds_with_approval_and_updates_supply_correctly( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); let contract_bob = Erc1155Supply::new(contract_addr, &bob.wallet); @@ -373,7 +387,9 @@ async fn burn_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn burn_batch(alice: Account) -> eyre::Result<()> { +async fn burn_batch_succeeds_and_updates_supply_correctly( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -420,7 +436,7 @@ async fn burn_batch(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn burn_batch_with_approval( +async fn burn_batch_succeeds_with_approval_and_updates_supply_correctly( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -474,7 +490,7 @@ async fn burn_batch_with_approval( } #[e2e::test] -async fn supply_unaffected_by_safe_transfer_from( +async fn total_supply_remains_unchanged_after_single_transfer( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -540,7 +556,7 @@ async fn supply_unaffected_by_safe_transfer_from( } #[e2e::test] -async fn supply_unaffected_by_safe_transfer_from_batch( +async fn total_supply_remains_unchanged_after_batch_transfer( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -627,7 +643,9 @@ async fn supply_unaffected_by_safe_transfer_from_batch( // ===================================================================== #[e2e::test] -async fn balance_of_zero_balance(alice: Account) -> eyre::Result<()> { +async fn balance_of_returns_zero_for_unowned_token( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); let token_ids = random_token_ids(1); @@ -640,7 +658,7 @@ async fn balance_of_zero_balance(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn balance_of_batch_zero_balance( +async fn balance_of_batch_returns_zeros_for_unowned_tokens( alice: Account, bob: Account, dave: Account, @@ -660,7 +678,7 @@ async fn balance_of_batch_zero_balance( } #[e2e::test] -async fn set_approval_for_all( +async fn set_approval_for_all_updates_approval_status_correctly( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -702,7 +720,9 @@ async fn set_approval_for_all( } #[e2e::test] -async fn is_approved_for_all_zero_address(alice: Account) -> eyre::Result<()> { +async fn is_approved_for_all_returns_false_for_zero_address( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -719,7 +739,10 @@ async fn is_approved_for_all_zero_address(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { +async fn safe_transfer_succeed_with_valid_transfer( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155Supply::new(contract_addr, &alice.wallet); @@ -767,7 +790,7 @@ async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn safe_transfer_from_with_approval( +async fn safe_transfer_from_succeeds_with_operator_approval( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -822,7 +845,7 @@ async fn safe_transfer_from_with_approval( } #[e2e::test] -async fn safe_transfer_to_receiver_contract( +async fn safe_transfer_from_succeeds_with_receiver_contract( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -884,7 +907,7 @@ async fn safe_transfer_to_receiver_contract( } #[e2e::test] -async fn safe_batch_transfer_from( +async fn safe_batch_transfer_from_succeeds_with_valid_transfer( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -953,7 +976,7 @@ async fn safe_batch_transfer_from( } #[e2e::test] -async fn safe_batch_transfer_to_receiver_contract( +async fn safe_batch_transfer_from_succeeds_with_receiver_contract( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1039,7 +1062,7 @@ async fn safe_batch_transfer_to_receiver_contract( } #[e2e::test] -async fn safe_batch_transfer_from_with_approval( +async fn safe_batch_transfer_from_succeeds_with_operator_approval( alice: Account, bob: Account, dave: Account, diff --git a/examples/erc1155/tests/erc1155.rs b/examples/erc1155/tests/erc1155.rs index 18a54db1f..8ad04ac9d 100644 --- a/examples/erc1155/tests/erc1155.rs +++ b/examples/erc1155/tests/erc1155.rs @@ -35,7 +35,7 @@ impl EncodeAsStr for T { // ============================================================================ #[e2e::test] -async fn invalid_array_length_error_in_balance_of_batch( +async fn balance_of_batch_reverts_when_ids_and_accounts_length_mismatch( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -60,7 +60,9 @@ async fn invalid_array_length_error_in_balance_of_batch( } #[e2e::test] -async fn balance_of_zero_balance(alice: Account) -> eyre::Result<()> { +async fn balance_of_returns_zero_for_unowned_token( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); let token_ids = random_token_ids(1); @@ -73,7 +75,7 @@ async fn balance_of_zero_balance(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn balance_of_batch_zero_balance( +async fn balance_of_batch_returns_zeros_for_unowned_tokens( alice: Account, bob: Account, dave: Account, @@ -93,7 +95,7 @@ async fn balance_of_batch_zero_balance( } #[e2e::test] -async fn mints(alice: Account) -> eyre::Result<()> { +async fn mint_succeeds_and_updates_balance(alice: Account) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -124,7 +126,9 @@ async fn mints(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mints_to_receiver_contract(alice: Account) -> eyre::Result<()> { +async fn mint_succeeds_with_receiver_contract( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -166,7 +170,7 @@ async fn mints_to_receiver_contract(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn errors_when_receiver_reverts_with_reason_in_mint( +async fn mint_reverts_when_receiver_reverts_with_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -200,7 +204,7 @@ async fn errors_when_receiver_reverts_with_reason_in_mint( } #[e2e::test] -async fn errors_when_receiver_reverts_without_reason_in_mint( +async fn mint_reverts_when_receiver_reverts_without_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -231,9 +235,7 @@ async fn errors_when_receiver_reverts_without_reason_in_mint( } #[e2e::test] -async fn errors_when_receiver_panics_in_mint( - alice: Account, -) -> eyre::Result<()> { +async fn mint_reverts_when_receiver_panics(alice: Account) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -262,7 +264,7 @@ async fn errors_when_receiver_panics_in_mint( } #[e2e::test] -async fn errors_when_invalid_receiver_contract_in_mint( +async fn mint_reverts_when_receiver_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -287,7 +289,9 @@ async fn errors_when_invalid_receiver_contract_in_mint( } #[e2e::test] -async fn mint_batch(alice: Account) -> eyre::Result<()> { +async fn mint_batch_succeeds_and_updates_balances( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -329,7 +333,7 @@ async fn mint_batch(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mint_batch_transfer_to_receiver_contract( +async fn mint_batch_succeeds_with_receiver_contract( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -395,7 +399,7 @@ async fn mint_batch_transfer_to_receiver_contract( } #[e2e::test] -async fn errors_when_receiver_reverts_with_reason_in_batch_mint( +async fn mint_batch_reverts_when_receiver_reverts_with_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -429,7 +433,7 @@ async fn errors_when_receiver_reverts_with_reason_in_batch_mint( } #[e2e::test] -async fn errors_when_receiver_reverts_without_reason_in_batch_mint( +async fn mint_batch_reverts_when_receiver_reverts_without_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -460,7 +464,7 @@ async fn errors_when_receiver_reverts_without_reason_in_batch_mint( } #[e2e::test] -async fn errors_when_receiver_panics_in_batch_mint( +async fn mint_batch_reverts_when_receiver_panics( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -516,7 +520,7 @@ async fn errors_when_invalid_receiver_contract_in_batch_mint( } #[e2e::test] -async fn error_invalid_array_length_in_batch_mint( +async fn mint_batch_reverts_when_array_length_invalid( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -544,7 +548,7 @@ async fn error_invalid_array_length_in_batch_mint( } #[e2e::test] -async fn set_approval_for_all( +async fn set_approval_for_all_updates_approval_status( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -586,7 +590,7 @@ async fn set_approval_for_all( } #[e2e::test] -async fn error_when_invalid_operator_approval_for_all( +async fn set_approval_for_all_reverts_when_operator_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -605,7 +609,9 @@ async fn error_when_invalid_operator_approval_for_all( } #[e2e::test] -async fn is_approved_for_all_zero_address(alice: Account) -> eyre::Result<()> { +async fn is_approved_for_all_returns_false_for_zero_address( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -622,7 +628,10 @@ async fn is_approved_for_all_zero_address(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { +async fn safe_transfer_from_succeeds_with_valid_transfer( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -670,7 +679,7 @@ async fn safe_transfer_from(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn safe_transfer_from_with_approval( +async fn safe_transfer_from_succeeds_with_operator_approval( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -725,7 +734,7 @@ async fn safe_transfer_from_with_approval( } #[e2e::test] -async fn safe_transfer_to_receiver_contract( +async fn safe_transfer_from_succeeds_with_receiver_contract( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -787,7 +796,7 @@ async fn safe_transfer_to_receiver_contract( } #[e2e::test] -async fn errors_when_receiver_reverts_with_reason( +async fn safe_transfer_from_reverts_when_receiver_reverts_with_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -830,7 +839,7 @@ async fn errors_when_receiver_reverts_with_reason( } #[e2e::test] -async fn errors_when_receiver_reverts_without_reason( +async fn safe_transfer_from_reverts_when_receiver_reverts_without_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -870,7 +879,9 @@ async fn errors_when_receiver_reverts_without_reason( } #[e2e::test] -async fn errors_when_receiver_panics(alice: Account) -> eyre::Result<()> { +async fn safe_transfer_from_reverts_when_receiver_panics( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -908,7 +919,7 @@ async fn errors_when_receiver_panics(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn errors_when_invalid_receiver_contract( +async fn safe_transfer_from_reverts_when_receiver_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -942,7 +953,7 @@ async fn errors_when_invalid_receiver_contract( } #[e2e::test] -async fn error_when_invalid_receiver_safe_transfer_from( +async fn safe_transfer_from_reverts_when_missing_approval( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -971,7 +982,7 @@ async fn error_when_invalid_receiver_safe_transfer_from( } #[e2e::test] -async fn error_when_missing_approval_safe_transfer_from( +async fn safe_transfer_from_reverts_when_approval_missing( alice: Account, bob: Account, dave: Account, @@ -1004,7 +1015,7 @@ async fn error_when_missing_approval_safe_transfer_from( } #[e2e::test] -async fn error_when_insufficient_balance_safe_transfer_from( +async fn safe_transfer_from_reverts_when_balance_insufficient( alice: Account, bob: Account, dave: Account, @@ -1042,7 +1053,7 @@ async fn error_when_insufficient_balance_safe_transfer_from( } #[e2e::test] -async fn safe_batch_transfer_from( +async fn safe_batch_transfer_from_succeeds_with_valid_transfer( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -1110,7 +1121,7 @@ async fn safe_batch_transfer_from( } #[e2e::test] -async fn safe_batch_transfer_to_receiver_contract( +async fn safe_batch_transfer_from_succeeds_with_receiver_contract( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1196,7 +1207,7 @@ async fn safe_batch_transfer_to_receiver_contract( } #[e2e::test] -async fn errors_when_receiver_reverts_with_reason_in_batch_transfer( +async fn safe_batch_transfer_from_reverts_when_receiver_reverts_with_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1239,7 +1250,7 @@ async fn errors_when_receiver_reverts_with_reason_in_batch_transfer( } #[e2e::test] -async fn errors_when_receiver_reverts_without_reason_in_batch_transfer( +async fn safe_batch_transfer_from_reverts_when_receiver_reverts_without_reason( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1279,7 +1290,7 @@ async fn errors_when_receiver_reverts_without_reason_in_batch_transfer( } #[e2e::test] -async fn errors_when_receiver_panics_in_batch_transfer( +async fn safe_batch_transfer_from_reverts_when_receiver_panics( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1319,7 +1330,7 @@ async fn errors_when_receiver_panics_in_batch_transfer( } #[e2e::test] -async fn errors_when_invalid_receiver_contract_in_batch_transfer( +async fn safe_batch_transfer_from_reverts_when_receiver_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1353,7 +1364,7 @@ async fn errors_when_invalid_receiver_contract_in_batch_transfer( } #[e2e::test] -async fn safe_batch_transfer_from_with_approval( +async fn safe_batch_transfer_from_succeeds_with_operator_approval( alice: Account, bob: Account, dave: Account, @@ -1426,7 +1437,7 @@ async fn safe_batch_transfer_from_with_approval( } #[e2e::test] -async fn error_when_invalid_receiver_safe_batch_transfer_from( +async fn safe_batch_transfer_from_reverts_when_receiver_is_zero_address( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1461,7 +1472,7 @@ async fn error_when_invalid_receiver_safe_batch_transfer_from( } #[e2e::test] -async fn error_invalid_array_length_in_safe_batch_transfer_from( +async fn safe_batch_transfer_from_reverts_when_array_length_invalid( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -1498,7 +1509,7 @@ async fn error_invalid_array_length_in_safe_batch_transfer_from( } #[e2e::test] -async fn error_when_missing_approval_safe_batch_transfer_from( +async fn safe_batch_transfer_from_reverts_when_approval_missing( alice: Account, bob: Account, dave: Account, @@ -1537,7 +1548,7 @@ async fn error_when_missing_approval_safe_batch_transfer_from( } #[e2e::test] -async fn error_when_insufficient_balance_safe_batch_transfer_from( +async fn safe_batch_transfer_from_reverts_when_balance_insufficient( alice: Account, bob: Account, dave: Account, @@ -1584,7 +1595,7 @@ async fn error_when_insufficient_balance_safe_batch_transfer_from( // ============================================================================ #[e2e::test] -async fn burns(alice: Account) -> eyre::Result<()> { +async fn burn_succeeds_and_updates_balance(alice: Account) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -1616,7 +1627,10 @@ async fn burns(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn burns_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { +async fn burn_succeeds_with_operator_approval( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); let contract_bob = Erc1155::new(contract_addr, &bob.wallet); @@ -1652,7 +1666,7 @@ async fn burns_with_approval(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_missing_approval_burn( +async fn burn_reverts_when_approval_missing( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -1678,7 +1692,7 @@ async fn error_when_missing_approval_burn( } #[e2e::test] -async fn error_when_insufficient_balance_burn( +async fn burn_reverts_when_balance_insufficient( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -1705,7 +1719,9 @@ async fn error_when_insufficient_balance_burn( } #[e2e::test] -async fn burns_batch(alice: Account) -> eyre::Result<()> { +async fn burn_batch_succeeds_and_updates_balances( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc1155::new(contract_addr, &alice.wallet); @@ -1748,7 +1764,7 @@ async fn burns_batch(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn burns_batch_with_approval( +async fn burn_batch_succeeds_with_operator_approval( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -1798,7 +1814,7 @@ async fn burns_batch_with_approval( } #[e2e::test] -async fn error_when_missing_approval_burn_batch( +async fn burn_batch_reverts_when_approval_missing( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -1829,7 +1845,7 @@ async fn error_when_missing_approval_burn_batch( } #[e2e::test] -async fn error_when_insufficient_balance_burn_batch( +async fn burn_batch_reverts_when_balance_insufficient( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; diff --git a/examples/erc20-flash-mint/tests/erc20_flash_mint.rs b/examples/erc20-flash-mint/tests/erc20_flash_mint.rs index ab8fdc280..7a033982f 100644 --- a/examples/erc20-flash-mint/tests/erc20_flash_mint.rs +++ b/examples/erc20-flash-mint/tests/erc20_flash_mint.rs @@ -15,7 +15,9 @@ const FEE_RECEIVER: Address = const FLASH_FEE_VALUE: U256 = uint!(100_U256); #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { +async fn constructor_initializes_contract_with_default_settings( + alice: Account, +) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc20FlashMint::new(contract_addr, &alice.wallet); watch!(contract.setFlashFeeReceiver(FEE_RECEIVER))?; @@ -31,7 +33,9 @@ async fn constructs(alice: Account) -> Result<()> { } #[e2e::test] -async fn max_flash_loan(alice: Account) -> Result<()> { +async fn max_flash_loan_returns_correct_max_loan_amount( + alice: Account, +) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc20FlashMint::new(contract_addr, &alice.wallet); watch!(contract.setFlashFeeReceiver(FEE_RECEIVER))?; @@ -48,7 +52,7 @@ async fn max_flash_loan(alice: Account) -> Result<()> { } #[e2e::test] -async fn max_flash_loan_return_zero_if_no_more_tokens_to_mint( +async fn max_flash_loan_returns_zero_when_total_supply_exceeds_maximum( alice: Account, ) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -66,7 +70,7 @@ async fn max_flash_loan_return_zero_if_no_more_tokens_to_mint( } #[e2e::test] -async fn max_flash_loan_returns_zero_on_invalid_address( +async fn max_flash_loan_returns_zero_for_non_token_addresses( alice: Account, ) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -93,7 +97,7 @@ async fn max_flash_loan_returns_zero_on_invalid_address( // implementations may have different behavior (e.g. return fee as a percentage // of the passed amount). #[e2e::test] -async fn flash_fee_returns_same_value_regardless_of_amount( +async fn flash_fee_success_with_different_amounts( alice: Account, ) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -111,7 +115,9 @@ async fn flash_fee_returns_same_value_regardless_of_amount( } #[e2e::test] -async fn flash_fee_reverts_on_unsupported_token(alice: Account) -> Result<()> { +async fn flash_fee_reverts_when_token_is_not_supported( + alice: Account, +) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc20FlashMint::new(contract_addr, &alice.wallet); watch!(contract.setFlashFeeReceiver(FEE_RECEIVER))?; @@ -143,7 +149,9 @@ async fn flash_fee_reverts_on_unsupported_token(alice: Account) -> Result<()> { } #[e2e::test] -async fn flash_loan_with_fee(alice: Account) -> Result<()> { +async fn flash_loan_succeeds_with_standard_fee_mechanism( + alice: Account, +) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); _ = watch!(erc20.setFlashFeeReceiver(Address::ZERO))?; @@ -196,7 +204,9 @@ async fn flash_loan_with_fee(alice: Account) -> Result<()> { } #[e2e::test] -async fn flash_loan_with_fee_receiver(alice: Account) -> Result<()> { +async fn flash_loan_succeeds_with_zero_fee_and_fee_receiver( + alice: Account, +) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); _ = watch!(erc20.setFlashFeeReceiver(FEE_RECEIVER))?; @@ -254,7 +264,9 @@ async fn flash_loan_with_fee_receiver(alice: Account) -> Result<()> { } #[e2e::test] -async fn flash_loan_with_fee_and_fee_receiver(alice: Account) -> Result<()> { +async fn flash_loan_succeeds_with_fee_and_dedicated_fee_receiver( + alice: Account, +) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; let erc20 = Erc20FlashMint::new(erc20_addr, &alice.wallet); _ = watch!(erc20.setFlashFeeReceiver(FEE_RECEIVER))?; @@ -318,7 +330,7 @@ async fn flash_loan_with_fee_and_fee_receiver(alice: Account) -> Result<()> { } #[e2e::test] -async fn flash_loan_reverts_when_loan_amount_greater_than_max_loan( +async fn flash_loan_reverts_when_loan_amount_exceeds_maximum_allowed( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -348,7 +360,7 @@ async fn flash_loan_reverts_when_loan_amount_greater_than_max_loan( } #[e2e::test] -async fn flash_loan_reverts_with_exceeded_max_with_unsupported_token( +async fn flash_loan_reverts_when_unsupported_token_with_non_zero_amount( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -376,7 +388,7 @@ async fn flash_loan_reverts_with_exceeded_max_with_unsupported_token( } #[e2e::test] -async fn flash_loan_reverts_with_unsupported_token_with_zero_loan_amount_and_unsupported_token( +async fn flash_loan_reverts_when_unsupported_token_with_zero_amount( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -404,7 +416,7 @@ async fn flash_loan_reverts_with_unsupported_token_with_zero_loan_amount_and_uns } #[e2e::test] -async fn flash_loan_reverts_when_invalid_receiver( +async fn flash_loan_reverts_when_receiver_invalid( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -436,7 +448,7 @@ async fn flash_loan_reverts_when_invalid_receiver( } #[e2e::test] -async fn flash_loan_reverts_when_receiver_callback_reverts( +async fn flash_loan_reverts_when_callback_reverts( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -464,7 +476,7 @@ async fn flash_loan_reverts_when_receiver_callback_reverts( } #[e2e::test] -async fn flash_loan_reverts_when_receiver_returns_invalid_callback_value( +async fn flash_loan_reverts_when_callback_value_invalid( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -492,7 +504,7 @@ async fn flash_loan_reverts_when_receiver_returns_invalid_callback_value( } #[e2e::test] -async fn flash_loan_reverts_when_receiver_doesnt_approve_allowance( +async fn flash_loan_reverts_when_allowance_not_approved( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -547,7 +559,7 @@ async fn flash_loan_reverts_when_allowance_overflows( } #[e2e::test] -async fn flash_loan_reverts_when_receiver_doesnt_have_enough_tokens( +async fn flash_loan_reverts_when_balance_insufficient( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -597,7 +609,7 @@ async fn flash_loan_reverts_when_receiver_doesnt_have_enough_tokens( } #[e2e::test] -async fn flash_loan_reverts_when_receiver_doesnt_have_enough_tokens_and_fee_is_zero( +async fn flash_loan_reverts_when_balance_insufficient_with_zero_fee( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; @@ -631,7 +643,7 @@ async fn flash_loan_reverts_when_receiver_doesnt_have_enough_tokens_and_fee_is_z } #[e2e::test] -async fn flash_loan_reverts_when_receiver_doesnt_have_enough_tokens_and_fee_receiver_is_zero( +async fn flash_loan_reverts_when_balance_insufficient_with_zero_receiver( alice: Account, ) -> Result<()> { let erc20_addr = alice.as_deployer().deploy().await?.contract_address; diff --git a/examples/erc20-permit/tests/erc20_permit.rs b/examples/erc20-permit/tests/erc20_permit.rs index 3027d95fb..172216b91 100644 --- a/examples/erc20-permit/tests/erc20_permit.rs +++ b/examples/erc20-permit/tests/erc20_permit.rs @@ -77,7 +77,7 @@ fn to_non_eip155_v(v: bool) -> u8 { // ============================================================================ #[e2e::test] -async fn error_when_expired_deadline_for_permit( +async fn permit_reverts_when_deadline_expired( alice: Account, bob: Account, ) -> Result<()> { @@ -123,7 +123,10 @@ async fn error_when_expired_deadline_for_permit( } #[e2e::test] -async fn permit_works(alice: Account, bob: Account) -> Result<()> { +async fn permit_allows_token_transfer_with_valid_signature( + alice: Account, + bob: Account, +) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract_alice = Erc20Permit::new(contract_addr, &alice.wallet); let alice_addr = alice.address(); @@ -211,7 +214,7 @@ async fn permit_works(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn permit_rejects_reused_signature( +async fn permit_reverts_when_signature_reused( alice: Account, bob: Account, ) -> Result<()> { @@ -286,7 +289,7 @@ async fn permit_rejects_reused_signature( } #[e2e::test] -async fn permit_rejects_invalid_signature( +async fn permit_reverts_when_signature_invalid( alice: Account, bob: Account, ) -> Result<()> { diff --git a/examples/erc20/tests/erc20.rs b/examples/erc20/tests/erc20.rs index 4acb3ce21..026758865 100644 --- a/examples/erc20/tests/erc20.rs +++ b/examples/erc20/tests/erc20.rs @@ -27,7 +27,9 @@ fn default_ctr() -> Constructor { // ============================================================================ #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { +async fn constructor_initializes_token_with_default_settings( + alice: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -54,7 +56,7 @@ async fn constructs(alice: Account) -> Result<()> { } #[e2e::test] -async fn mints(alice: Account) -> Result<()> { +async fn mint_adds_tokens_to_account_balance(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -91,7 +93,7 @@ async fn mints(alice: Account) -> Result<()> { } #[e2e::test] -async fn mints_rejects_invalid_receiver(alice: Account) -> Result<()> { +async fn mint_reverts_when_receiver_invalid(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -124,7 +126,7 @@ async fn mints_rejects_invalid_receiver(alice: Account) -> Result<()> { } #[e2e::test] -async fn mints_rejects_overflow(alice: Account) -> Result<()> { +async fn mint_reverts_when_supply_overflows(alice: Account) -> Result<()> { let max_cap = U256::MAX; let contract_addr = alice @@ -164,7 +166,10 @@ async fn mints_rejects_overflow(alice: Account) -> Result<()> { } #[e2e::test] -async fn transfers(alice: Account, bob: Account) -> Result<()> { +async fn transfer_moves_tokens_between_accounts( + alice: Account, + bob: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -210,7 +215,7 @@ async fn transfers(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn transfer_rejects_insufficient_balance( +async fn transfer_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> Result<()> { @@ -259,7 +264,7 @@ async fn transfer_rejects_insufficient_balance( } #[e2e::test] -async fn transfer_rejects_invalid_receiver(alice: Account) -> Result<()> { +async fn transfer_reverts_when_receiver_invalid(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -303,7 +308,10 @@ async fn transfer_rejects_invalid_receiver(alice: Account) -> Result<()> { } #[e2e::test] -async fn approves(alice: Account, bob: Account) -> Result<()> { +async fn approve_sets_token_allowance_for_spender( + alice: Account, + bob: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -375,7 +383,7 @@ async fn approves(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn approve_rejects_invalid_spender(alice: Account) -> Result<()> { +async fn approve_reverts_when_spender_invalid(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -430,7 +438,10 @@ async fn approve_rejects_invalid_spender(alice: Account) -> Result<()> { } #[e2e::test] -async fn transfers_from(alice: Account, bob: Account) -> Result<()> { +async fn transfer_from_moves_tokens_with_approved_allowance( + alice: Account, + bob: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -487,7 +498,7 @@ async fn transfers_from(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn transfer_from_reverts_insufficient_balance( +async fn transfer_from_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> Result<()> { @@ -547,7 +558,7 @@ async fn transfer_from_reverts_insufficient_balance( } #[e2e::test] -async fn transfer_from_rejects_insufficient_allowance( +async fn transfer_from_reverts_when_allowance_insufficient( alice: Account, bob: Account, ) -> Result<()> { @@ -607,7 +618,7 @@ async fn transfer_from_rejects_insufficient_allowance( } #[e2e::test] -async fn transfer_from_rejects_invalid_receiver( +async fn transfer_from_reverts_when_receiver_invalid( alice: Account, bob: Account, ) -> Result<()> { @@ -671,7 +682,9 @@ async fn transfer_from_rejects_invalid_receiver( // ============================================================================ #[e2e::test] -async fn burns(alice: Account) -> Result<()> { +async fn burn_removes_tokens_from_account_balance( + alice: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -711,7 +724,7 @@ async fn burns(alice: Account) -> Result<()> { } #[e2e::test] -async fn burn_rejects_insufficient_balance(alice: Account) -> Result<()> { +async fn burn_reverts_when_balance_insufficient(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -751,7 +764,10 @@ async fn burn_rejects_insufficient_balance(alice: Account) -> Result<()> { } #[e2e::test] -async fn burns_from(alice: Account, bob: Account) -> Result<()> { +async fn burn_from_removes_tokens_with_approved_allowance( + alice: Account, + bob: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -807,7 +823,7 @@ async fn burns_from(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn burn_from_reverts_insufficient_balance( +async fn burn_from_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> Result<()> { @@ -867,7 +883,7 @@ async fn burn_from_reverts_insufficient_balance( } #[e2e::test] -async fn burn_from_rejects_insufficient_allowance( +async fn burn_from_reverts_when_allowance_insufficient( alice: Account, bob: Account, ) -> Result<()> { @@ -931,7 +947,7 @@ async fn burn_from_rejects_insufficient_allowance( // ============================================================================ #[e2e::test] -async fn mint_rejects_exceeding_cap(alice: Account) -> Result<()> { +async fn mint_reverts_when_cap_exceeded(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -972,7 +988,7 @@ async fn mint_rejects_exceeding_cap(alice: Account) -> Result<()> { } #[e2e::test] -async fn mint_rejects_when_cap_reached(alice: Account) -> Result<()> { +async fn mint_reverts_when_cap_reached(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1012,9 +1028,7 @@ async fn mint_rejects_when_cap_reached(alice: Account) -> Result<()> { } #[e2e::test] -async fn should_not_deploy_capped_with_invalid_cap( - alice: Account, -) -> Result<()> { +async fn constructor_reverts_when_cap_invalid(alice: Account) -> Result<()> { let invalid_cap = U256::ZERO; let err = alice .as_deployer() @@ -1038,7 +1052,9 @@ async fn should_not_deploy_capped_with_invalid_cap( // ============================================================================ #[e2e::test] -async fn pauses(alice: Account) -> eyre::Result<()> { +async fn pause_changes_contract_state_to_paused( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1059,7 +1075,7 @@ async fn pauses(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { +async fn pause_reverts_when_already_paused(alice: Account) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1080,7 +1096,9 @@ async fn pause_reverts_in_paused_state(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn unpauses(alice: Account) -> eyre::Result<()> { +async fn unpause_changes_contract_state_to_unpaused( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1103,7 +1121,9 @@ async fn unpauses(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn unpause_reverts_in_unpaused_state(alice: Account) -> eyre::Result<()> { +async fn unpause_reverts_when_already_unpaused( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1126,7 +1146,7 @@ async fn unpause_reverts_in_unpaused_state(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_burn_in_paused_state(alice: Account) -> Result<()> { +async fn burn_reverts_when_paused(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1164,7 +1184,7 @@ async fn error_when_burn_in_paused_state(alice: Account) -> Result<()> { } #[e2e::test] -async fn error_when_burn_from_in_paused_state( +async fn burn_from_reverts_when_paused( alice: Account, bob: Account, ) -> Result<()> { @@ -1221,7 +1241,7 @@ async fn error_when_burn_from_in_paused_state( } #[e2e::test] -async fn error_when_mint_in_paused_state(alice: Account) -> Result<()> { +async fn mint_reverts_when_paused(alice: Account) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) @@ -1256,7 +1276,7 @@ async fn error_when_mint_in_paused_state(alice: Account) -> Result<()> { } #[e2e::test] -async fn error_when_transfer_in_paused_state( +async fn transfer_reverts_when_paused( alice: Account, bob: Account, ) -> Result<()> { @@ -1302,7 +1322,10 @@ async fn error_when_transfer_in_paused_state( } #[e2e::test] -async fn error_when_transfer_from(alice: Account, bob: Account) -> Result<()> { +async fn transfer_from_reverts_when_paused( + alice: Account, + bob: Account, +) -> Result<()> { let contract_addr = alice .as_deployer() .with_constructor(default_ctr()) diff --git a/examples/erc721-consecutive/tests/erc721_consecutive.rs b/examples/erc721-consecutive/tests/erc721_consecutive.rs index 65f42c53f..2239e6e69 100644 --- a/examples/erc721-consecutive/tests/erc721_consecutive.rs +++ b/examples/erc721-consecutive/tests/erc721_consecutive.rs @@ -37,7 +37,9 @@ fn ctr(receivers: Vec
, amounts: Vec) -> Constructor { } #[e2e::test] -async fn constructs(alice: Account) -> eyre::Result<()> { +async fn constructor_mints_tokens_to_specified_receivers( + alice: Account, +) -> eyre::Result<()> { let alice_addr = alice.address(); let receivers = vec![alice_addr]; let amounts = vec![uint!(10_U96)]; @@ -54,7 +56,9 @@ async fn constructs(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn mints(alice: Account) -> eyre::Result<()> { +async fn mint_succeeds_with_consecutive_and_non_consecutive_tokens( + alice: Account, +) -> eyre::Result<()> { let batch_size = uint!(10_U96); let receivers = vec![alice.address()]; let amounts = vec![batch_size]; @@ -87,7 +91,9 @@ async fn mints(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_to_is_zero(alice: Account) -> eyre::Result<()> { +async fn mint_consecutive_reverts_when_receiver_zero( + alice: Account, +) -> eyre::Result<()> { let receivers = vec![Address::ZERO]; let amounts = vec![uint!(10_U96)]; let err = alice @@ -110,7 +116,9 @@ async fn error_when_to_is_zero(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_exceed_batch_size(alice: Account) -> eyre::Result<()> { +async fn mint_consecutive_reverts_when_batch_size_exceeded( + alice: Account, +) -> eyre::Result<()> { let receivers = vec![alice.address()]; let amounts = vec![MAX_BATCH_SIZE + uint!(1_U96)]; let err = alice @@ -134,7 +142,10 @@ async fn error_when_exceed_batch_size(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { +async fn transfer_from_succeeds_with_consecutive_and_non_consecutive_tokens( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let receivers = vec![alice.address(), bob.address()]; let amounts = vec![uint!(1000_U96), uint!(1000_U96)]; // Deploy and mint batches of 1000 tokens to Alice and Bob. @@ -182,7 +193,9 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn burns(alice: Account) -> eyre::Result<()> { +async fn burn_succeeds_with_consecutive_and_non_consecutive_tokens( + alice: Account, +) -> eyre::Result<()> { let receivers = vec![alice.address()]; let amounts = vec![uint!(1000_U96)]; // Mint batch of 1000 tokens to Alice. diff --git a/examples/erc721-metadata/tests/erc721_metadata.rs b/examples/erc721-metadata/tests/erc721_metadata.rs index a0ef63280..12dd0d745 100644 --- a/examples/erc721-metadata/tests/erc721_metadata.rs +++ b/examples/erc721-metadata/tests/erc721_metadata.rs @@ -29,7 +29,9 @@ fn ctr(base_uri: &str) -> Constructor { // ============================================================================ #[e2e::test] -async fn constructs(alice: Account) -> eyre::Result<()> { +async fn constructor_initializes_token_metadata_correctly( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice .as_deployer() .with_constructor(ctr( @@ -54,7 +56,7 @@ async fn constructs(alice: Account) -> eyre::Result<()> { // ============================================================================ #[e2e::test] -async fn error_when_checking_token_uri_for_nonexistent_token( +async fn token_uri_reverts_when_token_nonexistent( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice @@ -81,7 +83,7 @@ async fn error_when_checking_token_uri_for_nonexistent_token( } #[e2e::test] -async fn return_empty_token_uri_when_without_base_uri_and_token_uri( +async fn token_uri_returns_empty_string_when_no_uri_set( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice @@ -106,7 +108,7 @@ async fn return_empty_token_uri_when_without_base_uri_and_token_uri( } #[e2e::test] -async fn return_token_uri_with_base_uri_and_without_token_uri( +async fn token_uri_returns_base_uri_with_token_id_when_no_token_uri_set( alice: Account, ) -> eyre::Result<()> { let base_uri = "https://github.com/OpenZeppelin/rust-contracts-stylus/"; @@ -132,7 +134,7 @@ async fn return_token_uri_with_base_uri_and_without_token_uri( } #[e2e::test] -async fn return_token_uri_with_base_uri_and_token_uri( +async fn token_uri_returns_combined_base_and_token_uri( alice: Account, ) -> eyre::Result<()> { let base_uri = "https://github.com/OpenZeppelin/rust-contracts-stylus/"; @@ -167,7 +169,9 @@ async fn return_token_uri_with_base_uri_and_token_uri( } #[e2e::test] -async fn set_token_uri_before_mint(alice: Account) -> eyre::Result<()> { +async fn set_token_uri_succeeds_before_token_minting( + alice: Account, +) -> eyre::Result<()> { let base_uri = "https://github.com/OpenZeppelin/rust-contracts-stylus/"; let contract_addr = alice @@ -210,7 +214,7 @@ async fn set_token_uri_before_mint(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn return_token_uri_after_burn_and_remint( +async fn token_uri_remains_consistent_after_burn_and_remint( alice: Account, ) -> eyre::Result<()> { let base_uri = "https://github.com/OpenZeppelin/rust-contracts-stylus/"; diff --git a/examples/erc721-wrapper/tests/erc721_wrapper.rs b/examples/erc721-wrapper/tests/erc721_wrapper.rs index 3ae5a5afb..2f599c8de 100644 --- a/examples/erc721-wrapper/tests/erc721_wrapper.rs +++ b/examples/erc721-wrapper/tests/erc721_wrapper.rs @@ -29,7 +29,9 @@ async fn deploy(account: &Account) -> Result<(Address, Address)> { } #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { +async fn constructor_initializes_with_underlying_asset( + alice: Account, +) -> Result<()> { let asset_address = erc721::deploy(&alice.wallet).await?; let contract_addr = alice .as_deployer() diff --git a/examples/erc721/tests/erc721.rs b/examples/erc721/tests/erc721.rs index adfa20d54..9731108cb 100644 --- a/examples/erc721/tests/erc721.rs +++ b/examples/erc721/tests/erc721.rs @@ -32,7 +32,7 @@ impl EncodeAsStr for T { // ============================================================================ #[e2e::test] -async fn error_when_checking_balance_of_invalid_owner( +async fn balance_of_reverts_when_owner_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -52,7 +52,9 @@ async fn error_when_checking_balance_of_invalid_owner( } #[e2e::test] -async fn balance_of_zero_balance(alice: Account) -> eyre::Result<()> { +async fn balance_of_returns_zero_for_new_address( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc721::new(contract_addr, &alice.wallet); @@ -64,7 +66,7 @@ async fn balance_of_zero_balance(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_checking_owner_of_nonexistent_token( +async fn owner_of_reverts_when_token_nonexistent( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -85,7 +87,9 @@ async fn error_when_checking_owner_of_nonexistent_token( } #[e2e::test] -async fn mints(alice: Account) -> eyre::Result<()> { +async fn mint_creates_token_for_valid_recipient( + alice: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc721::new(contract_addr, &alice.wallet); @@ -111,7 +115,7 @@ async fn mints(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_minting_token_id_twice(alice: Account) -> eyre::Result<()> { +async fn mint_reverts_when_token_id_exists(alice: Account) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc721::new(contract_addr, &alice.wallet); @@ -128,7 +132,7 @@ async fn error_when_minting_token_id_twice(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn error_when_minting_token_to_invalid_receiver( +async fn mint_reverts_when_receiver_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -147,7 +151,10 @@ async fn error_when_minting_token_to_invalid_receiver( } #[e2e::test] -async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { +async fn transfer_from_moves_token_between_owners( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc721::new(contract_addr, &alice.wallet); @@ -189,7 +196,7 @@ async fn transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn transfers_from_approved_token( +async fn transfer_from_succeeds_with_token_approval( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -237,7 +244,7 @@ async fn transfers_from_approved_token( } #[e2e::test] -async fn transfers_from_approved_for_all( +async fn transfer_from_succeeds_with_approval_for_all( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -285,7 +292,7 @@ async fn transfers_from_approved_for_all( } #[e2e::test] -async fn error_when_transfer_to_invalid_receiver( +async fn transfer_from_reverts_when_receiver_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -313,7 +320,7 @@ async fn error_when_transfer_to_invalid_receiver( } #[e2e::test] -async fn error_when_transfer_from_incorrect_owner( +async fn transfer_from_reverts_when_sender_is_not_owner( alice: Account, bob: Account, dave: Account, @@ -346,7 +353,7 @@ async fn error_when_transfer_from_incorrect_owner( } #[e2e::test] -async fn error_when_transfer_with_insufficient_approval( +async fn transfer_from_reverts_when_approval_insufficient( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -375,7 +382,7 @@ async fn error_when_transfer_with_insufficient_approval( } #[e2e::test] -async fn error_when_transfer_nonexistent_token( +async fn transfer_from_reverts_when_token_nonexistent( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -405,7 +412,10 @@ async fn error_when_transfer_nonexistent_token( } #[e2e::test] -async fn safe_transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { +async fn safe_transfer_from_moves_token_between_owners( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = Erc721::new(contract_addr, &alice.wallet); @@ -447,7 +457,7 @@ async fn safe_transfers_from(alice: Account, bob: Account) -> eyre::Result<()> { } #[e2e::test] -async fn safe_transfers_to_receiver_contract( +async fn safe_transfer_from_succeeds_with_receiver_contract( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -505,7 +515,7 @@ async fn safe_transfers_to_receiver_contract( } #[e2e::test] -async fn safe_transfers_from_approved_token( +async fn safe_transfer_from_succeeds_with_token_approval( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -554,7 +564,7 @@ async fn safe_transfers_from_approved_token( } #[e2e::test] -async fn safe_transfers_from_approved_for_all( +async fn safe_transfer_from_succeeds_with_approval_for_all( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -603,7 +613,7 @@ async fn safe_transfers_from_approved_for_all( } #[e2e::test] -async fn error_when_safe_transfer_to_invalid_receiver( +async fn safe_transfer_from_reverts_when_receiver_invalid( alice: Account, ) -> eyre::Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; @@ -633,7 +643,7 @@ async fn error_when_safe_transfer_to_invalid_receiver( } #[e2e::test] -async fn error_when_safe_transfer_from_incorrect_owner( +async fn safe_transfer_from_reverts_when_owner_incorrect( alice: Account, bob: Account, dave: Account, @@ -666,7 +676,7 @@ async fn error_when_safe_transfer_from_incorrect_owner( } #[e2e::test] -async fn error_when_safe_transfer_with_insufficient_approval( +async fn safe_transfer_from_reverts_when_approval_insufficient( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -697,7 +707,7 @@ async fn error_when_safe_transfer_with_insufficient_approval( } #[e2e::test] -async fn error_when_safe_transfer_nonexistent_token( +async fn safe_transfer_from_reverts_when_token_nonexistent( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -728,7 +738,7 @@ async fn error_when_safe_transfer_nonexistent_token( } #[e2e::test] -async fn safe_transfers_from_with_data( +async fn safe_transfer_from_moves_token_with_data( alice: Account, bob: Account, ) -> eyre::Result<()> { diff --git a/examples/ownable-two-step/tests/ownable_two_step.rs b/examples/ownable-two-step/tests/ownable_two_step.rs index a07d3cd48..ca636669c 100644 --- a/examples/ownable-two-step/tests/ownable_two_step.rs +++ b/examples/ownable-two-step/tests/ownable_two_step.rs @@ -22,7 +22,7 @@ fn ctr(owner: Address) -> Constructor { // ============================================================================ #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { +async fn constructor_initializes_ownership_state(alice: Account) -> Result<()> { let alice_addr = alice.address(); let receipt = alice.as_deployer().with_constructor(ctr(alice_addr)).deploy().await?; @@ -44,9 +44,7 @@ async fn constructs(alice: Account) -> Result<()> { } #[e2e::test] -async fn construct_reverts_when_owner_is_zero_address( - alice: Account, -) -> Result<()> { +async fn constructor_reverts_when_owner_zero(alice: Account) -> Result<()> { let err = alice .as_deployer() .with_constructor(ctr(Address::ZERO)) @@ -66,7 +64,7 @@ async fn construct_reverts_when_owner_is_zero_address( } #[e2e::test] -async fn transfer_ownership_initiates_transfer( +async fn transfer_ownership_updates_pending_owner( alice: Account, bob: Account, ) -> Result<()> { @@ -100,7 +98,7 @@ async fn transfer_ownership_initiates_transfer( } #[e2e::test] -async fn transfer_ownership_reverts_when_not_owner( +async fn transfer_should_revert_when_not_owner( alice: Account, bob: Account, ) -> Result<()> { @@ -125,7 +123,10 @@ async fn transfer_ownership_reverts_when_not_owner( } #[e2e::test] -async fn accept_ownership(alice: Account, bob: Account) -> Result<()> { +async fn accept_ownership_transfers_ownership_to_pending( + alice: Account, + bob: Account, +) -> Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); @@ -157,7 +158,7 @@ async fn accept_ownership(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn transfer_ownership_cancel_transfer( +async fn transfer_ownership_clears_pending_owner( alice: Account, bob: Account, ) -> Result<()> { @@ -187,7 +188,7 @@ async fn transfer_ownership_cancel_transfer( } #[e2e::test] -async fn overwrite_previous_transfer_ownership( +async fn transfer_ownership_replaces_pending_owner( alice: Account, bob: Account, charlie: Account, @@ -278,7 +279,9 @@ async fn accept_ownership_reverts_when_not_pending_owner( } #[e2e::test] -async fn renounce_ownership(alice: Account) -> Result<()> { +async fn renounce_ownership_removes_all_ownership( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let contract_addr = alice .as_deployer() diff --git a/examples/ownable/tests/ownable.rs b/examples/ownable/tests/ownable.rs index 507a5da3e..455ea9bce 100644 --- a/examples/ownable/tests/ownable.rs +++ b/examples/ownable/tests/ownable.rs @@ -19,7 +19,9 @@ fn ctr(owner: Address) -> Constructor { // ============================================================================ #[e2e::test] -async fn constructs(alice: Account) -> Result<()> { +async fn constructor_succeeds_initializing_ownership( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let receipt = alice.as_deployer().with_constructor(ctr(alice_addr)).deploy().await?; @@ -36,7 +38,7 @@ async fn constructs(alice: Account) -> Result<()> { } #[e2e::test] -async fn rejects_zero_address_initial_owner(alice: Account) -> Result<()> { +async fn constructor_reverts_when_owner_zero(alice: Account) -> Result<()> { let err = alice .as_deployer() .with_constructor(ctr(Address::ZERO)) @@ -55,7 +57,10 @@ async fn rejects_zero_address_initial_owner(alice: Account) -> Result<()> { } #[e2e::test] -async fn transfers_ownership(alice: Account, bob: Account) -> Result<()> { +async fn transfer_ownership_succeeds_updating_owner( + alice: Account, + bob: Account, +) -> Result<()> { let alice_addr = alice.address(); let bob_addr = bob.address(); @@ -80,7 +85,7 @@ async fn transfers_ownership(alice: Account, bob: Account) -> Result<()> { } #[e2e::test] -async fn prevents_non_owners_from_transferring( +async fn transfer_ownership_reverts_when_not_owner( alice: Account, bob: Account, ) -> Result<()> { @@ -105,7 +110,9 @@ async fn prevents_non_owners_from_transferring( } #[e2e::test] -async fn guards_against_stuck_state(alice: Account) -> Result<()> { +async fn transfer_ownership_reverts_when_zero_address( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let contract_addr = alice .as_deployer() @@ -126,7 +133,9 @@ async fn guards_against_stuck_state(alice: Account) -> Result<()> { } #[e2e::test] -async fn loses_ownership_after_renouncement(alice: Account) -> Result<()> { +async fn renounce_ownership_succeeds_removing_owner( + alice: Account, +) -> Result<()> { let alice_addr = alice.address(); let contract_addr = alice .as_deployer() @@ -149,7 +158,7 @@ async fn loses_ownership_after_renouncement(alice: Account) -> Result<()> { } #[e2e::test] -async fn prevents_non_owners_from_renouncement( +async fn renounce_ownership_reverts_when_not_owner( alice: Account, bob: Account, ) -> Result<()> { diff --git a/examples/pedersen/tests/pedersen.rs b/examples/pedersen/tests/pedersen.rs index 120ac9113..935426991 100644 --- a/examples/pedersen/tests/pedersen.rs +++ b/examples/pedersen/tests/pedersen.rs @@ -13,8 +13,8 @@ mod abi; // ============================================================================ #[e2e::test] -async fn pedersen_works(alice: Account) -> Result<()> { - let input_1: U256 = from_str_hex::<4>( +async fn hash_returns_expected_pedersen_result(alice: Account) -> Result<()> { + let input_1 = from_str_hex::<4>( "3d937c035c878245caf64531a5756109c53068da139362728feb561405371cb", ); let input_2: U256 = from_str_hex::<4>( diff --git a/examples/poseidon/tests/poseidon.rs b/examples/poseidon/tests/poseidon.rs index f948c6ed2..e2c80fef6 100644 --- a/examples/poseidon/tests/poseidon.rs +++ b/examples/poseidon/tests/poseidon.rs @@ -13,7 +13,7 @@ mod abi; // ============================================================================ #[e2e::test] -async fn poseidon_works(alice: Account) -> Result<()> { +async fn hash_returns_expected_poseidon_result(alice: Account) -> Result<()> { let contract_addr = alice.as_deployer().deploy().await?.contract_address; let contract = PoseidonExample::new(contract_addr, &alice.wallet); diff --git a/examples/safe-erc20/tests/safe_erc20_address_with_no_code.rs b/examples/safe-erc20/tests/safe_erc20_address_with_no_code.rs index 13ebcd0d1..3d313677e 100644 --- a/examples/safe-erc20/tests/safe_erc20_address_with_no_code.rs +++ b/examples/safe-erc20/tests/safe_erc20_address_with_no_code.rs @@ -8,7 +8,7 @@ mod abi; mod mock; #[e2e::test] -async fn reverts_on_transfer( +async fn safe_transfer_reverts_when_eoa_token( alice: Account, bob: Account, has_no_code: Account, @@ -55,7 +55,7 @@ async fn returns_false_on_try_safe_transfer( } #[e2e::test] -async fn reverts_on_transfer_from( +async fn safe_transfer_from_reverts_when_eoa_token( alice: Account, bob: Account, has_no_code: Account, @@ -109,7 +109,7 @@ async fn returns_false_on_try_safe_transfer_from( } #[e2e::test] -async fn reverts_on_increase_allowance( +async fn safe_increase_allowance_reverts_when_eoa_token( alice: Account, bob: Account, has_no_code: Account, @@ -135,7 +135,7 @@ async fn reverts_on_increase_allowance( } #[e2e::test] -async fn reverts_on_decrease_allowance( +async fn safe_decrease_allowance_reverts_when_eoa_token( alice: Account, bob: Account, has_no_code: Account, @@ -163,7 +163,7 @@ async fn reverts_on_decrease_allowance( } #[e2e::test] -async fn reverts_on_force_approve( +async fn force_approve_reverts_when_eoa_token( alice: Account, bob: Account, has_no_code: Account, diff --git a/examples/safe-erc20/tests/safe_erc20_erc20.rs b/examples/safe-erc20/tests/safe_erc20_erc20.rs index 26f7eb126..a6633b354 100644 --- a/examples/safe-erc20/tests/safe_erc20_erc20.rs +++ b/examples/safe-erc20/tests/safe_erc20_erc20.rs @@ -13,7 +13,7 @@ mod transfers { use super::*; #[e2e::test] - async fn does_not_revert_on_transfer( + async fn safe_transfer_succeeds_moving_tokens( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -60,7 +60,7 @@ mod transfers { } #[e2e::test] - async fn reverts_on_transfer_with_internal_error( + async fn safe_transfer_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -101,7 +101,7 @@ mod transfers { } #[e2e::test] - async fn does_not_revert_on_transfer_from( + async fn safe_transfer_from_succeeds_moving_approved_tokens( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -199,7 +199,7 @@ mod transfers { } #[e2e::test] - async fn reverts_on_transfer_from_internal_error( + async fn safe_transfer_from_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -299,7 +299,7 @@ mod approvals { use super::super::*; #[e2e::test] - async fn does_not_revert_when_force_approving_a_non_zero_allowance( + async fn force_approve_succeeds_setting_nonzero_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -342,7 +342,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_force_approving_a_zero_allowance( + async fn force_approve_succeeds_clearing_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -383,7 +383,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_increasing_the_allowance( + async fn safe_increase_allowance_succeeds_updating_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -426,7 +426,7 @@ mod approvals { } #[e2e::test] - async fn panics_when_increasing_the_allowance_overflow( + async fn safe_increase_allowance_reverts_when_allowance_overflows( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -459,7 +459,7 @@ mod approvals { } #[e2e::test] - async fn reverts_when_decreasing_the_allowance( + async fn safe_decrease_allowance_reverts_when_insufficient_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -501,7 +501,7 @@ mod approvals { use super::super::*; #[e2e::test] - async fn does_not_revert_when_force_approving_a_non_zero_allowance( + async fn force_approve_succeeds_setting_nonzero_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -546,7 +546,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_force_approving_a_zero_allowance( + async fn force_approve_succeeds_clearing_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -589,7 +589,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_increasing_the_allowance( + async fn safe_increase_allowance_succeeds_updating_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -634,7 +634,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_decreasing_the_allowance_to_a_positive_value( + async fn safe_decrease_allowance_succeeds_reducing_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -679,7 +679,7 @@ mod approvals { } #[e2e::test] - async fn reverts_when_decreasing_the_allowance_to_a_negative_value( + async fn safe_decrease_allowance_reverts_when_amount_exceeds_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = diff --git a/examples/safe-erc20/tests/safe_erc20_erc20_that_always_returns_false.rs b/examples/safe-erc20/tests/safe_erc20_erc20_that_always_returns_false.rs index d41e927ee..cb151a8f5 100644 --- a/examples/safe-erc20/tests/safe_erc20_erc20_that_always_returns_false.rs +++ b/examples/safe-erc20/tests/safe_erc20_erc20_that_always_returns_false.rs @@ -9,7 +9,10 @@ mod abi; mod mock; #[e2e::test] -async fn reverts_on_transfer(alice: Account, bob: Account) -> eyre::Result<()> { +async fn safe_transfer_reverts_when_token_returns_false( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let safe_erc20_addr = alice.as_deployer().deploy().await?.contract_address; let safe_erc20_alice = SafeErc20::new(safe_erc20_addr, &alice.wallet); let bob_addr = bob.address(); @@ -71,7 +74,7 @@ async fn returns_false_on_try_safe_transfer( } #[e2e::test] -async fn reverts_on_transfer_from( +async fn safe_transfer_from_reverts_when_token_returns_false( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -137,7 +140,7 @@ async fn returns_false_on_try_safe_transfer_from( } #[e2e::test] -async fn reverts_on_increase_allowance( +async fn safe_increase_allowance_reverts_when_token_returns_false( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -161,7 +164,7 @@ async fn reverts_on_increase_allowance( } #[e2e::test] -async fn reverts_on_decrease_allowance( +async fn safe_decrease_allowance_reverts_when_token_returns_false( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -185,7 +188,7 @@ async fn reverts_on_decrease_allowance( } #[e2e::test] -async fn reverts_on_force_approve( +async fn force_approve_reverts_when_token_returns_false( alice: Account, bob: Account, ) -> eyre::Result<()> { diff --git a/examples/safe-erc20/tests/safe_erc20_erc20_that_does_not_return.rs b/examples/safe-erc20/tests/safe_erc20_erc20_that_does_not_return.rs index 1eb0a9239..02237c06a 100644 --- a/examples/safe-erc20/tests/safe_erc20_erc20_that_does_not_return.rs +++ b/examples/safe-erc20/tests/safe_erc20_erc20_that_does_not_return.rs @@ -13,7 +13,7 @@ mod transfers { use super::*; #[e2e::test] - async fn does_not_revert_on_transfer( + async fn safe_transfer_succeeds_with_no_return_value( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -60,7 +60,7 @@ mod transfers { } #[e2e::test] - async fn reverts_on_transfer_with_internal_error( + async fn safe_transfer_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -149,7 +149,7 @@ mod transfers { } #[e2e::test] - async fn does_not_revert_on_transfer_from( + async fn safe_transfer_from_succeeds_with_no_return_value( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -198,7 +198,7 @@ mod transfers { } #[e2e::test] - async fn reverts_on_transfer_from_internal_error( + async fn safe_transfer_from_reverts_when_balance_insufficient( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -297,7 +297,7 @@ mod approvals { use super::super::*; #[e2e::test] - async fn does_not_revert_when_force_approving_a_non_zero_allowance( + async fn force_approve_succeeds_setting_nonzero_amount( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -341,7 +341,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_force_approving_a_zero_allowance( + async fn force_approve_succeeds_setting_zero_amount( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -383,7 +383,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_increasing_the_allowance( + async fn safe_increase_allowance_succeeds_from_zero( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -427,7 +427,7 @@ mod approvals { } #[e2e::test] - async fn panics_when_increasing_the_allowance_overflow( + async fn safe_increase_allowance_reverts_when_allowance_overflows( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -461,7 +461,7 @@ mod approvals { } #[e2e::test] - async fn reverts_when_decreasing_the_allowance( + async fn safe_decrease_allowance_reverts_when_insufficient_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -504,7 +504,7 @@ mod approvals { use super::super::*; #[e2e::test] - async fn does_not_revert_when_force_approving_a_non_zero_allowance( + async fn force_approve_succeeds_updating_existing_amount( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -550,7 +550,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_force_approving_a_zero_allowance( + async fn force_approve_succeeds_clearing_existing_amount( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -594,7 +594,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_increasing_the_allowance( + async fn safe_increase_allowance_succeeds_with_existing_amount( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -640,7 +640,7 @@ mod approvals { } #[e2e::test] - async fn does_not_revert_when_decreasing_the_allowance_to_a_positive_value( + async fn safe_decrease_allowance_succeeds_maintaining_positive_balance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = @@ -686,7 +686,7 @@ mod approvals { } #[e2e::test] - async fn reverts_when_decreasing_the_allowance_to_a_negative_value( + async fn safe_decrease_allowance_reverts_when_amount_exceeds_allowance( alice: Account, ) -> eyre::Result<()> { let safe_erc20_addr = diff --git a/examples/safe-erc20/tests/safe_erc20_usdt_approval_behavior.rs b/examples/safe-erc20/tests/safe_erc20_usdt_approval_behavior.rs index e79d98aaa..3b41d1e1a 100644 --- a/examples/safe-erc20/tests/safe_erc20_usdt_approval_behavior.rs +++ b/examples/safe-erc20/tests/safe_erc20_usdt_approval_behavior.rs @@ -9,7 +9,7 @@ mod abi; mod mock; #[e2e::test] -async fn safe_increase_allowance_works( +async fn safe_increase_allowance_succeeds_with_force_approve( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -49,7 +49,7 @@ async fn safe_increase_allowance_works( } #[e2e::test] -async fn safe_decrease_allowance_works( +async fn safe_decrease_allowance_succeeds_with_force_approve( alice: Account, bob: Account, ) -> eyre::Result<()> { @@ -89,7 +89,10 @@ async fn safe_decrease_allowance_works( } #[e2e::test] -async fn force_approve_works(alice: Account, bob: Account) -> eyre::Result<()> { +async fn force_approve_succeeds_with_updated_approval( + alice: Account, + bob: Account, +) -> eyre::Result<()> { let safe_erc20_addr = alice.as_deployer().deploy().await?.contract_address; let safe_erc20_alice = SafeErc20::new(safe_erc20_addr, &alice.wallet); let bob_addr = bob.address(); diff --git a/examples/vesting-wallet/tests/vesting-wallet.rs b/examples/vesting-wallet/tests/vesting-wallet.rs index 0acac3d12..97a75f356 100644 --- a/examples/vesting-wallet/tests/vesting-wallet.rs +++ b/examples/vesting-wallet/tests/vesting-wallet.rs @@ -54,7 +54,9 @@ fn assert_in_delta(expected: U256, actual: U256) { } #[e2e::test] -async fn constructs(alice: Account) -> eyre::Result<()> { +async fn constructor_succeeds_with_valid_parameters( + alice: Account, +) -> eyre::Result<()> { let start_timestamp = block_timestamp(&alice).await?; let contract_addr = alice .as_deployer() @@ -78,7 +80,7 @@ async fn constructs(alice: Account) -> eyre::Result<()> { } #[e2e::test] -async fn rejects_zero_address_for_beneficiary( +async fn constructor_reverts_when_beneficiary_zero( alice: Account, ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; @@ -172,34 +174,44 @@ mod ether_vesting { } #[e2e::test] - async fn check_release_0_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_zero_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, 0).await } #[e2e::test] - async fn check_release_25_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_25_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, DURATION / 4).await } #[e2e::test] - async fn check_release_50_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_50_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, DURATION / 2).await } #[e2e::test] - async fn check_release_100_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_100_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, DURATION).await } #[e2e::test] - async fn check_release_100_percent_vesting_in_the_past( + async fn release_eth_succeeds_with_past_vesting( alice: Account, ) -> eyre::Result<()> { run_check_release(alice, DURATION * 4 / 3).await } #[e2e::test] - async fn check_vested_amount(alice: Account) -> eyre::Result<()> { + async fn vested_amount_eth_succeeds_for_multiple_timestamps( + alice: Account, + ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; let contract_addr = deploy(&alice, start, DURATION, BALANCE).await?; @@ -320,34 +332,44 @@ mod erc20_vesting { } #[e2e::test] - async fn check_release_0_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_zero_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, 0).await } #[e2e::test] - async fn check_release_25_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_25_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, DURATION / 4).await } #[e2e::test] - async fn check_release_50_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_50_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, DURATION / 2).await } #[e2e::test] - async fn check_release_100_percent(alice: Account) -> eyre::Result<()> { + async fn release_eth_succeeds_at_100_percent( + alice: Account, + ) -> eyre::Result<()> { run_check_release(alice, DURATION).await } #[e2e::test] - async fn check_release_100_percent_vesting_in_the_past( + async fn release_eth_succeeds_with_past_vesting( alice: Account, ) -> eyre::Result<()> { run_check_release(alice, DURATION * 4 / 3).await } #[e2e::test] - async fn check_vested_amount(alice: Account) -> eyre::Result<()> { + async fn vested_amount_eth_succeeds_for_multiple_timestamps( + alice: Account, + ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; let contract_addr = deploy(&alice, start, DURATION).await?; let erc20_address = @@ -377,7 +399,7 @@ mod erc20_vesting { } #[e2e::test] - async fn releasable_erc20_reverts_on_invalid_token( + async fn releasable_erc20_reverts_when_token_invalid( alice: Account, ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; @@ -396,7 +418,7 @@ mod erc20_vesting { } #[e2e::test] - async fn release_erc20_reverts_on_invalid_token( + async fn release_erc20_reverts_when_token_invalid( alice: Account, ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; @@ -415,7 +437,7 @@ mod erc20_vesting { } #[e2e::test] - async fn release_erc20_reverts_on_failed_transfer( + async fn release_erc20_reverts_when_transfer_fails( alice: Account, ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; @@ -436,7 +458,7 @@ mod erc20_vesting { } #[e2e::test] - async fn vested_amount_erc20_reverts_on_invalid_token( + async fn vested_amount_erc20_reverts_when_token_invalid( alice: Account, ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; @@ -455,7 +477,7 @@ mod erc20_vesting { } #[e2e::test] - async fn vested_amount_reverts_on_scaled_allocation_overflow( + async fn vested_amount_reverts_when_allocation_overflows( alice: Account, ) -> eyre::Result<()> { let start = block_timestamp(&alice).await?; diff --git a/lib/crypto/src/field/fp.rs b/lib/crypto/src/field/fp.rs index cc6e9dacd..a89b2811f 100644 --- a/lib/crypto/src/field/fp.rs +++ b/lib/crypto/src/field/fp.rs @@ -1052,7 +1052,7 @@ mod tests { const MODULUS: i128 = 1000003; // Prime number #[test] - fn add() { + fn add_succeeds_for_field_elements() { proptest!(|(a: i64, b: i64)| { let res = Field64::from(a) + Field64::from(b); let res: i128 = res.into(); @@ -1063,7 +1063,7 @@ mod tests { } #[test] - fn double() { + fn double_succeeds_with_expected_value() { proptest!(|(a: i64)| { let res = Field64::from(a).double(); let res: i128 = res.into(); @@ -1073,7 +1073,7 @@ mod tests { } #[test] - fn sub() { + fn sub_succeeds_for_field_elements() { proptest!(|(a: i64, b: i64)| { let res = Field64::from(a) - Field64::from(b); let res: i128 = res.into(); @@ -1084,7 +1084,7 @@ mod tests { } #[test] - fn mul() { + fn mul_succeeds_for_field_elements() { proptest!(|(a: i64, b: i64)| { let res = Field64::from(a) * Field64::from(b); let res: i128 = res.into(); @@ -1095,7 +1095,7 @@ mod tests { } #[test] - fn square() { + fn square_succeeds_with_expected_value() { proptest!(|(a: i64)| { let res = Field64::from(a).square(); let res: i128 = res.into(); @@ -1117,7 +1117,7 @@ mod tests { } #[test] - fn div() { + fn div_succeeds_when_denominator_is_nonzero() { proptest!(|(a: i64, b in non_zero_modulo_i64())| { let res = Field64::from(a) / Field64::from(b); let res: i128 = res.into(); @@ -1134,7 +1134,7 @@ mod tests { } #[test] - fn pow() { + fn pow_succeeds_with_expected_value() { proptest!(|(a: i64, b in 0_u32..1000)| { let res = Field64::from(a).pow(b); let res: i128 = res.into(); @@ -1145,7 +1145,7 @@ mod tests { } #[test] - fn neg() { + fn neg_succeeds_returning_correct_field_element() { proptest!(|(a: i64)| { let res = -Field64::from(a); let res: i128 = res.into(); @@ -1155,7 +1155,7 @@ mod tests { } #[test] - fn one() { + fn one_succeeds_with_multiplicative_identity() { proptest!(|(a: i64)| { let res = Field64::one(); let res: i128 = res.into(); @@ -1169,7 +1169,7 @@ mod tests { } #[test] - fn zero() { + fn zero_succeeds_with_additive_identity() { proptest!(|(a: i64)| { let res = Field64::zero(); let res: i128 = res.into(); diff --git a/lib/crypto/src/merkle.rs b/lib/crypto/src/merkle.rs index 642fbd376..59743b28b 100644 --- a/lib/crypto/src/merkle.rs +++ b/lib/crypto/src/merkle.rs @@ -531,7 +531,7 @@ mod tests { } #[test] - fn verifies_valid_proofs() { + fn verify_succeeds_with_valid_proof() { // ```js // const merkleTree = StandardMerkleTree.of( // toElements('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='), @@ -567,7 +567,7 @@ mod tests { } #[test] - fn rejects_invalid_proofs() { + fn verify_reverts_when_proof_invalid() { // ```js // const correctMerkleTree = StandardMerkleTree.of(toElements('abc'), ['string']); // const otherMerkleTree = StandardMerkleTree.of(toElements('def'), ['string']); @@ -587,7 +587,7 @@ mod tests { } #[test] - fn rejects_proofs_with_invalid_length() { + fn verify_reverts_when_proof_length_invalid() { // ```js // const merkleTree = StandardMerkleTree.of(toElements('abc'), ['string']); // @@ -610,7 +610,7 @@ mod tests { } #[test] - fn verifies_valid_multi_proof() { + fn verify_multi_proof_succeeds_with_valid_leaves() { // ```js // const merkleTree = StandardMerkleTree.of(toElements('abcdef'), ['string']); // @@ -638,7 +638,7 @@ mod tests { } #[test] - fn rejects_invalid_multi_proof() { + fn verify_multi_proof_reverts_when_proof_invalid() { // ```js // const merkleTree = StandardMerkleTree.of(toElements('abcdef'), ['string']); // const otherMerkleTree = StandardMerkleTree.of(toElements('ghi'), ['string']); @@ -757,7 +757,7 @@ mod tests { #[test] /// Errors when processing manipulated proofs with a zero-value node at /// depth 1. - fn errors_manipulated_multi_proof() { + fn verify_multi_proof_reverts_when_proof_manipulated() { // Create a merkle tree that contains a zero leaf at depth 1 // // Taken from https://github.com/advisories/GHSA-wprv-93r4-jj2p diff --git a/lib/crypto/src/poseidon2/instance/babybear.rs b/lib/crypto/src/poseidon2/instance/babybear.rs index 32915e2bb..58db57225 100644 --- a/lib/crypto/src/poseidon2/instance/babybear.rs +++ b/lib/crypto/src/poseidon2/instance/babybear.rs @@ -812,7 +812,7 @@ mod tests { type Scalar = FpBabyBear; #[test] - fn smoke() { + fn poseidon2_hash_succeeds_with_outputs() { let mut poseidon2 = Poseidon2::::new(); for i in 1..BabyBear24Params::T { poseidon2.absorb(&Scalar::from(i as u64)); diff --git a/lib/crypto/src/poseidon2/instance/bls12.rs b/lib/crypto/src/poseidon2/instance/bls12.rs index dd6c11de5..7cc2e623a 100644 --- a/lib/crypto/src/poseidon2/instance/bls12.rs +++ b/lib/crypto/src/poseidon2/instance/bls12.rs @@ -1039,7 +1039,7 @@ mod tests { type Scalar = FpBLS12; #[test] - fn smoke() { + fn poseidon2_hash_succeeds_with_outputs() { let mut poseidon2 = Poseidon2::::new(); for i in 1..BLS2Params::T { poseidon2.absorb(&Scalar::from(i as u64)); diff --git a/lib/crypto/src/poseidon2/instance/bn256.rs b/lib/crypto/src/poseidon2/instance/bn256.rs index ca12b20b0..1981b2171 100644 --- a/lib/crypto/src/poseidon2/instance/bn256.rs +++ b/lib/crypto/src/poseidon2/instance/bn256.rs @@ -362,7 +362,7 @@ mod tests { type Scalar = FpBN256; #[test] - fn smoke() { + fn poseidon2_hash_succeeds_with_outputs() { let mut poseidon2 = Poseidon2::::new(); for i in 1..BN256Params::T { poseidon2.absorb(&Scalar::from(i as u64)); diff --git a/lib/crypto/src/poseidon2/instance/goldilocks.rs b/lib/crypto/src/poseidon2/instance/goldilocks.rs index 17cdecc2c..a686fd91b 100644 --- a/lib/crypto/src/poseidon2/instance/goldilocks.rs +++ b/lib/crypto/src/poseidon2/instance/goldilocks.rs @@ -468,7 +468,7 @@ mod tests { type Scalar = FpGoldiLocks; #[test] - fn smoke() { + fn poseidon2_hash_succeeds_with_outputs() { let mut poseidon2 = Poseidon2::::new(); for i in 1..Goldilocks12Params::T { poseidon2.absorb(&Scalar::from(i as u64)); diff --git a/lib/crypto/src/poseidon2/instance/pallas.rs b/lib/crypto/src/poseidon2/instance/pallas.rs index 7b3dd451c..2675b196d 100644 --- a/lib/crypto/src/poseidon2/instance/pallas.rs +++ b/lib/crypto/src/poseidon2/instance/pallas.rs @@ -361,7 +361,7 @@ mod tests { type Scalar = FpPallas; #[test] - fn smoke() { + fn poseidon2_hash_succeeds_with_outputs() { let mut poseidon2 = Poseidon2::::new(); for i in 1..PallasParams::T { poseidon2.absorb(&Scalar::from(i as u64)); diff --git a/lib/crypto/src/poseidon2/instance/vesta.rs b/lib/crypto/src/poseidon2/instance/vesta.rs index aac8c65ec..1696a39d3 100644 --- a/lib/crypto/src/poseidon2/instance/vesta.rs +++ b/lib/crypto/src/poseidon2/instance/vesta.rs @@ -363,7 +363,7 @@ mod tests { type Scalar = FpVesta; #[test] - fn smoke() { + fn poseidon2_hash_succeeds_with_outputs() { let mut poseidon2 = Poseidon2::::new(); for i in 1..VestaParams::T { poseidon2.absorb(&Scalar::from(i as u64));