2018-02-07 14:16:50 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
2018-03-04 13:56:49 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
2018-02-07 14:16:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadersEncodeDecode(t *testing.T) {
|
|
|
|
headers := &Headers{[]*core.Header{
|
|
|
|
&core.Header{
|
|
|
|
BlockBase: core.BlockBase{
|
|
|
|
Version: 0,
|
|
|
|
Index: 1,
|
2018-03-04 13:56:49 +00:00
|
|
|
Script: &transaction.Witness{
|
2018-02-07 14:16:50 +00:00
|
|
|
InvocationScript: []byte{0x0},
|
|
|
|
VerificationScript: []byte{0x1},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
&core.Header{
|
|
|
|
BlockBase: core.BlockBase{
|
|
|
|
Version: 0,
|
|
|
|
Index: 2,
|
2018-03-04 13:56:49 +00:00
|
|
|
Script: &transaction.Witness{
|
2018-02-07 14:16:50 +00:00
|
|
|
InvocationScript: []byte{0x0},
|
|
|
|
VerificationScript: []byte{0x1},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
&core.Header{
|
|
|
|
BlockBase: core.BlockBase{
|
|
|
|
Version: 0,
|
|
|
|
Index: 3,
|
2018-03-04 13:56:49 +00:00
|
|
|
Script: &transaction.Witness{
|
2018-02-07 14:16:50 +00:00
|
|
|
InvocationScript: []byte{0x0},
|
|
|
|
VerificationScript: []byte{0x1},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
}}
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := headers.EncodeBinary(buf); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
headersDecode := &Headers{}
|
|
|
|
if err := headersDecode.DecodeBinary(buf); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(headers, headersDecode) {
|
|
|
|
t.Fatalf("expected both header payload to be equal %+v and %+v", headers, headersDecode)
|
|
|
|
}
|
|
|
|
}
|