mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
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
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package util
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestWriteVarUint1(t *testing.T) {
|
|
var (
|
|
val = uint64(1)
|
|
buf = new(bytes.Buffer)
|
|
)
|
|
if err := WriteVarUint(buf, val); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assert.Equal(t, 1, buf.Len())
|
|
}
|
|
|
|
func TestWriteVarUint1000(t *testing.T) {
|
|
var (
|
|
val = uint64(1000)
|
|
buf = new(bytes.Buffer)
|
|
)
|
|
|
|
if err := WriteVarUint(buf, val); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assert.Equal(t, 3, buf.Len())
|
|
assert.Equal(t, byte(0xfd), buf.Bytes()[0])
|
|
res := ReadVarUint(buf)
|
|
assert.Equal(t, val, res)
|
|
}
|
|
|
|
func TestWriteVarUint100000(t *testing.T) {
|
|
var (
|
|
val = uint64(100000)
|
|
buf = new(bytes.Buffer)
|
|
)
|
|
|
|
if err := WriteVarUint(buf, val); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assert.Equal(t, 5, buf.Len())
|
|
assert.Equal(t, byte(0xfe), buf.Bytes()[0])
|
|
res := ReadVarUint(buf)
|
|
assert.Equal(t, val, res)
|
|
}
|
|
|
|
func TestWriteVarUint100000000000(t *testing.T) {
|
|
var (
|
|
val = uint64(1000000000000)
|
|
buf = new(bytes.Buffer)
|
|
)
|
|
|
|
if err := WriteVarUint(buf, val); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assert.Equal(t, 9, buf.Len())
|
|
assert.Equal(t, byte(0xff), buf.Bytes()[0])
|
|
res := ReadVarUint(buf)
|
|
assert.Equal(t, val, res)
|
|
}
|