2016-09-22 10:20:44 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2016 The Bitcoin Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2019-01-07 10:55:35 +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.
|
|
|
|
"""
|
2016-09-22 10:20:44 +02:00
|
|
|
|
2016-09-29 16:45:42 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2016-09-22 10:20:44 +02:00
|
|
|
from test_framework.util import *
|
|
|
|
from test_framework.mininode import CTransaction, NetworkThread
|
2018-01-30 20:18:17 +01:00
|
|
|
from test_framework.blocktools import create_coinbase, create_block
|
2016-09-22 10:20:44 +02:00
|
|
|
from test_framework.script import CScript
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
|
|
|
|
|
|
|
|
def trueDummy(tx):
|
|
|
|
scriptSig = CScript(tx.vin[0].scriptSig)
|
|
|
|
newscript = []
|
|
|
|
for i in scriptSig:
|
|
|
|
if (len(newscript) == 0):
|
|
|
|
assert(len(i) == 0)
|
|
|
|
newscript.append(b'\x51')
|
|
|
|
else:
|
|
|
|
newscript.append(i)
|
|
|
|
tx.vin[0].scriptSig = CScript(newscript)
|
|
|
|
tx.rehash()
|
|
|
|
|
2016-09-29 16:45:42 +02:00
|
|
|
class NULLDUMMYTest(BitcoinTestFramework):
|
2016-09-22 10:20:44 +02:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.num_nodes = 1
|
2016-09-29 16:45:42 +02:00
|
|
|
self.setup_clean_chain = True
|
2016-09-22 10:20:44 +02:00
|
|
|
|
|
|
|
def setup_network(self):
|
|
|
|
# Must set the blockversion for this test
|
|
|
|
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
2017-03-09 21:16:20 +01:00
|
|
|
extra_args=[['-whitelist=127.0.0.1']])
|
2016-09-22 10:20:44 +02:00
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
self.address = self.nodes[0].getnewaddress()
|
|
|
|
self.ms_address = self.nodes[0].addmultisigaddress(1,[self.address])
|
|
|
|
|
|
|
|
NetworkThread().start() # Start up network handling in another thread
|
|
|
|
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2
|
|
|
|
coinbase_txid = []
|
|
|
|
for i in self.coinbase_blocks:
|
|
|
|
coinbase_txid.append(self.nodes[0].getblock(i)['tx'][0])
|
|
|
|
self.nodes[0].generate(427) # Block 429
|
|
|
|
self.lastblockhash = self.nodes[0].getbestblockhash()
|
|
|
|
self.tip = int("0x" + self.lastblockhash, 0)
|
|
|
|
self.lastblockheight = 429
|
2018-04-18 13:48:59 +02:00
|
|
|
self.lastblocktime = get_mocktime() + 429
|
2016-09-22 10:20:44 +02:00
|
|
|
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]")
|
2016-09-22 10:20:44 +02:00
|
|
|
test1txs = [self.create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, 49)]
|
|
|
|
txid1 = self.tx_submit(self.nodes[0], test1txs[0])
|
|
|
|
test1txs.append(self.create_transaction(self.nodes[0], txid1, self.ms_address, 48))
|
|
|
|
txid2 = self.tx_submit(self.nodes[0], test1txs[1])
|
2018-01-30 20:18:17 +01:00
|
|
|
self.block_submit(self.nodes[0], test1txs, True)
|
2016-09-22 10:20:44 +02:00
|
|
|
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
|
2018-06-12 13:33:23 +02:00
|
|
|
test2tx = self.create_transaction(self.nodes[0], txid2, self.ms_address, 47)
|
2016-09-22 10:20:44 +02:00
|
|
|
trueDummy(test2tx)
|
|
|
|
txid4 = self.tx_submit(self.nodes[0], test2tx, NULLDUMMY_ERROR)
|
|
|
|
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [431]")
|
2018-01-30 20:18:17 +01:00
|
|
|
self.block_submit(self.nodes[0], [test2tx], True)
|
2016-09-22 10:20:44 +02:00
|
|
|
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
|
2018-06-12 13:33:23 +02:00
|
|
|
test4tx = self.create_transaction(self.nodes[0], txid4, self.address, 46)
|
2016-09-22 10:20:44 +02:00
|
|
|
test6txs=[CTransaction(test4tx)]
|
|
|
|
trueDummy(test4tx)
|
|
|
|
self.tx_submit(self.nodes[0], test4tx, NULLDUMMY_ERROR)
|
|
|
|
self.block_submit(self.nodes[0], [test4tx])
|
|
|
|
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("Test 6: NULLDUMMY compliant transactions should be accepted to mempool and in block after activation [432]")
|
2016-09-22 10:20:44 +02:00
|
|
|
for i in test6txs:
|
|
|
|
self.tx_submit(self.nodes[0], i)
|
2018-01-30 20:18:17 +01:00
|
|
|
self.block_submit(self.nodes[0], test6txs, True)
|
2016-09-22 10:20:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_transaction(self, node, txid, to_address, amount):
|
|
|
|
inputs = [{ "txid" : txid, "vout" : 0}]
|
|
|
|
outputs = { to_address : amount }
|
|
|
|
rawtx = node.createrawtransaction(inputs, outputs)
|
|
|
|
signresult = node.signrawtransaction(rawtx)
|
|
|
|
tx = CTransaction()
|
|
|
|
f = BytesIO(hex_str_to_bytes(signresult['hex']))
|
|
|
|
tx.deserialize(f)
|
|
|
|
return tx
|
|
|
|
|
|
|
|
|
|
|
|
def tx_submit(self, node, tx, msg = ""):
|
|
|
|
tx.rehash()
|
|
|
|
try:
|
2018-01-30 20:18:17 +01:00
|
|
|
node.sendrawtransaction(bytes_to_hex_str(tx.serialize()), True)
|
2016-09-22 10:20:44 +02:00
|
|
|
except JSONRPCException as exp:
|
|
|
|
assert_equal(exp.error["message"], msg)
|
2016-09-30 12:34:08 +02:00
|
|
|
else:
|
|
|
|
assert_equal('', msg)
|
2016-09-22 10:20:44 +02:00
|
|
|
return tx.hash
|
|
|
|
|
|
|
|
|
2018-01-30 20:18:17 +01:00
|
|
|
def block_submit(self, node, txs, accept = False):
|
2018-05-29 14:13:50 +02:00
|
|
|
dip4_activated = self.lastblockheight + 1 >= 432
|
|
|
|
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1, dip4_activated=dip4_activated), self.lastblocktime + 1)
|
2016-09-22 10:20:44 +02:00
|
|
|
block.nVersion = 4
|
|
|
|
for tx in txs:
|
|
|
|
tx.rehash()
|
|
|
|
block.vtx.append(tx)
|
|
|
|
block.hashMerkleRoot = block.calc_merkle_root()
|
|
|
|
block.rehash()
|
|
|
|
block.solve()
|
2018-01-30 20:18:17 +01:00
|
|
|
node.submitblock(bytes_to_hex_str(block.serialize()))
|
2016-09-22 10:20:44 +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 16:45:42 +02:00
|
|
|
NULLDUMMYTest().main()
|