From 560169c7c3cf18c685da0391b7919a9c4203346f Mon Sep 17 00:00:00 2001 From: Noisekit Date: Fri, 17 Nov 2023 15:17:12 +0800 Subject: [PATCH] Get ipfs url from build logs --- .circleci/config.yml | 4 +-- e2e/fetch-local-deployment.js | 52 +++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8f9df2706..414af0e58 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -133,7 +133,7 @@ jobs: --chain-id 84531 \ --provider-url https://base-goerli.infura.io/v3/$INFURA_API_KEY \ --write-script ./e2e/upgrade--base-goerli-andromeda.json \ - --write-script-format json + --write-script-format json | tee ./e2e/cannon-build.log yarn prettier --write ./e2e/upgrade--base-goerli-andromeda.json - store_artifacts: @@ -141,7 +141,7 @@ jobs: - run: name: "Generate deployments" - command: node e2e/fetch-local-deployment.js 84531 omnibus-base-goerli-andromeda.toml + command: node e2e/fetch-local-deployment.js ./e2e/cannon-build.log - store_artifacts: path: "./e2e/deployments" diff --git a/e2e/fetch-local-deployment.js b/e2e/fetch-local-deployment.js index ae5e19d85..67e1fe367 100755 --- a/e2e/fetch-local-deployment.js +++ b/e2e/fetch-local-deployment.js @@ -3,9 +3,7 @@ const os = require('os'); const path = require('path'); const fs = require('fs/promises'); -const toml = require('@iarna/toml'); const { ethers } = require('ethers'); -const { LocalRegistry } = require('@usecannon/cli/dist/src/registry'); const { CliLoader } = require('@usecannon/cli/dist/src/loader'); const CANNON_DIRECTORY = path.join(os.homedir(), '.local', 'share', 'cannon'); @@ -15,14 +13,12 @@ const fgGreen = '\x1b[32m'; const fgYellow = '\x1b[33m'; const fgCyan = '\x1b[36m'; -const [chainId, deploymentFile] = process.argv.slice(2); -if (!chainId || !deploymentFile) { - console.error(`${fgRed}ERROR: Expected 2 arguments${fgReset}`); +const [buildLog] = process.argv.slice(2); +if (!buildLog) { + console.error(`${fgRed}ERROR: Expected 1 argument${fgReset}`); + console.error(`Usage: ${fgGreen}node e2e/fetch-local-deployment.js ${fgCyan}buildLog${fgReset}`); console.error( - `Usage: ${fgGreen}node e2e/fetch-local-deployment.js ${fgYellow}chainId ${fgCyan}deploymentFile${fgReset}` - ); - console.error( - `Example: ${fgGreen}node e2e/fetch-local-deployment.js ${fgYellow}84531 ${fgCyan}omnibus-base-goerli-andromeda.toml${fgReset}` + `Example: ${fgGreen}node e2e/fetch-local-deployment.js ${fgCyan}e2e/cannon-build.log${fgReset}` ); process.exit(1); } @@ -32,36 +28,40 @@ function readableAbi(abi) { } async function run() { - const config = await fs.readFile(deploymentFile, 'utf8'); - const { name, version, setting } = toml.parse(config); - const preset = setting?.target_preset?.defaultValue ?? 'main'; + console.log('Resolving Deployment Data URL from log', { buildLog }); + const log = await fs.readFile(buildLog, 'utf8'); - console.log('Resolving URL', { - packageRef: `${name}:${version}`, - variant: `${chainId}-${preset}`, - }); - const localRegistry = new LocalRegistry(CANNON_DIRECTORY); - const url = await await localRegistry.getUrl(`${name}:${version}`, `${chainId}-${preset}`); + const [, url] = log.match(/Deployment Data\s*│\s*(ipfs:\/\/Qm\S+)/im) || []; console.log(`Resolved URL:`, { url }); - console.log('Fetching deployment state', { url }); + const hash = CliLoader.getCacheHash(url); + console.log(`Resolved FileName hash:`, { hash }); + const deployments = JSON.parse( await fs.readFile(`${CANNON_DIRECTORY}/ipfs_cache/${CliLoader.getCacheHash(url)}.json`, 'utf8') ); await fs.mkdir(`${__dirname}/deployments`, { recursive: true }); - const snxAddress = setting?.snx_address?.defaultValue ?? ethers.constants.AddressZero; - await fs.writeFile( - `${__dirname}/deployments/snx.json`, - JSON.stringify({ address: snxAddress }, null, 2) - ); + const meta = { + chainId: deployments.chainId, + name: deployments.def.name, + version: deployments.def.version, + generator: deployments.generator, + timestamp: deployments.timestamp, + miscUrl: deployments.miscUrl, + }; + console.log('Generating deployments info for', meta); const system = deployments.state['provision.system'].artifacts.imports.system; + console.log('Writing', 'deployments/CoreProxy.json', { + address: system.contracts.CoreProxy.address, + }); await fs.writeFile( `${__dirname}/deployments/CoreProxy.json`, JSON.stringify( { + ...meta, address: system.contracts.CoreProxy.address, abi: readableAbi(system.contracts.CoreProxy.abi), }, @@ -75,10 +75,14 @@ async function run() { deployments?.state?.[`provision.${provisionStep}`]?.artifacts?.imports?.[provisionStep]; if (fakeCollateral) { const [, ticker] = fakeCollateral.contracts.MintableToken.constructorArgs; + console.log('Writing', `deployments/FakeCollateral${ticker}.json`, { + address: fakeCollateral.contracts.MintableToken.address, + }); await fs.writeFile( `${__dirname}/deployments/FakeCollateral${ticker}.json`, JSON.stringify( { + ...meta, address: fakeCollateral.contracts.MintableToken.address, abi: readableAbi(fakeCollateral.contracts.MintableToken.abi), },