diff --git a/packages/usdc_migration/src/errors.cairo b/packages/usdc_migration/src/errors.cairo index 80bbf1f..4ca5f69 100644 --- a/packages/usdc_migration/src/errors.cairo +++ b/packages/usdc_migration/src/errors.cairo @@ -1,3 +1,4 @@ pub mod Errors { pub const THRESHOLD_TOO_SMALL: felt252 = 'Threshold is too small'; + pub const AMOUNT_IS_ZERO: felt252 = 'Amount is zero'; } diff --git a/packages/usdc_migration/src/tests/test_usdc_migration.cairo b/packages/usdc_migration/src/tests/test_usdc_migration.cairo index e81ada4..2158cd9 100644 --- a/packages/usdc_migration/src/tests/test_usdc_migration.cairo +++ b/packages/usdc_migration/src/tests/test_usdc_migration.cairo @@ -226,6 +226,11 @@ fn test_swap_to_new_assertions() { cheat_caller_address_once(contract_address: cfg.usdc_migration_contract, caller_address: user); let res = usdc_migration_safe_dispatcher.swap_to_new(:amount); assert_panic_with_error(res, Erc20Error::INSUFFICIENT_BALANCE.describe()); + + // Amount is zero. + cheat_caller_address_once(contract_address: cfg.usdc_migration_contract, caller_address: user); + let res = usdc_migration_safe_dispatcher.swap_to_new(amount: Zero::zero()); + assert_panic_with_felt_error(res, Errors::AMOUNT_IS_ZERO); } #[test] @@ -350,4 +355,9 @@ fn test_swap_to_legacy_assertions() { cheat_caller_address_once(contract_address: cfg.usdc_migration_contract, caller_address: user); let res = usdc_migration_safe_dispatcher.swap_to_legacy(:amount); assert_panic_with_error(res, Erc20Error::INSUFFICIENT_BALANCE.describe()); + + // Amount is zero. + cheat_caller_address_once(contract_address: cfg.usdc_migration_contract, caller_address: user); + let res = usdc_migration_safe_dispatcher.swap_to_legacy(amount: Zero::zero()); + assert_panic_with_felt_error(res, Errors::AMOUNT_IS_ZERO); } diff --git a/packages/usdc_migration/src/usdc_migration.cairo b/packages/usdc_migration/src/usdc_migration.cairo index e7733dd..9ba00fc 100644 --- a/packages/usdc_migration/src/usdc_migration.cairo +++ b/packages/usdc_migration/src/usdc_migration.cairo @@ -160,6 +160,7 @@ pub mod USDCMigration { to_token: IERC20Dispatcher, amount: u256, ) { + assert(amount > 0, Errors::AMOUNT_IS_ZERO); let contract_address = get_contract_address(); let user = get_caller_address(); from_token.checked_transfer_from(sender: user, recipient: contract_address, :amount);