Skip to content

Commit 7cc77f3

Browse files
MarcoFalkeknst
authored andcommitted
Merge bitcoin#21373: test: generate fewer blocks in feature_nulldummy to fix timeouts, speed up
ccd976d test: use 327 fewer blocks in feature_nulldummy (Jon Atack) 68c280f test, refactor: abstract the feature_nulldummy blockheight values (Jon Atack) Pull request description: The resolved timeout issue seen in the CI can be reproduced locally by running `test/functional/feature_nulldummy.py --valgrind --loglevel=debug` Speeds up the normal test runtime for me from 3.8 to 2.2 seconds (debug build). Thanks to Marco Falke for the approach suggestion. ACKs for top commit: AnthonyRonning: reACK ccd976d - ran a few times with the rest of the tests and still passing for me with just the fewer block change. MarcoFalke: review ACK ccd976d 🏝 Tree-SHA512: 38339dca4276d1972e3a5a5ee436da64e9e58fd3b50b186e34b07ade9523ac4c03f6c3869c5f2a59c23b43c44f87e712f8297a01a8d83202049c081e3eeb4445
1 parent a933a60 commit 7cc77f3

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

test/functional/feature_nulldummy.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@
66
77
Connect to a single node.
88
Generate 2 blocks (save the coinbases for later).
9-
Generate 427 more blocks.
10-
[Policy/Consensus] Check that NULLDUMMY compliant transactions are accepted in the 430th block.
9+
Generate COINBASE_MATURITY (CB) more blocks to ensure the coinbases are mature.
10+
[Policy/Consensus] Check that NULLDUMMY compliant transactions are accepted in block CB + 3.
1111
[Policy] Check that non-NULLDUMMY transactions are rejected before activation.
12-
[Consensus] Check that the new NULLDUMMY rules are not enforced on the 431st block.
13-
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on the 432nd block.
12+
[Consensus] Check that the new NULLDUMMY rules are not enforced on block CB + 4.
13+
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on block CB + 5.
1414
"""
1515

16-
from test_framework.blocktools import NORMAL_GBT_REQUEST_PARAMS, create_block, create_transaction
16+
from test_framework.blocktools import (
17+
COINBASE_MATURITY,
18+
NORMAL_GBT_REQUEST_PARAMS,
19+
create_block,
20+
create_transaction,
21+
)
1722
from test_framework.messages import CTransaction
1823
from test_framework.script import CScript
1924
from test_framework.test_framework import BitcoinTestFramework
2025
from test_framework.util import assert_equal, assert_raises_rpc_error
2126

22-
2327
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
2428

2529
def trueDummy(tx):
2630
scriptSig = CScript(tx.vin[0].scriptSig)
2731
newscript = []
2832
for i in scriptSig:
29-
if (len(newscript) == 0):
33+
if len(newscript) == 0:
3034
assert len(i) == 0
3135
newscript.append(b'\x51')
3236
else:
@@ -37,10 +41,10 @@ def trueDummy(tx):
3741
class NULLDUMMYTest(BitcoinTestFramework):
3842

3943
def set_test_params(self):
40-
# Need two nodes only so GBT doesn't complain that it's not connected
44+
# Need two nodes so GBT (getblocktemplate) doesn't complain that it's not connected.
4145
self.num_nodes = 2
4246
self.setup_clean_chain = True
43-
self.extra_args = [['-whitelist=127.0.0.1']] * 2
47+
self.extra_args = [['-whitelist=127.0.0.1', '-dip3params=105:105', '-bip147height=105']] * 2
4448

4549
def skip_test_if_missing_module(self):
4650
self.skip_if_no_wallet()
@@ -56,16 +60,16 @@ def run_test(self):
5660
# Legacy wallets need to import these so that they are watched by the wallet. This is unnecssary (and does not need to be tested) for descriptor wallets
5761
wmulti.importaddress(self.ms_address)
5862

59-
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
63+
self.coinbase_blocks = self.nodes[0].generate(2) # block height = 2
6064
coinbase_txid = []
6165
for i in self.coinbase_blocks:
6266
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
63-
self.nodes[0].generate(427) # Block 429
67+
self.nodes[0].generate(COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
6468
self.lastblockhash = self.nodes[0].getbestblockhash()
65-
self.lastblockheight = 429
66-
self.lastblocktime = self.mocktime + 429
69+
self.lastblockheight = COINBASE_MATURITY + 2
70+
self.lastblocktime = self.mocktime + self.lastblockheight
6771

68-
self.log.info("Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]")
72+
self.log.info(f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{COINBASE_MATURITY + 3}]")
6973
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49)]
7074
txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize().hex(), 0)
7175
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48))
@@ -77,7 +81,7 @@ def run_test(self):
7781
trueDummy(test2tx)
7882
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize().hex(), 0)
7983

80-
self.log.info("Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [431]")
84+
self.log.info(f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{COINBASE_MATURITY + 4}]")
8185
self.block_submit(self.nodes[0], [test2tx], True)
8286

8387
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
@@ -87,14 +91,14 @@ def run_test(self):
8791
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test4tx.serialize().hex(), 0)
8892
self.block_submit(self.nodes[0], [test4tx])
8993

90-
self.log.info("Test 6: NULLDUMMY compliant transactions should be accepted to mempool and in block after activation [432]")
94+
self.log.info(f"Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [{COINBASE_MATURITY + 5}]")
9195
for i in test6txs:
9296
self.nodes[0].sendrawtransaction(i.serialize().hex(), 0)
9397
self.block_submit(self.nodes[0], test6txs, True)
9498

9599

96100
def block_submit(self, node, txs, accept = False):
97-
dip4_activated = self.lastblockheight + 1 >= 432
101+
dip4_activated = self.lastblockheight + 1 >= COINBASE_MATURITY + 5
98102
tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
99103
assert_equal(tmpl['previousblockhash'], self.lastblockhash)
100104
assert_equal(tmpl['height'], self.lastblockheight + 1)
@@ -114,5 +118,6 @@ def block_submit(self, node, txs, accept = False):
114118
else:
115119
assert_equal(node.getbestblockhash(), self.lastblockhash)
116120

121+
117122
if __name__ == '__main__':
118123
NULLDUMMYTest().main()

0 commit comments

Comments
 (0)