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

[3.2] cleos: only unpack action data when explicitly asked #158

Merged
merged 2 commits into from
Sep 15, 2022
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
7 changes: 5 additions & 2 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const fc::microseconds abi_serializer_max_time = fc::seconds(10); // No risk to
string tx_ref_block_num_or_id;
bool tx_force_unique = false;
bool tx_dont_broadcast = false;
bool tx_unpack_data = false;
bool tx_return_packed = false;
bool tx_skip_sign = false;
bool tx_print_json = false;
Expand Down Expand Up @@ -226,6 +227,7 @@ void add_standard_transaction_options(CLI::App* cmd, string default_permission =
cmd->add_flag("-j,--json", tx_print_json, localized("Print result as JSON"));
cmd->add_option("--json-file", tx_json_save_file, localized("Save result in JSON format into a file"));
cmd->add_flag("-d,--dont-broadcast", tx_dont_broadcast, localized("Don't broadcast transaction to the network (just print to stdout)"));
cmd->add_flag("-u,--unpack-action-data", tx_unpack_data, localized("Unpack all action data within transaction, needs interaction with ${n} unless --abi-file. Used in conjunction with --dont-broadcast.", ("n", node_executable_name)));
cmd->add_flag("--return-packed", tx_return_packed, localized("Used in conjunction with --dont-broadcast to get the packed transaction"));
cmd->add_option("-r,--ref-block", tx_ref_block_num_or_id, (localized("Set the reference block num or block id used for TAPOS (Transaction as Proof-of-Stake)")));
cmd->add_flag("--use-old-rpc", tx_use_old_rpc, localized("Use old RPC push_transaction, rather than new RPC send_transaction"));
Expand Down Expand Up @@ -499,14 +501,15 @@ fc::variant push_transaction( signed_transaction& trx, const std::vector<public_
}
} else {
if (!tx_return_packed) {
try {
if( tx_unpack_data ) {
fc::variant unpacked_data_trx;
abi_serializer::to_variant(trx, unpacked_data_trx, abi_serializer_resolver, abi_serializer::create_yield_function(abi_serializer_max_time));
return unpacked_data_trx;
} catch (...) {
} else {
return fc::variant(trx);
}
} else {
EOSC_ASSERT( !tx_unpack_data, "ERROR: --unpack-action-data not supported with --return-packed" );
return fc::variant(packed_transaction(trx, compression));
}
}
Expand Down
36 changes: 34 additions & 2 deletions tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,11 @@
if actual != expected:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (str(expected), str(actual)), raw=True)

Print("push transfer action to currency1111 contract with sign skipping option enabled")
# Test skip sign with unpacked action data
Print("push transfer action to currency1111 contract with sign skipping and unpack action data options enabled")
data="{\"from\":\"currency1111\",\"to\":\"defproducera\",\"quantity\":"
data +="\"00.0001 CUR\",\"memo\":\"test\"}"
opts="-s -d --permission currency1111@active"
opts="-s -d -u --permission currency1111@active"
trans=node.pushMessage(contract, action, data, opts, expectTrxTrace=False)

try:
Expand All @@ -603,6 +604,37 @@
if actual != expected:
errorExit("FAILURE - Wrong currency1111 balance (expectedgma=%s, actual=%s)" % (str(expected), str(actual)), raw=True)

# Test skip sign with packed action data
Print("push transfer action to currency1111 contract with sign skipping option enabled")
data="{\"from\":\"currency1111\",\"to\":\"defproducera\",\"quantity\":"
data +="\"00.0002 CUR\",\"memo\":\"test packed\"}"
opts="-s -d --permission currency1111@active"
trans=node.pushMessage(contract, action, data, opts, expectTrxTrace=False)

try:
assert(not trans[1]["signatures"])
except (AssertionError, KeyError) as _:
Print("ERROR: Expected signatures array to be empty due to skipping option enabled.")
raise

try:
data = trans[1]["actions"][0]["data"]
Print(f"Action data: {data}")
assert data == "1042081e4d75af4660ae423ad15b974a020000000000000004435552000000000b74657374207061636b6564"
except (AssertionError, KeyError) as _:
Print("ERROR: Expecting packed data on push transfer action json result.")
raise

result=node.pushTransaction(trans[1], None)

amountStr=node.getTableAccountBalance("currency1111", currencyAccount.name)

expected="99999.9997 CUR"
actual=amountStr
if actual != expected:
errorExit("FAILURE - Wrong currency1111 balance (expectedgma=%s, actual=%s)" % (str(expected), str(actual)), raw=True)


Print("---- Test for signing transaction ----")
testeraAccountAmountBeforeTrx=node.getAccountEosBalanceStr(testeraAccount.name)
currencyAccountAmountBeforeTrx=node.getAccountEosBalanceStr(currencyAccount.name)
Expand Down