prysm-pulse/beacon-chain/p2p/sender_test.go
kasey 588dea83b7
Config registry (#10683)
* test coverage and updates to config twiddlers

* LoadChainConfigFile error if SetActive conflicts

* lint

* wip working around test issues

* more fixes, mass test updates

* lint

* linting

* thanks deepsource!

* fix undeclared vars

* fixing more undefined

* fix a bug, make a bug, repeat

* gaz

* use stock mainnet in case fork schedule matters

* remove unused KnownConfigs

* post-merge cleanup

* eliminating OverrideBeaconConfig outside tests

* more cleanup of OverrideBeaconConfig outside tests

* config for interop w/ genesis gen support

* improve var name

* API on package instead of exported value

* cleanup remainders of "registry" naming

* Nishant feedback

* add ropstein to configset

* lint

* lint #2

* ✂️

* revert accidental commented line

* check if active is nil (replace called on empty)

* Nishant feedback

* replace OverrideBeaconConfig call

* update interop instructions w/ new flag

* don't let interop replace config set via cli flags

Co-authored-by: kasey <kasey@users.noreply.github.com>
2022-05-20 07:16:53 +00:00

64 lines
1.6 KiB
Go

package p2p
import (
"context"
"sync"
"testing"
"time"
"github.com/libp2p/go-libp2p-core/network"
testp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/config/params"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
)
func TestService_Send(t *testing.T) {
params.SetupTestConfigCleanup(t)
p1 := testp2p.NewTestP2P(t)
p2 := testp2p.NewTestP2P(t)
p1.Connect(p2)
svc := &Service{
host: p1.BHost,
cfg: &Config{},
}
msg := &ethpb.Fork{
CurrentVersion: []byte("fooo"),
PreviousVersion: []byte("barr"),
Epoch: 55,
}
// Register external listener which will repeat the message back.
var wg sync.WaitGroup
wg.Add(1)
topic := "/testing/1"
RPCTopicMappings[topic] = new(ethpb.Fork)
defer func() {
delete(RPCTopicMappings, topic)
}()
p2.SetStreamHandler(topic+"/ssz_snappy", func(stream network.Stream) {
rcvd := &ethpb.Fork{}
require.NoError(t, svc.Encoding().DecodeWithMaxLength(stream, rcvd))
_, err := svc.Encoding().EncodeWithMaxLength(stream, rcvd)
require.NoError(t, err)
assert.NoError(t, stream.Close())
wg.Done()
})
stream, err := svc.Send(context.Background(), msg, "/testing/1", p2.BHost.ID())
require.NoError(t, err)
util.WaitTimeout(&wg, 1*time.Second)
rcvd := &ethpb.Fork{}
require.NoError(t, svc.Encoding().DecodeWithMaxLength(stream, rcvd))
if !proto.Equal(rcvd, msg) {
t.Errorf("Expected identical message to be received. got %v want %v", rcvd, msg)
}
}