Skip to content

Commit

Permalink
Test: Add time advance in sync mempool checks for tests using mocked …
Browse files Browse the repository at this point in the history
…time.

Now the PoissonNextSend function utilize a mocked time, so if it does not advances, the node will not broadcast the tx inv.
  • Loading branch information
furszy committed Jun 14, 2021
1 parent 4e31c79 commit 6c626a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions test/functional/mining_pos_coldStaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def run_test(self):
assert_equal(self.nodes[1].getbalance(), 50 * 250)
txid = self.nodes[1].sendtoaddress(self.nodes[2].getnewaddress(), (50 * 250 - 0.01))
assert (txid is not None)
self.advance_mocktime(15) # PoissonNextSend is using a mocked time now, requires movement to broadcast the tx
self.sync_mempools()
self.mocktime = self.generate_pos(2, self.mocktime)
self.sync_blocks()
Expand Down
16 changes: 6 additions & 10 deletions test/functional/mining_pos_fakestake.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"""

from io import BytesIO
import time
from time import sleep

from test_framework.authproxy import JSONRPCException
Expand All @@ -59,13 +60,8 @@
class FakeStakeTest(PivxTestFramework):
def set_test_params(self):
self.num_nodes = 2
# nodes[0] moves the chain and checks the spam blocks, nodes[1] sends them

def setup_chain(self):
# Start with PoW cache: 200 blocks
self.log.info("Initializing test directory " + self.options.tmpdir)
self._initialize_chain()
self.enable_mocktime()
# nodes[0] moves the chain and checks the spam blocks, nodes[1] sends them

def log_title(self):
title = "*** Starting %s ***" % self.__class__.__name__
Expand All @@ -76,17 +72,16 @@ def log_title(self):
"3) Stake on a fork chain with coinstake input spent (later) in main chain\n"
self.log.info("\n\n%s\n%s\n%s\n", title, underline, description)


def run_test(self):
# init custom fields
self.mocktime -= (131 * 60)
self.mocktime = int(time.time())
set_node_times(self.nodes, self.mocktime)
self.recipient_0 = self.nodes[0].getnewaddress()
self.recipient_1 = self.nodes[1].getnewaddress()
self.init_dummy_key()

# start test
self.log_title()
set_node_times(self.nodes, self.mocktime)

# nodes[0] mines 50 blocks (201-250) to reach PoS activation
self.log.info("Mining 50 blocks to reach PoS phase...")
Expand Down Expand Up @@ -130,8 +125,9 @@ def test_2(self):
# nodes[1] spends utxos_to_spend at block 256
assert_equal(self.nodes[1].getblockcount(), 255)
txid = self.spend_utxos(1, self.utxos_to_spend, self.recipient_0)[0]
self.advance_mocktime(15) # PoissonNextSend is using a mocked time now, requires movement to broadcast the tx
self.log.info("'utxos_to_spend' spent on txid=(%s...) on block 256" % txid[:16])
self.sync_all()
self.sync_mempools()

# nodes[0] mines 5 more blocks (256-260) to include the spends
self.log.info("Mining 5 blocks to include the spends...")
Expand Down
1 change: 1 addition & 0 deletions test/functional/mining_pos_reorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def findUtxoInList(txid, vout, utxo_list):
self.log.info("Coinstake input %s...%s-%d is spendable again." % (
stakeinput["txid"][:9], stakeinput["txid"][-4:], stakeinput["vout"]))
self.nodes[0].sendrawtransaction(rawtx["hex"])
self.advance_mocktime(15) # PoissonNextSend is using a mocked time now, requires movement to broadcast the tx
self.sync_mempools()
self.mocktime = self.generate_pos(1, self.mocktime)
self.sync_blocks()
Expand Down

0 comments on commit 6c626a8

Please sign in to comment.