2020-01-14 12:32:07 +00:00
|
|
|
package block
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-02-22 16:27:32 +00:00
|
|
|
"os"
|
2020-01-14 12:32:07 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-11-23 11:09:00 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
2020-01-15 08:35:02 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-01-14 12:32:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func getDecodedBlock(t *testing.T, i int) *Block {
|
|
|
|
data, err := getBlockData(i)
|
2020-01-15 08:35:02 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-14 12:32:07 +00:00
|
|
|
|
|
|
|
b, err := hex.DecodeString(data["raw"].(string))
|
2020-01-15 08:35:02 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-14 12:32:07 +00:00
|
|
|
|
2021-03-25 18:46:52 +00:00
|
|
|
block := New(false)
|
2020-03-26 14:43:24 +00:00
|
|
|
require.NoError(t, testserdes.DecodeBinary(b, block))
|
2020-01-14 12:32:07 +00:00
|
|
|
|
|
|
|
return block
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBlockData(i int) (map[string]interface{}, error) {
|
2022-02-22 16:27:32 +00:00
|
|
|
b, err := os.ReadFile(fmt.Sprintf("../test_data/block_%d.json", i))
|
2020-01-14 12:32:07 +00:00
|
|
|
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
|
|
|
|
}
|