forked from TrueCloudLab/neoneo-go
block: use require in tests
This commit is contained in:
parent
489b88afbb
commit
79bceb3e40
2 changed files with 9 additions and 21 deletions
|
@ -9,20 +9,17 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/encoding/address"
|
"github.com/CityOfZion/neo-go/pkg/encoding/address"
|
||||||
"github.com/CityOfZion/neo-go/pkg/io"
|
"github.com/CityOfZion/neo-go/pkg/io"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test blocks are blocks from mainnet with their corresponding index.
|
// Test blocks are blocks from mainnet with their corresponding index.
|
||||||
|
|
||||||
func TestDecodeBlock1(t *testing.T) {
|
func TestDecodeBlock1(t *testing.T) {
|
||||||
data, err := getBlockData(1)
|
data, err := getBlockData(1)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := hex.DecodeString(data["raw"].(string))
|
b, err := hex.DecodeString(data["raw"].(string))
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
block := &Block{}
|
block := &Block{}
|
||||||
r := io.NewBinReaderFromBuf(b)
|
r := io.NewBinReaderFromBuf(b)
|
||||||
|
@ -51,14 +48,10 @@ func TestTrimmedBlock(t *testing.T) {
|
||||||
block := getDecodedBlock(t, 1)
|
block := getDecodedBlock(t, 1)
|
||||||
|
|
||||||
b, err := block.Trim()
|
b, err := block.Trim()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
trimmedBlock, err := NewBlockFromTrimmedBytes(b)
|
trimmedBlock, err := NewBlockFromTrimmedBytes(b)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.True(t, trimmedBlock.Trimmed)
|
assert.True(t, trimmedBlock.Trimmed)
|
||||||
assert.Equal(t, block.Version, trimmedBlock.Version)
|
assert.Equal(t, block.Version, trimmedBlock.Version)
|
||||||
|
|
|
@ -8,25 +8,20 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/CityOfZion/neo-go/pkg/io"
|
"github.com/CityOfZion/neo-go/pkg/io"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDecodedBlock(t *testing.T, i int) *Block {
|
func getDecodedBlock(t *testing.T, i int) *Block {
|
||||||
data, err := getBlockData(i)
|
data, err := getBlockData(i)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := hex.DecodeString(data["raw"].(string))
|
b, err := hex.DecodeString(data["raw"].(string))
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
block := &Block{}
|
block := &Block{}
|
||||||
r := io.NewBinReaderFromBuf(b)
|
r := io.NewBinReaderFromBuf(b)
|
||||||
block.DecodeBinary(r)
|
block.DecodeBinary(r)
|
||||||
if r.Err != nil {
|
require.NoError(t, r.Err)
|
||||||
t.Fatal(r.Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue