prysm-pulse/beacon-chain/sync/error_test.go
Nishant Das c09a6b87c3
Implement Attester Slashing Handler in Sync (#3260)
* add validation

* add test

* add new changes

* fix lint

* Update beacon-chain/sync/validate_attetser_slashing_test.go

Co-Authored-By: shayzluf <thezluf@gmail.com>

* terence's comments

* change key
2019-08-22 11:04:25 +05:30

36 lines
870 B
Go

package sync
import (
"bytes"
"testing"
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
func TestRegularSync_generateErrorResponse(t *testing.T) {
r := &RegularSync{
p2p: p2ptest.NewTestP2P(t),
}
data, err := r.generateErrorResponse(responseCodeServerError, "something bad happened")
if err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(data)
b := make([]byte, 1)
if _, err := buf.Read(b); err != nil {
t.Fatal(err)
}
if b[0] != responseCodeServerError {
t.Errorf("The first byte was not the status code. Got %#x wanted %#x", b, responseCodeServerError)
}
msg := &pb.ErrorMessage{}
if err := r.p2p.Encoding().Decode(buf, msg); err != nil {
t.Fatal(err)
}
if msg.ErrorMessage != "something bad happened" {
t.Errorf("Received the wrong message: %v", msg)
}
}