Skip to content

Commit

Permalink
Merge pull request #6894
Browse files Browse the repository at this point in the history
3e187f2 Fix BIP65 p2p test (Suhas Daftuar)
  • Loading branch information
laanwj committed Oct 29, 2015
2 parents 8daffe2 + 3e187f2 commit 2675276
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions qa/rpc-tests/bip65-cltv-p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,35 @@ def create_transaction(self, node, coinbase, to_address, amount):
def get_tests(self):

self.coinbase_blocks = self.nodes[0].generate(2)
height = 3 # height of the next block to build
self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
self.nodeaddress = self.nodes[0].getnewaddress()
self.last_block_time = time.time()

''' 98 more version 3 blocks '''
test_blocks = []
for i in xrange(98):
block = create_block(self.tip, create_coinbase(2), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 3
block.rehash()
block.solve()
test_blocks.append([block, True])
self.last_block_time += 1
self.tip = block.sha256
height += 1
yield TestInstance(test_blocks, sync_every_block=False)

''' Mine 749 version 4 blocks '''
test_blocks = []
for i in xrange(749):
block = create_block(self.tip, create_coinbase(2), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 4
block.rehash()
block.solve()
test_blocks.append([block, True])
self.last_block_time += 1
self.tip = block.sha256
height += 1
yield TestInstance(test_blocks, sync_every_block=False)

'''
Expand All @@ -104,7 +107,7 @@ def get_tests(self):
cltv_invalidate(spendtx)
spendtx.rehash()

block = create_block(self.tip, create_coinbase(2), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 4
block.vtx.append(spendtx)
block.hashMerkleRoot = block.calc_merkle_root()
Expand All @@ -113,6 +116,7 @@ def get_tests(self):

self.last_block_time += 1
self.tip = block.sha256
height += 1
yield TestInstance([[block, True]])

'''
Expand All @@ -124,7 +128,7 @@ def get_tests(self):
cltv_invalidate(spendtx)
spendtx.rehash()

block = create_block(self.tip, create_coinbase(1), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 4
block.vtx.append(spendtx)
block.hashMerkleRoot = block.calc_merkle_root()
Expand All @@ -136,35 +140,38 @@ def get_tests(self):
''' Mine 199 new version blocks on last valid tip '''
test_blocks = []
for i in xrange(199):
block = create_block(self.tip, create_coinbase(1), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 4
block.rehash()
block.solve()
test_blocks.append([block, True])
self.last_block_time += 1
self.tip = block.sha256
height += 1
yield TestInstance(test_blocks, sync_every_block=False)

''' Mine 1 old version block '''
block = create_block(self.tip, create_coinbase(1), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 3
block.rehash()
block.solve()
self.last_block_time += 1
self.tip = block.sha256
height += 1
yield TestInstance([[block, True]])

''' Mine 1 new version block '''
block = create_block(self.tip, create_coinbase(1), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 4
block.rehash()
block.solve()
self.last_block_time += 1
self.tip = block.sha256
height += 1
yield TestInstance([[block, True]])

''' Mine 1 old version block, should be invalid '''
block = create_block(self.tip, create_coinbase(1), self.last_block_time + 1)
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
block.nVersion = 3
block.rehash()
block.solve()
Expand Down

0 comments on commit 2675276

Please sign in to comment.