From 601c33b6c1fbf5b48ffa37219ece5056776a0518 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Thu, 9 Feb 2023 12:23:24 +0000 Subject: [PATCH 01/15] Disconnect nodes in rollback_to --- ...re_on_chain_government_fee_distribution.py | 18 ++------------- .../test_framework/test_framework.py | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/test/functional/feature_on_chain_government_fee_distribution.py b/test/functional/feature_on_chain_government_fee_distribution.py index 2e6f262831..18616a8467 100755 --- a/test/functional/feature_on_chain_government_fee_distribution.py +++ b/test/functional/feature_on_chain_government_fee_distribution.py @@ -7,9 +7,7 @@ from test_framework.test_framework import DefiTestFramework from test_framework.util import ( - assert_equal, - connect_nodes_bi, - disconnect_nodes, + assert_equal ) from decimal import ROUND_DOWN, Decimal @@ -120,19 +118,7 @@ def test_cfp_fee_distribution(self, amount, expectedFee, burnPct, vote, cycles=2 history = self.nodes[0].listaccounthistory(mn3['ownerAuthAddress'], {"txtype": "ProposalFeeRedistribution"}) assert_equal(history, []) - # Disconnect nodes and check connection count - for i in range(self.num_nodes - 1): - disconnect_nodes(self.nodes[i], i + 1) - assert_equal(self.nodes[i].getconnectioncount(), 0) - assert_equal(self.nodes[3].getconnectioncount(), 0) - - # Rollback nodes in isolation - for i in range(self.num_nodes): - self.rollback_to(height, nodes=[i]) - - # Connect nodes - for i in range(self.num_nodes - 1): - connect_nodes_bi(self.nodes, i, i + 1) + self.rollback_to(height, nodes=[0, 1, 2, 3]) def setup(self): # Get MN addresses diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 1ba5ee5a4e..d37967722a 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -22,9 +22,11 @@ from .mininode import NetworkThread from .util import ( MAX_NODES, + PORT_MIN, PortSeed, assert_equal, check_json_precision, + connect_nodes, connect_nodes_bi, disconnect_nodes, get_datadir_path, @@ -420,8 +422,27 @@ def rollback_to(self, block, nodes=None): if nodes is None: self._rollback_to(block) else: + connections = [] for node in nodes: - self._rollback_to(block, node=node) + nodes_connections = [] + for x in self.nodes[node].getpeerinfo(): + if not x['inbound']: + nodes_connections.append(int(x['addr'].split(':')[1]) - PORT_MIN) + connections.append(nodes) + + for node in nodes: + for x in connections[node]: + disconnect_nodes(self.nodes[node], x) + + for node in nodes: + assert (self.nodes[node].getconnectioncount() == 0) + + for node in nodes: + self._rollback_to(block, node) + + for node in nodes: + for x in connections[node]: + connect_nodes(self.nodes[node], x) def run_test(self): """Tests must override this method to define test logic""" From aff2ce06f6b80fc5a47788f932a4589143f48d6f Mon Sep 17 00:00:00 2001 From: Bushstar Date: Thu, 9 Feb 2023 13:26:10 +0000 Subject: [PATCH 02/15] Use dict --- test/functional/test_framework/test_framework.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index d37967722a..596b86f5e4 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -422,13 +422,13 @@ def rollback_to(self, block, nodes=None): if nodes is None: self._rollback_to(block) else: - connections = [] + connections = {} for node in nodes: nodes_connections = [] for x in self.nodes[node].getpeerinfo(): if not x['inbound']: nodes_connections.append(int(x['addr'].split(':')[1]) - PORT_MIN) - connections.append(nodes) + connections[node] = nodes_connections for node in nodes: for x in connections[node]: From adbd4e5111ace9b270bf2c6fc53c8794401f8331 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 07:18:33 +0000 Subject: [PATCH 03/15] Disconnect inbound peers. Wait until connection count 0. --- .../test_framework/test_framework.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 596b86f5e4..d4b0c61f2a 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -33,6 +33,7 @@ initialize_datadir, sync_blocks, sync_mempools, + wait_until, ) @@ -422,26 +423,33 @@ def rollback_to(self, block, nodes=None): if nodes is None: self._rollback_to(block) else: - connections = {} + connections_outbound = {} + connections_inbound = {} for node in nodes: - nodes_connections = [] + nodes_connections_outbound = [] + nodes_connections_inbound = [] for x in self.nodes[node].getpeerinfo(): - if not x['inbound']: - nodes_connections.append(int(x['addr'].split(':')[1]) - PORT_MIN) - connections[node] = nodes_connections + if x['inbound']: + nodes_connections_inbound.append(int(x['addrbind'].split(':')[1]) - PORT_MIN) + else: + nodes_connections_outbound.append(int(x['addr'].split(':')[1]) - PORT_MIN) + connections_outbound[node] = nodes_connections_outbound + connections_inbound[node] = nodes_connections_inbound for node in nodes: - for x in connections[node]: + for x in connections_outbound[node]: + disconnect_nodes(self.nodes[node], x) + for x in connections_inbound[node]: disconnect_nodes(self.nodes[node], x) for node in nodes: - assert (self.nodes[node].getconnectioncount() == 0) + wait_until(lambda: self.nodes[node].getconnectioncount() == 0) for node in nodes: self._rollback_to(block, node) for node in nodes: - for x in connections[node]: + for x in connections_outbound[node]: connect_nodes(self.nodes[node], x) def run_test(self): From 7259599874660ab11639718bf6d1cfd97f815b79 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 07:22:54 +0000 Subject: [PATCH 04/15] Remove local implementations of rollback_to --- .../feature_loan_payback_with_collateral.py | 11 ----------- test/functional/feature_negative_interest.py | 10 ---------- test/functional/rpc_getstoredinterest.py | 10 ---------- 3 files changed, 31 deletions(-) diff --git a/test/functional/feature_loan_payback_with_collateral.py b/test/functional/feature_loan_payback_with_collateral.py index 076cb5805f..16352a702a 100755 --- a/test/functional/feature_loan_payback_with_collateral.py +++ b/test/functional/feature_loan_payback_with_collateral.py @@ -36,17 +36,6 @@ def set_test_params(self): '-simulatemainnet=1' ]] - def rollback_to(self, block): - self.log.info("rollback to: %d", block) - node = self.nodes[0] - current_height = node.getblockcount() - if current_height == block: - return - blockhash = node.getblockhash(block + 1) - node.invalidateblock(blockhash) - node.clearmempool() - assert_equal(block, node.getblockcount()) - def createOracles(self): self.oracle_address1 = self.nodes[0].getnewaddress("", "legacy") price_feeds = [{"currency": "USD", "token": "DFI"}, diff --git a/test/functional/feature_negative_interest.py b/test/functional/feature_negative_interest.py index 4da02842df..401d2714b7 100755 --- a/test/functional/feature_negative_interest.py +++ b/test/functional/feature_negative_interest.py @@ -19,16 +19,6 @@ def getDecimalAmount(amount): class NegativeInterestTest (DefiTestFramework): - def rollback_to(self, block): - self.log.info("rollback to: %d", block) - current_height = self.nodes[0].getblockcount() - if current_height == block: - return - blockhash = self.nodes[0].getblockhash(block + 1) - self.nodes[0].invalidateblock(blockhash) - self.nodes[0].clearmempool() - assert_equal(block, self.nodes[0].getblockcount()) - def set_test_params(self): self.num_nodes = 1 self.setup_clean_chain = True diff --git a/test/functional/rpc_getstoredinterest.py b/test/functional/rpc_getstoredinterest.py index 8a91fedc49..f2e15cb958 100755 --- a/test/functional/rpc_getstoredinterest.py +++ b/test/functional/rpc_getstoredinterest.py @@ -43,16 +43,6 @@ def set_test_params(self): '-jellyfish_regtest=1', '-txindex=1', '-simulatemainnet=1'] ] - # Utils - def rollback_to(self, block): - node = self.nodes[0] - current_height = node.getblockcount() - if current_height == block: - return - blockhash = node.getblockhash(block + 1) - node.invalidateblock(blockhash) - node.clearmempool() - assert_equal(block, node.getblockcount()) def new_vault(self, loan_scheme, deposit=10): vaultId = self.nodes[0].createvault(self.account0, loan_scheme) From ebdbd971e52035985e010b85136a6b221bc6047e Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 08:01:18 +0000 Subject: [PATCH 05/15] Remove wait_until lambda --- test/functional/test_framework/test_framework.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index d4b0c61f2a..1a444d65de 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -442,9 +442,6 @@ def rollback_to(self, block, nodes=None): for x in connections_inbound[node]: disconnect_nodes(self.nodes[node], x) - for node in nodes: - wait_until(lambda: self.nodes[node].getconnectioncount() == 0) - for node in nodes: self._rollback_to(block, node) From 21957ffe9e6a5ef93bc8c6600e9eb03ae3e63cb6 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 08:07:17 +0000 Subject: [PATCH 06/15] Remove wait_until import --- test/functional/test_framework/test_framework.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 1a444d65de..008cfc596f 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -33,7 +33,6 @@ initialize_datadir, sync_blocks, sync_mempools, - wait_until, ) From 0770d4b22a0fc06e78e020a71219eda682fc7be9 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 08:42:15 +0000 Subject: [PATCH 07/15] Make sure that node is less than max --- test/functional/test_framework/test_framework.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 008cfc596f..b0b157de83 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -429,9 +429,13 @@ def rollback_to(self, block, nodes=None): nodes_connections_inbound = [] for x in self.nodes[node].getpeerinfo(): if x['inbound']: - nodes_connections_inbound.append(int(x['addrbind'].split(':')[1]) - PORT_MIN) + node_number = int(x['addrbind'].split(':')[1]) - PORT_MIN + if node_number <= MAX_NODES: + nodes_connections_inbound.append(node_number) else: - nodes_connections_outbound.append(int(x['addr'].split(':')[1]) - PORT_MIN) + node_number = int(x['addr'].split(':')[1]) - PORT_MIN + if node_number <= MAX_NODES: + nodes_connections_outbound.append(node_number) connections_outbound[node] = nodes_connections_outbound connections_inbound[node] = nodes_connections_inbound From 8af6d369ae48c454de3c06ad314b4d704d5ad56b Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 10:30:54 +0000 Subject: [PATCH 08/15] Simplify rollback code --- .../test_framework/test_framework.py | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index b0b157de83..ab7d2c354e 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -15,6 +15,7 @@ import sys import tempfile import time +import re from .authproxy import JSONRPCException from . import coverage @@ -422,34 +423,24 @@ def rollback_to(self, block, nodes=None): if nodes is None: self._rollback_to(block) else: - connections_outbound = {} - connections_inbound = {} + connections = {} for node in nodes: - nodes_connections_outbound = [] - nodes_connections_inbound = [] + nodes_connections = [] for x in self.nodes[node].getpeerinfo(): - if x['inbound']: - node_number = int(x['addrbind'].split(':')[1]) - PORT_MIN - if node_number <= MAX_NODES: - nodes_connections_inbound.append(node_number) - else: - node_number = int(x['addr'].split(':')[1]) - PORT_MIN - if node_number <= MAX_NODES: - nodes_connections_outbound.append(node_number) - connections_outbound[node] = nodes_connections_outbound - connections_inbound[node] = nodes_connections_inbound + if not x['inbound']: + node_number = re.findall(r'\d+', x['subver'])[-1] + nodes_connections.append(int(node_number)) + connections[node] = nodes_connections for node in nodes: - for x in connections_outbound[node]: - disconnect_nodes(self.nodes[node], x) - for x in connections_inbound[node]: + for x in connections[node]: disconnect_nodes(self.nodes[node], x) for node in nodes: self._rollback_to(block, node) for node in nodes: - for x in connections_outbound[node]: + for x in connections[node]: connect_nodes(self.nodes[node], x) def run_test(self): From b22290db02755890be8ff53cf9817605e1697277 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Fri, 10 Feb 2023 10:36:30 +0000 Subject: [PATCH 09/15] Remove unused import --- test/functional/test_framework/test_framework.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index ab7d2c354e..3b246ebf7c 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -23,7 +23,6 @@ from .mininode import NetworkThread from .util import ( MAX_NODES, - PORT_MIN, PortSeed, assert_equal, check_json_precision, From 197f0ee1cb09370a505295b67996780f7bdadfa6 Mon Sep 17 00:00:00 2001 From: DrPing Date: Thu, 16 Feb 2023 09:59:27 +0800 Subject: [PATCH 10/15] Set default args of rollback_to in test with all the nodes instead of specifying nodes --- test/functional/feature_on_chain_government_fee_distribution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/feature_on_chain_government_fee_distribution.py b/test/functional/feature_on_chain_government_fee_distribution.py index 18616a8467..8cad8a41ea 100755 --- a/test/functional/feature_on_chain_government_fee_distribution.py +++ b/test/functional/feature_on_chain_government_fee_distribution.py @@ -118,7 +118,7 @@ def test_cfp_fee_distribution(self, amount, expectedFee, burnPct, vote, cycles=2 history = self.nodes[0].listaccounthistory(mn3['ownerAuthAddress'], {"txtype": "ProposalFeeRedistribution"}) assert_equal(history, []) - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height) def setup(self): # Get MN addresses From ed7d3992786016059ac8864600b8ebd0b7bb7186 Mon Sep 17 00:00:00 2001 From: DrPing Date: Thu, 16 Feb 2023 10:24:38 +0800 Subject: [PATCH 11/15] Make self.nodes default for rollback_to function in test --- test/functional/test_framework/test_framework.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 8e8e86dc70..b41bd20ed7 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -420,6 +420,7 @@ def _rollback_to(self, block, node=0): # rollback to block # nodes param is a list of node numbers to roll back ([0, 1, 2, 3...] (Default -> None -> node 0) def rollback_to(self, block, nodes=None): + nodes = nodes or self.nodes if nodes is None: self._rollback_to(block) else: From 58d3b907d3d556bb85c48b12fac3e3478528d57e Mon Sep 17 00:00:00 2001 From: DrPing Date: Thu, 16 Feb 2023 11:23:27 +0800 Subject: [PATCH 12/15] Fix logic for rollback_to function in test --- .../test_framework/test_framework.py | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index b41bd20ed7..ee73bf8454 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -408,8 +408,7 @@ def import_deterministic_coinbase_privkeys(self): n.importprivkey(privkey=n.get_genesis_keys().operatorPrivKey, label='coinbase', rescan=True) # rollback one node (Default = node 0) - def _rollback_to(self, block, node=0): - node = self.nodes[node] + def _rollback_to(self, block, node): current_height = node.getblockcount() if current_height == block: return @@ -421,28 +420,25 @@ def _rollback_to(self, block, node=0): # nodes param is a list of node numbers to roll back ([0, 1, 2, 3...] (Default -> None -> node 0) def rollback_to(self, block, nodes=None): nodes = nodes or self.nodes - if nodes is None: - self._rollback_to(block) - else: - connections = {} - for node in nodes: - nodes_connections = [] - for x in self.nodes[node].getpeerinfo(): - if not x['inbound']: - node_number = re.findall(r'\d+', x['subver'])[-1] - nodes_connections.append(int(node_number)) + connections = {} + for node in nodes: + nodes_connections = [] + for x in node.getpeerinfo(): + if not x['inbound']: + node_number = re.findall(r'\d+', x['subver'])[-1] + nodes_connections.append(int(node_number)) connections[node] = nodes_connections - for node in nodes: - for x in connections[node]: - disconnect_nodes(self.nodes[node], x) + for node in nodes: + for x in connections[node]: + disconnect_nodes(node, x) - for node in nodes: - self._rollback_to(block, node) + for node in nodes: + self._rollback_to(block, node) - for node in nodes: - for x in connections[node]: - connect_nodes(self.nodes[node], x) + for node in nodes: + for x in connections[node]: + connect_nodes(node, x) def run_test(self): """Tests must override this method to define test logic""" From 25bbd58bd5205f54257ad97aa3201f2821f4e518 Mon Sep 17 00:00:00 2001 From: DrPing Date: Thu, 16 Feb 2023 12:28:38 +0800 Subject: [PATCH 13/15] Fix tests for rollback_to --- ...eature_on_chain_government_govvar_update.py | 18 +++++++++--------- test/functional/feature_poolswap.py | 2 +- test/functional/feature_restore_utxo.py | 2 +- .../test_framework/test_framework.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/functional/feature_on_chain_government_govvar_update.py b/test/functional/feature_on_chain_government_govvar_update.py index e4c3ac9803..473a6bb514 100755 --- a/test/functional/feature_on_chain_government_govvar_update.py +++ b/test/functional/feature_on_chain_government_govvar_update.py @@ -93,7 +93,7 @@ def test_cfp_update_automatic_payout(self): account = self.nodes[0].getaccount(address) assert_equal(account, ['100.00000000@DFI']) - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_quorum(self): height = self.nodes[0].getblockcount() @@ -157,7 +157,7 @@ def test_cfp_update_quorum(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_approval_threshold(self): height = self.nodes[0].getblockcount() @@ -230,7 +230,7 @@ def test_cfp_update_approval_threshold(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_fee_redistribution(self): height = self.nodes[0].getblockcount() @@ -297,7 +297,7 @@ def test_cfp_update_fee_redistribution(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_cfp_fee(self): height = self.nodes[0].getblockcount() @@ -358,7 +358,7 @@ def test_cfp_update_cfp_fee(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_voting_period(self): height = self.nodes[0].getblockcount() @@ -408,7 +408,7 @@ def test_cfp_update_voting_period(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Completed') - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_voc_emergency_period(self): height = self.nodes[0].getblockcount() @@ -433,7 +433,7 @@ def test_cfp_update_voc_emergency_period(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_update_voc_emergency_fee(self): height = self.nodes[0].getblockcount() @@ -478,7 +478,7 @@ def test_cfp_update_voc_emergency_fee(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def test_cfp_state_after_update(self): height = self.nodes[0].getblockcount() @@ -527,7 +527,7 @@ def test_cfp_state_after_update(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Completed') - self.rollback_to(height, nodes=[0, 1, 2, 3]) + self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) def setup(self): # Get MN addresses diff --git a/test/functional/feature_poolswap.py b/test/functional/feature_poolswap.py index 19ef7080da..b89831ebab 100755 --- a/test/functional/feature_poolswap.py +++ b/test/functional/feature_poolswap.py @@ -563,7 +563,7 @@ def test_testpoolswap_errors(self): "amountFrom": 0, "tokenFrom": self.symbolLTC, "tokenTo": self.symbolBTC, "from": self.accountGN0, "to": self.accountSN1, "maxPrice": 0.1}) def revert_to_initial_state(self): - self.rollback_to(block=0, nodes=[0, 1, 2]) + self.rollback_to(block=0, nodes={self.nodes[0], self.nodes[1], self.nodes[2]}) assert_equal(len(self.nodes[0].listpoolpairs()), 0) assert_equal(len(self.nodes[1].listpoolpairs()), 0) assert_equal(len(self.nodes[2].listpoolpairs()), 0) diff --git a/test/functional/feature_restore_utxo.py b/test/functional/feature_restore_utxo.py index a5f862ca2e..fec562bb37 100755 --- a/test/functional/feature_restore_utxo.py +++ b/test/functional/feature_restore_utxo.py @@ -72,7 +72,7 @@ def run_test(self): self.nodes[1].generate(1) self.nodes[1].accounttoaccount(node1_source, {node1_source: "1@BTC"}) self.nodes[1].generate(1) - self.rollback_to(block, nodes=[1]) + self.rollback_to(block, {self.nodes[1]}) assert_equal(len(self.nodes[1].listunspent()), node1_utxos) if __name__ == '__main__': diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index ee73bf8454..2598d6a11a 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -427,7 +427,7 @@ def rollback_to(self, block, nodes=None): if not x['inbound']: node_number = re.findall(r'\d+', x['subver'])[-1] nodes_connections.append(int(node_number)) - connections[node] = nodes_connections + connections[node] = nodes_connections for node in nodes: for x in connections[node]: From cb96de2e06ee40227ee0658842d0714d4e7418c5 Mon Sep 17 00:00:00 2001 From: DrPing Date: Thu, 16 Feb 2023 15:49:54 +0800 Subject: [PATCH 14/15] Fix tests for rollback_to --- ...eature_on_chain_government_govvar_update.py | 18 +++++++++--------- test/functional/feature_poolswap.py | 2 +- test/functional/feature_restore_utxo.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/functional/feature_on_chain_government_govvar_update.py b/test/functional/feature_on_chain_government_govvar_update.py index 473a6bb514..1128221537 100755 --- a/test/functional/feature_on_chain_government_govvar_update.py +++ b/test/functional/feature_on_chain_government_govvar_update.py @@ -93,7 +93,7 @@ def test_cfp_update_automatic_payout(self): account = self.nodes[0].getaccount(address) assert_equal(account, ['100.00000000@DFI']) - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_quorum(self): height = self.nodes[0].getblockcount() @@ -157,7 +157,7 @@ def test_cfp_update_quorum(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_approval_threshold(self): height = self.nodes[0].getblockcount() @@ -230,7 +230,7 @@ def test_cfp_update_approval_threshold(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_fee_redistribution(self): height = self.nodes[0].getblockcount() @@ -297,7 +297,7 @@ def test_cfp_update_fee_redistribution(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_cfp_fee(self): height = self.nodes[0].getblockcount() @@ -358,7 +358,7 @@ def test_cfp_update_cfp_fee(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_voting_period(self): height = self.nodes[0].getblockcount() @@ -408,7 +408,7 @@ def test_cfp_update_voting_period(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Completed') - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_voc_emergency_period(self): height = self.nodes[0].getblockcount() @@ -433,7 +433,7 @@ def test_cfp_update_voc_emergency_period(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_update_voc_emergency_fee(self): height = self.nodes[0].getblockcount() @@ -478,7 +478,7 @@ def test_cfp_update_voc_emergency_fee(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def test_cfp_state_after_update(self): height = self.nodes[0].getblockcount() @@ -527,7 +527,7 @@ def test_cfp_state_after_update(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Completed') - self.rollback_to(height, {self.nodes[0], self.nodes[1], self.nodes[2], self.nodes[3]}) + self.rollback_to(height, self.nodes[0:4]) def setup(self): # Get MN addresses diff --git a/test/functional/feature_poolswap.py b/test/functional/feature_poolswap.py index b89831ebab..a4ea39962c 100755 --- a/test/functional/feature_poolswap.py +++ b/test/functional/feature_poolswap.py @@ -563,7 +563,7 @@ def test_testpoolswap_errors(self): "amountFrom": 0, "tokenFrom": self.symbolLTC, "tokenTo": self.symbolBTC, "from": self.accountGN0, "to": self.accountSN1, "maxPrice": 0.1}) def revert_to_initial_state(self): - self.rollback_to(block=0, nodes={self.nodes[0], self.nodes[1], self.nodes[2]}) + self.rollback_to(block=0, nodes=self.nodes[:3]) assert_equal(len(self.nodes[0].listpoolpairs()), 0) assert_equal(len(self.nodes[1].listpoolpairs()), 0) assert_equal(len(self.nodes[2].listpoolpairs()), 0) diff --git a/test/functional/feature_restore_utxo.py b/test/functional/feature_restore_utxo.py index fec562bb37..2672fdb09b 100755 --- a/test/functional/feature_restore_utxo.py +++ b/test/functional/feature_restore_utxo.py @@ -72,7 +72,7 @@ def run_test(self): self.nodes[1].generate(1) self.nodes[1].accounttoaccount(node1_source, {node1_source: "1@BTC"}) self.nodes[1].generate(1) - self.rollback_to(block, {self.nodes[1]}) + self.rollback_to(block, self.nodes[:1]) assert_equal(len(self.nodes[1].listunspent()), node1_utxos) if __name__ == '__main__': From 935139535f39a5e86bc9d4c047aca6430e155b50 Mon Sep 17 00:00:00 2001 From: DrPing Date: Thu, 16 Feb 2023 16:07:27 +0800 Subject: [PATCH 15/15] Remove useless array slicing for rollback_to --- ...eature_on_chain_government_govvar_update.py | 18 +++++++++--------- test/functional/feature_poolswap.py | 2 +- test/functional/feature_restore_utxo.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/functional/feature_on_chain_government_govvar_update.py b/test/functional/feature_on_chain_government_govvar_update.py index 1128221537..82bef5eb02 100755 --- a/test/functional/feature_on_chain_government_govvar_update.py +++ b/test/functional/feature_on_chain_government_govvar_update.py @@ -93,7 +93,7 @@ def test_cfp_update_automatic_payout(self): account = self.nodes[0].getaccount(address) assert_equal(account, ['100.00000000@DFI']) - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_quorum(self): height = self.nodes[0].getblockcount() @@ -157,7 +157,7 @@ def test_cfp_update_quorum(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_approval_threshold(self): height = self.nodes[0].getblockcount() @@ -230,7 +230,7 @@ def test_cfp_update_approval_threshold(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_fee_redistribution(self): height = self.nodes[0].getblockcount() @@ -297,7 +297,7 @@ def test_cfp_update_fee_redistribution(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_cfp_fee(self): height = self.nodes[0].getblockcount() @@ -358,7 +358,7 @@ def test_cfp_update_cfp_fee(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_voting_period(self): height = self.nodes[0].getblockcount() @@ -408,7 +408,7 @@ def test_cfp_update_voting_period(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Completed') - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_voc_emergency_period(self): height = self.nodes[0].getblockcount() @@ -433,7 +433,7 @@ def test_cfp_update_voc_emergency_period(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Rejected') - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_update_voc_emergency_fee(self): height = self.nodes[0].getblockcount() @@ -478,7 +478,7 @@ def test_cfp_update_voc_emergency_fee(self): account1 = self.nodes[0].getaccount(mn1['ownerAuthAddress']) assert_equal(account1[0], expectedAmount) - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def test_cfp_state_after_update(self): height = self.nodes[0].getblockcount() @@ -527,7 +527,7 @@ def test_cfp_state_after_update(self): proposal = self.nodes[0].getgovproposal(propId) assert_equal(proposal['status'], 'Completed') - self.rollback_to(height, self.nodes[0:4]) + self.rollback_to(height) def setup(self): # Get MN addresses diff --git a/test/functional/feature_poolswap.py b/test/functional/feature_poolswap.py index a4ea39962c..97e24d4d54 100755 --- a/test/functional/feature_poolswap.py +++ b/test/functional/feature_poolswap.py @@ -563,7 +563,7 @@ def test_testpoolswap_errors(self): "amountFrom": 0, "tokenFrom": self.symbolLTC, "tokenTo": self.symbolBTC, "from": self.accountGN0, "to": self.accountSN1, "maxPrice": 0.1}) def revert_to_initial_state(self): - self.rollback_to(block=0, nodes=self.nodes[:3]) + self.rollback_to(block=0) assert_equal(len(self.nodes[0].listpoolpairs()), 0) assert_equal(len(self.nodes[1].listpoolpairs()), 0) assert_equal(len(self.nodes[2].listpoolpairs()), 0) diff --git a/test/functional/feature_restore_utxo.py b/test/functional/feature_restore_utxo.py index 2672fdb09b..1e37a9a007 100755 --- a/test/functional/feature_restore_utxo.py +++ b/test/functional/feature_restore_utxo.py @@ -72,7 +72,7 @@ def run_test(self): self.nodes[1].generate(1) self.nodes[1].accounttoaccount(node1_source, {node1_source: "1@BTC"}) self.nodes[1].generate(1) - self.rollback_to(block, self.nodes[:1]) + self.rollback_to(block) assert_equal(len(self.nodes[1].listunspent()), node1_utxos) if __name__ == '__main__':