Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_nulldummy.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2016 The Bitcoin Core developers | # Copyright (c) 2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.messages import FromHex | from test_framework.messages import FromHex, ToHex | ||||
from test_framework.mininode import CTransaction, network_thread_start | from test_framework.mininode import CTransaction, network_thread_start | ||||
from test_framework.blocktools import create_coinbase, create_block | from test_framework.blocktools import create_coinbase, create_block | ||||
from test_framework.script import CScript | from test_framework.script import CScript | ||||
import time | import time | ||||
NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)" | NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)" | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.tip = int("0x" + self.lastblockhash, 0) | self.tip = int("0x" + self.lastblockhash, 0) | ||||
self.lastblockheight = 429 | self.lastblockheight = 429 | ||||
self.lastblocktime = int(time.time()) + 429 | self.lastblocktime = int(time.time()) + 429 | ||||
self.log.info( | self.log.info( | ||||
"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]") | "Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [430]") | ||||
test1txs = [self.create_transaction( | test1txs = [self.create_transaction( | ||||
self.nodes[0], coinbase_txid[0], self.ms_address, 49)] | self.nodes[0], coinbase_txid[0], self.ms_address, 49)] | ||||
txid1 = self.nodes[0].sendrawtransaction( | txid1 = self.nodes[0].sendrawtransaction(ToHex(test1txs[0]), True) | ||||
bytes_to_hex_str(test1txs[0].serialize()), True) | |||||
test1txs.append(self.create_transaction( | test1txs.append(self.create_transaction( | ||||
self.nodes[0], txid1, self.ms_address, 48)) | self.nodes[0], txid1, self.ms_address, 48)) | ||||
txid2 = self.nodes[0].sendrawtransaction( | txid2 = self.nodes[0].sendrawtransaction(ToHex(test1txs[1]), True) | ||||
bytes_to_hex_str(test1txs[1].serialize()), True) | |||||
self.block_submit(self.nodes[0], test1txs, True) | self.block_submit(self.nodes[0], test1txs, True) | ||||
self.log.info( | self.log.info( | ||||
"Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation") | "Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation") | ||||
test2tx = self.create_transaction( | test2tx = self.create_transaction( | ||||
self.nodes[0], txid2, self.ms_address, 48) | self.nodes[0], txid2, self.ms_address, 48) | ||||
trueDummy(test2tx) | trueDummy(test2tx) | ||||
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, | assert_raises_rpc_error(-26, NULLDUMMY_ERROR, | ||||
self.nodes[0].sendrawtransaction, bytes_to_hex_str(test2tx.serialize()), True) | self.nodes[0].sendrawtransaction, ToHex(test2tx), True) | ||||
self.log.info( | self.log.info( | ||||
"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [431]") | "Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [431]") | ||||
self.block_submit(self.nodes[0], [test2tx], True) | self.block_submit(self.nodes[0], [test2tx], True) | ||||
def create_transaction(self, node, txid, to_address, amount): | def create_transaction(self, node, txid, to_address, amount): | ||||
inputs = [{"txid": txid, "vout": 0}] | inputs = [{"txid": txid, "vout": 0}] | ||||
outputs = {to_address: amount} | outputs = {to_address: amount} | ||||
rawtx = node.createrawtransaction(inputs, outputs) | rawtx = node.createrawtransaction(inputs, outputs) | ||||
signresult = node.signrawtransaction(rawtx) | signresult = node.signrawtransaction(rawtx) | ||||
return FromHex(CTransaction(), signresult['hex']) | return FromHex(CTransaction(), signresult['hex']) | ||||
def block_submit(self, node, txs, accept=False): | def block_submit(self, node, txs, accept=False): | ||||
block = create_block(self.tip, create_coinbase( | block = create_block(self.tip, create_coinbase( | ||||
self.lastblockheight + 1), self.lastblocktime + 1) | self.lastblockheight + 1), self.lastblocktime + 1) | ||||
block.nVersion = 4 | block.nVersion = 4 | ||||
for tx in txs: | for tx in txs: | ||||
tx.rehash() | tx.rehash() | ||||
block.vtx.append(tx) | block.vtx.append(tx) | ||||
block.vtx = [block.vtx[0]] + \ | block.vtx = [block.vtx[0]] + \ | ||||
sorted(block.vtx[1:], key=lambda tx: tx.get_id()) | sorted(block.vtx[1:], key=lambda tx: tx.get_id()) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
block.rehash() | block.rehash() | ||||
block.solve() | block.solve() | ||||
node.submitblock(bytes_to_hex_str(block.serialize())) | node.submitblock(ToHex(block)) | ||||
if (accept): | if (accept): | ||||
assert_equal(node.getbestblockhash(), block.hash) | assert_equal(node.getbestblockhash(), block.hash) | ||||
self.tip = block.sha256 | self.tip = block.sha256 | ||||
self.lastblockhash = block.hash | self.lastblockhash = block.hash | ||||
self.lastblocktime += 1 | self.lastblocktime += 1 | ||||
self.lastblockheight += 1 | self.lastblockheight += 1 | ||||
else: | else: | ||||
assert_equal(node.getbestblockhash(), self.lastblockhash) | assert_equal(node.getbestblockhash(), self.lastblockhash) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
NULLDUMMYTest().main() | NULLDUMMYTest().main() |