From 0da3c374dbec9b5546784d3c4990a626e97abb48 Mon Sep 17 00:00:00 2001 From: 0g-peterzhb <158457852+0g-peterzhb@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:18:58 +0800 Subject: [PATCH] add snapshot test (#276) * add snapshot test --- requirements.txt | 10 +++--- tests/snapshot_test.py | 41 +++++++++++++++++++++++++ tests/test_framework/blockchain_node.py | 6 ++-- tests/test_framework/test_framework.py | 2 +- 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 tests/snapshot_test.py diff --git a/requirements.txt b/requirements.txt index ec81c35..0ebfdb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ jsonrpcclient==4.0.3 pyyaml==6.0.1 -pysha3==1.0.2 -coincurve==18.0.0 -eth-utils==3.0.0 +safe-pysha3==1.0.4 +coincurve==20.0.0 +eth-utils==5.1.0 py-ecc==7.0.0 -web3==6.14.0 +web3==7.5.0 eth_tester cffi==1.16.0 -rtoml==0.10.0 \ No newline at end of file +rtoml==0.11.0 \ No newline at end of file diff --git a/tests/snapshot_test.py b/tests/snapshot_test.py new file mode 100644 index 0000000..dc31c35 --- /dev/null +++ b/tests/snapshot_test.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import os +import shutil +from test_framework.test_framework import TestFramework +from utility.utils import wait_until + +class SnapshotTask(TestFramework): + def setup_params(self): + self.num_nodes = 2 + + # Enable random auto sync only + for i in range(self.num_nodes): + self.zgs_node_configs[i] = { + "sync": { + "auto_sync_enabled": True, + "max_sequential_workers": 3, + "max_random_workers": 3, + "neighbors_only": True, + } + } + + def run_test(self): + # Submit and upload files on node 0 + data_root_1 = self.__upload_file__(0, 256 * 1024) + wait_until(lambda: self.nodes[1].zgs_get_file_info(data_root_1) is not None) + wait_until(lambda: self.nodes[1].zgs_get_file_info(data_root_1)["finalized"]) + + # Start the last node to verify historical file sync + self.nodes[1].shutdown() + shutil.rmtree(os.path.join(self.nodes[1].data_dir, 'db/data_db')) + + self.start_storage_node(1) + self.nodes[1].wait_for_rpc_connection() + + wait_until(lambda: self.nodes[1].zgs_get_file_info(data_root_1) is not None) + wait_until(lambda: self.nodes[1].zgs_get_file_info(data_root_1)["finalized"]) + + +if __name__ == "__main__": + SnapshotTask().main() diff --git a/tests/test_framework/blockchain_node.py b/tests/test_framework/blockchain_node.py index e25a274..943f508 100644 --- a/tests/test_framework/blockchain_node.py +++ b/tests/test_framework/blockchain_node.py @@ -4,7 +4,7 @@ import tempfile import time from web3 import Web3, HTTPProvider -from web3.middleware import construct_sign_and_send_raw_middleware +from web3.middleware import SignAndSendRawMiddlewareBuilder from enum import Enum, unique from config.node_config import ( GENESIS_PRIV_KEY, @@ -262,7 +262,7 @@ class BlockchainNode(TestNode): account1 = w3.eth.account.from_key(GENESIS_PRIV_KEY) account2 = w3.eth.account.from_key(GENESIS_PRIV_KEY1) w3.middleware_onion.add( - construct_sign_and_send_raw_middleware([account1, account2]) + SignAndSendRawMiddlewareBuilder.build([account1, account2]) ) # account = w3.eth.account.from_key(GENESIS_PRIV_KEY1) # w3.middleware_onion.add(construct_sign_and_send_raw_middleware(account)) @@ -365,7 +365,7 @@ class BlockchainNode(TestNode): account1 = w3.eth.account.from_key(GENESIS_PRIV_KEY) account2 = w3.eth.account.from_key(GENESIS_PRIV_KEY1) w3.middleware_onion.add( - construct_sign_and_send_raw_middleware([account1, account2]) + SignAndSendRawMiddlewareBuilder.build([account1, account2]) ) contract_interface = load_contract_metadata(self.contract_path, "Flow") diff --git a/tests/test_framework/test_framework.py b/tests/test_framework/test_framework.py index 0fc03a3..a940d7a 100644 --- a/tests/test_framework/test_framework.py +++ b/tests/test_framework/test_framework.py @@ -44,7 +44,7 @@ class TestFramework: self.num_blockchain_nodes = 1 self.num_nodes = 1 self.blockchain_nodes = [] - self.nodes = [] + self.nodes: list[ZgsNode] = [] self.contract = None self.blockchain_node_configs = {} self.zgs_node_configs = {}