qa: Use named args in some tests

Github-Pull: #14101
Rebased-From: fa782a308d
This commit is contained in:
MarcoFalke 2018-08-29 12:42:46 -04:00
parent 73e538cf6a
commit 168efeaca6
3 changed files with 12 additions and 12 deletions

View file

@ -42,7 +42,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
# Save the coinbase for later # Save the coinbase for later
block1 = block block1 = block
tip = block.sha256 tip = block.sha256
node.p2p.send_blocks_and_test([block1], node, True) node.p2p.send_blocks_and_test([block1], node, success=True)
self.log.info("Mature the block.") self.log.info("Mature the block.")
node.generate(100) node.generate(100)
@ -79,7 +79,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
assert_equal(orig_hash, block2.rehash()) assert_equal(orig_hash, block2.rehash())
assert(block2_orig.vtx != block2.vtx) assert(block2_orig.vtx != block2.vtx)
node.p2p.send_blocks_and_test([block2], node, False, False, 16, b'bad-txns-duplicate') node.p2p.send_blocks_and_test([block2], node, success=False, request_block=False, reject_code=16, reject_reason=b'bad-txns-duplicate')
# Check transactions for duplicate inputs # Check transactions for duplicate inputs
self.log.info("Test duplicate input block.") self.log.info("Test duplicate input block.")
@ -102,7 +102,7 @@ class InvalidBlockRequestTest(BitcoinTestFramework):
block3.rehash() block3.rehash()
block3.solve() block3.solve()
node.p2p.send_blocks_and_test([block3], node, False, False, 16, b'bad-cb-amount') node.p2p.send_blocks_and_test([block3], node, success=False, request_block=False, reject_code=16, reject_reason=b'bad-cb-amount')
if __name__ == '__main__': if __name__ == '__main__':
InvalidBlockRequestTest().main() InvalidBlockRequestTest().main()

View file

@ -119,7 +119,7 @@ def get_virtual_size(witness_block):
vsize = int((3 * base_size + total_size + 3) / 4) vsize = int((3 * base_size + total_size + 3) / 4)
return vsize return vsize
def test_transaction_acceptance(rpc, p2p, tx, with_witness, accepted, reason=None): def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None):
"""Send a transaction to the node and check that it's accepted to the mempool """Send a transaction to the node and check that it's accepted to the mempool
- Submit the transaction over the p2p interface - Submit the transaction over the p2p interface
@ -129,13 +129,13 @@ def test_transaction_acceptance(rpc, p2p, tx, with_witness, accepted, reason=Non
tx_message = msg_witness_tx(tx) tx_message = msg_witness_tx(tx)
p2p.send_message(tx_message) p2p.send_message(tx_message)
p2p.sync_with_ping() p2p.sync_with_ping()
assert_equal(tx.hash in rpc.getrawmempool(), accepted) assert_equal(tx.hash in node.getrawmempool(), accepted)
if (reason is not None and not accepted): if (reason is not None and not accepted):
# Check the rejection reason as well. # Check the rejection reason as well.
with mininode_lock: with mininode_lock:
assert_equal(p2p.last_message["reject"].reason, reason) assert_equal(p2p.last_message["reject"].reason, reason)
def test_witness_block(rpc, p2p, block, accepted, with_witness=True, reason=None): def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=None):
"""Send a block to the node and check that it's accepted """Send a block to the node and check that it's accepted
- Submit the block over the p2p interface - Submit the block over the p2p interface
@ -145,7 +145,7 @@ def test_witness_block(rpc, p2p, block, accepted, with_witness=True, reason=None
else: else:
p2p.send_message(msg_block(block)) p2p.send_message(msg_block(block))
p2p.sync_with_ping() p2p.sync_with_ping()
assert_equal(rpc.getbestblockhash() == block.hash, accepted) assert_equal(node.getbestblockhash() == block.hash, accepted)
if (reason is not None and not accepted): if (reason is not None and not accepted):
# Check the rejection reason as well. # Check the rejection reason as well.
with mininode_lock: with mininode_lock:

View file

@ -482,7 +482,7 @@ class P2PDataStore(P2PInterface):
self.reject_code_received = message.code self.reject_code_received = message.code
self.reject_reason_received = message.reason self.reject_reason_received = message.reason
def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60): def send_blocks_and_test(self, blocks, node, *, success=True, request_block=True, reject_code=None, reject_reason=None, timeout=60):
"""Send blocks to test node and test whether the tip advances. """Send blocks to test node and test whether the tip advances.
- add all blocks to our block_store - add all blocks to our block_store
@ -508,16 +508,16 @@ class P2PDataStore(P2PInterface):
wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock) wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)
if success: if success:
wait_until(lambda: rpc.getbestblockhash() == blocks[-1].hash, timeout=timeout) wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
else: else:
assert rpc.getbestblockhash() != blocks[-1].hash assert node.getbestblockhash() != blocks[-1].hash
if reject_code is not None: if reject_code is not None:
wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock) wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock)
if reject_reason is not None: if reject_reason is not None:
wait_until(lambda: self.reject_reason_received == reject_reason, lock=mininode_lock) wait_until(lambda: self.reject_reason_received == reject_reason, lock=mininode_lock)
def send_txs_and_test(self, txs, rpc, success=True, expect_disconnect=False, reject_code=None, reject_reason=None): def send_txs_and_test(self, txs, node, *, 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
@ -541,7 +541,7 @@ class P2PDataStore(P2PInterface):
else: else:
self.sync_with_ping() self.sync_with_ping()
raw_mempool = rpc.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: