Skip to content

Commit

Permalink
fix upgradeable contract and health tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanzhelyazkov committed Aug 21, 2024
1 parent 0ec0282 commit 620826e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
3 changes: 3 additions & 0 deletions contracts/utility/Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ abstract contract Upgradeable is IUpgradeable, AccessControlEnumerableUpgradeabl
*/
function postUpgrade(bytes calldata data) external {
uint16 initializations = _initializations + 1;
if (initializations < version()) {
initializations = version();
}
if (initializations != version()) {
revert AlreadyInitialized();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/vortex/CarbonVortex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable,
* @inheritdoc Upgradeable
*/
function version() public pure override(IVersioned, Upgradeable) returns (uint16) {
return 1;
return 2;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion data/named-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const TestNamedAccounts = {
...getAddress(mantle, '0xf89d7b9c864f589bbF53a82105107622B35EaA40')
},
daiWhale: {
...getAddress(mainnet, '0x66F62574ab04989737228D18C3624f7FC1edAe14'),
...getAddress(mainnet, '0xD1668fB5F690C59Ab4B0CAbAd0f8C1617895052B'),
...getAddress(base, '0xe9b14a1Be94E70900EDdF1E22A4cB8c56aC9e10a'),
...getAddress(arbitrum, '0xd85E038593d7A098614721EaE955EC2022B9B91B'),
...getAddress(mantle, ZERO_ADDRESS)
Expand Down
10 changes: 9 additions & 1 deletion deploy/scripts/network/0002-Voucher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deployProxy, InstanceName, setDeploymentMetadata } from '../../../utils/Deploy';
import { deployProxy, execute, InstanceName, setDeploymentMetadata } from '../../../utils/Deploy';
import { VOUCHER_URI } from '../../../utils/Constants';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
Expand All @@ -16,6 +16,14 @@ const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironm
}
);

// Call post upgrade (required once per deployment)
await execute({
name: InstanceName.Voucher,
methodName: 'postUpgrade',
args: ["0x"],
from: deployer
});

return true;
};

Expand Down
8 changes: 5 additions & 3 deletions deploy/tests/mainnet/carbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ import { ethers, getNamedAccounts } from 'hardhat';
let carbonVortex: CarbonVortex;

let daoMultisig: SignerWithAddress;
let oldVortex: string;

shouldHaveGap('CarbonController');
shouldHaveGap('Pairs', '_lastPairId');
shouldHaveGap('Strategies', '_strategyCounter');
shouldHaveGap('Voucher', '_useGlobalURI');
shouldHaveGap('CarbonVortex', '_totalBurned');
shouldHaveGap('CarbonVortex', '_totalCollected');
shouldHaveGap('CarbonPOL', '_marketPriceMultiply');

before(async () => {
({ daoMultisig } = await getNamedSigners());
({ oldVortex } = await getNamedAccounts());
});

beforeEach(async () => {
Expand All @@ -74,8 +76,8 @@ import { ethers, getNamedAccounts } from 'hardhat';
await expectRoleMembers(voucher, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]);
await expectRoleMembers(carbonVortex, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]);

// expect fee burner to have fee manager role in Carbon
await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [carbonVortex.address]);
// expect carbon vortex to have fee manager role in Carbon
await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [oldVortex, carbonVortex.address]);

// expect carbonController to have minter role in voucher
await expectRoleMembers(voucher, Roles.Voucher.ROLE_MINTER, [carbonController.address]);
Expand Down
6 changes: 6 additions & 0 deletions deploy/tests/network/0002-voucher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describeDeployment(__filename, () => {
const tx = await voucherImpl.initialize(true, '1', '1', { gasLimit: 6000000 });
await expect(tx.wait()).to.be.reverted;
});

it('cannot call postUpgrade on voucher', async () => {
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted)
const tx = await voucher.postUpgrade("0x", { gasLimit: 6000000 });
await expect(tx.wait()).to.be.reverted;
});
});
6 changes: 6 additions & 0 deletions deploy/tests/network/0003-carbon-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ describeDeployment(__filename, () => {
const tx = await carbonControllerImpl.initialize({ gasLimit: 6000000 });
await expect(tx.wait()).to.be.reverted;
});

it('cannot call postUpgrade on carbon controller', async () => {
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted)
const tx = await carbonController.postUpgrade("0x", { gasLimit: 6000000 });
await expect(tx.wait()).to.be.reverted;
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test:nightly": "NIGHTLY=1 CI=1 forge test",
"test:deploy": "TEST_FORK=1 ./deployments/run-fork.sh HARDHAT_NETWORK=tenderly mocha --require hardhat/register --extension ts --recursive --exit --timeout 600000 --bail --no-exit 'deploy/tests/network/**/*.ts'",
"test:deploy:mainnet": "TEST_FORK=1 ./deployments/run-fork.sh HARDHAT_NETWORK=tenderly mocha --require hardhat/register --extension ts --recursive --exit --timeout 600000 --bail --no-exit 'deploy/tests/mainnet/**/*.ts'",
"test:health": "pnpm test:deploy",
"test:health": "pnpm test:deploy:mainnet",
"export:storage": "pnpm cleanbuild && hardhat run deployments/storage-layout.ts",
"deploy:prepare": "rm -rf ./node_modules && rm pnpm-lock.yaml && pnpm install && pnpm cleanbuild",
"deploy:network": "./deployments/run-network.sh hardhat deploy",
Expand Down

0 comments on commit 620826e

Please sign in to comment.