2016-08-31 13:38:23 +02:00
|
|
|
#!/usr/bin/env python3
|
2019-02-21 02:03:13 +01:00
|
|
|
# Copyright (c) 2016-2019 The Bitcoin Core developers
|
2016-08-31 13:38:23 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2017-01-18 00:34:40 +01:00
|
|
|
"""Test NULLDUMMY softfork.
|
|
|
|
|
|
|
|
Connect to a single node.
|
|
|
|
Generate 2 blocks (save the coinbases for later).
|
|
|
|
Generate 427 more blocks.
|
|
|
|
[Policy/Consensus] Check that NULLDUMMY compliant transactions are accepted in the 430th block.
|
|
|
|
[Policy] Check that non-NULLDUMMY transactions are rejected before activation.
|
|
|
|
[Consensus] Check that the new NULLDUMMY rules are not enforced on the 431st block.
|
|
|
|
[Policy/Consensus] Check that the new NULLDUMMY rules are enforced on the 432nd block.
|
|
|
|
"""
|
2018-09-23 14:50:47 +02:00
|
|
|
import time
|
2016-08-31 13:38:23 +02:00
|
|
|
|
2018-07-30 10:16:40 +02:00
|
|
|
from test_framework.blocktools import create_coinbase, create_block, create_transaction, add_witness_commitment
|
2018-07-07 00:10:35 +02:00
|
|
|
from test_framework.messages import CTransaction
|
2016-08-31 13:38:23 +02:00
|
|
|
from test_framework.script import CScript
|
2018-07-07 00:10:35 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2019-02-18 16:35:48 +01:00
|
|
|
from test_framework.util import assert_equal, assert_raises_rpc_error
|
2018-07-07 00:10:35 +02:00
|
|
|
|
2018-02-07 00:47:51 +01:00
|
|
|
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero) (code 64)"
|
2016-08-31 13:38:23 +02:00
|
|
|
|
|
|
|
def trueDummy(tx):
|
|
|
|
scriptSig = CScript(tx.vin[0].scriptSig)
|
|
|
|
newscript = []
|
|
|
|
for i in scriptSig:
|
|
|
|
if (len(newscript) == 0):
|
2019-02-19 23:43:44 +01:00
|
|
|
assert len(i) == 0
|
2016-08-31 13:38:23 +02:00
|
|
|
newscript.append(b'\x51')
|
|
|
|
else:
|
|
|
|
newscript.append(i)
|
|
|
|
tx.vin[0].scriptSig = CScript(newscript)
|
|
|
|
tx.rehash()
|
|
|
|
|
2016-09-29 15:34:04 +02:00
|
|
|
class NULLDUMMYTest(BitcoinTestFramework):
|
2016-08-31 13:38:23 +02:00
|
|
|
|
2017-06-10 00:21:21 +02:00
|
|
|
def set_test_params(self):
|
2016-08-31 13:38:23 +02:00
|
|
|
self.num_nodes = 1
|
2016-09-29 15:34:04 +02:00
|
|
|
self.setup_clean_chain = True
|
2017-10-12 05:25:18 +02:00
|
|
|
# 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).
|
2019-05-20 20:59:07 +02:00
|
|
|
self.extra_args = [['-whitelist=127.0.0.1', '-segwitheight=432', '-addresstype=legacy']]
|
2016-08-31 13:38:23 +02:00
|
|
|
|
2018-09-09 19:32:37 +02:00
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
2018-09-09 19:32:37 +02:00
|
|
|
def skip_test_if_missing_module(self):
|
|
|
|
self.skip_if_no_wallet()
|
|
|
|
|
2016-08-31 13:38:23 +02:00
|
|
|
def run_test(self):
|
|
|
|
self.address = self.nodes[0].getnewaddress()
|
2018-09-09 19:32:37 +02:00
|
|
|
self.ms_address = self.nodes[0].addmultisigaddress(1, [self.address])['address']
|
2018-09-22 21:32:53 +02:00
|
|
|
self.wit_address = self.nodes[0].getnewaddress(address_type='p2sh-segwit')
|
2018-01-18 00:30:56 +01:00
|
|
|
self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
|
2016-08-31 13:38:23 +02:00
|
|
|
|
2018-09-23 14:50:47 +02:00
|
|
|
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
2016-08-31 13:38:23 +02:00
|
|
|
coinbase_txid = []
|
|
|
|
for i in self.coinbase_blocks:
|
|
|
|
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
|
2019-09-27 18:49:15 +02:00
|
|
|
self.nodes[0].generate(145) # Block 147
|
2016-08-31 13:38:23 +02:00
|
|
|
self.lastblockhash = self.nodes[0].getbestblockhash()
|
|
|
|
self.tip = int("0x" + self.lastblockhash, 0)
|
2019-09-27 18:49:15 +02:00
|
|
|
self.lastblockheight = 147
|
|
|
|
self.lastblocktime = int(time.time()) + 147
|
2016-08-31 13:38:23 +02:00
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]")
|
2019-09-19 16:31:07 +02:00
|
|
|
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=0.98)]
|
2018-06-27 10:21:07 +02:00
|
|
|
txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize_with_witness().hex(), 0)
|
2019-09-19 16:31:07 +02:00
|
|
|
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=0.96))
|
2018-06-27 10:21:07 +02:00
|
|
|
txid2 = self.nodes[0].sendrawtransaction(test1txs[1].serialize_with_witness().hex(), 0)
|
2019-09-19 16:31:07 +02:00
|
|
|
test1txs.append(create_transaction(self.nodes[0], coinbase_txid[1], self.wit_ms_address, amount=0.98))
|
2018-06-27 10:21:07 +02:00
|
|
|
txid3 = self.nodes[0].sendrawtransaction(test1txs[2].serialize_with_witness().hex(), 0)
|
2016-08-31 13:38:23 +02:00
|
|
|
self.block_submit(self.nodes[0], test1txs, False, True)
|
|
|
|
|
2017-03-08 00:46:17 +01:00
|
|
|
self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
|
2019-09-19 16:31:07 +02:00
|
|
|
test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, amount=0.94)
|
2016-08-31 13:38:23 +02:00
|
|
|
trueDummy(test2tx)
|
2018-06-27 10:21:07 +02:00
|
|
|
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize_with_witness().hex(), 0)
|
2016-08-31 13:38:23 +02:00
|
|
|
|
2019-09-27 18:49:15 +02:00
|
|
|
self.log.info("Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [149]")
|
2016-08-31 13:38:23 +02:00
|
|
|
self.block_submit(self.nodes[0], [test2tx], False, True)
|
|
|
|
|
2017-03-17 23:36:39 +01:00
|
|
|
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
|
2019-09-19 16:31:07 +02:00
|
|
|
test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, amount=0.92)
|
2018-09-23 14:50:47 +02:00
|
|
|
test6txs = [CTransaction(test4tx)]
|
2016-08-31 13:38:23 +02:00
|
|
|
trueDummy(test4tx)
|
2018-06-27 10:21:07 +02:00
|
|
|
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test4tx.serialize_with_witness().hex(), 0)
|
2016-08-31 13:38:23 +02:00
|
|
|
self.block_submit(self.nodes[0], [test4tx])
|
|
|
|
|
2017-03-17 23:36:39 +01:00
|
|
|
self.log.info("Test 5: Non-NULLDUMMY P2WSH multisig transaction invalid after activation")
|
2019-09-19 16:31:07 +02:00
|
|
|
test5tx = create_transaction(self.nodes[0], txid3, self.wit_address, amount=0.96)
|
2016-08-31 13:38:23 +02:00
|
|
|
test6txs.append(CTransaction(test5tx))
|
|
|
|
test5tx.wit.vtxinwit[0].scriptWitness.stack[0] = b'\x01'
|
2018-06-27 10:21:07 +02:00
|
|
|
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test5tx.serialize_with_witness().hex(), 0)
|
2016-08-31 13:38:23 +02:00
|
|
|
self.block_submit(self.nodes[0], [test5tx], True)
|
|
|
|
|
2019-09-27 18:49:15 +02:00
|
|
|
self.log.info("Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [150]")
|
2016-08-31 13:38:23 +02:00
|
|
|
for i in test6txs:
|
2018-06-27 10:21:07 +02:00
|
|
|
self.nodes[0].sendrawtransaction(i.serialize_with_witness().hex(), 0)
|
2016-08-31 13:38:23 +02:00
|
|
|
self.block_submit(self.nodes[0], test6txs, True, True)
|
|
|
|
|
2018-09-23 14:50:47 +02:00
|
|
|
def block_submit(self, node, txs, witness=False, accept=False):
|
2016-08-31 13:38:23 +02:00
|
|
|
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1)
|
|
|
|
block.nVersion = 4
|
|
|
|
for tx in txs:
|
|
|
|
tx.rehash()
|
|
|
|
block.vtx.append(tx)
|
|
|
|
block.hashMerkleRoot = block.calc_merkle_root()
|
|
|
|
witness and add_witness_commitment(block)
|
|
|
|
block.rehash()
|
|
|
|
block.solve()
|
2019-05-08 16:03:06 +02:00
|
|
|
node.submitblock(block.serialize().hex())
|
2016-08-31 13:38:23 +02:00
|
|
|
if (accept):
|
|
|
|
assert_equal(node.getbestblockhash(), block.hash)
|
|
|
|
self.tip = block.sha256
|
|
|
|
self.lastblockhash = block.hash
|
|
|
|
self.lastblocktime += 1
|
|
|
|
self.lastblockheight += 1
|
|
|
|
else:
|
|
|
|
assert_equal(node.getbestblockhash(), self.lastblockhash)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-09-29 15:34:04 +02:00
|
|
|
NULLDUMMYTest().main()
|