forked from TrueCloudLab/neoneo-go
45 lines
759 B
Go
45 lines
759 B
Go
|
package block
|
||
|
|
||
|
import (
|
||
|
"encoding/hex"
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"io/ioutil"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/CityOfZion/neo-go/pkg/io"
|
||
|
)
|
||
|
|
||
|
func getDecodedBlock(t *testing.T, i int) *Block {
|
||
|
data, err := getBlockData(i)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
b, err := hex.DecodeString(data["raw"].(string))
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
block := &Block{}
|
||
|
r := io.NewBinReaderFromBuf(b)
|
||
|
block.DecodeBinary(r)
|
||
|
if r.Err != nil {
|
||
|
t.Fatal(r.Err)
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|