Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_dersig.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-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. | ||||
"""Test BIP66 (DER SIG). | """Test BIP66 (DER SIG). | ||||
Test that the DERSIG soft-fork activates at (regtest) height 1251. | Test that the DERSIG soft-fork activates at (regtest) height 1251. | ||||
""" | """ | ||||
from test_framework.blocktools import create_block, create_coinbase | from test_framework.blocktools import create_block, create_coinbase | ||||
from test_framework.messages import CTransaction, FromHex, msg_block | from test_framework.messages import CTransaction, FromHex, msg_block, ToHex | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
mininode_lock, | mininode_lock, | ||||
network_thread_start, | network_thread_start, | ||||
P2PInterface, | P2PInterface, | ||||
) | ) | ||||
from test_framework.script import CScript | 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, wait_until | from test_framework.util import assert_equal, wait_until | ||||
Show All 31 Lines | def create_transaction(node, coinbase, to_address, amount): | ||||
rawtx = node.createrawtransaction(inputs, outputs) | rawtx = node.createrawtransaction(inputs, outputs) | ||||
signresult = node.signrawtransactionwithwallet(rawtx) | signresult = node.signrawtransactionwithwallet(rawtx) | ||||
return FromHex(CTransaction(), signresult['hex']) | return FromHex(CTransaction(), signresult['hex']) | ||||
class BIP66Test(BitcoinTestFramework): | class BIP66Test(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [ | self.extra_args = [['-whitelist=127.0.0.1']] | ||||
['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']] | |||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
def run_test(self): | def run_test(self): | ||||
self.nodes[0].add_p2p_connection(P2PInterface()) | self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
network_thread_start() | network_thread_start() | ||||
# wait_for_verack ensures that the P2P connection is fully up. | # wait_for_verack ensures that the P2P connection is fully up. | ||||
Show All 29 Lines | def run_test(self): | ||||
"Test that transactions with non-DER signatures cannot appear in a block") | "Test that transactions with non-DER signatures cannot appear in a block") | ||||
block.nVersion = 3 | block.nVersion = 3 | ||||
spendtx = create_transaction(self.nodes[0], self.coinbase_blocks[1], | spendtx = create_transaction(self.nodes[0], self.coinbase_blocks[1], | ||||
self.nodeaddress, 1.0) | self.nodeaddress, 1.0) | ||||
unDERify(spendtx) | unDERify(spendtx) | ||||
spendtx.rehash() | spendtx.rehash() | ||||
# Now we verify that a block with this transaction is invalid. | # First we show that this tx is valid except for DERSIG by getting it | ||||
# rejected from the mempool for exactly that reason. | |||||
assert_equal( | |||||
[{'txid': spendtx.hash, 'allowed': False, | |||||
'reject-reason': '16: mandatory-script-verify-flag-failed (Non-canonical DER signature)'}], | |||||
self.nodes[0].testmempoolaccept( | |||||
rawtxs=[ToHex(spendtx)], allowhighfees=True) | |||||
) | |||||
# Now we verify that a block with this transaction is also invalid. | |||||
block.vtx.append(spendtx) | block.vtx.append(spendtx) | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
block.rehash() | block.rehash() | ||||
block.solve() | block.solve() | ||||
self.nodes[0].p2p.send_and_ping(msg_block(block)) | self.nodes[0].p2p.send_and_ping(msg_block(block)) | ||||
assert_equal(self.nodes[0].getbestblockhash(), tip) | assert_equal(self.nodes[0].getbestblockhash(), tip) | ||||
Show All 33 Lines |