Skip to content

Commit

Permalink
adds test to show changing owner and upgrade after (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xean authored Jun 18, 2024
1 parent 6349847 commit d72a427
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions foundry/test/StakingTestUpgrades.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,47 @@ contract FoxStakingTestUpgrades is Test {
// Attempt to perform the upgrade, but as a non-owner
upgradeHelper.doUpgrade(nonOwner, foxStakingProxy);
}

function testChangeOwnerAndUpgrade() public {
// Check the current version
uint256 expectedCurrentVersion = 1;
assertEq(foxStakingV1.version(), expectedCurrentVersion);

address newOwner = address(0x0FF1CE);

// confirm the new owner cannot upgrade yet!
vm.expectRevert(
abi.encodeWithSelector(
Ownable.OwnableUnauthorizedAccount.selector,
address(newOwner)
)
);

// Attempt to perform the upgrade, but as a non-owner
upgradeHelper.doUpgrade(newOwner, foxStakingProxy);

// confrim still on old version
assertEq(foxStakingV1.version(), expectedCurrentVersion);

// Change the owner
vm.startPrank(owner);
foxStakingV1.transferOwnership(newOwner);
vm.stopPrank();

// Check the new owner
assertEq(Ownable(foxStakingProxy).owner(), newOwner);

// Perform the upgrade
upgradeHelper.doUpgrade(newOwner, foxStakingProxy);

MockStakingV2 foxStakingV2 = MockStakingV2(foxStakingProxy);

// Check the new version
uint256 expectedUpgradedVersion = 2;
assertEq(foxStakingV2.version(), expectedUpgradedVersion);

// Check we can call the new function
string memory result = foxStakingV2.newV2Function();
assertEq(result, "new v2 function");
}
}

0 comments on commit d72a427

Please sign in to comment.