fix file CI and slither-read-storage test paths

pull/1782/head
alpharush 2 years ago
parent b0e589ec4f
commit 97b91a0eac
  1. 2
      .github/workflows/IR.yml
  2. 2
      .github/workflows/features.yml
  3. 0
      tests/tools/read-storage/test_data/StorageLayout.abi
  4. 0
      tests/tools/read-storage/test_data/StorageLayout.bin
  5. 0
      tests/tools/read-storage/test_data/TEST_storage_layout.json
  6. 74
      tests/tools/read-storage/test_data/storage_layout-0.8.10.sol
  7. 16
      tests/tools/read-storage/test_read_storage.py

@ -48,4 +48,4 @@ jobs:
- name: Test with pytest
run: |
pytest tests/slithir/
pytest tests/unit/slithir/

@ -41,4 +41,4 @@ jobs:
- name: Test with pytest
run: |
pytest tests/unit/
pytest tests/unit/core/

@ -0,0 +1,74 @@
// overwrite abi and bin:
// solc tests/storage-layout/storage_layout-0.8.10.sol --abi --bin -o tests/storage-layout --overwrite
contract StorageLayout {
uint248 packedUint = 1;
bool packedBool = true;
struct PackedStruct {
bool b;
uint248 a;
}
PackedStruct _packedStruct = PackedStruct(packedBool, packedUint);
mapping (uint => PackedStruct) mappingPackedStruct;
mapping (address => mapping (uint => PackedStruct)) deepMappingPackedStruct;
mapping (address => mapping (uint => bool)) deepMappingElementaryTypes;
mapping (address => PackedStruct[]) mappingDynamicArrayOfStructs;
address _address;
string _string = "slither-read-storage";
uint8 packedUint8 = 8;
bytes8 packedBytes = "aaaaaaaa";
enum Enum {
a,
b,
c
}
Enum _enumA = Enum.a;
Enum _enumB = Enum.b;
Enum _enumC = Enum.c;
uint256[3] fixedArray;
uint256[3][] dynamicArrayOfFixedArrays;
uint[][3] fixedArrayofDynamicArrays;
uint[][] multidimensionalArray;
PackedStruct[] dynamicArrayOfStructs;
PackedStruct[3] fixedArrayOfStructs;
function store() external {
require(_address == address(0));
_address = msg.sender;
mappingPackedStruct[packedUint] = _packedStruct;
deepMappingPackedStruct[_address][packedUint] = _packedStruct;
deepMappingElementaryTypes[_address][1] = true;
deepMappingElementaryTypes[_address][2] = true;
fixedArray = [1, 2, 3];
dynamicArrayOfFixedArrays.push(fixedArray);
dynamicArrayOfFixedArrays.push([4, 5, 6]);
fixedArrayofDynamicArrays[0].push(7);
fixedArrayofDynamicArrays[1].push(8);
fixedArrayofDynamicArrays[1].push(9);
fixedArrayofDynamicArrays[2].push(10);
fixedArrayofDynamicArrays[2].push(11);
fixedArrayofDynamicArrays[2].push(12);
multidimensionalArray.push([13]);
multidimensionalArray.push([14, 15]);
multidimensionalArray.push([16, 17, 18]);
dynamicArrayOfStructs.push(_packedStruct);
dynamicArrayOfStructs.push(PackedStruct(false, 10));
fixedArrayOfStructs[0] = _packedStruct;
fixedArrayOfStructs[1] = PackedStruct(false, 10);
mappingDynamicArrayOfStructs[_address].push(dynamicArrayOfStructs[0]);
mappingDynamicArrayOfStructs[_address].push(dynamicArrayOfStructs[1]);
}
}

@ -4,6 +4,7 @@ import re
import shutil
import subprocess
from time import sleep
from pathlib import Path
from typing import Generator
import pytest
@ -14,8 +15,7 @@ from web3.contract import Contract
from slither import Slither
from slither.tools.read_storage import SlitherReadStorage
TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STORAGE_TEST_ROOT = os.path.join(TOOLS_ROOT, "storage-layout")
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"
# pylint: disable=too-few-public-methods
class GanacheInstance:
@ -93,15 +93,15 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi) -> Contract:
@pytest.mark.usefixtures("web3", "ganache")
def test_read_storage(web3, ganache) -> None:
assert web3.is_connected()
bin_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.bin")
abi_path = os.path.join(STORAGE_TEST_ROOT, "StorageLayout.abi")
bin_path = Path(TEST_DATA_DIR, "StorageLayout.bin").as_posix()
abi_path = Path(TEST_DATA_DIR, "StorageLayout.abi").as_posix()
bytecode = get_source_file(bin_path)
abi = get_source_file(abi_path)
contract = deploy_contract(web3, ganache, bytecode, abi)
contract.functions.store().transact({"from": ganache.eth_address})
address = contract.address
sl = Slither(os.path.join(STORAGE_TEST_ROOT, "storage_layout-0.8.10.sol"))
sl = Slither(Path(TEST_DATA_DIR, "storage_layout-0.8.10.sol").as_posix())
contracts = sl.contracts
srs = SlitherReadStorage(contracts, 100)
@ -110,12 +110,12 @@ def test_read_storage(web3, ganache) -> None:
srs.get_all_storage_variables()
srs.get_storage_layout()
srs.walk_slot_info(srs.get_slot_values)
with open("storage_layout.json", "w", encoding="utf-8") as file:
actual_file = Path(TEST_DATA_DIR, "storage_layout.json").as_posix()
with open(actual_file, "w", encoding="utf-8") as file:
slot_infos_json = srs.to_json()
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")
expected_file = Path(TEST_DATA_DIR, "TEST_storage_layout.json").as_posix()
with open(expected_file, "r", encoding="utf8") as f:
expected = json.load(f)

Loading…
Cancel
Save