Skip to content

Commit

Permalink
transfer and buy/sell tests for v1 before/after migration
Browse files Browse the repository at this point in the history
  • Loading branch information
nerfZael committed Jan 27, 2025
1 parent 31643a9 commit 45d8f01
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/GeckoMigration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,81 @@ contract GeckoMigrationTest is Test {
migrator.migrate();
}

function test_forbidsTransferringV1TokensBeforeMigration() public {
vm.startPrank(user);

vm.expectRevert("TRANSFERS_DISABLED");
geckoV1.transfer(recipient, 1 * 1e18);
}

function test_forbidsTransferringV1TokensAfterMigration() public {
_migrate();

vm.startPrank(user);
vm.expectRevert("Contract is stopped");
geckoV1.transfer(recipient, 1 * 1e18);
}

function test_allowsBuyingV1TokensBeforeMigration() public {
uint256 amountToSpend = 1 ether;
vm.deal(user, amountToSpend);

uint256 startTokenBalance = geckoV1.balanceOf(user);

vm.startPrank(user);

uint256 minBuyAmount = geckoV1.estimateBuyValue(amountToSpend);
assertGt(minBuyAmount, 0);

geckoV1.buy{value: amountToSpend}(user, amountToSpend, minBuyAmount);

assertGt(geckoV1.balanceOf(user), startTokenBalance);
}

function test_forbidsBuyingV1TokensAfterMigration() public {
uint256 amountToSpend = 1 ether;
vm.deal(user, amountToSpend);

_migrate();

uint256 startTokenBalance = geckoV1.balanceOf(user);

vm.startPrank(user);

uint256 minBuyAmount = geckoV1.estimateBuyValue(amountToSpend);
assertGt(minBuyAmount, 0);

vm.expectRevert(); // Out of funds error since the reserve is transferred to the migrator
geckoV1.buy{value: amountToSpend}(user, amountToSpend, minBuyAmount);
}

function test_allowsSellingV1TokensBeforeMigration() public {
_buyV1Tokens(user, 1 ether);

uint256 amountToSell = geckoV1.balanceOf(user);

vm.startPrank(user);

geckoV1.sell(payable(user), amountToSell, 1);

uint256 balance = geckoV1.balanceOf(user);

assertEq(balance, 0);
}

function test_forbidsSellingV1TokensAfterMigration() public {
_migrate();

uint256 amountToSell = geckoV1.balanceOf(user);

assertGt(amountToSell, 0);

vm.startPrank(user);

vm.expectRevert("PRICE_SLIPPAGE"); // Price slippage error since the reserve is transferred to the migrator
geckoV1.sell(payable(user), amountToSell, 1);
}

function test_canClaimV2TokensAfterMigration() public {
_migrate();

Expand Down

0 comments on commit 45d8f01

Please sign in to comment.