2019-08-16 20:03:11 +00:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
2020-10-14 07:55:28 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/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{
|
2021-11-05 19:08:58 +00:00
|
|
|
cfg: &config{p2p: p2ptest.NewTestP2P(t)},
|
2019-08-16 20:03:11 +00:00
|
|
|
}
|
|
|
|
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)
|
2020-08-25 15:23:06 +00:00
|
|
|
_, err = buf.Read(b)
|
|
|
|
require.NoError(t, err)
|
2020-07-15 04:41:11 +00:00
|
|
|
assert.Equal(t, responseCodeServerError, b[0], "The first byte was not the status code")
|
2020-10-14 07:55:28 +00:00
|
|
|
msg := &types.ErrorMessage{}
|
2021-11-05 19:08:58 +00:00
|
|
|
require.NoError(t, r.cfg.p2p.Encoding().DecodeWithMaxLength(buf, msg))
|
2020-10-14 07:55:28 +00:00
|
|
|
assert.Equal(t, "something bad happened", string(*msg), "Received the wrong message")
|
2019-08-16 20:03:11 +00:00
|
|
|
}
|