a67728628e
* Created test_data folder with block json files for testing + create separate file for block base. * Fixed bug in WriteVarUint + Trim logic + unit tests * Refactored store and add more tests for it. * restore headerList from chain file * Fix tx decode bug + lots of housekeeping. * Implemented Node restore state from chain file. * Created standalone package for storage. Added couple more methods to Batch and Store interfaces. * Block persisting + tests * bumped version -> 0.31.0
57 lines
880 B
Go
57 lines
880 B
Go
package storage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
prefixes = []KeyPrefix{
|
|
DataBlock,
|
|
DataTransaction,
|
|
STAccount,
|
|
STCoin,
|
|
STValidator,
|
|
STAsset,
|
|
STContract,
|
|
STStorage,
|
|
IXHeaderHashList,
|
|
IXValidatorsCount,
|
|
SYSCurrentBlock,
|
|
SYSCurrentHeader,
|
|
SYSVersion,
|
|
}
|
|
|
|
expected = []uint8{
|
|
0x01,
|
|
0x02,
|
|
0x40,
|
|
0x44,
|
|
0x48,
|
|
0x4c,
|
|
0x50,
|
|
0x70,
|
|
0x80,
|
|
0x90,
|
|
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]))
|
|
}
|
|
}
|