From a8509cf0884b36b35b6a3eda7208cbc56d9ca261 Mon Sep 17 00:00:00 2001 From: Vedran Bidin Date: Wed, 3 Jul 2024 15:18:43 +0300 Subject: [PATCH] test: add additional unit test --- tests/Migrator.t.sol | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Migrator.t.sol b/tests/Migrator.t.sol index 185397c..d738846 100644 --- a/tests/Migrator.t.sol +++ b/tests/Migrator.t.sol @@ -109,6 +109,9 @@ contract MigratorTest is Test { address account = makeAddr("account"); address operationalAdmin = makeAddr("operationalAdmin"); address recipient = makeAddr("recipient"); + address sender = makeAddr("sender"); + + uint256 amount = 100e18; Migrator internal _migrator; MockERC20 internal _oldToken; @@ -159,6 +162,32 @@ contract MigratorTest is Test { _migrator.migrate(1); } + function test_migrate_recipient() external { + _oldToken.mint(address(sender), amount); + + vm.prank(sender); + _oldToken.approve(address(_migrator), amount); + + assertEq(_oldToken.balanceOf(address(sender)), amount); + assertEq(_oldToken.balanceOf(address(_migrator)), 0); + assertEq(_oldToken.balanceOf(address(recipient)), 0); + + assertEq(_newToken.balanceOf(address(sender)), 0); + assertEq(_newToken.balanceOf(address(_migrator)), OLD_SUPPLY * SCALAR); + assertEq(_newToken.balanceOf(address(recipient)), 0); + + vm.prank(sender); + _migrator.migrate(address(recipient), amount); + + assertEq(_oldToken.balanceOf(address(sender)), 0); + assertEq(_oldToken.balanceOf(address(_migrator)), amount); + assertEq(_oldToken.balanceOf(address(recipient)), 0); + + assertEq(_newToken.balanceOf(address(sender)), 0); + assertEq(_newToken.balanceOf(address(_migrator)), (OLD_SUPPLY - amount) * SCALAR); + assertEq(_newToken.balanceOf(address(recipient)), amount * SCALAR); + } + function testFuzz_migrate_insufficientApproval(uint256 amount_) external { amount_ = bound(amount_, 1, OLD_SUPPLY);