(self)
| 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] |
nothing calls this directly
no test coverage detected