Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions test/functional/feature_governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
DashTestFramework,
MasternodeInfo,
)
from test_framework.governance import have_trigger_for_height, prepare_object
from test_framework.governance import (
have_funded_trigger_for_height,
have_trigger_for_height,
prepare_object,
)
from test_framework.util import assert_equal, satoshi_round

GOVERNANCE_UPDATE_MIN = 60 * 60 # src/governance/object.h
Expand Down Expand Up @@ -310,7 +314,7 @@ def sync_gov(node):
# voted NO vote for the trigger non-isolated node created.
# So everyone should be on the same page now with 25 votes total.
for node in self.nodes:
assert_equal(node.gobject("count")["votes"], 25)
self.wait_until(lambda node=node: node.gobject("count")["votes"] == 25, timeout=5)

self.log.info("Remember vote count")
before = self.nodes[1].gobject("count")["votes"]
Expand All @@ -330,9 +334,13 @@ def sync_gov(node):

block_count = self.nodes[0].getblockcount()
n = sb_cycle - block_count % sb_cycle
sb_block_height = block_count + n

self.log.info("Move remaining n blocks until actual Superblock")
for i in range(n):
if i == n - 1:
self.log.info("Wait for Superblock trigger before mining actual Superblock")
self.wait_until(lambda: have_funded_trigger_for_height(self.nodes, sb_block_height))
self.bump_mocktime(1)
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
Expand Down Expand Up @@ -364,7 +372,7 @@ def sync_gov(node):
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.wait_until(lambda: have_trigger_for_height(self.nodes, 180), timeout=1, do_assert=False)
self.log.info("Wait for new trigger and votes")
self.wait_until(lambda: have_trigger_for_height(self.nodes, 180))
self.wait_until(lambda: have_funded_trigger_for_height(self.nodes, 180))
self.log.info("Mine superblock")
self.bump_mocktime(1)
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
Expand All @@ -379,9 +387,13 @@ def sync_gov(node):
for _ in range(sb_maturity_window - 1):
self.bump_mocktime(1)
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height), timeout=1, do_assert=False)
self.wait_until(
lambda sb_height=sb_block_height: have_trigger_for_height(self.nodes, sb_height),
timeout=1,
do_assert=False,
)
# Wait for new trigger and votes
self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height))
self.wait_until(lambda sb_height=sb_block_height: have_funded_trigger_for_height(self.nodes, sb_height))
# Mine superblock
self.bump_mocktime(1)
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
Expand Down
10 changes: 7 additions & 3 deletions test/functional/test_framework/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ def prepare_object(node, object_type, parent_hash, creation_time, revision, name
"data": proposal_template,
}

def have_trigger_for_height(nodes, sb_block_height):
def have_trigger_for_height(nodes, sb_block_height, signal="valid"):
count = 0
for node in nodes:
valid_triggers = node.gobject("list", "valid", "triggers")
for trigger in list(valid_triggers.values()):
triggers = node.gobject("list", signal, "triggers")
for trigger in list(triggers.values()):
if json.loads(trigger["DataString"])["event_block_height"] != sb_block_height:
continue
if trigger['AbsoluteYesCount'] > 0:
count = count + 1
break
return count == len(nodes)


def have_funded_trigger_for_height(nodes, sb_block_height):
return have_trigger_for_height(nodes, sb_block_height, signal="funding")

Loading