Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/p2p.py
| Show First 20 Lines • Show All 907 Lines • ▼ Show 20 Lines | ): | ||||
| assert node.getbestblockhash() != blocks[-1].hash_hex | assert node.getbestblockhash() != blocks[-1].hash_hex | ||||
| if reject_reason: | if reject_reason: | ||||
| with node.assert_debug_log(expected_msgs=[reject_reason]): | with node.assert_debug_log(expected_msgs=[reject_reason]): | ||||
| test() | test() | ||||
| else: | else: | ||||
| test() | test() | ||||
| def send_txs_and_test( | def send_txs_and_test(self, txs, node, *, success=True, reject_reason=None): | ||||
| self, txs, node, *, success=True, expect_disconnect=False, reject_reason=None | |||||
| ): | |||||
| """Send txs to test node and test whether they're accepted to the mempool. | """Send txs to test node and test whether they're accepted to the mempool. | ||||
| - add all txs to our tx_store | - add all txs to our tx_store | ||||
| - send tx messages for all txs | - send tx messages for all txs | ||||
| - if success is True/False: assert that the txs are/are not accepted to the mempool | - if success is True/False: assert that the txs are/are not accepted to the mempool | ||||
| - if expect_disconnect is True: Skip the sync with ping | |||||
| - if reject_reason is set: assert that the correct reject message is logged.""" | - if reject_reason is set: assert that the correct reject message is logged.""" | ||||
| with p2p_lock: | with p2p_lock: | ||||
| for tx in txs: | for tx in txs: | ||||
| self.tx_store[tx.txid_int] = tx | self.tx_store[tx.txid_int] = tx | ||||
| def test(): | def test(): | ||||
| for tx in txs: | for tx in txs: | ||||
| self.send_message(msg_tx(tx)) | self.send_message(msg_tx(tx)) | ||||
| if expect_disconnect: | |||||
| self.wait_for_disconnect() | |||||
| else: | |||||
| self.sync_with_ping() | self.sync_with_ping() | ||||
| raw_mempool = node.getrawmempool() | raw_mempool = node.getrawmempool() | ||||
| if success: | if success: | ||||
| # Check that all txs are now in the mempool | # Check that all txs are now in the mempool | ||||
| for tx in txs: | for tx in txs: | ||||
| assert tx.txid_hex in raw_mempool, ( | assert tx.txid_hex in raw_mempool, ( | ||||
| f"{tx.txid_hex} not found in mempool" | f"{tx.txid_hex} not found in mempool" | ||||
| ) | ) | ||||
| ▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines | |||||