-
Notifications
You must be signed in to change notification settings - Fork 696
feat: add --hex-file <file_path>
option to blockstack-cli contract-call
#6195
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
base: develop
Are you sure you want to change the base?
feat: add --hex-file <file_path>
option to blockstack-cli contract-call
#6195
Conversation
-xf <file_path>
option to blockstack-cli contract-call--hex-file <file_path>
option to blockstack-cli contract-call
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.
Tested locally using a 1.5MB hex file (which was not possible before this feature because of shell limitations), and seems to work fine. What I used to test:
# Call the contract with the file containing the hex-encoded argument.
./stacks-core/target/release-lite/blockstack-cli \
contract-call \
<private-key> \
10000000 \
1 \
<stx-addr> \
contract-name \
function-name \
--hex-file ./hex-args.txt
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 PR looks good! I only left a minor test-related suggestion.
stackslib/src/blockstack_cli.rs
Outdated
#[test] | ||
fn test_contract_call_with_serialized_arg_from_file_fails_due_to_content() { | ||
//Scenerio 01: Bad hex string but (good except for the \n) | ||
let mut file = NamedTempFile::new().expect("Cannot create tempfile!"); | ||
write!(file, "0000000000000000000000000000000001\n").expect("Cannot Write to temp file"); | ||
let file_path = file.path().to_str().unwrap(); | ||
|
||
let cc_args = [ | ||
"contract-call", | ||
"043ff5004e3d695060fa48ac94c96049b8c14ef441c50a184a6a3875d2a000f3", | ||
"1", | ||
"0", | ||
"SPJT598WY1RJN792HRKRHRQYFB7RJ5ZCG6J6GEZ4", | ||
"foo-contract", | ||
"transfer-fookens", | ||
"--hex-file", | ||
&file_path, | ||
]; | ||
|
||
let result = main_handler(to_string_vec(&cc_args)); | ||
assert!(result.is_err(), "Result should be err!"); | ||
|
||
let expected_msg = "Failed to deserialize: Deserialization error: Bad hex string"; | ||
assert_eq!(expected_msg, result.unwrap_err().to_string()); | ||
|
||
//Scenerio 02: short buffer | ||
let mut file = NamedTempFile::new().expect("Cannot create tempfile!"); | ||
write!(file, "0101").expect("Cannot Write to temp file"); | ||
let file_path = file.path().to_str().unwrap(); | ||
|
||
let cc_args = [ | ||
"contract-call", | ||
"043ff5004e3d695060fa48ac94c96049b8c14ef441c50a184a6a3875d2a000f3", | ||
"1", | ||
"0", | ||
"SPJT598WY1RJN792HRKRHRQYFB7RJ5ZCG6J6GEZ4", | ||
"foo-contract", | ||
"transfer-fookens", | ||
"--hex-file", | ||
&file_path, | ||
]; | ||
|
||
let result = main_handler(to_string_vec(&cc_args)); | ||
assert!(result.is_err(), "Result should be err!"); | ||
|
||
let expected_msg = | ||
"Failed to deserialize: Serialization error caused by IO: failed to fill whole buffer"; | ||
assert_eq!(expected_msg, result.unwrap_err().to_string()); | ||
} | ||
|
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.
The only thing I'd suggest (sorry for nitpicking) is to break this test into two, or at least not use the same failed assertion message in the two assert!(result.is_err(), "Result should be err!");
.
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.
No problem at all! I was trying to follow the codebase style, but I’ve gone ahead and split the test into two.: ecbc255
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.
LGTM 🚀
Description
This change, add
--hex-file <file_path>
option toblockstack-cli contract-call
that allows to allow a serialized Clarity value by file.This is useful in case the value is great enough to not fit in the command-line.
It can be used like this:
Applicable issues
blockstack-cli
contract-call
hex function args #6193Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml