From 6c626a8eb498a1dc76f435366c9991fa54cd4338 Mon Sep 17 00:00:00 2001 From: furszy Date: Mon, 14 Jun 2021 16:58:56 -0300 Subject: [PATCH] Test: Add time advance in sync mempool checks for tests using mocked time. Now the PoissonNextSend function utilize a mocked time, so if it does not advances, the node will not broadcast the tx inv. --- test/functional/mining_pos_coldStaking.py | 1 + test/functional/mining_pos_fakestake.py | 16 ++++++---------- test/functional/mining_pos_reorg.py | 1 + 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/test/functional/mining_pos_coldStaking.py b/test/functional/mining_pos_coldStaking.py index fdb93a65daa6ba..1c388aa9daff66 100755 --- a/test/functional/mining_pos_coldStaking.py +++ b/test/functional/mining_pos_coldStaking.py @@ -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() diff --git a/test/functional/mining_pos_fakestake.py b/test/functional/mining_pos_fakestake.py index 82b9990697495b..52612375d41be0 100755 --- a/test/functional/mining_pos_fakestake.py +++ b/test/functional/mining_pos_fakestake.py @@ -44,6 +44,7 @@ """ from io import BytesIO +import time from time import sleep from test_framework.authproxy import JSONRPCException @@ -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__ @@ -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...") @@ -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...") diff --git a/test/functional/mining_pos_reorg.py b/test/functional/mining_pos_reorg.py index 1eae7fed8fa428..cb1e9ef2bb4aee 100755 --- a/test/functional/mining_pos_reorg.py +++ b/test/functional/mining_pos_reorg.py @@ -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()