From f0c222b385a5cd77d2b1a4f4f56e6497c020361e Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 30 Mar 2021 16:47:15 +0300 Subject: [PATCH] core: move StorageItem-related constants to `storage` pkg Need this to avoid import cycle problem. --- pkg/core/interop_system.go | 13 +++---------- pkg/core/interop_system_test.go | 7 ++++--- pkg/core/storage/store.go | 8 ++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index b37b2b2d9..eb17b7ee7 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/native" + "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -16,14 +17,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) -const ( - // MaxStorageKeyLen is the maximum length of a key for storage items. - MaxStorageKeyLen = 64 - // MaxStorageValueLen is the maximum length of a value for storage items. - // It is set to be the maximum value for uint16. - MaxStorageValueLen = 65535 -) - // StorageContext contains storing id and read/write flag, it's used as // a context for storage manipulation functions. type StorageContext struct { @@ -104,10 +97,10 @@ func storageGetContextInternal(ic *interop.Context, isReadOnly bool) error { } func putWithContext(ic *interop.Context, stc *StorageContext, key []byte, value []byte) error { - if len(key) > MaxStorageKeyLen { + if len(key) > storage.MaxStorageKeyLen { return errors.New("key is too big") } - if len(value) > MaxStorageValueLen { + if len(value) > storage.MaxStorageValueLen { return errors.New("value is too big") } if stc.ReadOnly { diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index feaaf581a..b682f204c 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -198,7 +199,7 @@ func TestStoragePut(t *testing.T) { }) t.Run("check limits", func(t *testing.T) { - initVM(t, make([]byte, MaxStorageKeyLen), make([]byte, MaxStorageValueLen), -1) + initVM(t, make([]byte, storage.MaxStorageKeyLen), make([]byte, storage.MaxStorageValueLen), -1) require.NoError(t, storagePut(ic)) }) @@ -209,11 +210,11 @@ func TestStoragePut(t *testing.T) { require.Error(t, storagePut(ic)) }) t.Run("big key", func(t *testing.T) { - initVM(t, make([]byte, MaxStorageKeyLen+1), []byte{1}, -1) + initVM(t, make([]byte, storage.MaxStorageKeyLen+1), []byte{1}, -1) require.Error(t, storagePut(ic)) }) t.Run("big value", func(t *testing.T) { - initVM(t, []byte{1}, make([]byte, MaxStorageValueLen+1), -1) + initVM(t, []byte{1}, make([]byte, storage.MaxStorageValueLen+1), -1) require.Error(t, storagePut(ic)) }) }) diff --git a/pkg/core/storage/store.go b/pkg/core/storage/store.go index 485d45104..14bd13888 100644 --- a/pkg/core/storage/store.go +++ b/pkg/core/storage/store.go @@ -23,6 +23,14 @@ const ( SYSVersion KeyPrefix = 0xf0 ) +const ( + // MaxStorageKeyLen is the maximum length of a key for storage items. + MaxStorageKeyLen = 64 + // MaxStorageValueLen is the maximum length of a value for storage items. + // It is set to be the maximum value for uint16. + MaxStorageValueLen = 65535 +) + // ErrKeyNotFound is an error returned by Store implementations // when a certain key is not found. var ErrKeyNotFound = errors.New("key not found")