Skip to content

Commit

Permalink
GH-2125 Access block number regardless of transaction status type
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 9, 2024
1 parent fdeb7fc commit 68f9ee1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/trx_finality_status_forked_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3

import sys
import time
import decimal
import json
Expand Down Expand Up @@ -119,6 +119,14 @@ def getState(status):
f"ERROR: getTransactionStatus returned a status object that didn't have a \"state\" field. state: {json.dumps(status, indent=1)}"
return status["state"]

def getBlockNum(status):
assert status is not None, "ERROR: getTransactionStatus failed to return any status"
assert "head_number" in status, \
f"ERROR: getTransactionStatus returned a status object that didn't have a \"head_number\" field. state: {json.dumps(status, indent=1)}"
if "block_number" in status:
return status["block_number"]
return status["head_number"]

transferAmount = 10
# Does not use transaction retry (not needed)
transfer = prodD.transferFunds(cluster.eosioAccount, cluster.defproduceraAccount, f"{transferAmount}.0000 {CORE_SYMBOL}", "fund account")
Expand Down Expand Up @@ -163,8 +171,9 @@ def getState(status):
while True:
retStatus = prodD.getTransactionStatus(transId)
state = getState(retStatus)
blockNum = getBlockNum(retStatus)
info = prodD.getInfo()
if state == forkedOutState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > transBlockNum ):
if state == forkedOutState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > blockNum ):
break

if state == irreversibleState:
Expand Down Expand Up @@ -192,10 +201,8 @@ def getState(status):
info = prodD.getInfo()
retStatus = prodD.getTransactionStatus(transId)
state = getState(retStatus)
if state == localState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > retBlockNum ):
continue
retBlockNum = retStatus["block_number"]
if (state == inBlockState or state == irreversibleState) or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > retBlockNum ):
blockNum = getBlockNum(retStatus)
if (state == inBlockState or state == irreversibleState) or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > blockNum ):
break

assert state == inBlockState or state == irreversibleState, \
Expand Down Expand Up @@ -227,7 +234,8 @@ def getState(status):
info = prodD.getInfo()
retStatus = prodD.getTransactionStatus(transId)
state = getState(retStatus)
if state == irreversibleState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > retStatus["block_number"] ):
blockNum = getBlockNum(retStatus)
if state == irreversibleState or ( info['head_block_producer'] == 'defproducerd' and info['last_irreversible_block_num'] > blockNum ):
break

assert state == irreversibleState, \
Expand Down

0 comments on commit 68f9ee1

Please sign in to comment.