Skip to content

Commit

Permalink
test: move differing sync logic into sync_fun lambda in Dash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Sep 30, 2024
1 parent c586562 commit cc97aab
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 50 deletions.
3 changes: 1 addition & 2 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ def run_test(self):

for _ in range(2):
self.dynamically_add_masternode(evo=True)
self.generate(node, 8)
self.sync_blocks()
self.generate(node, 8, sync_fun=lambda: self.sync_blocks())

self.set_sporks()
self.generate(node, 1)
Expand Down
9 changes: 3 additions & 6 deletions test/functional/feature_dip3_v19.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def run_test(self):

evo_info_0 = self.dynamically_add_masternode(evo=True, rnd=7)
assert evo_info_0 is not None
self.generate(self.nodes[0], 8)
self.sync_blocks(self.nodes)
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(self.nodes))

self.log.info("Checking that protxs with duplicate EvoNodes fields are rejected")
evo_info_1 = self.dynamically_add_masternode(evo=True, rnd=7, should_be_rejected=True)
Expand All @@ -101,8 +100,7 @@ def run_test(self):
assert evo_info_2 is None
evo_info_3 = self.dynamically_add_masternode(evo=True, rnd=9)
assert evo_info_3 is not None
self.generate(self.nodes[0], 8)
self.sync_blocks(self.nodes)
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(self.nodes))
self.dynamically_evo_update_service(evo_info_0, 9, should_be_rejected=True)

revoke_protx = self.mninfo[-1].proTxHash
Expand Down Expand Up @@ -130,9 +128,8 @@ def test_revoke_protx(self, node_idx, revoke_protx, revoke_keyoperator):
funds_address = self.nodes[0].getnewaddress()
fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
self.wait_for_instantlock(fund_txid, self.nodes[0])
tip = self.generate(self.nodes[0], 1)[0]
tip = self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_all(self.nodes))[0]
assert_equal(self.nodes[0].getrawtransaction(fund_txid, 1, tip)['confirmations'], 1)
self.sync_all(self.nodes)

protx_result = self.nodes[0].protx('revoke', revoke_protx, revoke_keyoperator, 1, funds_address)
self.wait_for_instantlock(protx_result, self.nodes[0])
Expand Down
18 changes: 6 additions & 12 deletions test/functional/feature_governance_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def run_test(self):
n = sb_cycle - self.nodes[0].getblockcount() % sb_cycle
for _ in range(n):
self.bump_mocktime(156)
self.generate(self.nodes[0], 1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks())

self.log.info("Prepare proposals")

Expand Down Expand Up @@ -116,8 +115,7 @@ def run_test(self):
assert n >= 0
for _ in range(n + 1):
self.bump_mocktime(156)
self.generate(self.nodes[0], 1)
self.sync_blocks(self.nodes[0:5])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:5]))

self.log.info("Wait for new trigger and votes on non-isolated nodes")
sb_block_height = self.nodes[0].getblockcount() // sb_cycle * sb_cycle + sb_cycle
Expand All @@ -130,29 +128,25 @@ def run_test(self):
self.log.info("Move remaining n blocks until the next Superblock")
for _ in range(n - 1):
self.bump_mocktime(156)
self.generate(self.nodes[0], 1)
self.sync_blocks(self.nodes[0:5])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:5]))

# Confirm all is good
self.wait_until(lambda: have_trigger_for_height(self.nodes[0:5], sb_block_height), timeout=5)

self.log.info("Mine superblock")
self.bump_mocktime(156)
self.generate(self.nodes[0], 1)
self.sync_blocks(self.nodes[0:5])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:5]))
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[0].getbestblockhash())

self.log.info("Mine (superblock cycle + 1) blocks on non-isolated nodes to forget about this trigger")
for _ in range(sb_cycle):
self.bump_mocktime(156)
self.generate(self.nodes[0], 1)
self.sync_blocks(self.nodes[0:5])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:5]))
# Should still have at least 1 trigger for the old sb cycle and 0 for the current one
assert len(self.nodes[0].gobject("list", "valid", "triggers")) >= 1
assert not have_trigger_for_height(self.nodes[0:5], sb_block_height + sb_cycle)
self.bump_mocktime(156)
self.generate(self.nodes[0], 1)
self.sync_blocks(self.nodes[0:5])
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(self.nodes[0:5]))
# Trigger scheduler to mark old triggers for deletion
self.bump_mocktime(5 * 60)
# Let it do the job
Expand Down
3 changes: 1 addition & 2 deletions test/functional/feature_llmq_chainlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ def run_test(self):

