diff --git a/test/escrow/migration/MigrationStateful.t.sol b/test/escrow/migration/MigrationStateful.t.sol index 1c59880..dc0a602 100644 --- a/test/escrow/migration/MigrationStateful.t.sol +++ b/test/escrow/migration/MigrationStateful.t.sol @@ -44,18 +44,17 @@ contract TestMigrationStateful is MigrationBase, IGaugeVote { // tests votes reset if the user is voting function testVotesResetIfVoting(uint32 _warp) public { - src.escrow.enableMigration(address(migrator)); - // setup a gauge vote src.voter.createGauge(gauge, "metadata"); address depositor = address(420); src.token.mint(depositor, 100 ether); + uint tokenId; vm.startPrank(depositor); { src.token.approve(address(src.escrow), 100 ether); - uint tokenId = src.escrow.createLock(100 ether); + tokenId = src.escrow.createLock(100 ether); // arbitrary jump for voting power vm.warp(1 weeks); @@ -68,10 +67,15 @@ contract TestMigrationStateful is MigrationBase, IGaugeVote { // check votes are set assertGt(src.voter.totalVotingPowerCast(), 0, "votes cast"); + } + vm.stopPrank(); - // random warp: means we can be in either voting or non-voting period - vm.warp(block.timestamp + uint(_warp)); + // random warp: means we can be in either voting or non-voting period + vm.warp(block.timestamp + uint(_warp)); + src.escrow.enableMigration(address(migrator)); + vm.startPrank(depositor); + { // migrate - requires approving the escrow src.nftLock.approve(address(src.escrow), tokenId); src.escrow.migrateFrom(tokenId); @@ -83,7 +87,6 @@ contract TestMigrationStateful is MigrationBase, IGaugeVote { } function testExitingUserIsUnaffected() public { - src.escrow.enableMigration(address(dst.escrow)); dst.dao.grant({ _who: address(src.escrow), _where: address(dst.escrow), @@ -113,6 +116,8 @@ contract TestMigrationStateful is MigrationBase, IGaugeVote { } vm.stopPrank(); + src.escrow.enableMigration(address(dst.escrow)); + // u1 goes through the exit queue vm.warp(10 weeks); // arbitrary time diff --git a/test/escrow/migration/MigrationStateless.t.sol b/test/escrow/migration/MigrationStateless.t.sol index 363a853..f616693 100644 --- a/test/escrow/migration/MigrationStateless.t.sol +++ b/test/escrow/migration/MigrationStateless.t.sol @@ -87,8 +87,6 @@ contract TestMigrationStateless is MigrationBase { } function testCannotMigrateIfNotOwner() public { - src.escrow.enableMigration(address(migrator)); - address depositor = address(420); src.token.mint(depositor, 100 ether); @@ -101,13 +99,13 @@ contract TestMigrationStateless is MigrationBase { } vm.stopPrank(); + src.escrow.enableMigration(address(migrator)); + vm.expectRevert(NotOwner.selector); src.escrow.migrateFrom(tokenId); } function testCannotMigrateIfNoVotingPower() public { - src.escrow.enableMigration(address(migrator)); - address depositor = address(420); src.token.mint(depositor, 100 ether); @@ -117,15 +115,35 @@ contract TestMigrationStateless is MigrationBase { { src.token.approve(address(src.escrow), 100 ether); tokenId = src.escrow.createLock(100 ether); + } + vm.stopPrank(); + + src.escrow.enableMigration(address(migrator)); + + vm.startPrank(depositor); + { vm.expectRevert(CannotExit.selector); src.escrow.migrateFrom(tokenId); } vm.stopPrank(); } - - function testCannotMigrateIfMigratorRoleNotGivenToDestination() public { + function testCannotDepositIfMigrationEnabled() public { src.escrow.enableMigration(address(dst.escrow)); + address depositor = address(420); + + src.token.mint(depositor, 100 ether); + uint tokenId; + + vm.startPrank(depositor); + { + src.token.approve(address(src.escrow), 100 ether); + vm.expectRevert(MigrationActive.selector); + tokenId = src.escrow.createLock(100 ether); + } + vm.stopPrank(); + } + function testCannotMigrateIfMigratorRoleNotGivenToDestination() public { address depositor = address(420); src.token.mint(depositor, 100 ether); @@ -137,7 +155,13 @@ contract TestMigrationStateless is MigrationBase { tokenId = src.escrow.createLock(100 ether); vm.warp(src.clock.checkpointInterval() + 1); + } + vm.stopPrank(); + + src.escrow.enableMigration(address(dst.escrow)); + vm.startPrank(depositor); + { vm.expectRevert( _authErr( address(dst.dao), @@ -152,8 +176,6 @@ contract TestMigrationStateless is MigrationBase { } function testMigrateFromAndTo() public { - src.escrow.enableMigration(address(dst.escrow)); - dst.dao.grant({ _who: address(src.escrow), _where: address(dst.escrow), @@ -170,9 +192,14 @@ contract TestMigrationStateless is MigrationBase { { src.token.approve(address(src.escrow), 100 ether); tokenId = src.escrow.createLock(100 ether); + } + vm.stopPrank(); - vm.warp(src.clock.checkpointInterval() + 1); + vm.warp(src.clock.checkpointInterval() + 1); + src.escrow.enableMigration(address(dst.escrow)); + vm.startPrank(depositor); + { vm.expectEmit(true, true, true, true); emit Migrated(depositor, tokenId, 1, 100 ether); newTokenId = src.escrow.migrateFrom(tokenId);