|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
|
|
import dataclasses |
|
|
|
import re |
|
|
|
import re |
|
|
|
import os |
|
|
|
import os |
|
|
|
import sys |
|
|
|
import sys |
|
|
@ -14,6 +15,7 @@ from slither.tools.read_storage import SlitherReadStorage |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
from web3 import Web3 |
|
|
|
from web3 import Web3 |
|
|
|
|
|
|
|
from web3.contract import Contract |
|
|
|
except ImportError: |
|
|
|
except ImportError: |
|
|
|
print("ERROR: in order to use slither-read-storage, you need to install web3") |
|
|
|
print("ERROR: in order to use slither-read-storage, you need to install web3") |
|
|
|
print("$ pip3 install web3 --user\n") |
|
|
|
print("$ pip3 install web3 --user\n") |
|
|
@ -67,14 +69,14 @@ def fixture_ganache() -> Generator[GanacheInstance, None, None]: |
|
|
|
p.wait() |
|
|
|
p.wait() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_source_file(file_path): |
|
|
|
def get_source_file(file_path) -> str: |
|
|
|
with open(file_path, "r", encoding="utf8") as f: |
|
|
|
with open(file_path, "r", encoding="utf8") as f: |
|
|
|
source = f.read() |
|
|
|
source = f.read() |
|
|
|
|
|
|
|
|
|
|
|
return source |
|
|
|
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""" |
|
|
|
"""Deploy contract to the local ganache network""" |
|
|
|
signed_txn = w3.eth.account.sign_transaction( |
|
|
|
signed_txn = w3.eth.account.sign_transaction( |
|
|
|
dict( |
|
|
|
dict( |
|
|
@ -96,7 +98,7 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi): |
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-many-locals |
|
|
|
# pylint: disable=too-many-locals |
|
|
|
@pytest.mark.usefixtures("web3", "ganache") |
|
|
|
@pytest.mark.usefixtures("web3", "ganache") |
|
|
|
def test_read_storage(web3, ganache): |
|
|
|
def test_read_storage(web3, ganache) -> None: |
|
|
|
assert web3.isConnected() |
|
|
|
assert web3.isConnected() |
|
|
|
bin_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.bin") |
|
|
|
bin_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.bin") |
|
|
|
abi_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.abi") |
|
|
|
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_storage_layout() |
|
|
|
srs.get_slot_values() |
|
|
|
srs.get_slot_values() |
|
|
|
with open("storage_layout.json", "w", encoding="utf-8") as file: |
|
|
|
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") |
|
|
|
expected_file = os.path.join(STORAGE_TEST_ROOT, "TEST_storage_layout.json") |
|
|
|
actual_file = os.path.join(SLITHER_ROOT, "storage_layout.json") |
|
|
|
actual_file = os.path.join(SLITHER_ROOT, "storage_layout.json") |
|
|
|