self.log.info("Test that new node can mine without Chainlock info")
tip_0 = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 2)
self.generate(self.nodes[added_idx], 1)
self.sync_blocks(self.nodes)
self.generate(self.nodes[added_idx], 1, sync_fun=lambda: self.sync_blocks(self.nodes))
tip_1 = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 2)
assert_equal(tip_1['cbTx']['bestCLSignature'], tip_0['cbTx']['bestCLSignature'])
assert_equal(tip_1['cbTx']['bestCLHeightDiff'], tip_0['cbTx']['bestCLHeightDiff'] + 1)
Expand Down
6 changes: 2 additions & 4 deletions test/functional/feature_llmq_evo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def run_test(self):
for i in range(self.evo_count):
evo_info = self.dynamically_add_masternode(evo=True)
evo_protxhash_list.append(evo_info.proTxHash)
self.generate(self.nodes[0], 8)
self.sync_blocks(self.nodes)
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(self.nodes))

expectedUpdated.append(evo_info.proTxHash)
b_i = self.nodes[0].getbestblockhash()
Expand All @@ -120,8 +119,7 @@ def run_test(self):

# Generate a few blocks to make EvoNode/MN analysis on a pure MN RewardReallocation window
self.bump_mocktime(1)
self.generate(self.nodes[0], 4)
self.sync_blocks()
self.generate(self.nodes[0], 4, sync_fun=lambda: self.sync_blocks())

self.log.info("Test that EvoNodes are paid 1 block in a row after MN RewardReallocation activation")
self.test_evo_payments(window_analysis=48, mnrr_active=True)
Expand Down
3 changes: 1 addition & 2 deletions test/functional/feature_llmq_is_cl_conflicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ def test_chainlock_overrides_islock(self, test_block_conflict, mine_confllicting
cl = self.create_chainlock(self.nodes[0].getblockcount() + 1, block)

if mine_confllicting:
islock_tip = self.generate(self.nodes[0], 1)[-1]
# Make sure we won't sent clsig too early
self.sync_blocks()
islock_tip = self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks())[-1]

self.test_node.send_clsig(cl)

Expand Down
6 changes: 2 additions & 4 deletions test/functional/feature_llmq_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ def run_test(self):
# At this point, we want to wait for CLs just before the self.mine_cycle_quorum to diversify the CLs in CbTx.
# Although because here a new quorum cycle is starting, and we don't want to mine them now, mine 8 blocks (to skip all DKG phases)
nodes = [self.nodes[0]] + [mn.node for mn in self.mninfo.copy()]
self.generate(self.nodes[0], 8)
self.sync_blocks(nodes)
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(nodes))
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())

# And for the remaining blocks, enforce new CL in CbTx
skip_count = 23 - (self.nodes[0].getblockcount() % 24)
for _ in range(skip_count):
self.generate(self.nodes[0], 1)
self.sync_blocks(nodes)
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(nodes))
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())


Expand Down
6 changes: 2 additions & 4 deletions test/functional/feature_llmq_simplepose.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def mine_quorum_less_checks(self, expected_good_nodes, mninfos_online):
self.log.info("Mining final commitment")
self.bump_mocktime(1, nodes=nodes)
self.nodes[0].getblocktemplate() # this calls CreateNewBlock
self.generate(self.nodes[0], 1)
self.sync_blocks(nodes)
self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks(nodes))

self.log.info("Waiting for quorum to appear in the list")
self.wait_for_quorum_list(q, nodes)
Expand All @@ -153,8 +152,7 @@ def mine_quorum_less_checks(self, expected_good_nodes, mninfos_online):

# Mine 8 (SIGN_HEIGHT_OFFSET) more blocks to make sure that the new quorum gets eligible for signing sessions
self.bump_mocktime(8)
self.generate(self.nodes[0], 8)
self.sync_blocks(nodes)
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(nodes))
self.log.info("New quorum: height=%d, quorumHash=%s, quorumIndex=%d, minedBlock=%s" % (quorum_info["height"], new_quorum, quorum_info["quorumIndex"], quorum_info["minedBlock"]))

