forked from TrueCloudLab/neoneo-go
storage: drop AppendPrefix/AppendPrefixInt APIs
We're not using them anymore and they allocate.
This commit is contained in:
parent
d2db58d748
commit
522229d731
3 changed files with 3 additions and 58 deletions
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in a new issue