mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 01:10:36 +00:00
4023661cf1
* added headersOp for safely processing headers * Better handling of protocol messages. * housekeeping + cleanup tests * Added more blockchain logic + unit tests * fixed unreachable error. * added structured logging for all (node) components. * added relay flag + bumped version
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package payload
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/core"
|
|
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestHeadersEncodeDecode(t *testing.T) {
|
|
headers := &Headers{[]*core.Header{
|
|
&core.Header{
|
|
BlockBase: core.BlockBase{
|
|
Version: 0,
|
|
Index: 1,
|
|
Script: &transaction.Witness{
|
|
InvocationScript: []byte{0x0},
|
|
VerificationScript: []byte{0x1},
|
|
},
|
|
}},
|
|
&core.Header{
|
|
BlockBase: core.BlockBase{
|
|
Version: 0,
|
|
Index: 2,
|
|
Script: &transaction.Witness{
|
|
InvocationScript: []byte{0x0},
|
|
VerificationScript: []byte{0x1},
|
|
},
|
|
}},
|
|
&core.Header{
|
|
BlockBase: core.BlockBase{
|
|
Version: 0,
|
|
Index: 3,
|
|
Script: &transaction.Witness{
|
|
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)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|