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

Method run_test

test/functional/feature_cltv.py:103–194  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

101 )
102
103 def run_test(self):
104 peer = self.nodes[0].add_p2p_connection(P2PInterface())
105 wallet = MiniWallet(self.nodes[0], mode=MiniWalletMode.RAW_OP_TRUE)
106
107 self.test_cltv_info(is_active=False)
108
109 self.log.info("Mining %d blocks", CLTV_HEIGHT - 2)
110 self.generate(wallet, 10)
111 self.generate(self.nodes[0], CLTV_HEIGHT - 2 - 10)
112 assert_equal(self.nodes[0].getblockcount(), CLTV_HEIGHT - 2)
113
114 self.log.info("Test that invalid-according-to-CLTV transactions can still appear in a block")
115
116 # create one invalid tx per CLTV failure reason (5 in total) and collect them
117 invalid_cltv_txs = []
118 for i in range(5):
119 spendtx = wallet.create_self_transfer()['tx']
120 cltv_invalidate(spendtx, i)
121 invalid_cltv_txs.append(spendtx)
122
123 tip = self.nodes[0].getbestblockhash()
124 block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
125 block = create_block(int(tip, 16), create_coinbase(CLTV_HEIGHT - 1), block_time, version=3, txlist=invalid_cltv_txs)
126 block.solve()
127
128 self.test_cltv_info(is_active=False) # Not active as of current tip and next block does not need to obey rules
129 peer.send_and_ping(msg_block(block))
130 self.test_cltv_info(is_active=True) # Not active as of current tip, but next block must obey rules
131 assert_equal(self.nodes[0].getbestblockhash(), block.hash)
132
133 self.log.info("Test that blocks must now be at least version 4")
134 tip = block.sha256
135 block_time += 1
136 block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time, version=3)
137 block.solve()
138
139 with self.nodes[0].assert_debug_log(expected_msgs=[f'{block.hash}, bad-version(0x00000003)']):
140 peer.send_and_ping(msg_block(block))
141 assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
142 peer.sync_with_ping()
143
144 self.log.info("Test that invalid-according-to-CLTV transactions cannot appear in a block")
145 block.nVersion = 4
146 block.vtx.append(CTransaction()) # dummy tx after coinbase that will be replaced later
147
148 # create and test one invalid tx per CLTV failure reason (5 in total)
149 for i in range(5):
150 spendtx = wallet.create_self_transfer()['tx']
151 cltv_invalidate(spendtx, i)
152
153 tx_rej = "mempool-script-verify-flag-failed"
154 expected_cltv_reject_reason = [
155 " (Operation not valid with the current stack size)",
156 " (Negative locktime)",
157 " (Locktime requirement not satisfied)",
158 " (Locktime requirement not satisfied)",
159 " (Locktime requirement not satisfied)",
160 ][i]

Callers

nothing calls this directly

Calls 15

test_cltv_infoMethod · 0.95
create_self_transferMethod · 0.95
P2PInterfaceClass · 0.90
MiniWalletClass · 0.90
assert_equalFunction · 0.90
create_blockFunction · 0.90
create_coinbaseFunction · 0.90
msg_blockClass · 0.90
CTransactionClass · 0.90
infoMethod · 0.80
getwtxidMethod · 0.80
hexMethod · 0.80

Tested by

no test coverage detected