Skip to content

Commit

Permalink
Merge pull request #280 from thrasher-/master
Browse files Browse the repository at this point in the history
Litecoin: Additional segwit coverage
  • Loading branch information
shaolinfry authored Jan 29, 2017
2 parents 347f110 + d1d7fbb commit 33bec35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 4 additions & 3 deletions qa/rpc-tests/nulldummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
24 changes: 17 additions & 7 deletions qa/rpc-tests/p2p-segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 33bec35

Please sign in to comment.