diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 7f7bf6743c6..3a3c5d119ff 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -343,6 +343,10 @@ auto abi_serializer_resolver = [](const name& account) -> fc::optionalsecond; }; +auto abi_serializer_resolver_empty = [](const name& account) -> fc::optional { + return fc::optional(); +}; + void prompt_for_wallet_password(string& pw, const string& name) { if(pw.size() == 0 && name != "SecureEnclave") { std::cout << localized("password: "); @@ -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(); + 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()))) diff --git a/tests/Node.py b/tests/Node.py index f4fb1ab25ec..f9ca6553a6d 100644 --- a/tests/Node.py +++ b/tests/Node.py @@ -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)) @@ -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) diff --git a/tests/nodeos_run_test.py b/tests/nodeos_run_test.py index 71ef7667858..cec79cc6ca3 100755 --- a/tests/nodeos_run_test.py +++ b/tests/nodeos_run_test.py @@ -10,6 +10,8 @@ import decimal import re +import json +import os ############################################################### # nodeos_run_test @@ -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)) diff --git a/tests/testUtils.py b/tests/testUtils.py index c831e9ab023..c3224120000 100755 --- a/tests/testUtils.py +++ b/tests/testUtils.py @@ -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