Skip to content

Commit

Permalink
Merge pull request #1081 from AntelopeIO/GH-1078-distributed-trx-test
Browse files Browse the repository at this point in the history
Test: Wait for finalization to verify fund transfers
  • Loading branch information
heifner authored Dec 19, 2024
2 parents ae0f627 + 24ffc3c commit 9a8dad3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions tests/TestHarness/Cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def launchUnstarted(self, numToLaunch=1):

# Spread funds across accounts with transactions spread through cluster nodes.
# Validate transactions are synchronized on root node
def spreadFunds(self, source, accounts, amount=1):
def spreadFunds(self, source, accounts, amount=1, waitForFinalization=False):
assert(source)
assert(isinstance(source, Account))
assert(accounts)
Expand Down Expand Up @@ -819,9 +819,14 @@ def spreadFunds(self, source, accounts, amount=1):
# As an extra step wait for last transaction on the root node
node=self.nodes[0]
if Utils.Debug: Utils.Print("Wait for transaction id %s on node port %d" % (transId, node.port))
if node.waitForTransactionInBlock(transId) is False:
Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, node.port))
return False
if waitForFinalization:
if node.waitForTransFinalization(transId) is False:
Utils.Print("ERROR: Failed to validate transaction %s got rolled into a final block on server port %d." % (transId, node.port))
return False
else:
if node.waitForTransactionInBlock(transId) is False:
Utils.Print("ERROR: Failed to validate transaction %s got rolled into a block on server port %d." % (transId, node.port))
return False

return True

Expand Down Expand Up @@ -850,7 +855,7 @@ def validateSpreadFunds(self, initialBalances, transferAmount, source, accounts)

return True

def spreadFundsAndValidate(self, transferAmount=1):
def spreadFundsAndValidate(self, transferAmount=1, waitForFinalization=False):
"""Sprays 'transferAmount' funds across configured accounts and validates action. The spray is done in a trickle down fashion with account 1
receiving transferAmount*n SYS and forwarding x-transferAmount funds. Transfer actions are spread round-robin across the cluster to vaidate system cohesiveness."""

Expand All @@ -859,7 +864,7 @@ def spreadFundsAndValidate(self, transferAmount=1):
assert(initialBalances)
assert(isinstance(initialBalances, dict))

if False == self.spreadFunds(self.defproduceraAccount, self.accounts, transferAmount):
if False == self.spreadFunds(self.defproduceraAccount, self.accounts, transferAmount, waitForFinalization=waitForFinalization):
Utils.Print("ERROR: Failed to spread funds across nodes.")
return False

Expand Down
3 changes: 2 additions & 1 deletion tests/distributed-transactions-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
errorExit("Accounts creation failed.")

Print("Spread funds and validate")
if not cluster.spreadFundsAndValidate(10):
# if activateIF then irreversible node needs funds to be irreversible before validation
if not cluster.spreadFundsAndValidate(10, waitForFinalization=activateIF):
errorExit("Failed to spread and validate funds.")

print("Funds spread validated")
Expand Down

0 comments on commit 9a8dad3

Please sign in to comment.