-
Notifications
You must be signed in to change notification settings - Fork 21
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: parse user inputs for Option arguments #332
base: feat-call-ui-contracts
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #332 +/- ##
==========================================
+ Coverage 70.32% 71.78% +1.46%
==========================================
Files 53 55 +2
Lines 9098 9910 +812
Branches 9098 9910 +812
==========================================
+ Hits 6398 7114 +716
- Misses 1718 1735 +17
- Partials 982 1061 +79
|
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.
Nicely done! Mostly minor naming and parameter type improvements.
Also - the linked issue is about constructor args, but there is nothing specific about that in this PR, only generalised message calling. Has it been tested with constructor args? If not, then this PR doesnt address that issue and it should be unlinked as appropriate.
I believe the constructor case is still not covered. Tested locally modifying a contract to accept But when executing
Which seems to point to the argument not being wrapped in the Option type as it is done for the contract calls. |
You're right; the logic for constructors was indeed missing. The main change is to move the logic for parsing metadata and processing arguments into a filed used by |
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.
Option
types are covered for constructors now, awesome!
Doing some local testing I detected the following:
The contract constructor I have been using for this test:
#[ink(constructor)]
pub fn new(init_value: Option<bool>, other_value: Option<bool>) -> Self {
Self { value: init_value.unwrap_or(false) }
}
If I execute:
pop up contract --args false,false
The behavior is the expected, the args are wrapped an it works nicely.
Although, it seems we are counting space chars as arguments.
pop up contract --constructor new --args false, false
// outputs
An error occurred instantiating the contract: Incorrect number of arguments provided. Expecting 2, 3 provided
I have created an issue for this. https://github.com/r0gue-io/pop-cli/issues/336
Removed. This is better addressed as part of this PR as pointed out.
Good catch! Seems |
Why create an issue, this should be addressed in this PR. |
The best solution I have found for this issue is to remove the "," as delimiter Open to better suggestions! |
As a (lazy) user, I would want to write as little as possible, so would opt for |
In your example with parameters The format |
I agree that separating the different args with a space is nicer. Less typing. Check this out - https://docs.rs/clap/latest/clap/struct.Arg.html#method.num_args |
* fix: automatically add some or none to Option argument * fix: tests
bafa53b
to
314fa45
Compare
Whilst manually testing with Options I found that the UI would show the type as Option only, without the underlying type which makes valid entry impossible. #339 uses the type registry to format the type with its full representation, which should ease entry. An example is a complex type like Weight, where previously I had to try various combinations until I discovered the correct syntax. The linked PR should show the expected type/value/shape for data entered. |
Shows the full type representation, making it easier to see the entry format of parameter values.
This PR improves the DevEx for
pop call contract
when calling contracts with optional parameters (e.g.Option<String>
). Previously, users were required to wrap optional parameter values inSome(...)
themselves. Now, users can simply enter the raw value, andpop-cli
will automatically handle the wrapping, addingSome(...)
orNone
if empty.This logic (
generate_message_args
) has been integrated intopop_contracts
crate when preparing the preprocessed data for a contract call (set_up_call
). With the check there, both CLI users andpop_contracts
crate consumers no longer need to manually wrap optional values inSome(...)
or specifyNone
for missing values.Update
Update the logic for the missing feature for
pop up contract
when calling contracts with optional parameters.Fixes: #319
The main change is to move the logic for parsing metadata and processing arguments into a filed used by
call
andup
. and includes the parsing metadata and processing arguments for constructors.Testing
Most of the code changes has been to adjust testing. To adjust that the contract used for testing has been updated. Is basically the
flipper
contract with a third call to test parsing arguments: