From 00fda7daed0debeed5fea23ecff60102912da317 Mon Sep 17 00:00:00 2001 From: leovct Date: Thu, 25 Jul 2024 18:48:24 +0200 Subject: [PATCH] chore: rename methods --- README.md | 4 ++-- memory.go | 8 ++++---- memory_ops.go | 4 ++-- memory_test.go | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2d002e9..b823d28 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,10 @@ type IMemory interface { Access(offset, size int) []byte // Load a word (32 bytes) from memory at the given offset. - Load32(offset int) []byte + LoadWord(offset int) []byte // Store a word (32 bytes) to memory at the given offset. - Store32(word [32]byte, offset int) + StoreWord(word [32]byte, offset int) } // Memory represents a byte-addressable memory structure. diff --git a/memory.go b/memory.go index b629f6c..eb86eea 100644 --- a/memory.go +++ b/memory.go @@ -13,10 +13,10 @@ type IMemory interface { Access(offset, size int) []byte // Load a word (32 bytes) from memory at the given offset. - Load32(offset int) []byte + LoadWord(offset int) []byte // Store a word (32 bytes) to memory at the given offset. - Store32(word [32]byte, offset int) + StoreWord(word [32]byte, offset int) } // Memory represents a byte-addressable memory structure. @@ -58,10 +58,10 @@ func (m *Memory) Access(offset, size int) []byte { return m.data[offset : offset+size] } -func (m *Memory) Load32(offset int) []byte { +func (m *Memory) LoadWord(offset int) []byte { return m.Access(offset, 32) } -func (m *Memory) Store32(word [32]byte, offset int) { +func (m *Memory) StoreWord(word [32]byte, offset int) { m.Store(word[:], offset) } diff --git a/memory_ops.go b/memory_ops.go index ff88cc0..bbb6d88 100644 --- a/memory_ops.go +++ b/memory_ops.go @@ -26,7 +26,7 @@ func (e *EVM) MLoad() error { } // Load memory from memory at given offset. - word := e.memory.Load32(int(offset.Uint64())) + word := e.memory.LoadWord(int(offset.Uint64())) // Store word at the top of the stack. value := new(uint256.Int).SetBytes(word) @@ -49,6 +49,6 @@ func (e *EVM) MStore() error { // Store word at the given offset in memory. word := value.Bytes32() - e.memory.Store32(word, int(offset.Uint64())) + e.memory.StoreWord(word, int(offset.Uint64())) return nil } diff --git a/memory_test.go b/memory_test.go index aff7750..98b688c 100644 --- a/memory_test.go +++ b/memory_test.go @@ -179,7 +179,7 @@ func TestAccessPartial0utOfBonds(t *testing.T) { } } -func TestLoad32(t *testing.T) { +func TestLoadWord(t *testing.T) { // Create an empty memory. m := NewMemory() @@ -194,7 +194,7 @@ func TestLoad32(t *testing.T) { m.Store(data, 0) // Load the first word (32 bytes) from memory. - word1 := m.Load32(0) + word1 := m.LoadWord(0) expectedWord1 := []byte{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, // 10 elements 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, @@ -206,7 +206,7 @@ func TestLoad32(t *testing.T) { } // Load the second word (32 bytes) from memory. - word2 := m.Load32(32) + word2 := m.LoadWord(32) expectedWord2 := []byte{ 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -218,7 +218,7 @@ func TestLoad32(t *testing.T) { } } -func TestStore32(t *testing.T) { +func TestStoreWord(t *testing.T) { // Create an empty memory. m := NewMemory() @@ -227,31 +227,31 @@ func TestStore32(t *testing.T) { word1 := uint256.NewInt(333).Bytes32() word2 := uint256.NewInt(222).Bytes32() word3 := uint256.NewInt(111).Bytes32() - m.Store32(word1, 0) - m.Store32(word2, 32*2) - m.Store32(word3, 32*3) + m.StoreWord(word1, 0) + m.StoreWord(word2, 32*2) + m.StoreWord(word3, 32*3) // Load the first word from memory. - expectedWord1 := m.Load32(0) + expectedWord1 := m.LoadWord(0) if !bytes.Equal(word1[:], expectedWord1) { t.Errorf("Load() at offset 32 returned word %v, wanted %v", word1, expectedWord1) } // Load empty word from memory. - expectedEmptyWord := m.Load32(32) + expectedEmptyWord := m.LoadWord(32) var emptyWord [32]byte if !bytes.Equal(emptyWord[:], expectedEmptyWord) { t.Errorf("Load() at offset 32 returned word %v, wanted empty word %v", emptyWord, expectedEmptyWord) } // Load the second word from memory. - expectedWord2 := m.Load32(32 * 2) + expectedWord2 := m.LoadWord(32 * 2) if !bytes.Equal(word2[:], expectedWord2) { t.Errorf("Load() at offset 32*2 returned word %v, wanted %v", word2, expectedWord2) } // Load the third word from memory. - expectedWord3 := m.Load32(32 * 3) + expectedWord3 := m.LoadWord(32 * 3) if !bytes.Equal(word3[:], expectedWord3) { t.Errorf("Load() at offset 32*3 returned word %v, wanted %v", word3, expectedWord3) }