forked from TrueCloudLab/neoneo-go
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package storage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var (
|
|
prefixes = []KeyPrefix{
|
|
DataExecutable,
|
|
STAccount,
|
|
STStorage,
|
|
IXHeaderHashList,
|
|
SYSCurrentBlock,
|
|
SYSCurrentHeader,
|
|
SYSVersion,
|
|
}
|
|
|
|
expected = []uint8{
|
|
0x01,
|
|
0x40,
|
|
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{
|
|
{KeyValue: KeyValue{Key: []byte{byte(STStorage), 0x01}, Value: []byte{0x01}}},
|
|
{KeyValue: KeyValue{Key: []byte{byte(STAccount), 0x02}, Value: []byte{0x02}}},
|
|
{KeyValue: KeyValue{Key: []byte{byte(STStorage), 0x03}, Value: []byte{0x03}}, Exists: true},
|
|
},
|
|
Deleted: []KeyValueExists{
|
|
{KeyValue: KeyValue{Key: []byte{byte(STStorage), 0x04}, Value: []byte{0x04}}},
|
|
{KeyValue: KeyValue{Key: []byte{byte(STAccount), 0x05}, Value: []byte{0x05}}},
|
|
{KeyValue: KeyValue{Key: []byte{byte(STStorage), 0x06}, Value: []byte{0x06}}, Exists: true},
|
|
},
|
|
}
|
|
o := []Operation{
|
|
{State: "Added", Key: []byte{0x01}, Value: []byte{0x01}},
|
|
{State: "Changed", Key: []byte{0x03}, Value: []byte{0x03}},
|
|
{State: "Deleted", Key: []byte{0x06}},
|
|
}
|
|
require.Equal(t, o, BatchToOperations(b))
|
|
}
|