MCPcopy Create free account
hub / github.com/ElementsProject/elements / run_test

Method run_test

test/functional/feature_block_v4.py:28–82  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

26 self.skip_if_no_wallet()
27
28 def run_test(self):
29
30 # First, quick check that CSV is ACTIVE at genesis
31 assert_equal(self.nodes[0].getblockcount(), 0)
32 assert softfork_active(self.nodes[0], 'csv')
33
34 peer = self.nodes[0].add_p2p_connection(P2PInterface())
35
36 self.nodeaddress = self.nodes[0].getnewaddress()
37
38 self.log.info("Test that blocks past the genesis block must be at least version 4")
39
40 # Create a v3 block
41 tip = self.nodes[0].getbestblockhash()
42 block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
43 block = create_block(int(tip, 16), create_coinbase(1), block_time)
44 block.nVersion = 3
45 block.solve()
46
47 # The best block should not have changed, because...
48 assert_equal(self.nodes[0].getbestblockhash(), tip)
49
50 # ... we rejected it because it is v3
51 with self.nodes[0].assert_debug_log(expected_msgs=['{}, bad-version(0x00000003)'.format(block.hash)]):
52 # Send it to the node
53 peer.send_and_ping(msg_block(block))
54
55 self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted")
56
57 # Generate 100 blocks so that first coinbase matures
58 generated_blocks = self.generate(self.nodes[0], 100)
59 spendable_coinbase_txid = self.nodes[0].getblock(generated_blocks[0])['tx'][0]
60 coinbase_value = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(spendable_coinbase_txid)["hex"])["vout"][0]["value"]
61 tip = generated_blocks[-1]
62
63 # Construct a v4 block
64 block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
65 block = create_block(int(tip, 16), create_coinbase(len(generated_blocks) + 1), block_time)
66 block.nVersion = 4
67
68 # Create a CLTV transaction
69 spendtx = create_transaction(self.nodes[0], spendable_coinbase_txid,
70 self.nodeaddress, amount=1.0, fee=coinbase_value-1, locktime=1)
71 spendtx.nLockTime = 1
72 spendtx.vin[0].scriptSig = CScript([OP_TRUE, OP_CHECKLOCKTIMEVERIFY, OP_DROP] + list(CScript(spendtx.vin[0].scriptSig)))
73 spendtx.rehash()
74
75 # Add the CLTV transaction and prepare for sending
76 block.vtx.append(spendtx)
77 block.hashMerkleRoot = block.calc_merkle_root()
78 block.solve()
79
80 # Send block and check that it becomes new best block
81 peer.send_and_ping(msg_block(block))
82 assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
83
84if __name__ == '__main__':
85 BlockV4Test().main()

Callers

nothing calls this directly

Calls 15

assert_equalFunction · 0.90
softfork_activeFunction · 0.90
P2PInterfaceClass · 0.90
create_blockFunction · 0.90
create_coinbaseFunction · 0.90
msg_blockClass · 0.90
create_transactionFunction · 0.90
CScriptClass · 0.90
infoMethod · 0.80
formatMethod · 0.80
add_p2p_connectionMethod · 0.45
solveMethod · 0.45

Tested by

no test coverage detected