prysm-pulse/beacon-chain/sync/error_test.go
Raul Jordan 233171d17c
[Service Config Revamp] - Sync Service With Functional Options (#9859)
* sync config refactor

* rem

* rem

* testing

* gaz

* next

* fuzz

* build

* fuzz

* rev

* log

* cfg
2021-11-05 19:08:58 +00:00

29 lines
887 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/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
)
func TestRegularSync_generateErrorResponse(t *testing.T) {
r := &Service{
cfg: &config{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.cfg.p2p.Encoding().DecodeWithMaxLength(buf, msg))
assert.Equal(t, "something bad happened", string(*msg), "Received the wrong message")
}