MCPcopy Create free account
hub / github.com/Jesserc/gevm / TestMemory

Function TestMemory

gevm/memory_test.go:10–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestMemory(t *testing.T) {
11 tests := []struct {
12 name string
13 offset uint64
14 size uint64
15 value []byte
16 testFunc func(mem *Memory, offset uint64, size uint64, value []byte) (got1 any, got2 any)
17 want any
18 want2 any
19 }{
20 {
21 name: "TestMemory_Access",
22 offset: 0,
23 size: 4,
24 value: []byte{0x01, 0x02, 0x03, 0x04},
25 testFunc: func(mem *Memory, offset uint64, size uint64, value []byte) (any, any) {
26 mem.Store(offset, value)
27 return mem.Access(offset, size), nil
28 },
29 want: []byte{0x01, 0x02, 0x03, 0x04},
30 want2: nil,
31 },
32 {
33 name: "TestMemory_Load",
34 offset: 0,
35 size: 32,
36 value: common.RightPadBytes([]byte{0x01, 0x02, 0x03, 0x04}, 32),
37 testFunc: func(mem *Memory, offset uint64, size uint64, value []byte) (any, any) {
38 mem.Store(offset, value)
39 return mem.Load(offset), nil
40 },
41 want: common.RightPadBytes([]byte{0x01, 0x02, 0x03, 0x04}, 32),
42 want2: nil,
43 },
44 {
45 name: "TestMemory_Store",
46 offset: 0,
47 size: 4,
48 value: []byte{0x01, 0x02, 0x03, 0x04},
49 testFunc: func(mem *Memory, offset uint64, size uint64, value []byte) (any, any) {
50 expansionCost := mem.Store(offset, value)
51 return expansionCost, mem.Access(offset, size)
52 },
53 want: uint64(3),
54 want2: []byte{0x01, 0x02, 0x03, 0x04},
55 },
56 {
57 name: "TestMemory_Store32",
58 offset: 0,
59 size: 32,
60 value: common.RightPadBytes([]byte{0x01, 0x02, 0x03, 0x04}, 32),
61 testFunc: func(mem *Memory, offset uint64, size uint64, value []byte) (any, any) {
62 expansionCost := mem.Store32(offset, value)
63 return expansionCost, mem.Access(offset, size)
64 },
65 want: uint64(3),
66 want2: common.RightPadBytes([]byte{0x01, 0x02, 0x03, 0x04}, 32),
67 },

Callers

nothing calls this directly

Calls 8

StoreMethod · 0.95
AccessMethod · 0.95
LoadMethod · 0.95
Store32Method · 0.95
DataMethod · 0.95
LenMethod · 0.95
NewMemoryFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected