Skip to content

Commit

Permalink
Merge pull request #581 from eosnetworkfoundation/backport-fix-unpack…
Browse files Browse the repository at this point in the history
…-data

[3.2] Backport: Fix unpack data for signing transaction
  • Loading branch information
oschwaldp-oci authored Jul 1, 2022
2 parents 27abc7f + f184f2b commit 0bcd3e5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3618,7 +3618,7 @@ int main( int argc, char** argv ) {

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
13 changes: 8 additions & 5 deletions tests/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def __call__(self):
def waitForIrreversibleBlock(self, blockNum, timeout=None, reportInterval=None):
return self.waitForBlock(blockNum, timeout=timeout, blockType=BlockType.lib, reportInterval=reportInterval)

def __transferFundsCmdArr(self, source, destination, amountStr, memo, force, retry, sign, dontSend, expiration):
def __transferFundsCmdArr(self, source, destination, amountStr, memo, force, retry, sign, dontSend, expiration, skipSign):
assert isinstance(amountStr, str)
assert(source)
assert(isinstance(source, Account))
Expand All @@ -553,6 +553,9 @@ def __transferFundsCmdArr(self, source, destination, amountStr, memo, force, ret
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 All @@ -564,8 +567,8 @@ def __transferFundsCmdArr(self, source, destination, amountStr, memo, force, ret
return cmdArr

# Trasfer funds. Returns "transfer" json return object
def transferFunds(self, source, destination, amountStr, memo="memo", force=False, waitForTransBlock=False, exitOnError=True, reportStatus=True, retry=None, sign=False, dontSend=False, expiration=90):
cmdArr = self.__transferFundsCmdArr(source, destination, amountStr, memo, force, retry, sign, dontSend, expiration)
def transferFunds(self, source, destination, amountStr, memo="memo", force=False, waitForTransBlock=False, exitOnError=True, reportStatus=True, retry=None, sign=False, dontSend=False, expiration=90, skipSign=False):
cmdArr = self.__transferFundsCmdArr(source, destination, amountStr, memo, force, retry, sign, dontSend, expiration, skipSign)
trans=None
start=time.perf_counter()
try:
Expand All @@ -591,8 +594,8 @@ def transferFunds(self, source, destination, amountStr, memo="memo", force=False
return self.waitForTransBlockIfNeeded(trans, waitForTransBlock, exitOnError=exitOnError)

# Trasfer funds. Returns (popen, cmdArr) for checkDelayedOutput
def transferFundsAsync(self, source, destination, amountStr, memo="memo", force=False, exitOnError=True, retry=None, sign=False, dontSend=False, expiration=90):
cmdArr = self.__transferFundsCmdArr(source, destination, amountStr, memo, force, retry, sign, dontSend, expiration)
def transferFundsAsync(self, source, destination, amountStr, memo="memo", force=False, exitOnError=True, retry=None, sign=False, dontSend=False, expiration=90, skipSign=False):
cmdArr = self.__transferFundsCmdArr(source, destination, amountStr, memo, force, retry, sign, dontSend, expiration, skipSign)
start=time.perf_counter()
try:
popen=Utils.delayedCheckOutput(cmdArr)
Expand Down
31 changes: 31 additions & 0 deletions tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,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", force=False, waitForTransBlock=False, exitOnError=True, reportStatus=False, sign=False, dontSend=True, expiration=None, skipSign=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 @@ -473,6 +473,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

0 comments on commit 0bcd3e5

Please sign in to comment.