mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
78bf39aff7
* checkpoint * checkpoint * varint prefix for ssz * move the encoding API around a little bit to support reader writer * add a simple test for the happy path subscribe * move wait timeout to testutil * Add inverted topic mapping * Add varint prefixing to ssz network encoder * fix spacing * fix comments * fix comments * make anon methods more clear * clean up log fields * move topic mapping, reformat TODOs, get ready for brutal team review * lint * lint * lint * Update beacon-chain/p2p/gossip_topic_mappings.go Co-Authored-By: Nishant Das <nishdas93@gmail.com> * PR feedback * PR feedback * PR feedback * PR feedback * PR feedback * basic test with a hardcoded fork choice * updated beacon config to use genesis fork version * checkpoint on hello handler * create a testing db method that can be used with the new database interface * lint * lint * PR feedback * checkpoint * passing tests * comments, errors * comments, errors * remove swarm * Update WORKSPACE * Update WORKSPACE * merge * lint * lint * touch * touch * imports
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package sync
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
libp2pcore "github.com/libp2p/go-libp2p-core"
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
|
pb "github.com/prysmaticlabs/prysm/proto/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
)
|
|
|
|
// expectSuccess status code from a stream in regular sync.
|
|
func expectSuccess(t *testing.T, r *RegularSync, stream network.Stream) {
|
|
code, errMsg, err := r.readStatusCode(stream)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if code != 0 {
|
|
t.Fatalf("Received non-zero response code: %d", code)
|
|
}
|
|
if errMsg != nil {
|
|
t.Fatalf("Received error message from stream: %+v", errMsg)
|
|
}
|
|
}
|
|
|
|
func TestRegisterRPC_ReceivesValidMessage(t *testing.T) {
|
|
p2p := p2ptest.NewTestP2P(t)
|
|
r := &RegularSync{
|
|
ctx: context.Background(),
|
|
p2p: p2p,
|
|
}
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(1)
|
|
topic := "/testing/foobar/1"
|
|
handler := func(ctx context.Context, msg proto.Message, stream libp2pcore.Stream) error {
|
|
m := msg.(*pb.TestSimpleMessage)
|
|
if !bytes.Equal(m.Foo, []byte("foo")) {
|
|
t.Errorf("Unexpected incoming message: %+v", m)
|
|
}
|
|
wg.Done()
|
|
|
|
return nil
|
|
}
|
|
r.registerRPC(topic, &pb.TestSimpleMessage{}, handler)
|
|
|
|
p2p.ReceiveRPC(topic, &pb.TestSimpleMessage{Foo: []byte("foo")})
|
|
|
|
if testutil.WaitTimeout(&wg, time.Second) {
|
|
t.Fatal("Did not receive RPC in 1 second")
|
|
}
|
|
}
|