Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix unpack data for signing transaction #8931

Merged
merged 3 commits into from
Apr 11, 2020
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
6 changes: 5 additions & 1 deletion programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ auto abi_serializer_resolver = [](const name& account) -> fc::optional<abi_seria
return it->second;
};

auto abi_serializer_resolver_empty = [](const name& account) -> fc::optional<abi_serializer> {
return fc::optional<abi_serializer>();
};

void prompt_for_wallet_password(string& pw, const string& name) {
if(pw.size() == 0 && name != "SecureEnclave") {
std::cout << localized("password: ");
Expand Down Expand Up @@ -3444,7 +3448,7 @@ int main( int argc, char** argv ) {
fc::variant trx_var = json_from_file_or_string(trx_json_to_sign);
signed_transaction trx;
try {
trx = trx_var.as<signed_transaction>();
abi_serializer::from_variant( trx_var, trx, abi_serializer_resolver_empty, abi_serializer::create_yield_function( abi_serializer_max_time ) );
} EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Invalid transaction format: '${data}'",
("data", fc::json::to_string(trx_var, fc::time_point::maximum())))

Expand Down
5 changes: 4 additions & 1 deletion tests/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def waitForIrreversibleBlock(self, blockNum, timeout=None, blockType=BlockType.h
return self.waitForBlock(blockNum, timeout=timeout, blockType=blockType)

# Trasfer funds. Returns "transfer" json return object
def transferFunds(self, source, destination, amountStr, memo="memo", force=False, waitForTransBlock=False, exitOnError=True, reportStatus=True, sign=False, dontSend=False, expiration=None):
def transferFunds(self, source, destination, amountStr, memo="memo", force=False, waitForTransBlock=False, exitOnError=True, reportStatus=True, sign=False, dontSend=False, expiration=None, skipSign=False):
assert isinstance(amountStr, str)
assert(source)
assert(isinstance(source, Account))
Expand All @@ -741,6 +741,9 @@ def transferFunds(self, source, destination, amountStr, memo="memo", force=False
cmdArr.append("--sign-with")
cmdArr.append("[ \"%s\" ]" % (source.activePublicKey))

if skipSign:
cmdArr.append("--skip-sign")

cmdArr.append(source.name)
cmdArr.append(destination.name)
cmdArr.append(amountStr)
Expand Down
33 changes: 33 additions & 0 deletions tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import decimal
import re
import json
import os

###############################################################
# nodeos_run_test
Expand Down Expand Up @@ -629,6 +631,37 @@
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)

xferAmount="1.2345 {0}".format(CORE_SYMBOL)
unsignedTrxRet = node.transferFunds(currencyAccount, testeraAccount, xferAmount, "unsigned trx", False, False, True, False, False, True, None, True)
unsignedTrxJsonFile = "unsigned_trx_file"
with open(unsignedTrxJsonFile, 'w') as outfile:
json.dump(unsignedTrxRet, outfile)
testeraAccountAmountAftrTrx=node.getAccountEosBalanceStr(testeraAccount.name)
currencyAccountAmountAftrTrx=node.getAccountEosBalanceStr(currencyAccount.name)
try:
assert(testeraAccountAmountBeforeTrx == testeraAccountAmountAftrTrx)
assert(currencyAccountAmountBeforeTrx == currencyAccountAmountAftrTrx)
except (AssertionError) as _:
Print("ERROR: Expecting transfer is not executed.")
raise

signCmd = "sign --public-key {0} {1} -p".format(currencyAccount.activePublicKey, unsignedTrxJsonFile)
node.processCleosCmd(signCmd, "Sign and push a transaction", False, True)
os.remove(unsignedTrxJsonFile)

testeraAccountAmountAfterSign=node.getAccountEosBalanceStr(testeraAccount.name)
currencyAccountAmountAfterSign=node.getAccountEosBalanceStr(currencyAccount.name)
try:
assert(Utils.addAmount(testeraAccountAmountAftrTrx, xferAmount) == testeraAccountAmountAfterSign)
assert(Utils.deduceAmount(currencyAccountAmountAftrTrx, xferAmount) == currencyAccountAmountAfterSign)
except (AssertionError) as _:
Print("ERROR: Expecting transfer has been executed with exact amount.")
raise

Print("Locking wallet \"%s\"." % (defproduceraWallet.name))
if not walletMgr.lockWallet(defproduceraWallet):
cmdError("%s wallet lock" % (ClientName))
Expand Down
23 changes: 23 additions & 0 deletions tests/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,29 @@ def compare(obj1,obj2,context):

return "comparison of %s type is not supported, context=%s" % (typeName,context)

@staticmethod
def addAmount(assetStr: str, deltaStr: str) -> str:
asset = assetStr.split()
if len(asset) != 2:
return None
delta = deltaStr.split()
if len(delta) != 2:
return None
if asset[1] != delta[1]:
return None
return "{0} {1}".format(round(float(asset[0]) + float(delta[0]), 4), asset[1])

@staticmethod
def deduceAmount(assetStr: str, deltaStr: str) -> str:
asset = assetStr.split()
if len(asset) != 2:
return None
delta = deltaStr.split()
if len(delta) != 2:
return None
if asset[1] != delta[1]:
return None
return "{0} {1}".format(round(float(asset[0]) - float(delta[0]), 4), asset[1])
###########################################################################################
class Account(object):
# pylint: disable=too-few-public-methods
Expand Down