From d1d7fbb79ec0ae86457636d73577e1260bf80142 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Sun, 29 Jan 2017 07:00:00 -0800 Subject: [PATCH] Litecoin: Additional segwit coverage --- qa/rpc-tests/nulldummy.py | 7 ++++--- qa/rpc-tests/p2p-segwit.py | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/qa/rpc-tests/nulldummy.py b/qa/rpc-tests/nulldummy.py index 54b7eac3765e6..69562df9f35bb 100755 --- a/qa/rpc-tests/nulldummy.py +++ b/qa/rpc-tests/nulldummy.py @@ -12,6 +12,7 @@ import time NULLDUMMY_ERROR = "64: non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)" +VB_TOP_BITS = 0x20000000 def trueDummy(tx): scriptSig = CScript(tx.vin[0].scriptSig) @@ -99,7 +100,7 @@ def run_test(self): print ("Test 6: NULLDUMMY compliant base/witness transactions should be accepted to mempool and in block after activation [432]") for i in test6txs: self.tx_submit(self.nodes[0], i) - self.block_submit(self.nodes[0], test6txs, True, True) + self.block_submit(self.nodes[0], test6txs, True, True, VB_TOP_BITS) def create_transaction(self, node, txid, to_address, amount): @@ -124,9 +125,9 @@ def tx_submit(self, node, tx, msg = ""): return tx.hash - def block_submit(self, node, txs, witness = False, accept = False): + def block_submit(self, node, txs, witness = False, accept = False, version=4): block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1) - block.nVersion = 4 + block.nVersion = version for tx in txs: tx.rehash() block.vtx.append(tx) diff --git a/qa/rpc-tests/p2p-segwit.py b/qa/rpc-tests/p2p-segwit.py index 37e8604887e97..19df33d24afbe 100755 --- a/qa/rpc-tests/p2p-segwit.py +++ b/qa/rpc-tests/p2p-segwit.py @@ -195,7 +195,7 @@ def setup_network(self): ''' Helpers ''' # Build a block on top of node0's tip. - def build_next_block(self, nVersion=4): + def build_next_block(self, nVersion=VB_TOP_BITS): tip = self.nodes[0].getbestblockhash() height = self.nodes[0].getblockcount() + 1 block_time = self.nodes[0].getblockheader(tip)["mediantime"] + 1 @@ -1030,12 +1030,14 @@ def test_block_relay(self, segwit_activated): assert(self.test_node.last_getdata.inv[0].type == blocktype) self.test_node.test_witness_block(block1, True) - block2 = self.build_next_block(nVersion=4) - block2.solve() + # Litecoin: Blocks with nVersion < VB_TOP_BITS are rejected - self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True) - assert(self.test_node.last_getdata.inv[0].type == blocktype) - self.test_node.test_witness_block(block2, True) + # block2 = self.build_next_block(nVersion=4) + # block2.solve() + + # self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True) + # assert(self.test_node.last_getdata.inv[0].type == blocktype) + # self.test_node.test_witness_block(block2, True) block3 = self.build_next_block(nVersion=(VB_TOP_BITS | (1<<15))) block3.solve() @@ -1088,7 +1090,8 @@ def test_block_relay(self, segwit_activated): assert_equal(rpc_details["weight"], weight) # Upgraded node should not ask for blocks from unupgraded - block4 = self.build_next_block(nVersion=4) + # Litecoin: Blocks with nVersion < VB_TOP_BITS are rejected + block4 = self.build_next_block(nVersion=(VB_TOP_BITS | (1<<15))) block4.solve() self.old_node.getdataset = set() # Blocks can be requested via direct-fetch (immediately upon processing the announcement) @@ -1937,6 +1940,12 @@ def test_non_standard_witness(self): self.utxo.pop(0) + def test_reject_blocks(self): + print ("\tTesting rejection of block.nVersion < BIP9_TOP_BITS blocks") + block = self.build_next_block(nVersion=4) + block.solve() + resp = self.nodes[0].submitblock(bytes_to_hex_str(block.serialize(True))) + assert_equal(resp, 'bad-version(0x00000004)') def run_test(self): # Setup the p2p connections and start up the network thread. @@ -1996,6 +2005,7 @@ def run_test(self): sync_blocks(self.nodes) # Test P2SH witness handling again + self.test_reject_blocks() self.test_p2sh_witness(segwit_activated=True) self.test_witness_commitments() self.test_block_malleability()