Commit 9369371c authored by Adrian Sutton's avatar Adrian Sutton

op-node: Update peer_scores_test to create an ExtendedPeerStore

parent 82050f75
......@@ -9,9 +9,14 @@ import (
p2p "github.com/ethereum-optimism/optimism/op-node/p2p"
p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
"github.com/ethereum-optimism/optimism/op-node/p2p/store"
testlog "github.com/ethereum-optimism/optimism/op-node/testlog"
ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
suite "github.com/stretchr/testify/suite"
log "github.com/ethereum/go-ethereum/log"
......@@ -50,11 +55,28 @@ func TestPeerScores(t *testing.T) {
suite.Run(t, new(PeerScoresTestSuite))
}
type customPeerstoreNetwork struct {
network.Network
ps peerstore.Peerstore
}
func (c *customPeerstoreNetwork) Peerstore() peerstore.Peerstore {
return c.ps
}
func (c *customPeerstoreNetwork) Close() error {
_ = c.ps.Close()
return c.Network.Close()
}
// getNetHosts generates a slice of hosts using the [libp2p/go-libp2p] library.
func getNetHosts(testSuite *PeerScoresTestSuite, ctx context.Context, n int) []host.Host {
var out []host.Host
for i := 0; i < n; i++ {
netw := tswarm.GenSwarm(testSuite.T())
swarm := tswarm.GenSwarm(testSuite.T())
eps, err := store.NewExtendedPeerstore(ctx, swarm.Peerstore(), sync.MutexWrap(ds.NewMapDatastore()))
netw := &customPeerstoreNetwork{swarm, eps}
require.NoError(testSuite.T(), err)
h := bhost.NewBlankHost(netw)
testSuite.T().Cleanup(func() { h.Close() })
out = append(out, h)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment