prysm-pulse/beacon-chain/p2p/rpc_topic_mappings_test.go
Nishant Das d4c3546434
Validate RPC Topics Before Sending Requests (#6558)
* clean up

* fix panic

* add test mapping

* add schema version change

* fix test

* fix another test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-07-13 09:20:53 +08:00

32 lines
1.0 KiB
Go

package p2p
import (
"testing"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
func TestVerifyRPCMappings(t *testing.T) {
if err := VerifyTopicMapping(RPCStatusTopic, &pb.Status{}); err != nil {
t.Errorf("Failed to verify status rpc topic: %v", err)
}
if err := VerifyTopicMapping(RPCStatusTopic, new([]byte)); err == nil {
t.Errorf("Incorrect message type verified for status rpc topic")
}
if err := VerifyTopicMapping(RPCMetaDataTopic, new(interface{})); err != nil {
t.Errorf("Failed to verify metadata rpc topic: %v", err)
}
if err := VerifyTopicMapping(RPCStatusTopic, new([]byte)); err == nil {
t.Error("Incorrect message type verified for metadata rpc topic")
}
// TODO(#6408) Remove once issue is resolved
if err := VerifyTopicMapping(RPCBlocksByRootTopic, [][32]byte{}); err != nil {
t.Errorf("Failed to verify blocks by root rpc topic: %v", err)
}
if err := VerifyTopicMapping(RPCBlocksByRootTopic, new(pb.BeaconBlocksByRootRequest)); err != nil {
t.Errorf("Failed to verify blocks by root rpc topic: %v", err)
}
}