mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
37 lines
954 B
Go
37 lines
954 B
Go
package messagehandler_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/OffchainLabs/prysm/v7/runtime/messagehandler"
|
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestSafelyHandleMessage(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
|
|
messagehandler.SafelyHandleMessage(t.Context(), func(_ context.Context, _ *pubsub.Message) error {
|
|
panic("bad!")
|
|
return nil
|
|
}, &pubsub.Message{})
|
|
|
|
require.LogsContain(t, hook, "Panicked when handling p2p message!")
|
|
}
|
|
|
|
func TestSafelyHandleMessage_NoData(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
|
|
messagehandler.SafelyHandleMessage(t.Context(), func(_ context.Context, _ *pubsub.Message) error {
|
|
panic("bad!")
|
|
return nil
|
|
}, nil)
|
|
|
|
entry := hook.LastEntry()
|
|
if entry.Data["msg"] != "message contains no data" {
|
|
t.Errorf("Message logged was not what was expected: %s", entry.Data["msg"])
|
|
}
|
|
}
|