From 504a297a13abeb739c112fe9d2f3e914e4beb83d Mon Sep 17 00:00:00 2001 From: Morty Date: Fri, 22 Nov 2024 16:28:44 +0800 Subject: [PATCH 1/2] feat: support contracts verification --- README.md | 26 ++++- src/commands/setup/configs.ts | 4 +- src/commands/setup/verify-contracts.ts | 132 +++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 src/commands/setup/verify-contracts.ts diff --git a/README.md b/README.md index a284607..744b905 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ USAGE - [`scrollsdk setup prep-charts`](#scrollsdk-setup-prep-charts) - [`scrollsdk setup push-secrets`](#scrollsdk-setup-push-secrets) - [`scrollsdk setup tls`](#scrollsdk-setup-tls) + - [`scrollsdk setup verify-contracts`](#scrollsdk-setup-verify-contracts) - [`scrollsdk test contracts`](#scrollsdk-test-contracts) - [`scrollsdk test dependencies`](#scrollsdk-test-dependencies) - [`scrollsdk test e2e`](#scrollsdk-test-e2e) @@ -523,7 +524,7 @@ DESCRIPTION EXAMPLES $ scrollsdk setup configs - $ scrollsdk setup configs --image-tag gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1 + $ scrollsdk setup configs --image-tag gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10 $ scrollsdk setup configs --configs-dir custom-configs ``` @@ -704,6 +705,29 @@ EXAMPLES _See code: [src/commands/setup/tls.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/tls.ts)_ +## `scrollsdk setup verify-contracts` + +Verify both L1/L2 contracts scource code on block chain explorer + +``` +USAGE + $ scrollsdk setup verify-contracts [--image-tag ] + +FLAGS + --image-tag= Specify the Docker image tag to use + +DESCRIPTION + Verify both L1/L2 contracts scource code on block chain explorer + +EXAMPLES + $ scrollsdk setup verify-contracts + + $ scrollsdk setup verify-contracts --image-tag verify-8ff2948aa2b9cbd24a7644b060097765a6faee10 +``` + +_See code: [src/commands/setup/configs.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/verify-contracts.ts)_ + + ## `scrollsdk test contracts` Test contracts by checking deployment and initialization diff --git a/src/commands/setup/configs.ts b/src/commands/setup/configs.ts index c388a2d..102e4aa 100644 --- a/src/commands/setup/configs.ts +++ b/src/commands/setup/configs.ts @@ -14,7 +14,7 @@ export default class SetupConfigs extends Command { static override examples = [ '<%= config.bin %> <%= command.id %>', - '<%= config.bin %> <%= command.id %> --image-tag gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1', + '<%= config.bin %> <%= command.id %> --image-tag gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10', '<%= config.bin %> <%= command.id %> --configs-dir custom-configs', ] @@ -465,7 +465,7 @@ export default class SetupConfigs extends Command { } private async getDockerImageTag(providedTag: string | undefined): Promise { - const defaultTag = 'gen-configs-2eba3d2c418b16f4a66d9baadeb1c1bafdca81b1' + const defaultTag = 'gen-configs-8ff2948aa2b9cbd24a7644b060097765a6faee10' if (!providedTag) { return defaultTag diff --git a/src/commands/setup/verify-contracts.ts b/src/commands/setup/verify-contracts.ts new file mode 100644 index 0000000..d1aeabf --- /dev/null +++ b/src/commands/setup/verify-contracts.ts @@ -0,0 +1,132 @@ +import {Command, Flags} from '@oclif/core' +import chalk from 'chalk' +import { select } from '@inquirer/prompts' +import Docker from 'dockerode' + +export default class ContractsVerification extends Command { + static override description = 'Set up contracts verification' + + static override examples = [ + '<%= config.bin %> <%= command.id %>', + '<%= config.bin %> <%= command.id %> --image-tag verify-8ff2948aa2b9cbd24a7644b060097765a6faee10', + ] + + static override flags = { + 'image-tag': Flags.string({ + description: 'Specify the Docker image tag to use', + required: false, + }), + } + + private async fetchDockerTags(): Promise { + try { + const response = await fetch( + 'https://registry.hub.docker.com/v2/repositories/scrolltech/scroll-stack-contracts/tags?page_size=100', + ) + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + const data = await response.json() + return data.results.map((tag: any) => tag.name).filter((tag: string) => tag.startsWith('verify')) + } catch (error) { + this.error(`Failed to fetch Docker tags: ${error}`) + } + } + + private async getDockerImageTag(providedTag: string | undefined): Promise { + const defaultTag = 'verify-8ff2948aa2b9cbd24a7644b060097765a6faee10' + + if (!providedTag) { + return defaultTag + } + + const tags = await this.fetchDockerTags() + + if (providedTag.startsWith('gen-configs-v') && tags.includes(providedTag)) { + return providedTag + } else if (providedTag.startsWith('v') && tags.includes(`verify-${providedTag}`)) { + return `verify-${providedTag}` + } else if (/^\d+\.\d+\.\d+$/.test(providedTag) && tags.includes(`verify-v${providedTag}`)) { + return `verify-v${providedTag}` + } + + const selectedTag = await select({ + message: 'Select a Docker image tag:', + choices: tags.map((tag) => ({name: tag, value: tag})), + }) + + return selectedTag + } + + private async runDockerCommand(imageTag: string): Promise { + const docker = new Docker() + const image = `scrolltech/scroll-stack-contracts:${imageTag}` + + try { + this.log(chalk.cyan('Pulling Docker Image...')) + // Pull the image if it doesn't exist locally + const pullStream = await docker.pull(image) + await new Promise((resolve, reject) => { + docker.modem.followProgress(pullStream, (err, res) => { + if (err) { + reject(err) + } else { + this.log(chalk.green('Image pulled successfully')) + resolve(res) + } + }) + }) + + this.log(chalk.cyan('Creating Docker Container...')) + // Create and run the container + const container = await docker.createContainer({ + Image: image, + Cmd: [], // Add any command if needed + HostConfig: { + Binds: [`${process.cwd()}:/contracts/volume`], + }, + }) + + this.log(chalk.cyan('Starting Container')) + await container.start() + + // Wait for the container to finish and get the logs + const stream = await container.logs({ + follow: true, + stdout: true, + stderr: true, + }) + + // Print the logs + stream.pipe(process.stdout) + + // Wait for the container to finish + await new Promise((resolve) => { + container.wait((err, data) => { + if (err) { + this.error(`Container exited with error: ${err}`) + } else if (data.StatusCode !== 0) { + this.error(`Container exited with status code: ${data.StatusCode}`) + } + resolve(null) + }) + }) + + // Remove the container + await container.remove() + } catch (error) { + this.error(`Failed to run Docker command: ${error}`) + } + } + + public async run(): Promise { + this.log(chalk.blue('Running docker command to contracts verification...')) + + const {flags} = await this.parse(ContractsVerification) + + const imageTag = await this.getDockerImageTag(flags['image-tag']) + this.log(chalk.blue(`Using Docker image tag: ${imageTag}`)) + + await this.runDockerCommand(imageTag) + } +} From 05bc4e25d3cbdb5b2887d400f1da7e38f8b1fd95 Mon Sep 17 00:00:00 2001 From: Morty Date: Fri, 22 Nov 2024 16:29:39 +0800 Subject: [PATCH 2/2] 0.1.1 --- README.md | 108 ++++++++++++++++++++++++--------------------------- package.json | 2 +- 2 files changed, 52 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 744b905..13204bc 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ $ npm install -g @scroll-tech/scroll-sdk-cli $ scrollsdk COMMAND running command... $ scrollsdk (--version) -@scroll-tech/scroll-sdk-cli/0.1.0 darwin-arm64 node-v20.13.1 +@scroll-tech/scroll-sdk-cli/0.1.1 darwin-arm64 node-v20.10.0 $ scrollsdk --help [COMMAND] USAGE $ scrollsdk COMMAND @@ -38,40 +38,35 @@ USAGE # Commands -- [Scroll SDK CLI](#scroll-sdk-cli) - - [Introduction](#introduction) - - [Other Scroll SDK Repos](#other-scroll-sdk-repos) -- [Usage](#usage) -- [Commands](#commands) - - [`scrollsdk help [COMMAND]`](#scrollsdk-help-command) - - [`scrollsdk helper activity`](#scrollsdk-helper-activity) - - [`scrollsdk helper clear-accounts`](#scrollsdk-helper-clear-accounts) - - [`scrollsdk helper derive-enode NODEKEY`](#scrollsdk-helper-derive-enode-nodekey) - - [`scrollsdk helper fund-accounts`](#scrollsdk-helper-fund-accounts) - - [`scrollsdk helper set-scalars`](#scrollsdk-helper-set-scalars) - - [`scrollsdk plugins`](#scrollsdk-plugins) - - [`scrollsdk plugins add PLUGIN`](#scrollsdk-plugins-add-plugin) - - [`scrollsdk plugins:inspect PLUGIN...`](#scrollsdk-pluginsinspect-plugin) - - [`scrollsdk plugins install PLUGIN`](#scrollsdk-plugins-install-plugin) - - [`scrollsdk plugins link PATH`](#scrollsdk-plugins-link-path) - - [`scrollsdk plugins remove [PLUGIN]`](#scrollsdk-plugins-remove-plugin) - - [`scrollsdk plugins reset`](#scrollsdk-plugins-reset) - - [`scrollsdk plugins uninstall [PLUGIN]`](#scrollsdk-plugins-uninstall-plugin) - - [`scrollsdk plugins unlink [PLUGIN]`](#scrollsdk-plugins-unlink-plugin) - - [`scrollsdk plugins update`](#scrollsdk-plugins-update) - - [`scrollsdk setup configs`](#scrollsdk-setup-configs) - - [`scrollsdk setup db-init`](#scrollsdk-setup-db-init) - - [`scrollsdk setup domains [FILE]`](#scrollsdk-setup-domains-file) - - [`scrollsdk setup gas-token`](#scrollsdk-setup-gas-token) - - [`scrollsdk setup gen-keystore`](#scrollsdk-setup-gen-keystore) - - [`scrollsdk setup prep-charts`](#scrollsdk-setup-prep-charts) - - [`scrollsdk setup push-secrets`](#scrollsdk-setup-push-secrets) - - [`scrollsdk setup tls`](#scrollsdk-setup-tls) - - [`scrollsdk setup verify-contracts`](#scrollsdk-setup-verify-contracts) - - [`scrollsdk test contracts`](#scrollsdk-test-contracts) - - [`scrollsdk test dependencies`](#scrollsdk-test-dependencies) - - [`scrollsdk test e2e`](#scrollsdk-test-e2e) - - [`scrollsdk test ingress`](#scrollsdk-test-ingress) +* [`scrollsdk help [COMMAND]`](#scrollsdk-help-command) +* [`scrollsdk helper activity`](#scrollsdk-helper-activity) +* [`scrollsdk helper clear-accounts`](#scrollsdk-helper-clear-accounts) +* [`scrollsdk helper derive-enode NODEKEY`](#scrollsdk-helper-derive-enode-nodekey) +* [`scrollsdk helper fund-accounts`](#scrollsdk-helper-fund-accounts) +* [`scrollsdk helper set-scalars`](#scrollsdk-helper-set-scalars) +* [`scrollsdk plugins`](#scrollsdk-plugins) +* [`scrollsdk plugins add PLUGIN`](#scrollsdk-plugins-add-plugin) +* [`scrollsdk plugins:inspect PLUGIN...`](#scrollsdk-pluginsinspect-plugin) +* [`scrollsdk plugins install PLUGIN`](#scrollsdk-plugins-install-plugin) +* [`scrollsdk plugins link PATH`](#scrollsdk-plugins-link-path) +* [`scrollsdk plugins remove [PLUGIN]`](#scrollsdk-plugins-remove-plugin) +* [`scrollsdk plugins reset`](#scrollsdk-plugins-reset) +* [`scrollsdk plugins uninstall [PLUGIN]`](#scrollsdk-plugins-uninstall-plugin) +* [`scrollsdk plugins unlink [PLUGIN]`](#scrollsdk-plugins-unlink-plugin) +* [`scrollsdk plugins update`](#scrollsdk-plugins-update) +* [`scrollsdk setup configs`](#scrollsdk-setup-configs) +* [`scrollsdk setup db-init`](#scrollsdk-setup-db-init) +* [`scrollsdk setup domains [FILE]`](#scrollsdk-setup-domains-file) +* [`scrollsdk setup gas-token`](#scrollsdk-setup-gas-token) +* [`scrollsdk setup gen-keystore`](#scrollsdk-setup-gen-keystore) +* [`scrollsdk setup prep-charts`](#scrollsdk-setup-prep-charts) +* [`scrollsdk setup push-secrets`](#scrollsdk-setup-push-secrets) +* [`scrollsdk setup tls`](#scrollsdk-setup-tls) +* [`scrollsdk setup verify-contracts`](#scrollsdk-setup-verify-contracts) +* [`scrollsdk test contracts`](#scrollsdk-test-contracts) +* [`scrollsdk test dependencies`](#scrollsdk-test-dependencies) +* [`scrollsdk test e2e`](#scrollsdk-test-e2e) +* [`scrollsdk test ingress`](#scrollsdk-test-ingress) ## `scrollsdk help [COMMAND]` @@ -116,7 +111,7 @@ DESCRIPTION Generate transactions on the specified network(s) to produce more blocks ``` -_See code: [src/commands/helper/activity.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/helper/activity.ts)_ +_See code: [src/commands/helper/activity.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/helper/activity.ts)_ ## `scrollsdk helper clear-accounts` @@ -141,7 +136,7 @@ DESCRIPTION Clear pending transactions and optionally transfer remaining funds on Layer 2 ``` -_See code: [src/commands/helper/clear-accounts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/helper/clear-accounts.ts)_ +_See code: [src/commands/helper/clear-accounts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/helper/clear-accounts.ts)_ ## `scrollsdk helper derive-enode NODEKEY` @@ -161,7 +156,7 @@ EXAMPLES $ scrollsdk helper derive-enode 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef ``` -_See code: [src/commands/helper/derive-enode.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/helper/derive-enode.ts)_ +_See code: [src/commands/helper/derive-enode.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/helper/derive-enode.ts)_ ## `scrollsdk helper fund-accounts` @@ -191,7 +186,7 @@ DESCRIPTION Fund L1 and L2 accounts for contracts ``` -_See code: [src/commands/helper/fund-accounts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/helper/fund-accounts.ts)_ +_See code: [src/commands/helper/fund-accounts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/helper/fund-accounts.ts)_ ## `scrollsdk helper set-scalars` @@ -215,7 +210,7 @@ DESCRIPTION Set commit and blob scalars for Scroll SDK ``` -_See code: [src/commands/helper/set-scalars.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/helper/set-scalars.ts)_ +_See code: [src/commands/helper/set-scalars.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/helper/set-scalars.ts)_ ## `scrollsdk plugins` @@ -529,7 +524,7 @@ EXAMPLES $ scrollsdk setup configs --configs-dir custom-configs ``` -_See code: [src/commands/setup/configs.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/configs.ts)_ +_See code: [src/commands/setup/configs.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/configs.ts)_ ## `scrollsdk setup db-init` @@ -560,7 +555,7 @@ EXAMPLES $ scrollsdk setup db-init --update-db-port=25061 ``` -_See code: [src/commands/setup/db-init.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/db-init.ts)_ +_See code: [src/commands/setup/db-init.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/db-init.ts)_ ## `scrollsdk setup domains [FILE]` @@ -584,7 +579,7 @@ EXAMPLES $ scrollsdk setup domains ``` -_See code: [src/commands/setup/domains.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/domains.ts)_ +_See code: [src/commands/setup/domains.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/domains.ts)_ ## `scrollsdk setup gas-token` @@ -601,7 +596,7 @@ EXAMPLES $ scrollsdk setup gas-token ``` -_See code: [src/commands/setup/gas-token.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/gas-token.ts)_ +_See code: [src/commands/setup/gas-token.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/gas-token.ts)_ ## `scrollsdk setup gen-keystore` @@ -623,7 +618,7 @@ EXAMPLES $ scrollsdk setup gen-keystore --no-accounts ``` -_See code: [src/commands/setup/gen-keystore.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/gen-keystore.ts)_ +_See code: [src/commands/setup/gen-keystore.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/gen-keystore.ts)_ ## `scrollsdk setup prep-charts` @@ -653,7 +648,7 @@ EXAMPLES $ scrollsdk setup prep-charts --skip-auth-check ``` -_See code: [src/commands/setup/prep-charts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/prep-charts.ts)_ +_See code: [src/commands/setup/prep-charts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/prep-charts.ts)_ ## `scrollsdk setup push-secrets` @@ -678,7 +673,7 @@ EXAMPLES $ scrollsdk setup push-secrets --values-dir custom-values ``` -_See code: [src/commands/setup/push-secrets.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/push-secrets.ts)_ +_See code: [src/commands/setup/push-secrets.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/push-secrets.ts)_ ## `scrollsdk setup tls` @@ -703,21 +698,21 @@ EXAMPLES $ scrollsdk setup tls --values-dir custom-values ``` -_See code: [src/commands/setup/tls.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/tls.ts)_ +_See code: [src/commands/setup/tls.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/tls.ts)_ ## `scrollsdk setup verify-contracts` -Verify both L1/L2 contracts scource code on block chain explorer +Set up contracts verification ``` USAGE $ scrollsdk setup verify-contracts [--image-tag ] FLAGS - --image-tag= Specify the Docker image tag to use + --image-tag= Specify the Docker image tag to use DESCRIPTION - Verify both L1/L2 contracts scource code on block chain explorer + Set up contracts verification EXAMPLES $ scrollsdk setup verify-contracts @@ -725,8 +720,7 @@ EXAMPLES $ scrollsdk setup verify-contracts --image-tag verify-8ff2948aa2b9cbd24a7644b060097765a6faee10 ``` -_See code: [src/commands/setup/configs.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/setup/verify-contracts.ts)_ - +_See code: [src/commands/setup/verify-contracts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/setup/verify-contracts.ts)_ ## `scrollsdk test contracts` @@ -745,7 +739,7 @@ DESCRIPTION Test contracts by checking deployment and initialization ``` -_See code: [src/commands/test/contracts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/test/contracts.ts)_ +_See code: [src/commands/test/contracts.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/test/contracts.ts)_ ## `scrollsdk test dependencies` @@ -762,7 +756,7 @@ DESCRIPTION Check for required dependencies ``` -_See code: [src/commands/test/dependencies.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/test/dependencies.ts)_ +_See code: [src/commands/test/dependencies.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/test/dependencies.ts)_ ## `scrollsdk test e2e` @@ -785,7 +779,7 @@ DESCRIPTION Test contracts by checking deployment and initialization ``` -_See code: [src/commands/test/e2e.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/test/e2e.ts)_ +_See code: [src/commands/test/e2e.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/test/e2e.ts)_ ## `scrollsdk test ingress` @@ -804,5 +798,5 @@ DESCRIPTION Check for required ingress hosts and validate frontend URLs ``` -_See code: [src/commands/test/ingress.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.0/src/commands/test/ingress.ts)_ +_See code: [src/commands/test/ingress.ts](https://github.com/scroll-tech/scroll-sdk-cli/blob/v0.1.1/src/commands/test/ingress.ts)_ diff --git a/package.json b/package.json index 39e0ad9..8e699ab 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@scroll-tech/scroll-sdk-cli", "description": "A tool for managing and testing Scroll SDK deployments", - "version": "0.1.0", + "version": "0.1.1", "author": "Daniel Helm", "bin": { "scrollsdk": "bin/run.js"