Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 642 Lines • ▼ Show 20 Lines | def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60): | ||||
if reject_code is not None: | if reject_code is not None: | ||||
wait_until(lambda: self.reject_code_received == | wait_until(lambda: self.reject_code_received == | ||||
reject_code, lock=mininode_lock) | reject_code, lock=mininode_lock) | ||||
if reject_reason is not None: | if reject_reason is not None: | ||||
wait_until(lambda: self.reject_reason_received == | wait_until(lambda: self.reject_reason_received == | ||||
reject_reason, lock=mininode_lock) | reject_reason, lock=mininode_lock) | ||||
def send_txs_and_test(self, txs, rpc, success=True, reject_code=None, reject_reason=None): | def send_txs_and_test(self, txs, rpc, success=True, expect_disconnect=False, reject_code=None, 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: assert that the tx is accepted to the mempool | - if success is True/False: assert that the txs are/are not accepted to the mempool | ||||
- if success is False: assert that the tx is not accepted to the mempool | - if expect_disconnect is True: Skip the sync with ping | ||||
- if reject_code and reject_reason are set: assert that the correct reject message is received.""" | - if reject_code and reject_reason are set: assert that the correct reject message is received.""" | ||||
with mininode_lock: | with mininode_lock: | ||||
self.reject_code_received = None | self.reject_code_received = None | ||||
self.reject_reason_received = None | self.reject_reason_received = None | ||||
for tx in txs: | for tx in txs: | ||||
self.tx_store[tx.sha256] = tx | self.tx_store[tx.sha256] = tx | ||||
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 = rpc.getrawmempool() | raw_mempool = rpc.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.hash in raw_mempool, "{} not found in mempool".format( | assert tx.hash in raw_mempool, "{} not found in mempool".format( | ||||
tx.hash) | tx.hash) | ||||
else: | else: | ||||
Show All 11 Lines |