Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds test to show changing owner and upgrade after #68

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}