2019-08-16 20:03:11 +00:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
2020-06-09 22:40:48 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2020-07-15 04:41:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2019-08-16 20:03:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRegularSync_generateErrorResponse(t *testing.T) {
|
2019-12-17 01:53:55 +00:00
|
|
|
r := &Service{
|
2019-08-16 20:03:11 +00:00
|
|
|
p2p: p2ptest.NewTestP2P(t),
|
|
|
|
}
|
|
|
|
data, err := r.generateErrorResponse(responseCodeServerError, "something bad happened")
|
2020-07-15 04:41:11 +00:00
|
|
|
require.NoError(t, err)
|
2019-08-16 20:03:11 +00:00
|
|
|
|
|
|
|
buf := bytes.NewBuffer(data)
|
|
|
|
b := make([]byte, 1)
|
|
|
|
if _, err := buf.Read(b); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-07-15 04:41:11 +00:00
|
|
|
assert.Equal(t, responseCodeServerError, b[0], "The first byte was not the status code")
|
2020-06-09 22:40:48 +00:00
|
|
|
msg := &pb.ErrorResponse{}
|
2020-07-15 04:41:11 +00:00
|
|
|
require.NoError(t, r.p2p.Encoding().DecodeWithMaxLength(buf, msg))
|
|
|
|
assert.Equal(t, "something bad happened", string(msg.Message), "Received the wrong message")
|
2019-08-16 20:03:11 +00:00
|
|
|
}
|