diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 14c687a19..079b4efd3 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -124,8 +124,10 @@ func TestAddBlock(t *testing.T) { _, err = bc.persist(false) require.NoError(t, err) + key := make([]byte, 1+util.Uint256Size) + key[0] = byte(storage.DataExecutable) for _, block := range blocks { - key := storage.AppendPrefix(storage.DataExecutable, block.Hash().BytesBE()) + copy(key[1:], block.Hash().BytesBE()) _, err := bc.dao.Store.Get(key) require.NoErrorf(t, err, "block %s not persisted", block.Hash()) } diff --git a/pkg/core/storage/store.go b/pkg/core/storage/store.go index b6cfe80bf..0812a5f08 100644 --- a/pkg/core/storage/store.go +++ b/pkg/core/storage/store.go @@ -1,7 +1,6 @@ package storage import ( - "encoding/binary" "errors" "fmt" @@ -112,23 +111,6 @@ func (k KeyPrefix) Bytes() []byte { return []byte{byte(k)} } -// AppendPrefix appends byteslice b to the given KeyPrefix. -// AppendKeyPrefix(SYSVersion, []byte{0x00, 0x01}). -func AppendPrefix(k KeyPrefix, b []byte) []byte { - dest := make([]byte, len(b)+1) - dest[0] = byte(k) - copy(dest[1:], b) - return dest -} - -// AppendPrefixInt append int n to the given KeyPrefix. -// AppendPrefixInt(SYSCurrentHeader, 10001) -func AppendPrefixInt(k KeyPrefix, n int) []byte { - b := make([]byte, 4) - binary.BigEndian.PutUint32(b, uint32(n)) - return AppendPrefix(k, b) -} - func seekRangeToPrefixes(sr SeekRange) *util.Range { var ( rang *util.Range diff --git a/pkg/core/storage/store_test.go b/pkg/core/storage/store_test.go index a07b97ece..7191e46ad 100644 --- a/pkg/core/storage/store_test.go +++ b/pkg/core/storage/store_test.go @@ -3,48 +3,9 @@ package storage import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -var ( - prefixes = []KeyPrefix{ - DataExecutable, - DataMPT, - STStorage, - IXHeaderHashList, - SYSCurrentBlock, - SYSCurrentHeader, - SYSVersion, - } - - expected = []uint8{ - 0x01, - 0x03, - 0x70, - 0x80, - 0xc0, - 0xc1, - 0xf0, - } -) - -func TestAppendPrefix(t *testing.T) { - for i := 0; i < len(expected); i++ { - value := []byte{0x01, 0x02} - prefix := AppendPrefix(prefixes[i], value) - assert.Equal(t, KeyPrefix(expected[i]), KeyPrefix(prefix[0])) - } -} - -func TestAppendPrefixInt(t *testing.T) { - for i := 0; i < len(expected); i++ { - value := 2000 - prefix := AppendPrefixInt(prefixes[i], value) - assert.Equal(t, KeyPrefix(expected[i]), KeyPrefix(prefix[0])) - } -} - func TestBatchToOperations(t *testing.T) { b := &MemBatch{ Put: []KeyValueExists{