neo-go/pkg/core/block/helper_test.go

38 lines
755 B
Go
Raw Normal View History

package block
import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"testing"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
2020-01-15 08:35:02 +00:00
"github.com/stretchr/testify/require"
)
func getDecodedBlock(t *testing.T, i int) *Block {
data, err := getBlockData(i)
2020-01-15 08:35:02 +00:00
require.NoError(t, err)
b, err := hex.DecodeString(data["raw"].(string))
2020-01-15 08:35:02 +00:00
require.NoError(t, err)
block := &Block{}
require.NoError(t, testserdes.DecodeBinary(b, block))
return block
}
func getBlockData(i int) (map[string]interface{}, error) {
b, err := ioutil.ReadFile(fmt.Sprintf("../test_data/block_%d.json", i))
if err != nil {
return nil, err
}
var data map[string]interface{}
if err := json.Unmarshal(b, &data); err != nil {
return nil, err
}
return data, err
}