From ce960844d33d5ae51fa2f2376f5ab5ef93b23c03 Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Thu, 2 Feb 2023 15:23:34 -0500 Subject: [PATCH] refator(statetypes): Types -> Storage (#119) --- lib/utils/unsafe_bytes_test.go | 7 - .../types_test.go => lib/utils/utils_test.go | 6 +- .../v1/state.proto => storage/v1/slot.proto} | 8 +- .../types/types.go => constants/constants.go} | 8 +- x/evm/plugins/state/{types => }/interfaces.go | 2 +- x/evm/plugins/state/{types => }/keys.go | 8 +- x/evm/plugins/state/{types => }/keys_test.go | 4 +- x/evm/plugins/state/statedb.go | 46 +++--- x/evm/plugins/state/statedb_factory.go | 20 ++- x/evm/plugins/state/statedb_test.go | 24 +-- .../state/{types => storage}/errors.go | 2 +- .../state/{types/state.go => storage/slot.go} | 18 +-- .../{types/state.pb.go => storage/slot.pb.go} | 143 +++++++++--------- .../state_test.go => storage/slot_test.go} | 44 +++--- .../state/{types => storage}/storage.go | 32 ++-- .../state/{types => storage}/storage_test.go | 32 ++-- x/evm/plugins/state/store/cachemulti/store.go | 4 +- 17 files changed, 201 insertions(+), 207 deletions(-) rename x/evm/plugins/state/types/types_test.go => lib/utils/utils_test.go (91%) rename proto/stargazer/core/state/{types/v1/state.proto => storage/v1/slot.proto} (88%) rename x/evm/{plugins/state/types/types.go => constants/constants.go} (92%) rename x/evm/plugins/state/{types => }/interfaces.go (99%) rename x/evm/plugins/state/{types => }/keys.go (91%) rename x/evm/plugins/state/{types => }/keys_test.go (98%) rename x/evm/plugins/state/{types => storage}/errors.go (98%) rename x/evm/plugins/state/{types/state.go => storage/slot.go} (83%) rename x/evm/plugins/state/{types/state.pb.go => storage/slot.pb.go} (57%) rename x/evm/plugins/state/{types/state_test.go => storage/slot_test.go} (62%) rename x/evm/plugins/state/{types => storage}/storage.go (75%) rename x/evm/plugins/state/{types => storage}/storage_test.go (73%) diff --git a/lib/utils/unsafe_bytes_test.go b/lib/utils/unsafe_bytes_test.go index 2a47fd692..00a3dac4a 100644 --- a/lib/utils/unsafe_bytes_test.go +++ b/lib/utils/unsafe_bytes_test.go @@ -15,18 +15,11 @@ package utils_test import ( - "testing" - "github.com/berachain/stargazer/lib/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -func TestUtilsPkg(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "lib/utils") -} - var _ = Describe("UnsafeStrToBytes", func() { When("given a valid string", func() { It("should return a byte array with the same content", func() { diff --git a/x/evm/plugins/state/types/types_test.go b/lib/utils/utils_test.go similarity index 91% rename from x/evm/plugins/state/types/types_test.go rename to lib/utils/utils_test.go index 804dd5fdf..caca213ce 100644 --- a/x/evm/plugins/state/types/types_test.go +++ b/lib/utils/utils_test.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types_test +package utils_test import ( "testing" @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" ) -func TestStateTypes(t *testing.T) { +func TestUtils(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "x/evm/plugins/state/types") + RunSpecs(t, "lib/utils") } diff --git a/proto/stargazer/core/state/types/v1/state.proto b/proto/stargazer/core/state/storage/v1/slot.proto similarity index 88% rename from proto/stargazer/core/state/types/v1/state.proto rename to proto/stargazer/core/state/storage/v1/slot.proto index 130d12a2b..535d942db 100644 --- a/proto/stargazer/core/state/types/v1/state.proto +++ b/proto/stargazer/core/state/storage/v1/slot.proto @@ -14,12 +14,12 @@ syntax = "proto3"; -package stargazer.core.state.types.v1; +package stargazer.core.state.storage.v1; -option go_package = "github.com/berachain/stargazer/x/evm/plugins/state/types"; +option go_package = "github.com/berachain/stargazer/x/evm/plugins/state/storage"; -// `State` represents a single key/value pair of evm state data. -message State { +// `Slot` represents a single key/value pair of evm state data. +message Slot { // `key` is the stored key. string key = 1; diff --git a/x/evm/plugins/state/types/types.go b/x/evm/constants/constants.go similarity index 92% rename from x/evm/plugins/state/types/types.go rename to x/evm/constants/constants.go index 1177a3189..93438e503 100644 --- a/x/evm/plugins/state/types/types.go +++ b/x/evm/constants/constants.go @@ -12,7 +12,9 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package constants -const EvmStoreKey = "evm" -const EvmNamespace = "evm" +const ( + EvmStoreKey = "evm" + EvmNamespace = "evm" +) diff --git a/x/evm/plugins/state/types/interfaces.go b/x/evm/plugins/state/interfaces.go similarity index 99% rename from x/evm/plugins/state/types/interfaces.go rename to x/evm/plugins/state/interfaces.go index e48baab70..364cd3f8a 100644 --- a/x/evm/plugins/state/types/interfaces.go +++ b/x/evm/plugins/state/interfaces.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package state import ( coretypes "github.com/berachain/stargazer/eth/core/types" diff --git a/x/evm/plugins/state/types/keys.go b/x/evm/plugins/state/keys.go similarity index 91% rename from x/evm/plugins/state/types/keys.go rename to x/evm/plugins/state/keys.go index 1dae5dc24..007597277 100644 --- a/x/evm/plugins/state/types/keys.go +++ b/x/evm/plugins/state/keys.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package state import ( "github.com/berachain/stargazer/lib/common" @@ -34,12 +34,12 @@ func AddressStoragePrefix(address common.Address) []byte { return bz } -// `StateKeyFor` defines the full key under which an account state is stored. -func StateKeyFor(address common.Address, key common.Hash) []byte { +// `KeyForSlot` defines the full key under which an account state is stored. +func KeyForSlot(address common.Address, slot common.Hash) []byte { bz := make([]byte, 1+common.AddressLength+common.HashLength) copy(bz, []byte{keyPrefixStorage}) copy(bz[1:], address[:]) - copy(bz[1+common.AddressLength:], key[:]) + copy(bz[1+common.AddressLength:], slot[:]) return bz } diff --git a/x/evm/plugins/state/types/keys_test.go b/x/evm/plugins/state/keys_test.go similarity index 98% rename from x/evm/plugins/state/types/keys_test.go rename to x/evm/plugins/state/keys_test.go index cd6e5db10..6be684d27 100644 --- a/x/evm/plugins/state/types/keys_test.go +++ b/x/evm/plugins/state/keys_test.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package state import ( "github.com/berachain/stargazer/lib/common" @@ -34,7 +34,7 @@ var _ = Describe("StateKeyFor", func() { It("returns a storage key for a given account and storage slot", func() { address := common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678") slot := common.HexToHash("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef") - key := StateKeyFor(address, slot) + key := KeyForSlot(address, slot) Expect(key).To(HaveLen(1 + common.AddressLength + common.HashLength)) Expect(key[0]).To(Equal(keyPrefixStorage)) Expect(key[1 : 1+common.AddressLength]).To(Equal(address.Bytes())) diff --git a/x/evm/plugins/state/statedb.go b/x/evm/plugins/state/statedb.go index 6e3cd6ca2..d85b5fcf1 100644 --- a/x/evm/plugins/state/statedb.go +++ b/x/evm/plugins/state/statedb.go @@ -28,9 +28,9 @@ import ( "github.com/berachain/stargazer/lib/common" "github.com/berachain/stargazer/lib/crypto" "github.com/berachain/stargazer/lib/utils" + "github.com/berachain/stargazer/x/evm/constants" "github.com/berachain/stargazer/x/evm/plugins/state/store/cachekv" "github.com/berachain/stargazer/x/evm/plugins/state/store/cachemulti" - "github.com/berachain/stargazer/x/evm/plugins/state/types" ) var ( @@ -78,8 +78,8 @@ type StateDB struct { //nolint: revive // we like the vibe. ethStore cachekv.StateDBCacheKVStore // keepers used for balance and account information. - ak types.AccountKeeper - bk types.BankKeeper + ak AccountKeeper + bk BankKeeper // Any error that occurs during an sdk module read or write is // memoized here and is eventually be returned by `Commit`. @@ -113,10 +113,10 @@ type StateDB struct { //nolint: revive // we like the vibe. } // returns a *StateDB using the MultiStore belonging to ctx. -func NewStateDB( +func NewSlotDB( ctx sdk.Context, - ak types.AccountKeeper, - bk types.BankKeeper, + ak AccountKeeper, + bk BankKeeper, storeKey storetypes.StoreKey, evmDenom string, ) *StateDB { @@ -155,7 +155,7 @@ func (sdb *StateDB) CreateAccount(addr common.Address) { sdb.ak.SetAccount(sdb.ctx, acc) // initialize the code hash to empty - sdb.ethStore.Set(types.CodeHashKeyFor(addr), emptyCodeHashBytes) + sdb.ethStore.Set(CodeHashKeyFor(addr), emptyCodeHashBytes) } // ============================================================================= @@ -190,7 +190,7 @@ func (sdb *StateDB) Reset(ctx sdk.Context) { // sdb.accessList = newAccessList() // sdb.suicides = make([]common.Address, 0) // TODO: unghetto this - *sdb = *NewStateDB(ctx, sdb.ak, sdb.bk, sdb.storeKey, sdb.evmDenom) + *sdb = *NewSlotDB(ctx, sdb.ak, sdb.bk, sdb.storeKey, sdb.evmDenom) } // ============================================================================= @@ -210,13 +210,13 @@ func (sdb *StateDB) AddBalance(addr common.Address, amount *big.Int) { coins := sdk.NewCoins(sdk.NewCoin(sdb.evmDenom, sdk.NewIntFromBigInt(amount))) // Mint the coins to the evm module account - if err := sdb.bk.MintCoins(sdb.ctx, types.EvmNamespace, coins); err != nil { + if err := sdb.bk.MintCoins(sdb.ctx, constants.EvmNamespace, coins); err != nil { sdb.setErrorUnsafe(err) return } // Send the coins from the evm module account to the destination address. - if err := sdb.bk.SendCoinsFromModuleToAccount(sdb.ctx, types.EvmNamespace, addr[:], coins); err != nil { + if err := sdb.bk.SendCoinsFromModuleToAccount(sdb.ctx, constants.EvmNamespace, addr[:], coins); err != nil { sdb.setErrorUnsafe(err) } } @@ -227,13 +227,13 @@ func (sdb *StateDB) SubBalance(addr common.Address, amount *big.Int) { coins := sdk.NewCoins(sdk.NewCoin(sdb.evmDenom, sdk.NewIntFromBigInt(amount))) // Send the coins from the source address to the evm module account. - if err := sdb.bk.SendCoinsFromAccountToModule(sdb.ctx, addr[:], types.EvmNamespace, coins); err != nil { + if err := sdb.bk.SendCoinsFromAccountToModule(sdb.ctx, addr[:], constants.EvmNamespace, coins); err != nil { sdb.setErrorUnsafe(err) return } // Burn the coins from the evm module account. - if err := sdb.bk.BurnCoins(sdb.ctx, types.EvmNamespace, coins); err != nil { + if err := sdb.bk.BurnCoins(sdb.ctx, constants.EvmNamespace, coins); err != nil { sdb.setErrorUnsafe(err) return } @@ -288,7 +288,7 @@ func (sdb *StateDB) SetNonce(addr common.Address, nonce uint64) { // the code hash of account. func (sdb *StateDB) GetCodeHash(addr common.Address) common.Hash { if sdb.ak.HasAccount(sdb.ctx, addr[:]) { - if ch := sdb.ethStore.Get(types.CodeHashKeyFor(addr)); ch != nil { + if ch := sdb.ethStore.Get(CodeHashKeyFor(addr)); ch != nil { return common.BytesToHash(ch) } return emptyCodeHash @@ -306,7 +306,7 @@ func (sdb *StateDB) GetCode(addr common.Address) []byte { if (codeHash == common.Hash{}) || codeHash == emptyCodeHash { return nil } - return sdb.ethStore.Get(types.CodeKeyFor(codeHash)) + return sdb.ethStore.Get(CodeKeyFor(codeHash)) } // SetCode implements the `GethStateDB` interface by setting the code hash and @@ -314,12 +314,12 @@ func (sdb *StateDB) GetCode(addr common.Address) []byte { func (sdb *StateDB) SetCode(addr common.Address, code []byte) { codeHash := crypto.Keccak256Hash(code) - sdb.ethStore.Set(types.CodeHashKeyFor(addr), codeHash[:]) + sdb.ethStore.Set(CodeHashKeyFor(addr), codeHash[:]) // store or delete code if len(code) == 0 { - sdb.ethStore.Delete(types.CodeKeyFor(codeHash)) + sdb.ethStore.Delete(CodeKeyFor(codeHash)) } else { - sdb.ethStore.Set(types.CodeKeyFor(codeHash), code) + sdb.ethStore.Set(CodeKeyFor(codeHash), code) } } @@ -380,7 +380,7 @@ func (sdb *StateDB) getStateFromStore( store storetypes.KVStore, addr common.Address, slot common.Hash, ) common.Hash { - if value := store.Get(types.StateKeyFor(addr, slot)); value != nil { + if value := store.Get(KeyForSlot(addr, slot)); value != nil { return common.BytesToHash(value) } return common.Hash{} @@ -388,7 +388,7 @@ func (sdb *StateDB) getStateFromStore( // `SetState` implements the `GethStateDB` interface by setting the state of an // address. -func (sdb *StateDB) SetState(addr common.Address, key, value common.Hash) { +func (sdb *StateDB) SetState(addr common.Address, slot, value common.Hash) { // For performance reasons, we don't check to ensure the account exists before we execute. // This is reasonably safe since under normal operation, SetState is only ever called by the // SSTORE opcode in the EVM, which will only ever be called on an account that exists, since @@ -399,12 +399,12 @@ func (sdb *StateDB) SetState(addr common.Address, key, value common.Hash) { // If empty value is given, delete the state entry. if len(value) == 0 || (value == common.Hash{}) { - sdb.ethStore.Delete(types.StateKeyFor(addr, key)) + sdb.ethStore.Delete(KeyForSlot(addr, slot)) return } // Set the state entry. - sdb.ethStore.Set(types.StateKeyFor(addr, key), value[:]) + sdb.ethStore.Set(KeyForSlot(addr, slot), value[:]) } // ============================================================================= @@ -511,7 +511,7 @@ func (sdb *StateDB) ForEachStorage( addr common.Address, cb func(key, value common.Hash) bool, ) error { - it := sdk.KVStorePrefixIterator(sdb.ethStore, types.AddressStoragePrefix(addr)) + it := sdk.KVStorePrefixIterator(sdb.ethStore, AddressStoragePrefix(addr)) defer it.Close() for ; it.Valid(); it.Next() { @@ -553,7 +553,7 @@ func (sdb *StateDB) Commit() error { } // clear the codehash from this account - sdb.ethStore.Delete(types.CodeHashKeyFor(suicidalAddr)) + sdb.ethStore.Delete(CodeHashKeyFor(suicidalAddr)) // remove auth account sdb.ak.RemoveAccount(sdb.ctx, acct) diff --git a/x/evm/plugins/state/statedb_factory.go b/x/evm/plugins/state/statedb_factory.go index b0bb6dc82..40becf770 100644 --- a/x/evm/plugins/state/statedb_factory.go +++ b/x/evm/plugins/state/statedb_factory.go @@ -19,15 +19,13 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - // "github.com/berachain/stargazer/eth/params". - "github.com/berachain/stargazer/x/evm/plugins/state/types" ) type StateDBFactory struct { //nolint:revive // the vibes are good. // Cosmos Keeper References - ak types.AccountKeeper - bk types.BankKeeper + ak AccountKeeper + bk BankKeeper // evmStoreKey is the store key for the EVM store. evmStoreKey storetypes.StoreKey @@ -36,13 +34,13 @@ type StateDBFactory struct { //nolint:revive // the vibes are good. // evmDenom params.Retriever[params.EVMDenom] } -// NewStateDBFactory returns a new StateDBFactory instance. -func NewStateDBFactory( - ak types.AccountKeeper, - bk types.BankKeeper, +// NewSlotDBFactory returns a new StateDBFactory instance. +func NewSlotDBFactory( + ak AccountKeeper, + bk BankKeeper, evmStoreKey storetypes.StoreKey, // evmDenom params.Retriever[params.EVMDenom], - logFactory types.EthereumLogFactory, + logFactory EthereumLogFactory, ) *StateDBFactory { return &StateDBFactory{ ak: ak, @@ -53,8 +51,8 @@ func NewStateDBFactory( } } -// BuildNewStateDB returns a new StateDB instance. +// BuildNewSlotDB returns a new StateDB instance. func (sdf *StateDBFactory) BuildStateDB(ctx context.Context) *StateDB { - return NewStateDB(sdk.UnwrapSDKContext(ctx), sdf.ak, sdf.bk, sdf.evmStoreKey, "abera") + return NewSlotDB(sdk.UnwrapSDKContext(ctx), sdf.ak, sdf.bk, sdf.evmStoreKey, "abera") // sdf.evmDenom.Get(ctx), sdf.er) } diff --git a/x/evm/plugins/state/statedb_test.go b/x/evm/plugins/state/statedb_test.go index 9f944827c..390089454 100644 --- a/x/evm/plugins/state/statedb_test.go +++ b/x/evm/plugins/state/statedb_test.go @@ -29,21 +29,21 @@ import ( "github.com/berachain/stargazer/lib/crypto" "github.com/berachain/stargazer/testutil" "github.com/berachain/stargazer/x/evm/plugins/state" - "github.com/berachain/stargazer/x/evm/plugins/state/types" + "github.com/berachain/stargazer/x/evm/plugins/state/storage" ) var alice = testutil.Alice var bob = testutil.Bob var _ = Describe("StateDB", func() { - var ak types.AccountKeeper - var bk types.BankKeeper + var ak state.AccountKeeper + var bk state.BankKeeper var ctx sdk.Context var sdb *state.StateDB BeforeEach(func() { ctx, ak, bk, _ = testutil.SetupMinimalKeepers() - sdb = state.NewStateDB(ctx, ak, bk, testutil.EvmKey, "abera") // TODO: use lf + sdb = state.NewSlotDB(ctx, ak, bk, testutil.EvmKey, "abera") // TODO: use lf }) Describe("TestCreateAccount", func() { @@ -287,7 +287,7 @@ var _ = Describe("StateDB", func() { Expect(sdb.GetSavedErr()).To(BeNil()) Expect(sdb.HasSuicided(alice)).To(BeFalse()) // TODO: check the txhash and blockhash stuff - Expect(sdb, state.NewStateDB(ctx, ak, bk, testutil.EvmKey, "bera")) + Expect(sdb, state.NewSlotDB(ctx, ak, bk, testutil.EvmKey, "bera")) }) }) @@ -385,24 +385,24 @@ var _ = Describe("StateDB", func() { It("alice should have her code and state wiped, but not bob", func() { Expect(sdb.GetCode(alice)).To(BeNil()) Expect(sdb.GetCode(bob)).To(Equal(bobCode)) - var aliceStorage types.Storage + var aliceSlots storage.Slots err := sdb.ForEachStorage(alice, func(key, value common.Hash) bool { - aliceStorage = append(aliceStorage, - types.NewState(key, value)) + aliceSlots = append(aliceSlots, + storage.NewSlot(key, value)) return true }) Expect(err).To(BeNil()) - Expect(len(aliceStorage)).To(BeZero()) + Expect(len(aliceSlots)).To(BeZero()) - var bobStorage types.Storage + var bobSlots storage.Slots err = sdb.ForEachStorage(bob, func(key, value common.Hash) bool { - bobStorage = append(bobStorage, types.NewState(key, value)) + bobSlots = append(bobSlots, storage.NewSlot(key, value)) return true }) Expect(err).To(BeNil()) - Expect(len(bobStorage)).To(Equal(10)) + Expect(len(bobSlots)).To(Equal(10)) }) }) diff --git a/x/evm/plugins/state/types/errors.go b/x/evm/plugins/state/storage/errors.go similarity index 98% rename from x/evm/plugins/state/types/errors.go rename to x/evm/plugins/state/storage/errors.go index 0524e315e..680dfa841 100644 --- a/x/evm/plugins/state/types/errors.go +++ b/x/evm/plugins/state/storage/errors.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package storage import "errors" diff --git a/x/evm/plugins/state/types/state.go b/x/evm/plugins/state/storage/slot.go similarity index 83% rename from x/evm/plugins/state/types/state.go rename to x/evm/plugins/state/storage/slot.go index 76e82e27a..0da7bad43 100644 --- a/x/evm/plugins/state/types/state.go +++ b/x/evm/plugins/state/storage/slot.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package storage import ( "fmt" @@ -24,19 +24,19 @@ import ( ) // Compile-time interface assertions. -var _ libtypes.Cloneable[State] = &State{} -var _ fmt.Stringer = Storage{} +var _ libtypes.Cloneable[Slot] = &Slot{} +var _ fmt.Stringer = Slots{} -// `NewState` creates a new State instance. -func NewState(key, value common.Hash) State { - return State{ +// `NewSlot` creates a new State instance. +func NewSlot(key, value common.Hash) Slot { + return Slot{ Key: key.Hex(), Value: value.Hex(), } } // `ValidateBasic` checks to make sure the key is not empty. -func (s State) ValidateBasic() error { +func (s Slot) ValidateBasic() error { if strings.TrimSpace(s.Key) == "" { return errors.Wrapf(ErrInvalidState, "key cannot be empty %s", s.Key) } @@ -45,8 +45,8 @@ func (s State) ValidateBasic() error { } // `Clone` implements `types.Cloneable`. -func (s State) Clone() State { - return State{ +func (s Slot) Clone() Slot { + return Slot{ Key: s.Key, Value: s.Value, } diff --git a/x/evm/plugins/state/types/state.pb.go b/x/evm/plugins/state/storage/slot.pb.go similarity index 57% rename from x/evm/plugins/state/types/state.pb.go rename to x/evm/plugins/state/storage/slot.pb.go index 6027b3c3e..fd6290723 100644 --- a/x/evm/plugins/state/types/state.pb.go +++ b/x/evm/plugins/state/storage/slot.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: stargazer/core/state/types/v1/state.proto +// source: stargazer/core/state/storage/v1/slot.proto -package types +package storage import ( fmt "fmt" @@ -22,26 +22,26 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// `State` represents a single key/value pair of evm state data. -type State struct { +// `Slot` represents a single key/value pair of evm state data. +type Slot struct { // `key` is the stored key. Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // `value` is the stored value for the given key. Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` } -func (m *State) Reset() { *m = State{} } -func (m *State) String() string { return proto.CompactTextString(m) } -func (*State) ProtoMessage() {} -func (*State) Descriptor() ([]byte, []int) { - return fileDescriptor_9856deb21450adce, []int{0} +func (m *Slot) Reset() { *m = Slot{} } +func (m *Slot) String() string { return proto.CompactTextString(m) } +func (*Slot) ProtoMessage() {} +func (*Slot) Descriptor() ([]byte, []int) { + return fileDescriptor_a1051538c5179561, []int{0} } -func (m *State) XXX_Unmarshal(b []byte) error { +func (m *Slot) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *State) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *Slot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_State.Marshal(b, m, deterministic) + return xxx_messageInfo_Slot.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -51,26 +51,26 @@ func (m *State) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return b[:n], nil } } -func (m *State) XXX_Merge(src proto.Message) { - xxx_messageInfo_State.Merge(m, src) +func (m *Slot) XXX_Merge(src proto.Message) { + xxx_messageInfo_Slot.Merge(m, src) } -func (m *State) XXX_Size() int { +func (m *Slot) XXX_Size() int { return m.Size() } -func (m *State) XXX_DiscardUnknown() { - xxx_messageInfo_State.DiscardUnknown(m) +func (m *Slot) XXX_DiscardUnknown() { + xxx_messageInfo_Slot.DiscardUnknown(m) } -var xxx_messageInfo_State proto.InternalMessageInfo +var xxx_messageInfo_Slot proto.InternalMessageInfo -func (m *State) GetKey() string { +func (m *Slot) GetKey() string { if m != nil { return m.Key } return "" } -func (m *State) GetValue() string { +func (m *Slot) GetValue() string { if m != nil { return m.Value } @@ -78,30 +78,31 @@ func (m *State) GetValue() string { } func init() { - proto.RegisterType((*State)(nil), "stargazer.core.state.types.v1.State") + proto.RegisterType((*Slot)(nil), "stargazer.core.state.storage.v1.Slot") } func init() { - proto.RegisterFile("stargazer/core/state/types/v1/state.proto", fileDescriptor_9856deb21450adce) + proto.RegisterFile("stargazer/core/state/storage/v1/slot.proto", fileDescriptor_a1051538c5179561) } -var fileDescriptor_9856deb21450adce = []byte{ - // 188 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0x2e, 0x49, 0x2c, - 0x4a, 0x4f, 0xac, 0x4a, 0x2d, 0xd2, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x49, - 0xd5, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2f, 0x33, 0x84, 0x70, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, - 0xf2, 0x85, 0x64, 0xe1, 0x4a, 0xf5, 0x40, 0x4a, 0xf5, 0x20, 0x72, 0x60, 0xa5, 0x7a, 0x65, 0x86, - 0x4a, 0xfa, 0x5c, 0xac, 0xc1, 0x20, 0x11, 0x21, 0x01, 0x2e, 0xe6, 0xec, 0xd4, 0x4a, 0x09, 0x46, - 0x05, 0x46, 0x0d, 0xce, 0x20, 0x10, 0x53, 0x48, 0x84, 0x8b, 0xb5, 0x2c, 0x31, 0xa7, 0x34, 0x55, - 0x82, 0x09, 0x2c, 0x06, 0xe1, 0x38, 0x05, 0x9d, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, - 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, - 0x43, 0x94, 0x45, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x52, 0x6a, - 0x51, 0x62, 0x72, 0x46, 0x62, 0x66, 0x9e, 0x3e, 0xc2, 0xa5, 0x15, 0xfa, 0xa9, 0x65, 0xb9, 0xfa, - 0x05, 0x39, 0xa5, 0xe9, 0x99, 0x79, 0xc5, 0xc8, 0x4e, 0x4e, 0x62, 0x03, 0x3b, 0xd5, 0x18, 0x10, - 0x00, 0x00, 0xff, 0xff, 0xad, 0x4e, 0x3c, 0x4c, 0xd7, 0x00, 0x00, 0x00, +var fileDescriptor_a1051538c5179561 = []byte{ + // 193 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2a, 0x2e, 0x49, 0x2c, + 0x4a, 0x4f, 0xac, 0x4a, 0x2d, 0xd2, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x01, + 0x91, 0xf9, 0x45, 0x89, 0xe9, 0xa9, 0xfa, 0x65, 0x86, 0xfa, 0xc5, 0x39, 0xf9, 0x25, 0x7a, 0x05, + 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xf2, 0x70, 0xb5, 0x7a, 0x20, 0xb5, 0x7a, 0x60, 0xb5, 0x7a, 0x50, + 0xb5, 0x7a, 0x65, 0x86, 0x4a, 0x7a, 0x5c, 0x2c, 0xc1, 0x39, 0xf9, 0x25, 0x42, 0x02, 0x5c, 0xcc, + 0xd9, 0xa9, 0x95, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x20, 0xa6, 0x90, 0x08, 0x17, 0x6b, + 0x59, 0x62, 0x4e, 0x69, 0xaa, 0x04, 0x13, 0x58, 0x0c, 0xc2, 0x71, 0x0a, 0x39, 0xf1, 0x48, 0x8e, + 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, + 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xab, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, + 0xfc, 0x5c, 0xfd, 0xa4, 0xd4, 0xa2, 0xc4, 0xe4, 0x8c, 0xc4, 0xcc, 0x3c, 0x7d, 0x84, 0x5b, 0x2b, + 0xf4, 0x53, 0xcb, 0x72, 0xf5, 0x0b, 0x72, 0x4a, 0xd3, 0x33, 0xf3, 0x8a, 0x51, 0x1d, 0x9d, 0xc4, + 0x06, 0x76, 0xad, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x39, 0xf6, 0xf1, 0xdb, 0x00, 0x00, + 0x00, } -func (m *State) Marshal() (dAtA []byte, err error) { +func (m *Slot) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -111,12 +112,12 @@ func (m *State) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *State) MarshalTo(dAtA []byte) (int, error) { +func (m *Slot) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Slot) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -124,22 +125,22 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.Value) > 0 { i -= len(m.Value) copy(dAtA[i:], m.Value) - i = encodeVarintState(dAtA, i, uint64(len(m.Value))) + i = encodeVarintSlot(dAtA, i, uint64(len(m.Value))) i-- dAtA[i] = 0x12 } if len(m.Key) > 0 { i -= len(m.Key) copy(dAtA[i:], m.Key) - i = encodeVarintState(dAtA, i, uint64(len(m.Key))) + i = encodeVarintSlot(dAtA, i, uint64(len(m.Key))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func encodeVarintState(dAtA []byte, offset int, v uint64) int { - offset -= sovState(v) +func encodeVarintSlot(dAtA []byte, offset int, v uint64) int { + offset -= sovSlot(v) base := offset for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -149,7 +150,7 @@ func encodeVarintState(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *State) Size() (n int) { +func (m *Slot) Size() (n int) { if m == nil { return 0 } @@ -157,22 +158,22 @@ func (m *State) Size() (n int) { _ = l l = len(m.Key) if l > 0 { - n += 1 + l + sovState(uint64(l)) + n += 1 + l + sovSlot(uint64(l)) } l = len(m.Value) if l > 0 { - n += 1 + l + sovState(uint64(l)) + n += 1 + l + sovSlot(uint64(l)) } return n } -func sovState(x uint64) (n int) { +func sovSlot(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } -func sozState(x uint64) (n int) { - return sovState(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +func sozSlot(x uint64) (n int) { + return sovSlot(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *State) Unmarshal(dAtA []byte) error { +func (m *Slot) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -180,7 +181,7 @@ func (m *State) Unmarshal(dAtA []byte) error { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowState + return ErrIntOverflowSlot } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -195,10 +196,10 @@ func (m *State) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: State: wiretype end group for non-group") + return fmt.Errorf("proto: Slot: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: State: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Slot: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -208,7 +209,7 @@ func (m *State) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowState + return ErrIntOverflowSlot } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -222,11 +223,11 @@ func (m *State) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthState + return ErrInvalidLengthSlot } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthState + return ErrInvalidLengthSlot } if postIndex > l { return io.ErrUnexpectedEOF @@ -240,7 +241,7 @@ func (m *State) Unmarshal(dAtA []byte) error { var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowState + return ErrIntOverflowSlot } if iNdEx >= l { return io.ErrUnexpectedEOF @@ -254,11 +255,11 @@ func (m *State) Unmarshal(dAtA []byte) error { } intStringLen := int(stringLen) if intStringLen < 0 { - return ErrInvalidLengthState + return ErrInvalidLengthSlot } postIndex := iNdEx + intStringLen if postIndex < 0 { - return ErrInvalidLengthState + return ErrInvalidLengthSlot } if postIndex > l { return io.ErrUnexpectedEOF @@ -267,12 +268,12 @@ func (m *State) Unmarshal(dAtA []byte) error { iNdEx = postIndex default: iNdEx = preIndex - skippy, err := skipState(dAtA[iNdEx:]) + skippy, err := skipSlot(dAtA[iNdEx:]) if err != nil { return err } if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthState + return ErrInvalidLengthSlot } if (iNdEx + skippy) > l { return io.ErrUnexpectedEOF @@ -286,7 +287,7 @@ func (m *State) Unmarshal(dAtA []byte) error { } return nil } -func skipState(dAtA []byte) (n int, err error) { +func skipSlot(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 depth := 0 @@ -294,7 +295,7 @@ func skipState(dAtA []byte) (n int, err error) { var wire uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowState + return 0, ErrIntOverflowSlot } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -311,7 +312,7 @@ func skipState(dAtA []byte) (n int, err error) { case 0: for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowState + return 0, ErrIntOverflowSlot } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -327,7 +328,7 @@ func skipState(dAtA []byte) (n int, err error) { var length int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return 0, ErrIntOverflowState + return 0, ErrIntOverflowSlot } if iNdEx >= l { return 0, io.ErrUnexpectedEOF @@ -340,14 +341,14 @@ func skipState(dAtA []byte) (n int, err error) { } } if length < 0 { - return 0, ErrInvalidLengthState + return 0, ErrInvalidLengthSlot } iNdEx += length case 3: depth++ case 4: if depth == 0 { - return 0, ErrUnexpectedEndOfGroupState + return 0, ErrUnexpectedEndOfGroupSlot } depth-- case 5: @@ -356,7 +357,7 @@ func skipState(dAtA []byte) (n int, err error) { return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } if iNdEx < 0 { - return 0, ErrInvalidLengthState + return 0, ErrInvalidLengthSlot } if depth == 0 { return iNdEx, nil @@ -366,7 +367,7 @@ func skipState(dAtA []byte) (n int, err error) { } var ( - ErrInvalidLengthState = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowState = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupState = fmt.Errorf("proto: unexpected end of group") + ErrInvalidLengthSlot = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSlot = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSlot = fmt.Errorf("proto: unexpected end of group") ) diff --git a/x/evm/plugins/state/types/state_test.go b/x/evm/plugins/state/storage/slot_test.go similarity index 62% rename from x/evm/plugins/state/types/state_test.go rename to x/evm/plugins/state/storage/slot_test.go index 7eb94b2ff..18e1961a6 100644 --- a/x/evm/plugins/state/types/state_test.go +++ b/x/evm/plugins/state/storage/slot_test.go @@ -12,75 +12,75 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types_test +package storage_test import ( "math/rand" "github.com/berachain/stargazer/lib/common" - "github.com/berachain/stargazer/x/evm/plugins/state/types" + "github.com/berachain/stargazer/x/evm/plugins/state/storage" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -var _ = Describe("x/evm/plugins/state/types", func() { - var state types.State +var _ = Describe("x/evm/plugins/state/storage", func() { + var slot storage.Slot key := common.Hash{}.Bytes() value := common.Hash{}.Bytes() BeforeEach(func() { rand.Read(key) rand.Read(value) - state = types.NewState(common.BytesToHash(key), common.BytesToHash(value)) + slot = storage.NewSlot(common.BytesToHash(key), common.BytesToHash(value)) }) It("should return the correct key", func() { - Expect(state.Key).To(Equal(common.BytesToHash(key).Hex())) + Expect(slot.Key).To(Equal(common.BytesToHash(key).Hex())) }) It("should return the correct value", func() { - Expect(state.Value).To(Equal(common.BytesToHash(value).Hex())) + Expect(slot.Value).To(Equal(common.BytesToHash(value).Hex())) }) - It("should have valid state", func() { - Expect(state.ValidateBasic()).To(BeNil()) + It("should have valid slot", func() { + Expect(slot.ValidateBasic()).To(BeNil()) }) - When("state key is empty", func() { + When("slot key is empty", func() { BeforeEach(func() { - state.Key = "" + slot.Key = "" }) It("should return an error", func() { - Expect(state.ValidateBasic()).NotTo(BeNil()) + Expect(slot.ValidateBasic()).NotTo(BeNil()) }) }) - When("state key has leading or trailing spaces", func() { - When("state key is not empty", func() { + When("slot key has leading or trailing spaces", func() { + When("slot key is not empty", func() { BeforeEach(func() { - state.Key = " bingbong " + slot.Key = " bingbong " }) It("should not return an error", func() { - Expect(state.ValidateBasic()).To(BeNil()) + Expect(slot.ValidateBasic()).To(BeNil()) }) }) - When("state key is empty", func() { + When("slot key is empty", func() { BeforeEach(func() { - state.Key = " " + slot.Key = " " }) It("should return an error", func() { - Expect(state.ValidateBasic()).NotTo(BeNil()) + Expect(slot.ValidateBasic()).NotTo(BeNil()) }) }) }) It("is cloneable", func() { - clone := state.Clone() - Expect(clone).To(Equal(state)) - Expect(&clone).NotTo(BeIdenticalTo(&state)) + clone := slot.Clone() + Expect(clone).To(Equal(slot)) + Expect(&clone).NotTo(BeIdenticalTo(&slot)) }) }) diff --git a/x/evm/plugins/state/types/storage.go b/x/evm/plugins/state/storage/storage.go similarity index 75% rename from x/evm/plugins/state/types/storage.go rename to x/evm/plugins/state/storage/storage.go index 8ef1722ee..f88cef578 100644 --- a/x/evm/plugins/state/types/storage.go +++ b/x/evm/plugins/state/storage/storage.go @@ -12,7 +12,7 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package storage import ( "fmt" @@ -22,45 +22,45 @@ import ( ) // Compile-time type assertions. -var _ libtypes.Cloneable[Storage] = Storage{} -var _ fmt.Stringer = Storage{} +var _ libtypes.Cloneable[Slots] = Slots{} +var _ fmt.Stringer = Slots{} // `Storage` represents the account Storage map as a slice of single key value // State pairs. This helps to ensure that the Storage map can be iterated over // deterministically. -type Storage []State +type Slots []Slot // `ValidateBasic` performs basic validation of the Storage data structure. // It checks for duplicate keys and calls `ValidateBasic` on each `State`. -func (s Storage) ValidateBasic() error { - seenStorage := make(map[string]bool) - for i, state := range s { - if seenStorage[state.Key] { - return errors.Wrapf(ErrInvalidState, "duplicate state key %d: %s", i, state.Key) +func (s Slots) ValidateBasic() error { + seenSlots := make(map[string]bool) + for i, slot := range s { + if seenSlots[slot.Key] { + return errors.Wrapf(ErrInvalidState, "duplicate state key %d: %s", i, slot.Key) } - if err := state.ValidateBasic(); err != nil { + if err := slot.ValidateBasic(); err != nil { return err } - seenStorage[state.Key] = true + seenSlots[slot.Key] = true } return nil } // `String` implements `fmt.Stringer`. -func (s Storage) String() string { +func (s Slots) String() string { var str string - for _, state := range s { - str += fmt.Sprintf("%s\n", state.String()) + for _, slot := range s { + str += fmt.Sprintf("%s\n", slot.String()) } return str } // `Clone` implements `types.Cloneable`. -func (s Storage) Clone() Storage { - cpy := make(Storage, len(s)) +func (s Slots) Clone() Slots { + cpy := make(Slots, len(s)) copy(cpy, s) return cpy diff --git a/x/evm/plugins/state/types/storage_test.go b/x/evm/plugins/state/storage/storage_test.go similarity index 73% rename from x/evm/plugins/state/types/storage_test.go rename to x/evm/plugins/state/storage/storage_test.go index 87e7454ed..c260cdea0 100644 --- a/x/evm/plugins/state/types/storage_test.go +++ b/x/evm/plugins/state/storage/storage_test.go @@ -12,11 +12,11 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types_test +package storage_test import ( "github.com/berachain/stargazer/lib/common" - "github.com/berachain/stargazer/x/evm/plugins/state/types" + "github.com/berachain/stargazer/x/evm/plugins/state/storage" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -24,54 +24,54 @@ import ( var _ = Describe("StorageTest", func() { When("storage is empty", func() { It("should not return an error", func() { - storage := types.Storage{} - Expect(storage.ValidateBasic()).To(BeNil()) + slots := storage.Slots{} + Expect(slots.ValidateBasic()).To(BeNil()) }) }) When("storage is not empty", func() { - var storage types.Storage + var slots storage.Slots BeforeEach(func() { - storage = types.Storage{ - types.NewState(common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3})), + slots = storage.Slots{ + storage.NewSlot(common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3})), } }) It("should not return an error", func() { - Expect(storage.ValidateBasic()).To(BeNil()) + Expect(slots.ValidateBasic()).To(BeNil()) }) When("a storage key is empty", func() { BeforeEach(func() { - storage[0].Key = "" + slots[0].Key = "" }) It("should return an error", func() { - Expect(storage.ValidateBasic()).NotTo(BeNil()) + Expect(slots.ValidateBasic()).NotTo(BeNil()) }) }) It("should be Cloneable", func() { - clone := storage.Clone() - Expect(clone).To(Equal(storage)) - Expect(clone).NotTo(BeIdenticalTo(storage)) + clone := slots.Clone() + Expect(clone).To(Equal(slots)) + Expect(clone).NotTo(BeIdenticalTo(slots)) }) When("a storage key is duplicated", func() { BeforeEach(func() { - storage = append(storage, types.NewState( + slots = append(slots, storage.NewSlot( common.BytesToHash([]byte{1, 2, 3}), common.BytesToHash([]byte{1, 2, 3}), )) }) It("should return an error", func() { - Expect(storage.ValidateBasic()).NotTo(BeNil()) + Expect(slots.ValidateBasic()).NotTo(BeNil()) }) }) It("should be printable", func() { - Expect(storage.String()).To(ContainSubstring("key:" + + Expect(slots.String()).To(ContainSubstring("key:" + "\"0x0000000000000000000000000000000000000000000000000000000000010203\" value:" + "\"0x0000000000000000000000000000000000000000000000000000000000010203\"", )) diff --git a/x/evm/plugins/state/store/cachemulti/store.go b/x/evm/plugins/state/store/cachemulti/store.go index 10c9b8e2f..4ca517bd8 100644 --- a/x/evm/plugins/state/store/cachemulti/store.go +++ b/x/evm/plugins/state/store/cachemulti/store.go @@ -16,9 +16,9 @@ package cachemulti import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" + "github.com/berachain/stargazer/x/evm/constants" "github.com/berachain/stargazer/x/evm/plugins/state/store/cachekv" "github.com/berachain/stargazer/x/evm/plugins/state/store/journal" - statetypes "github.com/berachain/stargazer/x/evm/plugins/state/types" ) // Compile-time check to ensure `Store` implements `storetypes.CacheMultiStore`. @@ -76,7 +76,7 @@ func (s *Store) newCacheKVStore( key storetypes.StoreKey, kvstore storetypes.KVStore, ) storetypes.CacheKVStore { - if key.Name() == statetypes.EvmStoreKey { + if key.Name() == constants.EvmStoreKey { return cachekv.NewEvmStore(kvstore, s.JournalMgr) } return cachekv.NewStore(kvstore, s.JournalMgr)