From 59ee6ed2ee7da4c18cab98b1892b46f0a10a47f6 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 3 Nov 2022 08:27:25 -0500 Subject: [PATCH 1/3] GH-419 Previous fix for test was incomplete in that the validateTrxState needed to be updated for IN_BLOCK --- tests/trx_finality_status_test.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/trx_finality_status_test.py b/tests/trx_finality_status_test.py index 8f72abd1b0..fd5d37a0b1 100755 --- a/tests/trx_finality_status_test.py +++ b/tests/trx_finality_status_test.py @@ -150,16 +150,21 @@ def isState(state, expectedState, allowedState=None, notAllowedState=None): status.append(copy.copy(retStatus)) startingBlockNum=testNode.getInfo()["head_block_num"] - def validateTrxState(status, present): + def validateTrxState(status): + Print(f"status: {status}") + present = True + state = getState(status) + if state == localState or state == unknownState: + present = False bnPresent = "block_number" in status biPresent = "block_id" in status btPresent = "block_timestamp" in status - desc = "" if present else "not " + desc = "" if present else " not" group = bnPresent and biPresent and btPresent if present else not bnPresent and not biPresent and not btPresent assert group, \ f"ERROR: getTransactionStatus should{desc} contain \"block_number\", \"block_id\", or \"block_timestamp\" since state was \"{getState(status)}\".\nstatus: {json.dumps(status, indent=1)}" - validateTrxState(status[0], present=False) + validateTrxState(status[0]) def validate(status, knownTrx=True): assert "head_number" in status and "head_id" in status and "head_timestamp" in status, \ @@ -185,7 +190,7 @@ def validate(status, knownTrx=True): state = getState(status[1]) assert state == inBlockState, f"ERROR: getTransactionStatus never returned a \"{inBlockState}\" state" - validateTrxState(status[1], present=True) + validateTrxState(status[1]) validate(status[1]) @@ -212,7 +217,7 @@ def validate(status, knownTrx=True): state = getState(retStatus) assert state == unknownState, \ f"ERROR: Calling getTransactionStatus after the success_duration should have resulted in an \"{irreversibleState}\" state.\nstatus: {json.dumps(retStatus, indent=1)}" - validateTrxState(retStatus, present=False) + validateTrxState(retStatus) validate(retStatus, knownTrx=False) assert recentBlockNum <= retStatus["head_number"], \ "ERROR: Expected call to getTransactionStatus to return increasing values for \"head_number\" beyond previous known recent block number." From b92b997c6b72fc10f2876bf36208f563e258371d Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 3 Nov 2022 10:34:48 -0500 Subject: [PATCH 2/3] GH-419 Update to address PR comments. Revert to explicit present. --- tests/trx_finality_status_test.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/trx_finality_status_test.py b/tests/trx_finality_status_test.py index fd5d37a0b1..83f8bb11b7 100755 --- a/tests/trx_finality_status_test.py +++ b/tests/trx_finality_status_test.py @@ -150,12 +150,7 @@ def isState(state, expectedState, allowedState=None, notAllowedState=None): status.append(copy.copy(retStatus)) startingBlockNum=testNode.getInfo()["head_block_num"] - def validateTrxState(status): - Print(f"status: {status}") - present = True - state = getState(status) - if state == localState or state == unknownState: - present = False + def validateTrxState(status, present): bnPresent = "block_number" in status biPresent = "block_id" in status btPresent = "block_timestamp" in status @@ -164,7 +159,8 @@ def validateTrxState(status): assert group, \ f"ERROR: getTransactionStatus should{desc} contain \"block_number\", \"block_id\", or \"block_timestamp\" since state was \"{getState(status)}\".\nstatus: {json.dumps(status, indent=1)}" - validateTrxState(status[0]) + present = True if state == inBlockState else False + validateTrxState(status[0], present) def validate(status, knownTrx=True): assert "head_number" in status and "head_id" in status and "head_timestamp" in status, \ @@ -190,7 +186,7 @@ def validate(status, knownTrx=True): state = getState(status[1]) assert state == inBlockState, f"ERROR: getTransactionStatus never returned a \"{inBlockState}\" state" - validateTrxState(status[1]) + validateTrxState(status[1], present=True) validate(status[1]) @@ -217,7 +213,7 @@ def validate(status, knownTrx=True): state = getState(retStatus) assert state == unknownState, \ f"ERROR: Calling getTransactionStatus after the success_duration should have resulted in an \"{irreversibleState}\" state.\nstatus: {json.dumps(retStatus, indent=1)}" - validateTrxState(retStatus) + validateTrxState(retStatus, present=False) validate(retStatus, knownTrx=False) assert recentBlockNum <= retStatus["head_number"], \ "ERROR: Expected call to getTransactionStatus to return increasing values for \"head_number\" beyond previous known recent block number." From 4dcb8318a31c993d90dcaedc08f86139f27ab311 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 3 Nov 2022 10:48:19 -0500 Subject: [PATCH 3/3] GH-419 Improve assertion message by including both expected states. --- tests/trx_finality_status_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/trx_finality_status_test.py b/tests/trx_finality_status_test.py index 83f8bb11b7..9b9824dcd3 100755 --- a/tests/trx_finality_status_test.py +++ b/tests/trx_finality_status_test.py @@ -146,7 +146,7 @@ def isState(state, expectedState, allowedState=None, notAllowedState=None): state = getState(retStatus) assert (state == localState or state == inBlockState), \ - f"ERROR: getTransactionStatus didn't return \"{localState}\" state.\n\nstatus: {json.dumps(retStatus, indent=1)}" + f"ERROR: getTransactionStatus didn't return \"{localState}\" or \"{inBlockState}\" state.\n\nstatus: {json.dumps(retStatus, indent=1)}" status.append(copy.copy(retStatus)) startingBlockNum=testNode.getInfo()["head_block_num"]