mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
test, refactor: abstract the feature_nulldummy blockheight values
Refactoring only, no change in test behavior.
This commit is contained in:
parent
ed25cb58f6
commit
68c280f197
1 changed files with 14 additions and 12 deletions
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
Connect to a single node.
|
Connect to a single node.
|
||||||
Generate 2 blocks (save the coinbases for later).
|
Generate 2 blocks (save the coinbases for later).
|
||||||
Generate 427 more blocks.
|
Generate COINBASE_MATURITY (CB) more blocks to ensure the coinbases are mature.
|
||||||
[Policy/Consensus] Check that NULLDUMMY compliant transactions are accepted in the 430th block.
|
[Policy/Consensus] Check that NULLDUMMY compliant transactions are accepted in block CB + 3.
|
||||||
[Policy] Check that non-NULLDUMMY transactions are rejected before activation.
|
[Policy] Check that non-NULLDUMMY transactions are rejected before activation.
|
||||||
[Consensus] Check that the new NULLDUMMY rules are not enforced on the 431st block.
|
[Consensus] Check that the new NULLDUMMY rules are not enforced on block CB + 4.
|
||||||
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on the 432nd block.
|
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on block CB + 5.
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from test_framework.script import CScript
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal, assert_raises_rpc_error
|
from test_framework.util import assert_equal, assert_raises_rpc_error
|
||||||
|
|
||||||
|
COINBASE_MATURITY = 427
|
||||||
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
|
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
|
||||||
|
|
||||||
def trueDummy(tx):
|
def trueDummy(tx):
|
||||||
|
@ -43,7 +44,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
|
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
|
||||||
# normal segwit activation here (and don't use the default always-on behaviour).
|
# normal segwit activation here (and don't use the default always-on behaviour).
|
||||||
self.extra_args = [[
|
self.extra_args = [[
|
||||||
'-segwitheight=432',
|
f'-segwitheight={COINBASE_MATURITY + 5}',
|
||||||
'-addresstype=legacy',
|
'-addresstype=legacy',
|
||||||
]] * 2
|
]] * 2
|
||||||
|
|
||||||
|
@ -64,16 +65,16 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
wmulti.importaddress(self.ms_address)
|
wmulti.importaddress(self.ms_address)
|
||||||
wmulti.importaddress(self.wit_ms_address)
|
wmulti.importaddress(self.wit_ms_address)
|
||||||
|
|
||||||
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
self.coinbase_blocks = self.nodes[0].generate(2) # block height = 2
|
||||||
coinbase_txid = []
|
coinbase_txid = []
|
||||||
for i in self.coinbase_blocks:
|
for i in self.coinbase_blocks:
|
||||||
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
|
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
|
||||||
self.nodes[0].generate(427) # Block 429
|
self.nodes[0].generate(COINBASE_MATURITY) # block height = COINBASE_MATURITY + 2
|
||||||
self.lastblockhash = self.nodes[0].getbestblockhash()
|
self.lastblockhash = self.nodes[0].getbestblockhash()
|
||||||
self.lastblockheight = 429
|
self.lastblockheight = COINBASE_MATURITY + 2
|
||||||
self.lastblocktime = int(time.time()) + 429
|
self.lastblocktime = int(time.time()) + self.lastblockheight
|
||||||
|
|
||||||
self.log.info("Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]")
|
self.log.info(f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{COINBASE_MATURITY + 3}]")
|
||||||
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49)]
|
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49)]
|
||||||
txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize_with_witness().hex(), 0)
|
txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize_with_witness().hex(), 0)
|
||||||
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48))
|
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48))
|
||||||
|
@ -87,7 +88,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
trueDummy(test2tx)
|
trueDummy(test2tx)
|
||||||
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize_with_witness().hex(), 0)
|
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize_with_witness().hex(), 0)
|
||||||
|
|
||||||
self.log.info("Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [431]")
|
self.log.info(f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{COINBASE_MATURITY + 4}]")
|
||||||
self.block_submit(self.nodes[0], [test2tx], False, True)
|
self.block_submit(self.nodes[0], [test2tx], False, True)
|
||||||
|
|
||||||
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
|
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
|
||||||
|
@ -104,7 +105,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test5tx.serialize_with_witness().hex(), 0)
|
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test5tx.serialize_with_witness().hex(), 0)
|
||||||
self.block_submit(self.nodes[0], [test5tx], True)
|
self.block_submit(self.nodes[0], [test5tx], True)
|
||||||
|
|
||||||
self.log.info("Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [432]")
|
self.log.info(f"Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [{COINBASE_MATURITY + 5}]")
|
||||||
for i in test6txs:
|
for i in test6txs:
|
||||||
self.nodes[0].sendrawtransaction(i.serialize_with_witness().hex(), 0)
|
self.nodes[0].sendrawtransaction(i.serialize_with_witness().hex(), 0)
|
||||||
self.block_submit(self.nodes[0], test6txs, True, True)
|
self.block_submit(self.nodes[0], test6txs, True, True)
|
||||||
|
@ -130,5 +131,6 @@ class NULLDUMMYTest(BitcoinTestFramework):
|
||||||
else:
|
else:
|
||||||
assert_equal(node.getbestblockhash(), self.lastblockhash)
|
assert_equal(node.getbestblockhash(), self.lastblockhash)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
NULLDUMMYTest().main()
|
NULLDUMMYTest().main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue