From 165901c6544581e675a757bf3bb100b18046914d Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 23 Mar 2022 20:28:31 +0000 Subject: [PATCH] qa: Remove hard-coded consensus branch IDs from RPC tests Also fixes a bug in the `nuparams` helper, which would have caused MSB zeroes in consensus branch IDs to not be rendered in the `-nuparams` option. This hadn't been encountered because we haven't yet generated a consensus branch ID with a zero MSB. --- qa/rpc-tests/getblocktemplate.py | 5 ++- qa/rpc-tests/nuparams.py | 65 ++++++++++++++++------------- qa/rpc-tests/test_framework/util.py | 5 ++- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/qa/rpc-tests/getblocktemplate.py b/qa/rpc-tests/getblocktemplate.py index da3f638f9..3eb70a509 100755 --- a/qa/rpc-tests/getblocktemplate.py +++ b/qa/rpc-tests/getblocktemplate.py @@ -12,6 +12,7 @@ from test_framework.util import ( NU5_BRANCH_ID, hex_str_to_bytes, nuparams, + nustr, start_nodes, wait_and_assert_operationid_status, ) @@ -133,7 +134,7 @@ class GetBlockTemplateTest(BitcoinTestFramework): node.generate(15) # at height 120, NU5 is not active - assert_equal(node.getblockchaininfo()['upgrades']['37519621']['status'], 'pending') + assert_equal(node.getblockchaininfo()['upgrades'][nustr(NU5_BRANCH_ID)]['status'], 'pending') print("Testing getblocktemplate for pre-NU5") @@ -155,7 +156,7 @@ class GetBlockTemplateTest(BitcoinTestFramework): # Activate NU5, repeat the above cases node.generate(7) - assert_equal(node.getblockchaininfo()['upgrades']['37519621']['status'], 'active') + assert_equal(node.getblockchaininfo()['upgrades'][nustr(NU5_BRANCH_ID)]['status'], 'active') print("Testing getblocktemplate for post-NU5") diff --git a/qa/rpc-tests/nuparams.py b/qa/rpc-tests/nuparams.py index 4482f116a..b90fee231 100755 --- a/qa/rpc-tests/nuparams.py +++ b/qa/rpc-tests/nuparams.py @@ -8,7 +8,12 @@ from test_framework.util import ( assert_equal, start_nodes, nuparams, + nustr, + OVERWINTER_BRANCH_ID, + SAPLING_BRANCH_ID, + BLOSSOM_BRANCH_ID, HEARTWOOD_BRANCH_ID, + CANOPY_BRANCH_ID, NU5_BRANCH_ID, ) @@ -40,32 +45,32 @@ class NuparamsTest(BitcoinTestFramework): assert_equal(bci['blocks'], 0) upgrades = bci['upgrades'] - overwinter = upgrades['5ba81b19'] + overwinter = upgrades[nustr(OVERWINTER_BRANCH_ID)] assert_equal(overwinter['name'], 'Overwinter') assert_equal(overwinter['activationheight'], 1) assert_equal(overwinter['status'], 'pending') - sapling = upgrades['76b809bb'] + sapling = upgrades[nustr(SAPLING_BRANCH_ID)] assert_equal(sapling['name'], 'Sapling') assert_equal(sapling['activationheight'], 1) assert_equal(sapling['status'], 'pending') - blossom = upgrades['2bb40e60'] + blossom = upgrades[nustr(BLOSSOM_BRANCH_ID)] assert_equal(blossom['name'], 'Blossom') assert_equal(blossom['activationheight'], 3) assert_equal(blossom['status'], 'pending') - heartwood = upgrades['f5b9230b'] + heartwood = upgrades[nustr(HEARTWOOD_BRANCH_ID)] assert_equal(heartwood['name'], 'Heartwood') assert_equal(heartwood['activationheight'], 3) assert_equal(heartwood['status'], 'pending') - canopy = upgrades['e9ff75a6'] + canopy = upgrades[nustr(CANOPY_BRANCH_ID)] assert_equal(canopy['name'], 'Canopy') assert_equal(canopy['activationheight'], 5) assert_equal(canopy['status'], 'pending') - nu5 = upgrades['37519621'] + nu5 = upgrades[nustr(NU5_BRANCH_ID)] assert_equal(nu5['name'], 'NU5') assert_equal(nu5['activationheight'], 5) assert_equal(nu5['status'], 'pending') @@ -77,32 +82,32 @@ class NuparamsTest(BitcoinTestFramework): assert_equal(bci['blocks'], 1) upgrades = bci['upgrades'] - overwinter = upgrades['5ba81b19'] + overwinter = upgrades[nustr(OVERWINTER_BRANCH_ID)] assert_equal(overwinter['name'], 'Overwinter') assert_equal(overwinter['activationheight'], 1) assert_equal(overwinter['status'], 'active') - sapling = upgrades['76b809bb'] + sapling = upgrades[nustr(SAPLING_BRANCH_ID)] assert_equal(sapling['name'], 'Sapling') assert_equal(sapling['activationheight'], 1) assert_equal(sapling['status'], 'active') - blossom = upgrades['2bb40e60'] + blossom = upgrades[nustr(BLOSSOM_BRANCH_ID)] assert_equal(blossom['name'], 'Blossom') assert_equal(blossom['activationheight'], 3) assert_equal(blossom['status'], 'pending') - heartwood = upgrades['f5b9230b'] + heartwood = upgrades[nustr(HEARTWOOD_BRANCH_ID)] assert_equal(heartwood['name'], 'Heartwood') assert_equal(heartwood['activationheight'], 3) assert_equal(heartwood['status'], 'pending') - canopy = upgrades['e9ff75a6'] + canopy = upgrades[nustr(CANOPY_BRANCH_ID)] assert_equal(canopy['name'], 'Canopy') assert_equal(canopy['activationheight'], 5) assert_equal(canopy['status'], 'pending') - nu5 = upgrades['37519621'] + nu5 = upgrades[nustr(NU5_BRANCH_ID)] assert_equal(nu5['name'], 'NU5') assert_equal(nu5['activationheight'], 5) assert_equal(nu5['status'], 'pending') @@ -112,32 +117,32 @@ class NuparamsTest(BitcoinTestFramework): assert_equal(bci['blocks'], 2) upgrades = bci['upgrades'] - overwinter = upgrades['5ba81b19'] + overwinter = upgrades[nustr(OVERWINTER_BRANCH_ID)] assert_equal(overwinter['name'], 'Overwinter') assert_equal(overwinter['activationheight'], 1) assert_equal(overwinter['status'], 'active') - sapling = upgrades['76b809bb'] + sapling = upgrades[nustr(SAPLING_BRANCH_ID)] assert_equal(sapling['name'], 'Sapling') assert_equal(sapling['activationheight'], 1) assert_equal(sapling['status'], 'active') - blossom = upgrades['2bb40e60'] + blossom = upgrades[nustr(BLOSSOM_BRANCH_ID)] assert_equal(blossom['name'], 'Blossom') assert_equal(blossom['activationheight'], 3) assert_equal(blossom['status'], 'pending') - heartwood = upgrades['f5b9230b'] + heartwood = upgrades[nustr(HEARTWOOD_BRANCH_ID)] assert_equal(heartwood['name'], 'Heartwood') assert_equal(heartwood['activationheight'], 3) assert_equal(heartwood['status'], 'pending') - canopy = upgrades['e9ff75a6'] + canopy = upgrades[nustr(CANOPY_BRANCH_ID)] assert_equal(canopy['name'], 'Canopy') assert_equal(canopy['activationheight'], 5) assert_equal(canopy['status'], 'pending') - nu5 = upgrades['37519621'] + nu5 = upgrades[nustr(NU5_BRANCH_ID)] assert_equal(nu5['name'], 'NU5') assert_equal(nu5['activationheight'], 5) assert_equal(nu5['status'], 'pending') @@ -147,32 +152,32 @@ class NuparamsTest(BitcoinTestFramework): assert_equal(bci['blocks'], 4) upgrades = bci['upgrades'] - overwinter = upgrades['5ba81b19'] + overwinter = upgrades[nustr(OVERWINTER_BRANCH_ID)] assert_equal(overwinter['name'], 'Overwinter') assert_equal(overwinter['activationheight'], 1) assert_equal(overwinter['status'], 'active') - sapling = upgrades['76b809bb'] + sapling = upgrades[nustr(SAPLING_BRANCH_ID)] assert_equal(sapling['name'], 'Sapling') assert_equal(sapling['activationheight'], 1) assert_equal(sapling['status'], 'active') - blossom = upgrades['2bb40e60'] + blossom = upgrades[nustr(BLOSSOM_BRANCH_ID)] assert_equal(blossom['name'], 'Blossom') assert_equal(blossom['activationheight'], 3) assert_equal(blossom['status'], 'active') - heartwood = upgrades['f5b9230b'] + heartwood = upgrades[nustr(HEARTWOOD_BRANCH_ID)] assert_equal(heartwood['name'], 'Heartwood') assert_equal(heartwood['activationheight'], 3) assert_equal(heartwood['status'], 'active') - canopy = upgrades['e9ff75a6'] + canopy = upgrades[nustr(CANOPY_BRANCH_ID)] assert_equal(canopy['name'], 'Canopy') assert_equal(canopy['activationheight'], 5) assert_equal(canopy['status'], 'pending') - nu5 = upgrades['37519621'] + nu5 = upgrades[nustr(NU5_BRANCH_ID)] assert_equal(nu5['name'], 'NU5') assert_equal(nu5['activationheight'], 5) assert_equal(nu5['status'], 'pending') @@ -182,32 +187,32 @@ class NuparamsTest(BitcoinTestFramework): assert_equal(bci['blocks'], 5) upgrades = bci['upgrades'] - overwinter = upgrades['5ba81b19'] + overwinter = upgrades[nustr(OVERWINTER_BRANCH_ID)] assert_equal(overwinter['name'], 'Overwinter') assert_equal(overwinter['activationheight'], 1) assert_equal(overwinter['status'], 'active') - sapling = upgrades['76b809bb'] + sapling = upgrades[nustr(SAPLING_BRANCH_ID)] assert_equal(sapling['name'], 'Sapling') assert_equal(sapling['activationheight'], 1) assert_equal(sapling['status'], 'active') - blossom = upgrades['2bb40e60'] + blossom = upgrades[nustr(BLOSSOM_BRANCH_ID)] assert_equal(blossom['name'], 'Blossom') assert_equal(blossom['activationheight'], 3) assert_equal(blossom['status'], 'active') - heartwood = upgrades['f5b9230b'] + heartwood = upgrades[nustr(HEARTWOOD_BRANCH_ID)] assert_equal(heartwood['name'], 'Heartwood') assert_equal(heartwood['activationheight'], 3) assert_equal(heartwood['status'], 'active') - canopy = upgrades['e9ff75a6'] + canopy = upgrades[nustr(CANOPY_BRANCH_ID)] assert_equal(canopy['name'], 'Canopy') assert_equal(canopy['activationheight'], 5) assert_equal(canopy['status'], 'active') - nu5 = upgrades['37519621'] + nu5 = upgrades[nustr(NU5_BRANCH_ID)] assert_equal(nu5['name'], 'NU5') assert_equal(nu5['activationheight'], 5) assert_equal(nu5['status'], 'active') diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 01880e04d..2079f6276 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -666,5 +666,8 @@ def check_node_log(self, node_number, line_to_check, stop_node = True): return n raise AssertionError(repr(line_to_check) + " not found") +def nustr(branch_id): + return '%08x' % branch_id + def nuparams(branch_id, height): - return '-nuparams=%x:%d' % (branch_id, height) + return '-nuparams=%s:%d' % (nustr(branch_id), height)