-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add verify
feature
#194
Merged
Merged
Add verify
feature
#194
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e663e5d
Add verifiable build
prxgr4mm3r 3b8d255
Add verify command
prxgr4mm3r f1d543e
Update docker image and add verify status to check
prxgr4mm3r 6d13fab
Remove unused func
prxgr4mm3r c1f9b72
Update dockerfile
prxgr4mm3r 93343fa
Fix image path and descriptions
prxgr4mm3r aba4052
Fixes
prxgr4mm3r 418c94a
Fix cargo version check
prxgr4mm3r f478d21
fixes
prxgr4mm3r bd56a8a
Merge branch 'ink-devhub-1' into feature/verifiable
ipapandinas b695727
chore: synchronous execution for commandStdoutOrNull
ipapandinas 53e6d65
fix: Ensuring minimal cargo-contract version helper fixed
ipapandinas f63fff4
chore: make cargo-contract extraction generic
ipapandinas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Args, Flags } from "@oclif/core"; | ||
import path from "node:path"; | ||
import { checkCargoVersion, Spinner } from "../../lib/index.js"; | ||
import { pathExists } from "fs-extra/esm"; | ||
import { SwankyCommand } from "../../lib/swankyCommand.js"; | ||
import { ConfigError, InputError, ProcessError } from "../../lib/errors.js"; | ||
import { spawn } from "node:child_process"; | ||
|
||
export class VerifyContract extends SwankyCommand<typeof VerifyContract> { | ||
static description = "Verify the smart contract(s) in your contracts directory"; | ||
|
||
static flags = { | ||
all: Flags.boolean({ | ||
default: false, | ||
char: "a", | ||
description: "Set all to true to verify all contracts", | ||
}), | ||
}; | ||
|
||
static args = { | ||
contractName: Args.string({ | ||
name: "contractName", | ||
required: false, | ||
default: "", | ||
description: "Name of the contract to verify", | ||
}), | ||
}; | ||
|
||
ipapandinas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async run(): Promise<void> { | ||
const { args, flags } = await this.parse(VerifyContract); | ||
|
||
ipapandinas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
checkCargoVersion("4.0.0", ["4.0.0-alpha"]); | ||
|
||
if (args.contractName === undefined && !flags.all) { | ||
ipapandinas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new InputError("No contracts were selected to verify", { winston: { stack: true } }); | ||
} | ||
|
||
const contractNames = flags.all | ||
? Object.keys(this.swankyConfig.contracts) | ||
: [args.contractName]; | ||
|
||
const spinner = new Spinner(); | ||
|
||
for (const contractName of contractNames) { | ||
this.logger.info(`Started compiling contract [${contractName}]`); | ||
const contractInfo = this.swankyConfig.contracts[contractName]; | ||
if (!contractInfo) { | ||
throw new ConfigError( | ||
`Cannot find contract info for ${contractName} contract in swanky.config.json` | ||
); | ||
} | ||
const contractPath = path.resolve("contracts", contractInfo.name); | ||
this.logger.info(`"Looking for contract ${contractInfo.name} in path: [${contractPath}]`); | ||
if (!(await pathExists(contractPath))) { | ||
throw new InputError(`Contract folder not found at expected path`); | ||
} | ||
|
||
if(!contractInfo.build) { | ||
throw new InputError(`Contract ${contractName} is not compiled. Please compile it first`); | ||
} | ||
|
||
pmikolajczyk41 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await spinner.runCommand( | ||
async () => { | ||
return new Promise<boolean>((resolve, reject) => { | ||
const compileArgs = [ | ||
"contract", | ||
"verify", | ||
`artifacts/${contractName}/${contractName}.contract`, | ||
"--manifest-path", | ||
`contracts/${contractName}/Cargo.toml`, | ||
]; | ||
const compile = spawn("cargo", compileArgs); | ||
this.logger.info(`Running verify command: [${JSON.stringify(compile.spawnargs)}]`); | ||
let outputBuffer = ""; | ||
let errorBuffer = ""; | ||
|
||
compile.stdout.on("data", (data) => { | ||
outputBuffer += data.toString(); | ||
spinner.ora.clear(); | ||
}); | ||
|
||
compile.stderr.on("data", (data) => { | ||
errorBuffer += data; | ||
}); | ||
|
||
compile.on("exit", (code) => { | ||
if (code === 0) { | ||
const regex = /Successfully verified contract (.*) against reference contract (.*)/; | ||
const match = outputBuffer.match(regex); | ||
if (match) { | ||
this.logger.info(`Contract ${contractName} verification done.`); | ||
resolve(true); | ||
} | ||
} else { | ||
reject(new ProcessError(errorBuffer)); | ||
} | ||
}); | ||
}); | ||
}, | ||
`Verifying ${contractName} contract`, | ||
`${contractName} Contract verified successfully` | ||
); | ||
contractInfo.build.isVerified = true; | ||
|
||
this.swankyConfig.contracts[contractName] = contractInfo; | ||
|
||
await this.storeConfig(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess your are using this feature to execute the official Parity image within the devcontainer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, is the verification working inside your devcontainer?