Skip to content

Commit

Permalink
Update docker image and add verify status to check
Browse files Browse the repository at this point in the history
  • Loading branch information
prxgr4mm3r committed Nov 29, 2023
1 parent 3b8d255 commit f1d543e
Show file tree
Hide file tree
Showing 8 changed files with 1,691 additions and 1,367 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swanky-env",
"image": "ghcr.io/swankyhub/swanky-cli/swanky-base:swanky3.1.0-beta.0_v2.1.0",
"image": "ghcr.io/swankyhub/swanky-cli/swanky-base:swanky3.1.0-beta.0_v2.1.1",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version" : "latest"
Expand Down
12 changes: 6 additions & 6 deletions base-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ RUN curl -L https://github.com/swankyhub/swanky-cli/releases/download/v3.1.0-bet
# Install Rustup and Rust, additional components, packages, and verify the installations
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
/bin/bash -c "source $HOME/.cargo/env && \
rustup toolchain install nightly-2023-03-05 && \
rustup default nightly-2023-03-05 && \
rustup component add rust-src --toolchain nightly-2023-03-05 && \
rustup target add wasm32-unknown-unknown --toolchain nightly-2023-03-05 && \
cargo +stable install cargo-dylint dylint-link && \
cargo +stable install cargo-contract --force --version 4.0.0-alpha && \
rustup install 1.72 && \
rustup default 1.72 && \
rustup component add rust-src && \
rustup target add wasm32-unknown-unknown && \
cargo install cargo-dylint dylint-link && \
cargo install --git https://github.com/paritytech/cargo-contract --branch master && \
rustc --version"

# Install Yarn 1.x
Expand Down
22 changes: 14 additions & 8 deletions src/commands/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ export default class Check extends SwankyCommand<typeof Check> {
const cargoToml = TOML.parse(cargoTomlString);

const inkDependencies = Object.entries(cargoToml.dependencies)
.filter((dependency) => dependency[0].includes("ink_"))
.filter((dependency) => dependency[0].includes("ink"))
.map(([depName, depInfo]) => {
const dependency = depInfo as Dependency;
return [depName, dependency.version ?? dependency.tag];
});
ctx.versions.contracts[contract] = Object.fromEntries(inkDependencies);
ctx.versions.contracts[contract] = {
...ctx.versions.contracts[contract],
verified: swankyConfig.contracts[contract].build?.verified ?? false,
};
}
},
},
Expand All @@ -96,14 +100,16 @@ export default class Check extends SwankyCommand<typeof Check> {
const mismatched: Record<string, string> = {};
Object.entries(ctx.versions.contracts).forEach(([contract, inkPackages]) => {
Object.entries(inkPackages).forEach(([inkPackage, version]) => {
if (semver.gt(version, supportedInk!)) {
mismatched[
`${contract}-${inkPackage}`
] = `Version of ${inkPackage} (${version}) in ${contract} is higher than supported ink version (${supportedInk})`;
}
if (inkPackage != "verified") {
if (semver.gt(version, supportedInk!)) {
mismatched[
`${contract}-${inkPackage}`
] = `Version of ${inkPackage} (${version}) in ${contract} is higher than supported ink version (${supportedInk})`;
}

if (!(version.startsWith("=") || version.startsWith("v"))) {
ctx.looseDefinitionDetected = true;
if (!(version.startsWith("=") || version.startsWith("v"))) {
ctx.looseDefinitionDetected = true;
}
}
});
});
Expand Down
8 changes: 8 additions & 0 deletions src/commands/contract/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ export class CompileContract extends SwankyCommand<typeof CompileContract> {
`Generating ${contractName} contract ts types`,
`${contractName} contract's TS types Generated successfully`
);

this.swankyConfig.contracts[contractName].build = {
timestamp: Date.now(),
artifactsPath,
verified: false,
};

await this.storeConfig();
}
}
}
49 changes: 43 additions & 6 deletions src/commands/contract/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from "node:path";
import { Spinner } from "../../lib/index.js";
import { pathExists } from "fs-extra/esm";
import { SwankyCommand } from "../../lib/swankyCommand.js";
import { ConfigError, InputError } from "../../lib/errors.js";
import { Contract } from "../../lib/contract.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";
Expand Down Expand Up @@ -53,15 +53,52 @@ export class VerifyContract extends SwankyCommand<typeof VerifyContract> {
throw new InputError(`Contract folder not found at expected path`);
}

const contract = new Contract(contractInfo);

await spinner.runCommand(
async () => {
await contract.verify(spinner, this.logger);
},
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!.verified = true;

this.swankyConfig.contracts[contractName] = contractInfo;

await this.storeConfig();
}
}
}
43 changes: 1 addition & 42 deletions src/lib/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { AbiType, consts, printContractInfo } from "./index.js";
import { ContractData, DeploymentData } from "../types/index.js";
import { pathExists, readJSON } from "fs-extra/esm";
import path from "node:path";
import { FileError, ProcessError } from "./errors.js";
import { spawn } from "node:child_process";
import { Logger } from "winston";
import { Spinner } from "./spinner.js";
import { FileError } from "./errors.js";

export class Contract {
static artifactTypes = [".json", ".contract"];
Expand Down Expand Up @@ -80,42 +77,4 @@ export class Contract {
const abi = await this.getABI();
printContractInfo(abi);
}

async verify(spinner : Spinner, logger : Logger): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
const compileArgs = [
"contract",
"verify",
`artifacts/${this.name}/${this.name}.contract`,
"--manifest-path",
`contracts/${this.name}/Cargo.toml`,
];
const compile = spawn("cargo", compileArgs);
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) {
logger.info(`Contract ${this.name} verification done.`);
resolve(true);
}
} else {
reject(new ProcessError(errorBuffer));
}
});
});
}
}
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ChainProperty {

export type ExtrinsicPayload = SubmittableExtrinsic<"promise">;

export interface Encrypted { iv: string; data: string };
export interface Encrypted { iv: string; data: string }

export interface AccountData {
isDev: boolean;
Expand All @@ -30,6 +30,7 @@ export interface ContractData {
export interface BuildData {
timestamp: number;
artifactsPath: string;
verified: boolean;
}

export interface DeploymentData {
Expand Down
Loading

0 comments on commit f1d543e

Please sign in to comment.