From 240acb3c338053e48117d46c921454a3ef0223d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Mon, 4 Nov 2024 17:37:00 +0100 Subject: [PATCH] refactor: verification scripts --- migrations/scripts/3_framework.js | 8 ++++++ scripts/verify-apps.js | 29 --------------------- scripts/verify-core.js | 33 ------------------------ scripts/verify-impls.js | 32 ----------------------- scripts/verify-libs.js | 29 --------------------- scripts/verify.js | 43 +++++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 123 deletions(-) delete mode 100644 scripts/verify-apps.js delete mode 100644 scripts/verify-core.js delete mode 100644 scripts/verify-impls.js delete mode 100644 scripts/verify-libs.js create mode 100644 scripts/verify.js diff --git a/migrations/scripts/3_framework.js b/migrations/scripts/3_framework.js index 22da5507..67275797 100644 --- a/migrations/scripts/3_framework.js +++ b/migrations/scripts/3_framework.js @@ -474,6 +474,14 @@ function linkBaseLibs (bytecode, baseLibs, networkArtifacts) { return bytecode } +async function settleArtifactAddress(addresses, network, domain, artifact, addr) { + if (!addresses[network]) addresses[network] = {} + if (!addresses[network][domain]) addresses[network][domain] = {} + addresses[network][domain][artifact] = addr + await utils.overwriteJsonFile("./migrations/addresses.json", addresses) + return addresses +} + async function unfoldTargetSpecs (domain, target, targetBase, from, network, networkArtifacts, networkSpecs, ancestors) { if (!ancestors) ancestors = [] else if (ancestors.includes(targetBase)) { diff --git a/scripts/verify-apps.js b/scripts/verify-apps.js deleted file mode 100644 index 5b8d07a9..00000000 --- a/scripts/verify-apps.js +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env node - -const settings = require("../settings") -const utils = require("../src/utils") - -if (process.argv.length < 3) { - console.error("\nUsage:\n\n$ node ./scripts/verify-apps.js : ...OPTIONAL_ARGS\n") - process.exit(0) -} - -const network = process.argv[2].toLowerCase().replaceAll(".", ":") - -const header = network.toUpperCase() + " APPS" -console.info() -console.info(header) -console.info("=".repeat(header.length)) -console.info() - -const artifacts = settings.getArtifacts(network) -const apps = [ - artifacts.WitRandomness, -] -const constructorArgs = require("../migrations/constructorArgs.json") -if (!constructorArgs[network]) constructorArgs[network] = {} -for (const index in apps) { - utils.traceVerify(network, `${apps[index]} --forceConstructorArgs string:${ - constructorArgs[network][apps[index]] || constructorArgs?.default[apps[index]] - }`) -} diff --git a/scripts/verify-core.js b/scripts/verify-core.js deleted file mode 100644 index 88f32d19..00000000 --- a/scripts/verify-core.js +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env node - -const settings = require("../settings") -const utils = require("../src/utils") - -if (process.argv.length < 3) { - console.error("\nUsage:\n\n$ node ./scripts/verify-core.js : ...OPTIONAL_ARGS\n") - process.exit(0) -} - -const network = process.argv[2].toLowerCase().replaceAll(".", ":") - -const header = network.toUpperCase() + " CORE" -console.info() -console.info(header) -console.info("=".repeat(header.length)) -console.info() - -utils.traceVerify(network, settings.getArtifacts(network).WitnetDeployer) -utils.traceVerify(network, "WitnetProxy") - -const addresses = require("../migrations/addresses.json") -const singletons = [ - "WitOracle", - "WitPriceFeeds", - "WitOracleRadonRegistry", - "WitOracleRequestFactory", -] -for (const index in singletons) { - utils.traceVerify(network, `WitnetProxy@${ - addresses[network][singletons[index]] || addresses.default[singletons[index]] - } --custom-proxy WitnetProxy`) -} diff --git a/scripts/verify-impls.js b/scripts/verify-impls.js deleted file mode 100644 index bd7bc4c1..00000000 --- a/scripts/verify-impls.js +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env node - -const settings = require("../settings") -const utils = require("../src/utils") - -if (process.argv.length < 3) { - console.error("\nUsage:\n\n$ node ./scripts/verify-impls.js : ...OPTIONAL_ARGS\n") - process.exit(0) -} - -const network = process.argv[2].toLowerCase().replaceAll(".", ":") - -const header = network.toUpperCase() -console.info() -console.info(header) -console.info("=".repeat(header.length)) -console.info() - -const artifacts = settings.getArtifacts(network) -const impls = [ - artifacts.WitOracle, - artifacts.WitPriceFeeds, - artifacts.WitOracleRadonRegistry, - artifacts.WitOracleRequestFactory, -] -const constructorArgs = require("../migrations/constructorArgs.json") -if (!constructorArgs[network]) constructorArgs[network] = {} -for (const index in impls) { - utils.traceVerify(network, `${impls[index]} --forceConstructorArgs string:${ - constructorArgs[network][impls[index]] || constructorArgs?.default[impls[index]] - } --verifiers etherscan,sourcify`) -} diff --git a/scripts/verify-libs.js b/scripts/verify-libs.js deleted file mode 100644 index 93bf24c5..00000000 --- a/scripts/verify-libs.js +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env node - -const settings = require("../settings") -const utils = require("../src/utils") - -if (process.argv.length < 3) { - console.error("\nUsage:\n\n$ node ./scripts/verify-libs.js : ...OPTIONAL_ARGS\n") - process.exit(0) -} - -const network = process.argv[2].toLowerCase().replaceAll(".", ":") - -const header = network.toUpperCase() + " LIBS" -console.info() -console.info(header) -console.info("=".repeat(header.length)) -console.info() - -const addresses = require("../migrations/addresses.json") -const artifacts = settings.getArtifacts(network) -const libs = [ - artifacts.WitOracleRadonEncodingLib, - artifacts.WitOracleResultErrorsLib, - artifacts.WitOracleDataLib, - artifacts.WitPriceFeedsDataLib, -] -for (const index in libs) { - utils.traceVerify(network, `${libs[index]}@${addresses[network][libs[index]]}`) -} diff --git a/scripts/verify.js b/scripts/verify.js new file mode 100644 index 00000000..88e9ef79 --- /dev/null +++ b/scripts/verify.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +const addresses = require("../migrations/addresses.json") +const constructorArgs = require("../migrations/constructorArgs.json") +const settings = require("../settings") +const utils = require("../src/utils") + +if (process.argv.length < 3) { + console.error("\nUsage:\n\n$ node ./scripts/verify-core.js : ...OPTIONAL_ARGS\n") + process.exit(0) +} + +const network = process.argv[2].toLowerCase().replaceAll(".", ":") +const networkArtifacts = settings.getArtifacts(network) + +utils.traceVerify(network, networkArtifacts?.WitnetDeployer) + +const framework = { + libs: networkArtifacts.libs, + core: networkArtifacts.core, + apps: networkArtifacts.apps, +} + +for (const domain in framework) { + const header = network.toUpperCase() + " " + domain.toUpperCase() + console.info() + console.info(header) + console.info("=".repeat(header.length)) + console.info() + for (const base in framework[domain]) { + const impl = framework[domain][base] + if (utils.isUpgradableArtifact(impl)) { + const addr = utils.getNetworkArtifactAddress(network, domain, addresses, base) + utils.traceVerify(network, `WitnetProxy@${addr} --custom-proxy WitnetProxy`) + } + const forceConstructorArgs = constructorArgs[network][impl] || constructorArgs?.default[impl] + if (forceConstructorArgs) { + utils.traceVerify(network, `${impl} --forceConstructorArgs string:${forceConstructorArgs} --verifiers etherscan,sourcify`) + } else { + utils.traceVerify(network, `${impl} --verifiers etherscan,sourcify`) + } + } +}