prysm-pulse/beacon-chain/sync/error_test.go
Nishant Das 022b6667e5
Use Custom SSZ for P2P Types (#7436)
* checkpoint progress

* add roundtrip tests

* change all

* remove error response

* clean up

* Update beacon-chain/sync/error_test.go

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* gaz

* fix tests

* fmt

* gaz

* change back

* fix again

* clean up

* deep source

* fix all tests

* add gaz

* fix tests

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
2020-10-14 07:55:28 +00:00

29 lines
885 B
Go

package sync
import (
"bytes"
"testing"
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestRegularSync_generateErrorResponse(t *testing.T) {
r := &Service{
p2p: p2ptest.NewTestP2P(t),
}
data, err := r.generateErrorResponse(responseCodeServerError, "something bad happened")
require.NoError(t, err)
buf := bytes.NewBuffer(data)
b := make([]byte, 1)
_, err = buf.Read(b)
require.NoError(t, err)
assert.Equal(t, responseCodeServerError, b[0], "The first byte was not the status code")
msg := &types.ErrorMessage{}
require.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(buf, msg))
assert.Equal(t, "something bad happened", string(*msg), "Received the wrong message")
}