Merge pull request #280 from thrasher-/master

Litecoin: Additional segwit coverage
pull/285/head
shaolinfry 8 years ago committed by GitHub
commit 33bec35cf4

@ -12,6 +12,7 @@ from io import BytesIO
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 @@ class NULLDUMMYTest(BitcoinTestFramework):
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 @@ class NULLDUMMYTest(BitcoinTestFramework):
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)

@ -195,7 +195,7 @@ class SegWitTest(BitcoinTestFramework):
''' 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 @@ class SegWitTest(BitcoinTestFramework):
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 @@ class SegWitTest(BitcoinTestFramework):
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 @@ class SegWitTest(BitcoinTestFramework):
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 @@ class SegWitTest(BitcoinTestFramework):
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()

Loading…
Cancel
Save