Skip to content

Commit

Permalink
qa: Use named args in some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Aug 29, 2018
1 parent b4d3309 commit fa782a3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion test/functional/mining_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
# Should ask for the block from a p2p node, if they announce the header as well:
node.add_p2p_connection(P2PDataStore())
node.p2p.wait_for_getheaders(timeout=5) # Drop the first getheaders
node.p2p.send_blocks_and_test(blocks=[block], rpc=node)
node.p2p.send_blocks_and_test(blocks=[block], node=node)
# Must be active now:
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips()

Expand Down
6 changes: 3 additions & 3 deletions test/functional/p2p_invalid_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run_test(self):
# Save the coinbase for later
block1 = block
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.")
node.generate(100)
Expand Down Expand Up @@ -79,7 +79,7 @@ def run_test(self):
assert_equal(orig_hash, block2.rehash())
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')

self.log.info("Test very broken block.")

Expand All @@ -92,7 +92,7 @@ def run_test(self):
block3.rehash()
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__':
InvalidBlockRequestTest().main()
8 changes: 4 additions & 4 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_virtual_size(witness_block):
vsize = int((3 * base_size + total_size + 3) / 4)
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
- Submit the transaction over the p2p interface
Expand All @@ -129,13 +129,13 @@ def test_transaction_acceptance(rpc, p2p, tx, with_witness, accepted, reason=Non
tx_message = msg_witness_tx(tx)
p2p.send_message(tx_message)
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):
# Check the rejection reason as well.
with mininode_lock:
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
- Submit the block over the p2p interface
Expand All @@ -145,7 +145,7 @@ def test_witness_block(rpc, p2p, block, accepted, with_witness=True, reason=None
else:
p2p.send_message(msg_block(block))
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):
# Check the rejection reason as well.
with mininode_lock:
Expand Down
10 changes: 5 additions & 5 deletions test/functional/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def on_reject(self, message):
self.reject_code_received = message.code
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.
- add all blocks to our block_store
Expand All @@ -508,16 +508,16 @@ def send_blocks_and_test(self, blocks, rpc, success=True, request_block=True, re
wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)

if success:
wait_until(lambda: rpc.getbestblockhash() == blocks[-1].hash, timeout=timeout)
wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
else:
assert rpc.getbestblockhash() != blocks[-1].hash
assert node.getbestblockhash() != blocks[-1].hash

if reject_code is not None:
wait_until(lambda: self.reject_code_received == reject_code, lock=mininode_lock)
if reject_reason is not None:
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.
- add all txs to our tx_store
Expand All @@ -541,7 +541,7 @@ def send_txs_and_test(self, txs, rpc, success=True, expect_disconnect=False, rej
else:
self.sync_with_ping()

raw_mempool = rpc.getrawmempool()
raw_mempool = node.getrawmempool()
if success:
# Check that all txs are now in the mempool
for tx in txs:
Expand Down

0 comments on commit fa782a3

Please sign in to comment.