return new_quorum
Expand Down
6 changes: 2 additions & 4 deletions test/functional/feature_mnehf.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,13 @@ def run_test(self):

self.log.info("Testing duplicate EHF signal with same bit")
ehf_tx_duplicate = self.send_tx(self.create_mnehf(28, pubkey))
tip_blockhash = self.generate(node, 1)[0]
self.sync_blocks()
tip_blockhash = self.generate(node, 1, sync_fun=lambda: self.sync_blocks())[0]
block = node.getblock(tip_blockhash)
assert ehf_tx_duplicate in node.getrawmempool() and ehf_tx_duplicate not in block['tx']

self.log.info("Testing EHF signal with same bit but with newer start time")
self.bump_mocktime(int(60 * 60 * 24 * 14), update_schedulers=False)
self.generate(node, 1)
self.sync_blocks()
self.generate(node, 1, sync_fun=lambda: self.sync_blocks())
self.restart_all_nodes(params=[self.mocktime, self.mocktime + 1000000])
self.mine_quorum()

Expand Down
6 changes: 2 additions & 4 deletions test/functional/interface_zmq_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ def run_test(self):
def generate_blocks(self, num_blocks):
mninfos_online = self.mninfo.copy()
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
self.generate(self.nodes[0], num_blocks)
self.sync_blocks(nodes)
self.generate(self.nodes[0], num_blocks, sync_fun=lambda: self.sync_blocks(nodes))

def subscribe(self, publishers):
import zmq
Expand Down Expand Up @@ -375,8 +374,7 @@ def test_governance_publishers(self):
proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_data).encode())
collateral = self.nodes[0].gobject("prepare", "0", proposal_rev, proposal_time, proposal_hex)
self.wait_for_instantlock(collateral, self.nodes[0])
self.generate(self.nodes[0], 6)
self.sync_blocks()
self.generate(self.nodes[0], 6, sync_fun=lambda: self.sync_blocks())
rpc_proposal_hash = self.nodes[0].gobject("submit", "0", proposal_rev, proposal_time, proposal_hex, collateral)
# Validate hashgovernanceobject
zmq_governance_object_hash = self.subscribers[ZMQPublisher.hash_governance_object].receive().read(32).hex()
Expand Down
3 changes: 1 addition & 2 deletions test/functional/p2p_quorum_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ def force_request_expire(bump_seconds=self.quorum_data_request_expiration_timeou
self.bump_mocktime(bump_seconds)
# Test with/without expired request cleanup
if self.cleanup:
self.generate(node0, 1)
self.sync_blocks()
self.generate(node0, 1, sync_fun=lambda: self.sync_blocks())

def test_basics():
self.log.info("Testing basics of QGETDATA/QDATA")
Expand Down
8 changes: 4 additions & 4 deletions test/functional/p2p_sendheaders_compressed.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ def mine_reorg(self, length):
to-be-reorged-out blocks are mined, so that we don't break later tests.
return the list of block hashes newly mined."""

self.generate(self.nodes[0], length) # make sure all invalidated blocks are node0's
self.sync_blocks(self.nodes, wait=0.1)
# make sure all invalidated blocks are node0's
self.generate(self.nodes[0], length, sync_fun=lambda: self.sync_blocks(self.nodes, wait=0.1))
for p2p in self.nodes[0].p2ps:
p2p.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16))
p2p.clear_block_announcements()

tip_height = self.nodes[1].getblockcount()
hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1))
self.nodes[1].invalidateblock(hash_to_invalidate)
all_hashes = self.generate(self.nodes[1], length + 1) # Must be longer than the orig chain
self.sync_blocks(self.nodes, wait=0.1)
# Must be longer than the orig chain
all_hashes = self.generate(self.nodes[1], length + 1, sync_fun=lambda: self.sync_blocks(self.nodes, wait=0.1))
return [int(hash_value, 16) for hash_value in all_hashes]

def run_test(self):
Expand Down

0 comments on commit cc97aab

Please sign in to comment.