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

Add schema generation and verification #1404

Merged
merged 3 commits into from Nov 17, 2023
Merged

Add schema generation and verification #1404

merged 3 commits into from Nov 17, 2023

Conversation

SkymanOne
Copy link
Contributor

@SkymanOne SkymanOne commented Nov 16, 2023

Summary

Closes #1090 and use-ink/ink#1564

  • [n] y/n | Does it introduce breaking changes?
  • [y] y/n | Is it dependent on the specific version of ink or pallet-contracts? - 5.0.0-alpha

Introudeces schema generation and verfication commands.

Description

This PR automated proces for metadata schema generation.

Whenever there are changes to the schema, if cargo-contract targets the latest version of ink_metadata the scheme can be generated with cargo contract schema-generate inner/outer. This will print json to STDOUT.

And here is the sample of how to verify the metadata against specified schema file:

Bundle:

cargo contract verify-schema --schema /Users/skymanone/Projects/ink/crates/metadata/contract_schema.json --bundle target/ink/flipper.contract

Successfully verified metadata in `target/ink/flipper.contract` against schema `/Users/skymanone/Projects/ink/crates/metadata/contract_schema.json`!

Metadata file:

cargo contract verify-schema --schema /Users/skymanone/Projects/ink/crates/metadata/contract_schema.json --metadata target/ink/flipper.json

Successfully verified metadata in `target/ink/flipper.json` against schema `/Users/skymanone/Projects/ink/crates/metadata/contract_schema.json`!

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have added an entry to CHANGELOG.md
  • I have commented my code, particularly in hard-to-understand aras
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@SkymanOne SkymanOne changed the title add schema generation and verification Add schema generation and verification Nov 16, 2023
@@ -142,6 +144,12 @@ enum Command {
/// workspace.
#[clap(name = "verify")]
Verify(VerifyCommand),
/// Generates schema from the current metadata specification.
#[clap(name = "generate-schema")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to have a 'schema' command and use '-generate' and '-verify' as its arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many subcommands IMO: cargo contract schema ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think info and call have more arguments, but it's up to you whether to leave them as they are or make changes.

crates/cargo-contract/src/cmd/schema.rs Show resolved Hide resolved
crates/cargo-contract/src/cmd/schema.rs Outdated Show resolved Hide resolved
crates/cargo-contract/src/cmd/schema.rs Outdated Show resolved Hide resolved
crates/cargo-contract/src/cmd/schema.rs Show resolved Hide resolved
Copy link
Collaborator

@smiasojed smiasojed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SkymanOne SkymanOne merged commit e1f7ae2 into master Nov 17, 2023
11 checks passed
@SkymanOne SkymanOne deleted the gn/schema-ops branch November 17, 2023 16:05
@smiasojed smiasojed mentioned this pull request Nov 30, 2023
@smiasojed smiasojed mentioned this pull request Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema generation/validation
2 participants