From 5a883117dbaf28b0af9d2b53abd288075f653ae3 Mon Sep 17 00:00:00 2001 From: AlienTornadosaurusHex <> Date: Sat, 27 May 2023 20:53:48 +0000 Subject: [PATCH] add total gas calculation Signed-off-by: AlienTornadosaurusHex <> --- deploy/deployPatch.js | 4 ++-- deploy/deployRegistryImplementation.js | 2 +- package.json | 3 +++ test/patch/patch.test.js | 18 +++++++++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/deploy/deployPatch.js b/deploy/deployPatch.js index 57cb2e6..c582bb9 100644 --- a/deploy/deployPatch.js +++ b/deploy/deployPatch.js @@ -54,9 +54,9 @@ function timeout(seconds) { const promptMessageBase = (middle) => `\n${middle}\n\nAre you sure you would like to continue? (y/n): ` async function deploy() { - if (process.env.STAKING_PROXY_ADDRESS === "") throw Error('Missing STAKING_PROXY_ADDRESS.') + if (process.env.STAKING_PROXY_ADDRESS === '') throw Error('Missing STAKING_PROXY_ADDRESS.') - if (process.env.REGISTRY_IMPL_ADDRESS === "") throw Error('Missing REGISTRY_IMPL_ADDRESS.') + if (process.env.REGISTRY_IMPL_ADDRESS === '') throw Error('Missing REGISTRY_IMPL_ADDRESS.') const signer = await ethers.getSigner() diff --git a/deploy/deployRegistryImplementation.js b/deploy/deployRegistryImplementation.js index e41b7bc..3c3c0c5 100644 --- a/deploy/deployRegistryImplementation.js +++ b/deploy/deployRegistryImplementation.js @@ -56,7 +56,7 @@ function timeout(seconds) { const promptMessageBase = (middle) => `\n${middle}\n\nAre you sure you would like to continue? (y/n): ` async function deploy() { - if (process.env.STAKING_PROXY_ADDRESS === "") throw Error('Missing STAKING_PROXY_ADDRESS.') + if (process.env.STAKING_PROXY_ADDRESS === '') throw Error('Missing STAKING_PROXY_ADDRESS.') const signer = await ethers.getSigner() diff --git a/package.json b/package.json index 902eb3e..4935e54 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "contracts/*" ], "scripts": { + "deploy:patch": "yarn hardhat --network mainnet run deploy/deployPatch.js", + "deploy:staking": "yarn hardhat --network mainnet run deploy/deployStaking.js", + "deploy:registry": "yarn hardhat --network mainnet run deploy/deployRegistryImplementation.js", "eslint": "eslint --ext .js --ignore-path .gitignore .", "prettier:check": "prettier --check . --config .prettierrc", "prettier:fix": "prettier --write . --config .prettierrc", diff --git a/test/patch/patch.test.js b/test/patch/patch.test.js index a8b3bab..e7b946a 100644 --- a/test/patch/patch.test.js +++ b/test/patch/patch.test.js @@ -66,6 +66,8 @@ describe('Gov Exploit Patch Upgrade Tests', () => { let registryImplementation let staking + let totalGas = BigNumber.from(0) + let exploit = { hacker: undefined, salt: '00000000006578706c6f6974', // hex "exploit", hacker addrs must be prepended @@ -158,8 +160,12 @@ describe('Gov Exploit Patch Upgrade Tests', () => { staking = await stakingDeployer.deploy(config.governance, config.TORN, config.registry) + totalGas = totalGas.add((await staking.deployTransaction.wait()).cumulativeGasUsed) + staking = await proxyDeployer.deploy(staking.address, governance.address, []) + totalGas = totalGas.add((await staking.deployTransaction.wait()).cumulativeGasUsed) + registryImplementation = await registryDeployer.deploy( config.TORN, config.governance, @@ -168,6 +174,8 @@ describe('Gov Exploit Patch Upgrade Tests', () => { config.feeManager, ) + totalGas = totalGas.add((await registryImplementation.deployTransaction.wait()).cumulativeGasUsed) + exploit.address = await metamorphicFactory.findMetamorphicContractAddress(exploit.salt) // Snapshot @@ -175,6 +183,10 @@ describe('Gov Exploit Patch Upgrade Tests', () => { snapshotId = await takeSnapshot() }) + after(() => { + console.log('\n⛽ Total gas used => ', totalGas.toNumber()) + }) + describe('Integrative: Patched Governance', () => { after(async () => { await revertSnapshot(snapshotId) @@ -192,6 +204,8 @@ describe('Gov Exploit Patch Upgrade Tests', () => { const proposal = await proposalDeployer.deploy(staking.address, registryImplementation.address) + totalGas = totalGas.add((await proposal.deployTransaction.wait()).cumulativeGasUsed) + // Propose await governance.propose(proposal.address, 'PATCH') @@ -216,7 +230,9 @@ describe('Gov Exploit Patch Upgrade Tests', () => { await ethers.provider.send('evm_mine', []) - await governance.execute(proposalId) + const response = await governance.execute(proposalId) + + totalGas = totalGas.add((await response.wait()).cumulativeGasUsed) expect(await torn.balanceOf(await governance.Staking())).to.equal(pE('94092'))