Skip to content

Commit 2fefe64

Browse files
committed
docs
1 parent 7ef7c93 commit 2fefe64

File tree

6 files changed

+13
-47
lines changed

6 files changed

+13
-47
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
- [Performance]()
6363
- [Chaos](./framework/chaos/chaos.md)
6464
- [Fork Testing](./framework/fork.md)
65+
- [Fork Testing (Mutating Storage)](./framework/fork_storage.md)
6566
- [Libraries](./libraries.md)
6667
- [Seth](./libs/seth.md)
6768
- [WASP](./libs/wasp/overview.md)

framework/evm_storage/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This code is used in e2e tests where we need to modify production contracts with
44

55
See a simple example where we override different types [struct](layout_api_test.go)
66

7-
Run it with
7+
Run it with (devbox shell)
88
```
99
./setup.sh
1010
go test -v -run TestLayoutAPI

framework/evm_storage/forge/.github/workflows/test.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

framework/evm_storage/forge/foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[profile.default]
2+
required_version = "0.1.0"
23
src = "src"
34
out = "out"
45
libs = ["lib"]

framework/evm_storage/layout.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,13 @@ func mapSlot(baseSlot string, key string) string {
101101
return "0x" + hex.EncodeToString(hash)
102102
}
103103

104-
func ShiftHexByOffset(hexStr string, offset int) string {
105-
// Strip "0x"
104+
// ShiftHexByOffset is used to set values in slots with offsets
105+
func ShiftHexByOffset(hexStr string, offset uint) string {
106106
hexStr = strings.TrimPrefix(hexStr, "0x")
107-
108-
// Parse into big.Int
109107
n := new(big.Int)
110108
n.SetString(hexStr, 16)
111-
112109
// Shift left by offset * 8 bits
113-
n.Lsh(n, uint(offset*8))
114-
110+
n.Lsh(n, offset*8)
115111
// Return as 0x-prefixed, 32-byte hex
116112
return fmt.Sprintf("0x%064x", n)
117113
}
@@ -170,8 +166,10 @@ func MustEncodeStorageSlot(solidityType string, value interface{}) string {
170166

171167
// MergeHex merges two hex strings with bitwise "OR"
172168
// should be used when you see values with offsets in smart contract storage layout.json file
173-
// example:
174169
//
170+
// Example layout:
171+
// ╭----------------+-------------------------------------------+------+--------+-------+-------------------------╮
172+
// | Name | Type | Slot | Offset | Bytes | Contract |
175173
// |----------------+-------------------------------------------+------+--------+-------+-------------------------|
176174
// | number_uint8 | uint8 | 3 | 0 | 1 | src/Counter.sol:Counter |
177175
// |----------------+-------------------------------------------+------+--------+-------+-------------------------|

framework/evm_storage/layout_api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import (
1616

1717
// TestLayoutAPI that's the example of using helpers to override storage in your contracts
1818
func TestLayoutAPI(t *testing.T) {
19-
//t.Skip("this test is for manual debugging and figuring out layout of custom structs")
19+
t.Skip("this test is for manual debugging and figuring out layout of custom structs")
2020
// load contract layout file, see testdata/layout.json
2121
// more docs here - https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html#
2222
layout, err := evm_storage.New(layoutFile)
2323
if err != nil {
2424
t.Fatalf("failed to load layout: %v", err)
2525
}
2626

27-
encodeFunc := func(addr string, index uint8, group uint8) string {
27+
encodeCustomStructFunc := func(addr string, index uint8, group uint8) string {
2828
// huge structs can be packed differently to save space
2929
// cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3 0x1 --rpc-url http://localhost:8545
3030
addrBytes, _ := hex.DecodeString(strings.TrimPrefix(addr, "0x"))
@@ -82,7 +82,7 @@ func TestLayoutAPI(t *testing.T) {
8282
}
8383
{
8484
slot := layout.MustArraySlot("a_signers", 1)
85-
data := encodeFunc("0x00000000000000000000000000000000000000a5", 255, 42)
85+
data := encodeCustomStructFunc("0x00000000000000000000000000000000000000a5", 255, 42)
8686
fmt.Printf("setting slot: %s with data: %s\n", slot, data)
8787
r := rpc.New(testRPCURL, nil)
8888
err = r.AnvilSetStorageAt([]interface{}{contractAddr, slot, data})
@@ -91,7 +91,7 @@ func TestLayoutAPI(t *testing.T) {
9191
}
9292
{
9393
slot := layout.MustMapSlot("s_signers", "0x00000000000000000000000000000000000000a5")
94-
data := encodeFunc("0x00000000000000000000000000000000000000a5", 254, 40)
94+
data := encodeCustomStructFunc("0x00000000000000000000000000000000000000a5", 254, 40)
9595
fmt.Printf("setting slot: %s with data: %s\n", slot, data)
9696
r := rpc.New(testRPCURL, nil)
9797
err = r.AnvilSetStorageAt([]interface{}{contractAddr, slot, data})

0 commit comments

Comments
 (0)