Skip to content

Commit

Permalink
fixed tests for deposit blocks during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaniza committed Dec 27, 2024
1 parent c841236 commit dfaa51d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
17 changes: 11 additions & 6 deletions test/escrow/migration/MigrationStateful.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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),
Expand Down Expand Up @@ -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

Expand Down
45 changes: 36 additions & 9 deletions test/escrow/migration/MigrationStateless.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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);
Expand Down

0 comments on commit dfaa51d

Please sign in to comment.