diff --git a/tests/test_read_storage.py b/tests/test_read_storage.py index 0dbbb5bf2..157394000 100644 --- a/tests/test_read_storage.py +++ b/tests/test_read_storage.py @@ -1,3 +1,4 @@ +import dataclasses import re import os import sys @@ -14,6 +15,7 @@ from slither.tools.read_storage import SlitherReadStorage try: from web3 import Web3 + from web3.contract import Contract except ImportError: print("ERROR: in order to use slither-read-storage, you need to install web3") print("$ pip3 install web3 --user\n") @@ -67,14 +69,14 @@ def fixture_ganache() -> Generator[GanacheInstance, None, None]: p.wait() -def get_source_file(file_path): +def get_source_file(file_path) -> str: with open(file_path, "r", encoding="utf8") as f: source = f.read() return source -def deploy_contract(w3, ganache, contract_bin, contract_abi): +def deploy_contract(w3, ganache, contract_bin, contract_abi) -> Contract: """Deploy contract to the local ganache network""" signed_txn = w3.eth.account.sign_transaction( dict( @@ -96,7 +98,7 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi): # pylint: disable=too-many-locals @pytest.mark.usefixtures("web3", "ganache") -def test_read_storage(web3, ganache): +def test_read_storage(web3, ganache) -> None: assert web3.isConnected() bin_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.bin") abi_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.abi") @@ -116,7 +118,8 @@ def test_read_storage(web3, ganache): srs.get_storage_layout() srs.get_slot_values() with open("storage_layout.json", "w", encoding="utf-8") as file: - json.dump(srs.slot_info, file, indent=4) + slot_infos_json = {key: dataclasses.asdict(value) for key, value in srs.slot_info.items()} + json.dump(slot_infos_json, file, indent=4) expected_file = os.path.join(STORAGE_TEST_ROOT, "TEST_storage_layout.json") actual_file = os.path.join(SLITHER_ROOT, "storage_layout.json")