2020-07-01 16:29:09 +00:00
|
|
|
package testkit
|
2020-06-30 22:02:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
"github.com/filecoin-project/lotus/node"
|
|
|
|
"github.com/filecoin-project/lotus/node/config"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func withGenesis(gb []byte) node.Option {
|
|
|
|
return node.Override(new(modules.Genesis), modules.LoadGenesis(gb))
|
|
|
|
}
|
|
|
|
|
|
|
|
func withBootstrapper(ab []byte) node.Option {
|
|
|
|
return node.Override(new(dtypes.BootstrapPeers),
|
|
|
|
func() (dtypes.BootstrapPeers, error) {
|
|
|
|
if ab == nil {
|
|
|
|
return dtypes.BootstrapPeers{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
a, err := ma.NewMultiaddrBytes(ab)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ai, err := peer.AddrInfoFromP2pAddr(a)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return dtypes.BootstrapPeers{*ai}, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func withPubsubConfig(bootstrapper bool, pubsubTracer string) node.Option {
|
|
|
|
return node.Override(new(*config.Pubsub), func() *config.Pubsub {
|
|
|
|
return &config.Pubsub{
|
|
|
|
Bootstrapper: bootstrapper,
|
|
|
|
RemoteTracer: pubsubTracer,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func withListenAddress(ip string) node.Option {
|
2020-07-06 14:47:17 +00:00
|
|
|
addrs := []string{fmt.Sprintf("/ip4/%s/tcp/0", ip)}
|
2020-06-30 22:02:01 +00:00
|
|
|
return node.Override(node.StartListeningKey, lp2p.StartListening(addrs))
|
|
|
|
}
|
|
|
|
|
|
|
|
func withMinerListenAddress(ip string) node.Option {
|
2020-07-06 14:47:17 +00:00
|
|
|
addrs := []string{fmt.Sprintf("/ip4/%s/tcp/0", ip)}
|
2020-06-30 22:02:01 +00:00
|
|
|
return node.Override(node.StartListeningKey, lp2p.StartListening(addrs))
|
|
|
|
}
|
|
|
|
|
|
|
|
func withApiEndpoint(addr string) node.Option {
|
|
|
|
return node.Override(node.SetApiEndpointKey, func(lr repo.LockedRepo) error {
|
|
|
|
apima, err := ma.NewMultiaddr(addr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return lr.SetAPIEndpoint(apima)
|
|
|
|
})
|
|
|
|
}
|