Skip to content

Commit dc29f06

Browse files
committed
refactor: verification script
1 parent a34d2fd commit dc29f06

File tree

5 files changed

+19
-79
lines changed

5 files changed

+19
-79
lines changed

packages/solidity-contracts/deploy/upgradeTest/prepareUpgrade.chain_state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
2828
implementation: contractDeployment.implementation,
2929
linkedData: {
3030
constructorArgs: contractDeployment.linkedData.constructorArgs,
31-
isProxy: true,
32-
isImplementation: false,
31+
isProxy: false,
32+
isImplementation: true,
3333
proxyAddress: contractDeployment.address,
3434
},
3535
});

packages/solidity-contracts/deployments/upgradeTest/FuelChainState.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@
579579
30,
580580
5
581581
],
582-
"isProxy": true,
583-
"isImplementation": false,
582+
"isProxy": false,
583+
"isImplementation": true,
584584
"proxyAddress": "0x13Df4fD5e07Fc9E4336aF443F9E70b9f2Ebf2Dc9"
585585
},
586586
"implementation": "0x3bd5C81a8Adf3355078Dc5F73c41d3194B316690"

packages/solidity-contracts/deployments/upgradeTest/upgradeTest.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/solidity-contracts/scripts/hardhat/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export * from './pause';
22
export * from './unpause';
33
export * from './grantRole';
4-
export * from './prepareUpgradeFuelChainState';
54
export * from './verifyDeployment';
65
export * from './depositETH';
76
export * from './depositToken';

packages/solidity-contracts/scripts/hardhat/verifyDeployment.ts

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import { task } from 'hardhat/config';
22
import { HardhatRuntimeEnvironment } from 'hardhat/types';
3-
import fs from 'fs';
4-
import path from 'path';
5-
6-
interface Deployment {
7-
contractName: string;
8-
address: string;
9-
args: any[];
10-
isProxy?: boolean;
11-
isImplementation?: boolean;
12-
proxyAddress?: string;
13-
}
14-
15-
const BLOCKS_PER_COMMIT_INTERVAL = 30;
16-
const TIME_TO_FINALIZE = 5;
17-
const COMMIT_COOLDOWN = TIME_TO_FINALIZE;
183

194
task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
205
async (taskArgs: any, hre: HardhatRuntimeEnvironment): Promise<void> => {
@@ -23,41 +8,15 @@ task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
238
`Verifying contract bytecode on ${network}:${hre.network.config.chainId}...`
249
);
2510

26-
const deploymentsFile = path.join(`deployments/${network}/${network}.json`);
27-
if (!fs.existsSync(deploymentsFile)) {
28-
console.error(`Deployments file not found: ${deploymentsFile}`);
29-
return;
30-
}
31-
32-
const deployments: Deployment[] = JSON.parse(
33-
fs.readFileSync(deploymentsFile, 'utf8')
34-
);
11+
const deployments = await hre.deployments.all();
3512

36-
for (const deployment of deployments) {
37-
console.log(
38-
`\nVerifying ${deployment.contractName} (${deployment.address}):`
39-
);
13+
for (const [contractName, deployment] of Object.entries(deployments)) {
14+
console.log(`\nVerifying ${contractName} (${deployment.address}):`);
4015

4116
try {
42-
console.log(' Reading contract artifact...');
43-
const artifactPath = path.join(
44-
`artifacts/contracts/fuelchain/${deployment.contractName}.sol/${deployment.contractName}.json`
45-
);
46-
47-
if (!fs.existsSync(artifactPath)) {
48-
console.log(' Artifact not found. Compiling contracts...');
49-
await hre.run('compile');
50-
51-
if (!fs.existsSync(artifactPath)) {
52-
throw new Error(
53-
`Artifact not found even after compilation: ${artifactPath}`
54-
);
55-
}
56-
}
57-
5817
console.log('--- Fetching deployed bytecode...');
5918
let deployedBytecode: string;
60-
if (deployment.isProxy) {
19+
if (deployment.linkedData.isProxy) {
6120
const implementationAddress =
6221
await hre.upgrades.erc1967.getImplementationAddress(
6322
deployment.address
@@ -78,53 +37,45 @@ task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
7837

7938
console.log('--- Deploying contract locally...');
8039
const ContractFactory = await localHardhat.ethers.getContractFactory(
81-
deployment.contractName
40+
contractName
8241
);
8342
let localAddress: string;
84-
if (deployment.isProxy) {
43+
if (deployment.linkedData.isProxy) {
8544
const localContract = await localHardhat.upgrades.deployProxy(
8645
ContractFactory,
8746
[],
8847
{
8948
kind: 'uups',
9049
initializer: 'initialize',
91-
constructorArgs: [
92-
TIME_TO_FINALIZE,
93-
BLOCKS_PER_COMMIT_INTERVAL,
94-
COMMIT_COOLDOWN,
95-
],
50+
constructorArgs: deployment.linkedData.constructorArgs,
9651
}
9752
);
9853
await localContract.waitForDeployment();
9954
localAddress = await localContract.getAddress();
100-
} else if (deployment.isImplementation) {
55+
} else if (deployment.linkedData.isImplementation) {
10156
console.log('--- Validating Upgrade...');
10257
await localHardhat.upgrades.validateUpgrade(
103-
deployment.proxyAddress as string,
58+
deployment.linkedData.proxyAddress as string,
10459
ContractFactory,
10560
{
10661
kind: 'uups',
107-
constructorArgs: [
108-
TIME_TO_FINALIZE,
109-
BLOCKS_PER_COMMIT_INTERVAL,
110-
COMMIT_COOLDOWN,
111-
],
62+
constructorArgs: deployment.linkedData.constructorArgs,
11263
}
11364
);
11465

11566
console.log('--- Upgrade success');
11667
localAddress = deployment.address;
11768
} else {
11869
const localContract = await ContractFactory.deploy(
119-
...deployment.args
70+
...deployment.linkedData.constructorArgs
12071
);
12172
await localContract.deployed();
12273
localAddress = await localContract.getAddress();
12374
}
12475

12576
console.log('--- Fetching local deployment bytecode...');
12677
let localBytecode: string;
127-
if (deployment.isProxy) {
78+
if (deployment.linkedData.isProxy) {
12879
const localImplementationAddress =
12980
await localHardhat.upgrades.erc1967.getImplementationAddress(
13081
localAddress
@@ -153,17 +104,17 @@ task('verify-deployment', 'Verifies the deployed contract bytecode').setAction(
153104
hre.ethers.keccak256(localBytecode)
154105
) {
155106
console.log(
156-
`✅ ${deployment.contractName} (${deployment.address}): Bytecode verified successfully`
107+
`✅ ${contractName} (${deployment.address}): Bytecode verified successfully`
157108
);
158109
} else {
159110
console.log(
160-
`❌ ${deployment.contractName} (${deployment.address}): Bytecode mismatch`
111+
`❌ ${contractName} (${deployment.address}): Bytecode mismatch`
161112
);
162113
throw new Error('Bytecode mismatch');
163114
}
164115
} catch (error) {
165116
console.log(
166-
`❌ ${deployment.contractName} (${deployment.address}): Verification failed`
117+
`❌ ${contractName} (${deployment.address}): Verification failed`
167118
);
168119
console.error(` Error: ${error.message}`);
169120
}

0 commit comments

Comments
 (0)