-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[CLI] Add nested vector arg support, docs (#7709) #7790
Conversation
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.
Pretty nice, I'll have to test it out and all, been very busy. Noting that this is a breaking change. @0xjinn can take a look as well
crates/aptos/src/move_tool/mod.rs
Outdated
/// Vectors may be specified using JSON array literal syntax (you may need to escape this with | ||
/// quotes based on your shell interpreter) | ||
/// | ||
/// Example: `address:0x1 bool:true u8:0 u256:1234 "bool:[true, false]" 'address:[["0xace", "0xbee"], []]'` |
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.
This is pretty clean, might have to make a version bump and note that it's a breaking change in the CHANGELOG.md
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.
Can do, I'm glad to add these unless you would rather handle it.
/// Does not support string arguments that contain the following characters: | ||
/// | ||
/// * `,` | ||
/// * `[` | ||
/// * `]` |
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.
We'll need to add escaping soon
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.
Agreed.
@gregnazario I've addressed your comments above and resolved merge conflicts, so this should be ready to land! Let me know if you or @0xjinn have anything to discuss |
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'm going to approve this @0xjinn can you take another look at this.
arg_vec: ArgWithTypeVec { | ||
args: vec![ | ||
ArgWithType::address(self.account_id(operator_index)), | ||
ArgWithType::address(self.account_id(voter_index)), | ||
ArgWithType::u64(amount), | ||
ArgWithType::u64(commission_percentage), | ||
ArgWithType::bytes(vec![]), | ||
], |
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.
We should probably add a unit test for this function now (I feel like I've avoided it too long), that checks the multi-nested BCS, and ensures it can be deserialized as the type expected.
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.
Agreed. I am also working on a PR that will extend this functionality to include JSON input files, and it looks like it'll involve some minor refactors to struct nesting. Once we can get that in perhaps it'll be appropriate to add more unit testing?
} | ||
|
||
/// Recursively parse argument JSON into BCS representation. | ||
pub fn parse_arg_json(&self, arg: &serde_json::Value) -> CliTypedResult<ArgWithType> { |
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.
nit: Would be great if we can unit test and safeguard the parser
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.
Agreed. As I mention in #7790 (comment) I'm working on a separate PR that will extend support to JSON input files as well. Perhaps once both input types are supported an end-to-end test will be in order?
@gregnazario I believe I've addressed all of your comments/suggestions. @0xjinn I believe I've addressed your proposition. Is there anything else needed to get an approving review from @0xjinn and land in |
I think this looks good on my end. I did manual tested it and ensured the example transaction works. I can follow up with PR to update the changelog. cc: @gregnazario for final look |
claims it needs to be rebased |
@davidiw I just merged in Either way @gregnazario this should be ready to land |
@davidiw @gregnazario I've further squashed the PR so it reflects as a single commit against There still are no merge conflicts, so I'm not sure if there's anything else I can do to massage the diff history |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
love this @alnoki |
@lightmark see also #8054 |
@davidiw @gregnazario @movekevin
Addresses #7709
Summary of changes
ArgWithType
ArgWithTypeVec
field in accordance with DRY design principlesVector syntax
Previously, the CLI was restricted to vector arguments with a maximum depth of 1, per the below syntax:
vector<u8>:2,5,3
Notably, this schema does not support doubly nested vectors of the form
vector<vector<u8>>
, as there is no way to delimit inner vectors.However, since Move vectors must all use the same inner type, the new schema employs JSON array syntax of the form:
"u8:[[1, 2], [], [4, 5, 6]]"
Note here the use of quotes to escape spaces and square braces, as required for typical shell interpreters like
zsh
.Hence as described in the docs example from this PR, a Move function can be invoked via syntax of the form:
Additional example
See also testnet transaction 499639189 for a public entry function invocation with a
vector<vector<u64>>
argument, run from the CLI via:Local checks
The following commands were run in the below directories:
aptos-core/
aptos-core/crates/aptos/
cargo test
aptos-core/developer-docs-site/