add snapshot test (#276)

* add snapshot test
This commit is contained in:
0g-peterzhb 2024-11-19 11:18:58 +08:00 committed by GitHub
parent 2a24bbde18
commit 0da3c374db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 9 deletions

View File

@ -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
rtoml==0.11.0

41
tests/snapshot_test.py Normal file
View File

@ -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()

View File

@ -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")

View File

@ -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 = {}