Skip to content

Commit 1c541c4

Browse files
committed
add verify script for verifying a whole spec file
1 parent 88a71fa commit 1c541c4

File tree

4 files changed

+61
-21
lines changed

4 files changed

+61
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@open-ibc/vibc-core-smart-contracts",
3-
"version": "2.1.11",
3+
"version": "2.1.12",
44
"main": "dist/index.js",
55
"bin": {
66
"verify-vibc-core-smart-contracts": "./dist/scripts/verify-contract-script.js",

specs/evm.accounts.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# These accounts are derived from a test mnemonic by Anvil/Hardhat and used for testing purposes only.
22
- name: 'KEY_POLYMER'
3-
privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
3+
privateKey: '{{DEPLOYER_PRIVATE_KEY}}'
4+
45

56
# Dapp accounts
67
- name: 'KEY_DAPP1'
7-
privateKey: '0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1'
8+
privateKey: '{{ DAPP_PRIVATE_KEY_1 }}'
89
- name: 'KEY_DAPP2'
9-
privateKey: '0xb0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773'
10+
privateKey: '{{ DAPP_PRIVATE_KEY_2 }}'
1011
- name: 'KEY_DAPP3'
11-
privateKey: '0x829e924fdf021ba3dbbc4225edfece9aca04b929d6e75613329ca6f1d31c0bb4'
12+
privateKey: '{{ DAPP_PRIVATE_KEY_2 }}'

src/scripts/verify-contract-script.ts

+50-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
#!/usr/bin/env node
22
import {
3+
ChainFolder,
4+
parseObjFromFile,
35
parseVerifyArgsFromCLI,
46
readFromDeploymentFile,
57
readMetadata,
68
} from "../utils/io";
79
import { $, cd } from "zx";
810
import { MODULE_ROOT_PATH } from "../utils/constants";
9-
/**
10-
* Take a deployment name, and verify the result to blockscout api
11-
*/
12-
async function main() {
13-
const { deploymentName, verifierUrl, chainFolder, etherscanApiKey } =
14-
await parseVerifyArgsFromCLI();
11+
import { Logger } from "winston";
12+
import { getMainLogger } from "../utils/cli";
13+
import { ContractItemSchema } from "../evm/schemas/contract";
14+
import { loadContractUpdateRegistry } from "../evm/schemas/contractUpdate";
1515

16+
const verifyContract = async (
17+
deploymentName: string,
18+
chainFolder: ChainFolder,
19+
etherscanApiKey: string,
20+
verifierUrl: string,
21+
logger: Logger
22+
) => {
1623
// Read deployment file, so that we can find path to artifact
1724
const deployment = await readFromDeploymentFile(deploymentName, chainFolder);
1825
const metadata = await readMetadata(deployment.factory);
@@ -27,7 +34,6 @@ async function main() {
2734
`${etherscanApiKey}`,
2835
`--verifier-url=${verifierUrl}`,
2936
];
30-
3137
// Find libraries into string that foundry verification expects if there are any
3238
let libraries: Record<string, string> | null = null;
3339
if (deployment.libraries && deployment.libraries.length > 0) {
@@ -37,7 +43,7 @@ async function main() {
3743
});
3844
}
3945

40-
console.log(
46+
logger.info(
4147
`verifying ${deploymentName}'s deployment with ${deployment.factory} ${
4248
libraries ? `and libraries ${libraries}` : ``
4349
}`
@@ -49,10 +55,44 @@ async function main() {
4955
try {
5056
command = await $`forge verify-contract ${args} 2>&1 | tee verify-out.txt`; // command = await $`cd ${MODULE_ROOT_PATH} && forge verify-contract ${
5157
} catch (e) {
52-
console.log("error ", e);
58+
logger.error("error ", e);
5359
}
5460

55-
console.log("verification result ", command);
61+
logger.info("verification result ", command);
62+
};
63+
/**
64+
* Take a deployment name, and verify the result to blockscout api
65+
*/
66+
async function main() {
67+
const { verifierUrl, chainFolder, etherscanApiKey, updateSpecs } =
68+
await parseVerifyArgsFromCLI();
69+
70+
// Fetch spec from contract
71+
72+
const contractUpdates = loadContractUpdateRegistry(
73+
parseObjFromFile(updateSpecs)
74+
);
75+
76+
const logger = getMainLogger();
77+
for (const contractUpdate of contractUpdates.values()) {
78+
const parsed = ContractItemSchema.safeParse(contractUpdate);
79+
if (parsed.success) {
80+
// Only try to verify contractName if it matches the deploymentName
81+
try {
82+
await verifyContract(
83+
parsed.data.name,
84+
chainFolder,
85+
etherscanApiKey,
86+
verifierUrl,
87+
logger
88+
);
89+
} catch (e) {
90+
logger.error(
91+
`Failed to verify contract ${parsed.data.name} with error: ${e}`
92+
);
93+
}
94+
}
95+
}
5696
}
5797

5898
main();

src/utils/io.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
DEPLOYMENT_ENVIRONMENT,
2121
ANVIL_PORT,
2222
UPGRADE_SPECS_PATH,
23+
UPDATE_SPECS_PATH,
2324
} from "./constants";
2425
import yargs from "yargs/yargs";
2526
import { hideBin } from "yargs/helpers";
@@ -389,15 +390,11 @@ export const parseVerifyArgsFromCLI = async () => {
389390
const deploymentEnvironment =
390391
(argv1.DEPLOYMENT_ENVIRONMENT as string) || DEPLOYMENT_ENVIRONMENT; // Needed to search for deployment
391392

393+
const updateSpecs = (argv1.UPDATE_SPECS_PATH as string) || UPDATE_SPECS_PATH;
394+
392395
if (!verifierUrl) {
393396
throw new Error(`Verifier URL not provided`);
394397
}
395-
if (!deploymentName) {
396-
throw new Error(`Deployment name not provided`);
397-
}
398-
if (!rpcUrl) {
399-
throw new Error(`RPC url needed`);
400-
}
401398

402399
const chainFolderParse = ChainFolderSchema.safeParse({
403400
chainId,
@@ -416,5 +413,7 @@ export const parseVerifyArgsFromCLI = async () => {
416413
chainFolder: chainFolderParse.data,
417414
rpcUrl,
418415
etherscanApiKey,
416+
updateSpecs,
417+
args: argv1,
419418
};
420419
};

0 commit comments

Comments
 (0)