Skip to content
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

fix: remove anvil from inspect command and add support for target string #364

Merged
merged 5 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/commitlint-pr.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: 'Semantic Commit'

on:
pull_request:
types:
- opened
- edited
- synchronize
pull_request_target:
types:
- opened
Expand Down
31 changes: 16 additions & 15 deletions packages/builder/src/schemas.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ const jsonAbiPathRegex = RegExp(/^(?!.*\.d?$).*\.json?$/, 'i');
const artifactNameRegex = RegExp(/^[A-Z]{1}[\w]+$/, 'i');
const artifactPathRegex = RegExp(/^.*\.sol:\w+/, 'i');

// Invoke target string schema
const targetString = z.string().refine(
(val) =>
ethers.utils.isAddress(val) ||
!!val.match(interpolatedRegex) ||
!!val.match(stepRegex) ||
!!val.match(artifactNameRegex) ||
!!val.match(artifactPathRegex),
(val) => ({
message: `"${val}" must be a valid ethereum address, existing contract step name, contract artifact name or filepath`,
})
);

const targetSchema = targetString.or(z.array(targetString).nonempty());

export const contractSchema = z
.object({
/**
Expand Down Expand Up @@ -171,21 +186,7 @@ export const invokeSchema = z
/**
* Names of the contract to call or contract action that deployed the contract to call
*/
target: z
.array(
z.string().refine(
(val) =>
ethers.utils.isAddress(val) ||
!!val.match(interpolatedRegex) ||
!!val.match(stepRegex) ||
!!val.match(artifactNameRegex) ||
!!val.match(artifactPathRegex),
(val) => ({
message: `"${val}" must be a valid ethereum address, previously defined contract step name or contract artifact name or path`,
})
)
)
.nonempty(),
target: targetSchema,
/**
* Name of the function to call on the contract
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/builder/src/steps/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export default {
async getState(_runtime: ChainBuilderRuntimeInfo, ctx: ChainBuilderContextWithHelpers, config: Config) {
const cfg = this.configInject(ctx, config);

if (typeof cfg.target === 'string') {
cfg.target = [cfg.target as string];
}

return {
to: cfg.target?.map((t) => getContractFromPath(ctx, t)?.address),
func: cfg.func,
Expand All @@ -201,6 +205,10 @@ export default {
configInject(ctx: ChainBuilderContextWithHelpers, config: Config) {
config = _.cloneDeep(config);

if (typeof config.target === 'string') {
config.target = [config.target as string];
}

if (config.target) {
// [string, ...string[]] refers to a nonempty array
config.target = config.target.map((v) => _.template(v)(ctx)) as [string, ...string[]];
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/commands/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { createDefaultReadRegistry } from '../registry';
import { resolveCliSettings } from '../settings';
import fs from 'fs-extra';
import path from 'path';
import { setupAnvil } from '../helpers';
import { getMainLoader } from '../loader';

export async function inspect(packageRef: string, chainId: number, preset: string, json: boolean, writeDeployments: string) {
await setupAnvil();
const { name, version } = parsePackageRef(packageRef);

const resolver = await createDefaultReadRegistry(resolveCliSettings());
Expand All @@ -24,6 +22,15 @@ export async function inspect(packageRef: string, chainId: number, preset: strin
);
}

if (!chainId) {
console.warn(
yellow(
"The deployment data for the latest local version of this package (which runs with 'cannon PACKAGE_NAME') was exported. \
Specify the --chain-id parameter to retrieve the addresses/ABIs for other deployments."
)
);
}

const deployData = await loader[deployUrl.split(':')[0] as 'ipfs' | 'file'].read(deployUrl);

if (!deployData) {
Expand Down