Skip to content

Commit

Permalink
test: add coverage for single proposal sync based on an orphan propos…
Browse files Browse the repository at this point in the history
…al vote reception and single finalization sync based on an orphan finalization vote.

Github-Pull: bitcoin#2659
Rebased-From: 32196b1
  • Loading branch information
furszy committed Dec 14, 2021
1 parent 979bb2c commit 4cdb587
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions test/functional/tiertwo_governance_sync_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
assert_true,
connect_nodes,
get_datadir_path,
satoshi_round,
satoshi_round
)
import shutil
import os
Expand Down Expand Up @@ -235,11 +235,25 @@ def run_test(self):
self.check_vote_existence(firstProposal.name, self.mnOneCollateral.hash, "YES", True)
self.log.info("all good, MN1 vote accepted everywhere!")

# before broadcast the second vote, let's drop the budget data of ownerOne.
# so the node is forced to send a single proposal sync when the, now orphan, proposal vote is received.
self.log.info("Testing single proposal re-sync based on an orphan vote, dropping budget data...")
self.ownerOne.cleanbudget(try_sync=False)
assert_equal(self.ownerOne.getbudgetprojection(), []) # empty
assert_equal(self.ownerOne.getbudgetinfo(), [])

# now let's vote for the proposal with the second MN
self.log.info("Voting with MN2...")
voteResult = self.ownerTwo.mnbudgetvote("alias", firstProposal.proposalHash, "yes", self.masternodeTwoAlias, True)
assert_equal(voteResult["detail"][0]["result"], "success")

# check orphan vote proposal re-sync
self.log.info("checking orphan vote based proposal re-sync...")
time.sleep(5) # wait a bit before check it
self.check_proposal_existence(firstProposal.name, firstProposal.proposalHash)
self.check_vote_existence(firstProposal.name, self.mnOneCollateral.hash, "YES", True)
self.log.info("all good, orphan vote based proposal re-sync succeeded")

# check that the vote was accepted everywhere
self.stake(1, [self.remoteOne, self.remoteTwo])
self.check_vote_existence(firstProposal.name, self.mnTwoCollateral.hash, "YES", True)
Expand Down Expand Up @@ -288,22 +302,38 @@ def run_test(self):
self.check_budget_finalization_sync(0, "OK")

self.log.info("budget finalization synced!, now voting for the budget finalization..")
# Connecting owner to all the other nodes.
self.connect_to_all(self.ownerOnePos)

voteResult = self.ownerOne.mnfinalbudget("vote-many", budgetFinHash, True)
assert_equal(voteResult["detail"][0]["result"], "success")
time.sleep(2) # wait a bit
self.stake(2, [self.remoteOne, self.remoteTwo])
self.check_budget_finalization_sync(1, "OK")
self.log.info("Remote One voted successfully.")

# before broadcast the second finalization vote, let's drop the budget data of remoteOne.
# so the node is forced to send a single fin sync when the, now orphan, vote is received.
self.log.info("Testing single fin re-sync based on an orphan vote, dropping budget data...")
self.remoteOne.cleanbudget(try_sync=False)
assert_equal(self.remoteOne.getbudgetprojection(), []) # empty
assert_equal(self.remoteOne.getbudgetinfo(), [])

# vote for finalization with MN2 and the DMN
voteResult = self.ownerTwo.mnfinalbudget("vote-many", budgetFinHash, True)
assert_equal(voteResult["detail"][0]["result"], "success")
self.log.info("Remote Two voted successfully.")
voteResult = self.remoteDMN1.mnfinalbudget("vote", budgetFinHash)
assert_equal(voteResult["detail"][0]["result"], "success")
self.log.info("DMN voted successfully.")
time.sleep(2) # wait a bit
self.stake(2, [self.remoteOne, self.remoteTwo])

self.log.info("checking finalization votes..")
self.check_budget_finalization_sync(3, "OK")
self.log.info("orphan vote based finalization re-sync succeeded")

self.stake(8, [self.remoteOne, self.remoteTwo])
self.stake(6, [self.remoteOne, self.remoteTwo])
addrInfo = self.miner.listreceivedbyaddress(0, False, False, firstProposal.paymentAddr)
assert_equal(addrInfo[0]["amount"], firstProposal.amountPerCycle)

Expand Down Expand Up @@ -341,9 +371,7 @@ def run_test(self):
self.log.info("restarting node..")
self.start_node(self.ownerTwoPos)
self.ownerTwo.setmocktime(self.mocktime)
for i in range(self.num_nodes):
if i is not self.ownerTwoPos:
self.connect_nodes_bi(self.nodes, self.ownerTwoPos, i)
self.connect_to_all(self.ownerTwoPos)
self.stake(2, [self.remoteOne, self.remoteTwo])

self.log.info("syncing node..")
Expand Down

0 comments on commit 4cdb587

Please sign in to comment.