test: cleanup generate logic in some governance functional tests

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
Kittywhiskers Van Gogh 2024-10-01 15:50:09 +00:00
parent dfeeb34d18
commit 131d16133c
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 14 additions and 29 deletions

View File

@ -89,17 +89,15 @@ class DashGovernanceTest (DashTestFramework):
assert_equal(len(self.nodes[0].gobject("list-prepared")), 0)
self.log.info("Check 1st superblock before v20")
self.generate(self.nodes[0], 3, sync_fun=self.no_op)
self.bump_mocktime(3)
self.sync_blocks()
self.generate(self.nodes[0], 3, sync_fun=self.sync_blocks())
assert_equal(self.nodes[0].getblockcount(), 130)
assert_equal(self.nodes[0].getblockchaininfo()["softforks"]["v20"]["active"], False)
self.check_superblockbudget(False)
self.log.info("Check 2nd superblock before v20")
self.generate(self.nodes[0], 10, sync_fun=self.no_op)
self.bump_mocktime(10)
self.sync_blocks()
self.generate(self.nodes[0], 10, sync_fun=self.sync_blocks())
assert_equal(self.nodes[0].getblockcount(), 140)
assert_equal(self.nodes[0].getblockchaininfo()["softforks"]["v20"]["active"], False)
self.check_superblockbudget(False)
@ -117,9 +115,8 @@ class DashGovernanceTest (DashTestFramework):
p1_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address)
p2_collateral_prepare = prepare_object(self.nodes[0], 1, uint256_to_string(0), proposal_time, 1, "Proposal_2", self.p2_amount, self.p2_payout_address)
self.generate(self.nodes[0], 6, sync_fun=self.no_op)
self.bump_mocktime(6)
self.sync_blocks()
self.generate(self.nodes[0], 6, sync_fun=self.sync_blocks())
assert_equal(len(self.nodes[0].gobject("list-prepared")), 3)
assert_equal(len(self.nodes[0].gobject("list")), 0)
@ -165,9 +162,8 @@ class DashGovernanceTest (DashTestFramework):
self.log.info("v20 is expected to be activate since block 160")
assert block_count + n < 160
for _ in range(n - 1):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.check_superblockbudget(False)
assert_equal(len(self.nodes[0].gobject("list", "valid", "triggers")), 0)
@ -268,9 +264,8 @@ class DashGovernanceTest (DashTestFramework):
assert_equal(more_triggers, False)
self.log.info("Move another block inside the Superblock maturity window")
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.log.info("Should see NO votes on both triggers now")
self.wait_until(lambda: self.nodes[0].gobject("list", "valid", "triggers")[winning_trigger_hash]['NoCount'] == 1, timeout=5)
@ -284,9 +279,8 @@ class DashGovernanceTest (DashTestFramework):
self.log.info("Move another block inside the Superblock maturity window")
with self.nodes[1].assert_debug_log(["CGovernanceManager::VoteGovernanceTriggers"]):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.log.info("Vote count should not change even though MNs are allowed to vote again")
assert_equal(before, self.nodes[1].gobject("count")["votes"])
@ -298,9 +292,8 @@ class DashGovernanceTest (DashTestFramework):
self.log.info("Move remaining n blocks until actual Superblock")
for i in range(n):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
# comparing to 159 because bip9 forks are active when the tip is one block behind the activation height
self.check_superblockbudget(block_count + i + 1 >= 159)
@ -310,9 +303,8 @@ class DashGovernanceTest (DashTestFramework):
self.log.info("Move a few block past the recent superblock height and make sure we have no new votes")
for _ in range(5):
with self.nodes[1].assert_debug_log("", [f"Voting NO-FUNDING for trigger:{winning_trigger_hash} success"]):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
# Votes on both triggers should NOT change
assert_equal(self.nodes[0].gobject("list", "valid", "triggers")[winning_trigger_hash]['NoCount'], 1)
assert_equal(self.nodes[0].gobject("list", "valid", "triggers")[isolated_trigger_hash]['NoCount'], self.mn_count - 1)
@ -322,31 +314,27 @@ class DashGovernanceTest (DashTestFramework):
self.log.info("Move remaining n blocks until the next Superblock")
for _ in range(n - 1):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.log.info("Wait for new trigger and votes")
self.wait_until(lambda: have_trigger_for_height(self.nodes, 180))
self.log.info("Mine superblock")
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
assert_equal(self.nodes[0].getblockcount(), 180)
assert_equal(self.nodes[0].getblockchaininfo()["softforks"]["v20"]["active"], True)
self.log.info("Mine and check a couple more superblocks")
for i in range(2):
for _ in range(sb_cycle - 1):
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
# Wait for new trigger and votes
sb_block_height = 180 + (i + 1) * sb_cycle
self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height))
# Mine superblock
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
assert_equal(self.nodes[0].getblockcount(), sb_block_height)
assert_equal(self.nodes[0].getblockchaininfo()["softforks"]["v20"]["active"], True)
self.check_superblockbudget(True)

View File

@ -83,9 +83,7 @@ class DashGovernanceTest (DashTestFramework):
p1_collateral_prepare = self.prepare_object(1, uint256_to_string(0), proposal_time, 1, "Proposal_1", self.p1_amount, self.p1_payout_address)
self.bump_mocktime(60 * 10 + 1)
self.generate(self.nodes[0], 6, sync_fun=self.no_op)
self.bump_mocktime(6 * 156)
self.sync_blocks()
self.generate(self.nodes[0], 6, sync_fun=self.sync_blocks())
assert_equal(len(self.nodes[0].gobject("list-prepared")), 2)
assert_equal(len(self.nodes[0].gobject("list")), 0)
@ -158,10 +156,9 @@ class DashGovernanceTest (DashTestFramework):
self.log.info("Reconnect isolated node and confirm the next ChainLock will let it sync")
self.reconnect_isolated_node(5, 0)
assert_equal(self.nodes[5].mnsync("status")["IsSynced"], False)
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
# NOTE: bumping mocktime too much after recent reconnect can result in "timeout downloading block"
self.bump_mocktime(1)
self.sync_blocks()
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
if __name__ == '__main__':