test: rework feature_governance_cl.py

This commit is contained in:
UdjinM6 2024-08-30 16:08:53 +03:00
parent 11ac0819da
commit 0c5179462e
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9

View File

@ -5,11 +5,12 @@
"""Tests governance checks can be skipped for blocks covered by the best chainlock."""
import json
import time
from test_framework.governance import have_trigger_for_height
from test_framework.messages import uint256_to_string
from test_framework.test_framework import DashTestFramework
from test_framework.util import assert_equal, force_finish_mnsync, satoshi_round
from test_framework.util import assert_equal, satoshi_round
class DashGovernanceTest (DashTestFramework):
def set_test_params(self):
@ -22,7 +23,7 @@ class DashGovernanceTest (DashTestFramework):
"type": object_type,
"name": name,
"start_epoch": proposal_time,
"end_epoch": proposal_time + 24 * 60 * 60,
"end_epoch": proposal_time + 20 * 156,
"payment_amount": float(amount),
"payment_address": payment_address,
"url": "https://dash.org"
@ -40,6 +41,8 @@ class DashGovernanceTest (DashTestFramework):
def run_test(self):
sb_cycle = 20
sb_maturity_window = 10
sb_immaturity_window = sb_cycle - sb_maturity_window
self.log.info("Make sure ChainLocks are active")
@ -62,7 +65,14 @@ class DashGovernanceTest (DashTestFramework):
self.nodes[0].sporkupdate("SPORK_9_SUPERBLOCKS_ENABLED", 0)
self.wait_for_sporks_same()
self.log.info("Prepare and submit proposals")
# Move to the superblock cycle start block
n = sb_cycle - self.nodes[0].getblockcount() % sb_cycle
for _ in range(n):
self.bump_mocktime(156)
self.nodes[0].generate(1)
self.sync_blocks()
self.log.info("Prepare proposals")
proposal_time = self.mocktime
self.p0_payout_address = self.nodes[0].getnewaddress()
@ -81,6 +91,8 @@ class DashGovernanceTest (DashTestFramework):
assert_equal(len(self.nodes[0].gobject("list-prepared")), 2)
assert_equal(len(self.nodes[0].gobject("list")), 0)
self.log.info("Submit proposals")
self.p0_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p0_collateral_prepare["hex"], p0_collateral_prepare["collateralHash"])
self.p1_hash = self.nodes[0].gobject("submit", "0", 1, proposal_time, p1_collateral_prepare["hex"], p1_collateral_prepare["collateralHash"])
@ -99,31 +111,62 @@ class DashGovernanceTest (DashTestFramework):
assert_equal(len(self.nodes[0].gobject("list", "valid", "triggers")), 0)
n = sb_cycle - self.nodes[0].getblockcount() % sb_cycle
assert n > 1
# Move remaining n blocks until the next Superblock
for _ in range(n - 1):
self.nodes[0].generate(1)
self.log.info("Move 1 block into sb maturity window")
n = sb_immaturity_window - self.nodes[0].getblockcount() % sb_cycle
assert n >= 0
for _ in range(n + 1):
self.bump_mocktime(156)
self.nodes[0].generate(1)
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() + 1
self.wait_until(lambda: have_trigger_for_height(self.nodes[0:5], sb_block_height))
# Mine superblock
self.nodes[0].generate(1)
sb_block_height = self.nodes[0].getblockcount() // sb_cycle * sb_cycle + sb_cycle
assert_equal(sb_block_height % sb_cycle, 0)
self.wait_until(lambda: have_trigger_for_height(self.nodes[0:5], sb_block_height), timeout=5)
n = sb_cycle - self.nodes[0].getblockcount() % sb_cycle
assert n > 1
self.log.info("Move remaining n blocks until the next Superblock")
for _ in range(n - 1):
self.bump_mocktime(156)
self.nodes[0].generate(1)
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.nodes[0].generate(1)
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.nodes[0].generate(1)
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.nodes[0].generate(1)
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
time.sleep(1)
# Move forward to satisfy GOVERNANCE_DELETION_DELAY, should actually remove old triggers now
self.bump_mocktime(10 * 60)
self.wait_until(lambda: len(self.nodes[0].gobject("list", "valid", "triggers")) == 0, timeout=5)
self.log.info("Reconnect isolated node and confirm the next ChainLock will let it sync")
self.reconnect_isolated_node(5, 0)
# Force isolated node to be fully synced so that it would not request gov objects when reconnected
assert_equal(self.nodes[5].mnsync("status")["IsSynced"], False)
force_finish_mnsync(self.nodes[5])
self.nodes[0].generate(1)
self.bump_mocktime(156)
# NOTE: bumping mocktime too much after recent reconnect can result in "timeout downloading block"
self.bump_mocktime(1)
self.sync_blocks()