2018-02-07 14:16:50 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"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-03-09 15:55:25 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-02-07 14:16:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadersEncodeDecode(t *testing.T) {
|
|
|
|
headers := &Headers{[]*core.Header{
|
2019-01-25 11:20:35 +00:00
|
|
|
{
|
2018-02-07 14:16:50 +00:00
|
|
|
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},
|
|
|
|
},
|
|
|
|
}},
|
2019-01-25 11:20:35 +00:00
|
|
|
{
|
2018-02-07 14:16:50 +00:00
|
|
|
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},
|
|
|
|
},
|
|
|
|
}},
|
2019-01-25 11:20:35 +00:00
|
|
|
{
|
2018-02-07 14:16:50 +00:00
|
|
|
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)
|
2019-08-29 14:33:53 +00:00
|
|
|
err := headers.EncodeBinary(buf)
|
|
|
|
assert.Nil(t, err)
|
2018-02-07 14:16:50 +00:00
|
|
|
|
|
|
|
headersDecode := &Headers{}
|
2019-08-29 14:33:53 +00:00
|
|
|
err = headersDecode.DecodeBinary(buf)
|
|
|
|
assert.Nil(t, err)
|
2018-02-07 14:16:50 +00:00
|
|
|
|
2018-03-09 15:55:25 +00:00
|
|
|
for i := 0; i < len(headers.Hdrs); i++ {
|
|
|
|
assert.Equal(t, headers.Hdrs[i].Version, headersDecode.Hdrs[i].Version)
|
|
|
|
assert.Equal(t, headers.Hdrs[i].Index, headersDecode.Hdrs[i].Index)
|
|
|
|
assert.Equal(t, headers.Hdrs[i].Script, headersDecode.Hdrs[i].Script)
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|
|
|
|
}
|