Skip to content

Commit

Permalink
Merge pull request #2343 from AntelopeIO/GH-2310-test
Browse files Browse the repository at this point in the history
IF: Test: trx_finality_status_forked_test
  • Loading branch information
heifner authored Mar 28, 2024
2 parents 1cd0b35 + ba33ba8 commit ae08070
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tests/trx_finality_status_forked_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,25 @@
def getState(status):
assert status is not None, "ERROR: getTransactionStatus failed to return any status"
assert "state" in status, \
f"ERROR: getTransactionStatus returned a status object that didn't have a \"state\" field. state: {json.dumps(status, indent=1)}"
f"ERROR: getTransactionStatus returned a status object that didn't have a \"state\" field. status: {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"]
assert "head_number" in status, \
f"ERROR: getTransactionStatus returned a status object that didn't have a \"head_number\" field. status: {json.dumps(status, indent=1)}"
return status["head_number"]

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

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 @@ -210,18 +218,18 @@ def getBlockNum(status):
f"\n\nprod A info: {json.dumps(prodA.getInfo(), indent=1)}\n\nprod D info: {json.dumps(prodD.getInfo(), indent=1)}"

afterForkInBlockState = retStatus
afterForkBlockId = retStatus["block_id"]
assert afterForkInBlockState["block_number"] > originalInBlockState["block_number"], \
afterForkBlockId = getBlockID(retStatus)
assert getBlockNum(afterForkInBlockState) > getBlockNum(originalInBlockState), \
"ERROR: The way the test is designed, the transaction should be added to a block that has a higher number than it was in originally before it was forked out." + \
f"\n\noriginal in block state: {json.dumps(originalInBlockState, indent=1)}\n\nafter fork in block state: {json.dumps(afterForkInBlockState, indent=1)}"

assert prodD.waitForBlock(afterForkInBlockState["block_number"], timeout=120, blockType=BlockType.lib), \
assert prodD.waitForBlock(getBlockNum(afterForkInBlockState), timeout=120, blockType=BlockType.lib), \
f"ERROR: Block never finalized.\n\nprod A info: {json.dumps(prodA.getInfo(), indent=1)}\n\nprod C info: {json.dumps(prodD.getInfo(), indent=1)}" + \
f"\n\nafter fork in block state: {json.dumps(afterForkInBlockState, indent=1)}"

retStatus = prodD.getTransactionStatus(transId)
if afterForkBlockId != retStatus["block_id"]: # might have been forked out, if so wait for new block to become LIB
assert prodD.waitForBlock(retStatus["block_number"], timeout=120, blockType=BlockType.lib), \
if afterForkBlockId != getBlockID(retStatus): # might have been forked out, if so wait for new block to become LIB
assert prodD.waitForBlock(getBlockNum(retStatus), timeout=120, blockType=BlockType.lib), \
f"ERROR: Block never finalized.\n\nprod A info: {json.dumps(prodA.getInfo(), indent=1)}\n\nprod C info: {json.dumps(prodD.getInfo(), indent=1)}" + \
f"\n\nafter fork in block state: {json.dumps(afterForkInBlockState, indent=1)}"

Expand Down

0 comments on commit ae08070

Please sign in to comment.