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] Backport: Fix unpack data for signing transaction #581

Merged
merged 2 commits into from
Jul 1, 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
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