refactor: convert gateway tests to kit2
This commit is contained in:
parent
86cca7303d
commit
16cad0e01a
@ -9,7 +9,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -21,10 +20,11 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/api/client"
|
"github.com/filecoin-project/lotus/api/client"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/policy"
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
||||||
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/cli"
|
"github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/gateway"
|
"github.com/filecoin-project/lotus/gateway"
|
||||||
"github.com/filecoin-project/lotus/itests/kit"
|
"github.com/filecoin-project/lotus/itests/kit2"
|
||||||
"github.com/filecoin-project/lotus/node"
|
"github.com/filecoin-project/lotus/node"
|
||||||
|
|
||||||
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
|
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
|
||||||
@ -46,7 +46,7 @@ func init() {
|
|||||||
// node that is connected through a gateway to a full API node
|
// node that is connected through a gateway to a full API node
|
||||||
func TestGatewayWalletMsig(t *testing.T) {
|
func TestGatewayWalletMsig(t *testing.T) {
|
||||||
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
kit.QuietMiningLogs()
|
kit2.QuietMiningLogs()
|
||||||
|
|
||||||
blocktime := 5 * time.Millisecond
|
blocktime := 5 * time.Millisecond
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -180,7 +180,7 @@ func TestGatewayWalletMsig(t *testing.T) {
|
|||||||
// on a lite node that is connected through a gateway to a full API node
|
// on a lite node that is connected through a gateway to a full API node
|
||||||
func TestGatewayMsigCLI(t *testing.T) {
|
func TestGatewayMsigCLI(t *testing.T) {
|
||||||
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
kit.QuietMiningLogs()
|
kit2.QuietMiningLogs()
|
||||||
|
|
||||||
blocktime := 5 * time.Millisecond
|
blocktime := 5 * time.Millisecond
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -193,7 +193,7 @@ func TestGatewayMsigCLI(t *testing.T) {
|
|||||||
|
|
||||||
func TestGatewayDealFlow(t *testing.T) {
|
func TestGatewayDealFlow(t *testing.T) {
|
||||||
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
kit.QuietMiningLogs()
|
kit2.QuietMiningLogs()
|
||||||
|
|
||||||
blocktime := 5 * time.Millisecond
|
blocktime := 5 * time.Millisecond
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -205,26 +205,27 @@ func TestGatewayDealFlow(t *testing.T) {
|
|||||||
// so that the deal starts sealing in time
|
// so that the deal starts sealing in time
|
||||||
dealStartEpoch := abi.ChainEpoch(2 << 12)
|
dealStartEpoch := abi.ChainEpoch(2 << 12)
|
||||||
|
|
||||||
dh := kit.NewDealHarness(t, nodes.lite, nodes.miner)
|
dh := kit2.NewDealHarness(t, &nodes.lite, &nodes.miner)
|
||||||
dh.MakeFullDeal(ctx, 6, false, false, dealStartEpoch)
|
dealCid, res, _ := dh.MakeOnlineDeal(ctx, 6, false, dealStartEpoch)
|
||||||
|
dh.PerformRetrieval(ctx, dealCid, res.Root, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatewayCLIDealFlow(t *testing.T) {
|
func TestGatewayCLIDealFlow(t *testing.T) {
|
||||||
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
_ = os.Setenv("BELLMAN_NO_GPU", "1")
|
||||||
kit.QuietMiningLogs()
|
kit2.QuietMiningLogs()
|
||||||
|
|
||||||
blocktime := 5 * time.Millisecond
|
blocktime := 5 * time.Millisecond
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
nodes := startNodesWithFunds(ctx, t, blocktime, maxLookbackCap, maxStateWaitLookbackLimit)
|
nodes := startNodesWithFunds(ctx, t, blocktime, maxLookbackCap, maxStateWaitLookbackLimit)
|
||||||
defer nodes.closer()
|
defer nodes.closer()
|
||||||
|
|
||||||
kit.RunClientTest(t, cli.Commands, nodes.lite)
|
kit2.RunClientTest(t, cli.Commands, nodes.lite)
|
||||||
}
|
}
|
||||||
|
|
||||||
type testNodes struct {
|
type testNodes struct {
|
||||||
lite kit.TestFullNode
|
lite kit2.TestFullNode
|
||||||
full kit.TestFullNode
|
full kit2.TestFullNode
|
||||||
miner kit.TestMiner
|
miner kit2.TestMiner
|
||||||
closer jsonrpc.ClientCloser
|
closer jsonrpc.ClientCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,17 +262,19 @@ func startNodes(
|
|||||||
) *testNodes {
|
) *testNodes {
|
||||||
var closer jsonrpc.ClientCloser
|
var closer jsonrpc.ClientCloser
|
||||||
|
|
||||||
// Create one miner and two full nodes.
|
var (
|
||||||
|
full kit2.TestFullNode
|
||||||
|
lite kit2.TestFullNode
|
||||||
|
miner kit2.TestMiner
|
||||||
|
)
|
||||||
|
|
||||||
|
// - Create one full node and one lite node
|
||||||
// - Put a gateway server in front of full node 1
|
// - Put a gateway server in front of full node 1
|
||||||
// - Start full node 2 in lite mode
|
// - Start full node 2 in lite mode
|
||||||
// - Connect lite node -> gateway server -> full node
|
// - Connect lite node -> gateway server -> full node
|
||||||
opts := append(
|
|
||||||
// Full node
|
var liteOptBuilder kit2.OptBuilder
|
||||||
kit.OneFull,
|
liteOptBuilder = func(nodes []*kit2.TestFullNode) node.Option {
|
||||||
// Lite node
|
|
||||||
kit.FullNodeOpts{
|
|
||||||
Lite: true,
|
|
||||||
Opts: func(nodes []kit.TestFullNode) node.Option {
|
|
||||||
fullNode := nodes[0]
|
fullNode := nodes[0]
|
||||||
|
|
||||||
// Create a gateway server in front of the full node
|
// Create a gateway server in front of the full node
|
||||||
@ -279,7 +282,7 @@ func startNodes(
|
|||||||
handler, err := gateway.Handler(gwapi)
|
handler, err := gateway.Handler(gwapi)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
srv, _ := kit.CreateRPCServer(t, handler)
|
srv, _ := kit2.CreateRPCServer(t, handler)
|
||||||
|
|
||||||
// Create a gateway client API that connects to the gateway server
|
// Create a gateway client API that connects to the gateway server
|
||||||
var gapi api.Gateway
|
var gapi api.Gateway
|
||||||
@ -288,39 +291,20 @@ func startNodes(
|
|||||||
|
|
||||||
// Provide the gateway API to dependency injection
|
// Provide the gateway API to dependency injection
|
||||||
return node.Override(new(api.Gateway), gapi)
|
return node.Override(new(api.Gateway), gapi)
|
||||||
},
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
n, sn := kit.RPCMockMinerBuilder(t, opts, kit.OneMiner)
|
|
||||||
|
|
||||||
full := n[0]
|
kit2.NewEnsemble(t, kit2.MockProofs()).
|
||||||
lite := n[1]
|
FullNode(&full).
|
||||||
miner := sn[0]
|
FullNode(&lite, kit2.LiteNode(), kit2.ThroughRPC(), kit2.AddOptBuilder(liteOptBuilder)).
|
||||||
|
Miner(&miner, &full).
|
||||||
// Get the listener address for the full node
|
Start().
|
||||||
fullAddr, err := full.NetAddrsListen(ctx)
|
InterconnectAll().
|
||||||
require.NoError(t, err)
|
BeginMining(blocktime)
|
||||||
|
|
||||||
// Connect the miner and the full node
|
|
||||||
err = miner.NetConnect(ctx, fullAddr)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Connect the miner and the lite node (so that the lite node can send
|
|
||||||
// data to the miner)
|
|
||||||
liteAddr, err := lite.NetAddrsListen(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
err = miner.NetConnect(ctx, liteAddr)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Start mining blocks
|
|
||||||
bm := kit.NewBlockMiner(t, miner)
|
|
||||||
bm.MineBlocks(ctx, blocktime)
|
|
||||||
t.Cleanup(bm.Stop)
|
|
||||||
|
|
||||||
return &testNodes{lite: lite, full: full, miner: miner, closer: closer}
|
return &testNodes{lite: lite, full: full, miner: miner, closer: closer}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendFunds(ctx context.Context, fromNode kit.TestFullNode, fromAddr address.Address, toAddr address.Address, amt types.BigInt) error {
|
func sendFunds(ctx context.Context, fromNode kit2.TestFullNode, fromAddr address.Address, toAddr address.Address, amt types.BigInt) error {
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
From: fromAddr,
|
From: fromAddr,
|
||||||
To: toAddr,
|
To: toAddr,
|
||||||
|
@ -279,6 +279,11 @@ func (n *Ensemble) Start() *Ensemble {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call option builders, passing active nodes as the parameter
|
||||||
|
for _, bopt := range full.options.optBuilders {
|
||||||
|
opts = append(opts, bopt(n.active.fullnodes))
|
||||||
|
}
|
||||||
|
|
||||||
// Construct the full node.
|
// Construct the full node.
|
||||||
stop, err := node.New(ctx, opts...)
|
stop, err := node.New(ctx, opts...)
|
||||||
|
|
||||||
|
@ -30,5 +30,5 @@ func SendFunds(ctx context.Context, t *testing.T, sender TestFullNode, recipient
|
|||||||
res, err := sender.StateWaitMsg(ctx, sm.Cid(), 3, api.LookbackNoLimit, true)
|
res, err := sender.StateWaitMsg(ctx, sm.Cid(), 3, api.LookbackNoLimit, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, 0, res.Receipt.ExitCode, "did not successfully send funds")
|
require.EqualValues(t, 0, res.Receipt.ExitCode, "did not successfully send funds")
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ type nodeOpts struct {
|
|||||||
rpc bool
|
rpc bool
|
||||||
ownerKey *wallet.Key
|
ownerKey *wallet.Key
|
||||||
extraNodeOpts []node.Option
|
extraNodeOpts []node.Option
|
||||||
|
optBuilders []OptBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultNodeOpts are the default options that will be applied to test nodes.
|
// DefaultNodeOpts are the default options that will be applied to test nodes.
|
||||||
@ -31,6 +32,10 @@ var DefaultNodeOpts = nodeOpts{
|
|||||||
sectors: DefaultPresealsPerBootstrapMiner,
|
sectors: DefaultPresealsPerBootstrapMiner,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OptBuilder is used to create an option after some other node is already
|
||||||
|
// active. Takes all active nodes as a parameter.
|
||||||
|
type OptBuilder func(activeNodes []*TestFullNode) node.Option
|
||||||
|
|
||||||
// NodeOpt is a functional option for test nodes.
|
// NodeOpt is a functional option for test nodes.
|
||||||
type NodeOpt func(opts *nodeOpts) error
|
type NodeOpt func(opts *nodeOpts) error
|
||||||
|
|
||||||
@ -87,3 +92,12 @@ func ConstructorOpts(extra ...node.Option) NodeOpt {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddOptBuilder adds an OptionBuilder to a node. It is used to add Lotus node
|
||||||
|
// constructor options after some nodes are already active.
|
||||||
|
func AddOptBuilder(optBuilder OptBuilder) NodeOpt {
|
||||||
|
return func(opts *nodeOpts) error {
|
||||||
|
opts.optBuilders = append(opts.optBuilders, optBuilder)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -22,7 +22,7 @@ func TestMultisig(t *testing.T) {
|
|||||||
kit2.QuietMiningLogs()
|
kit2.QuietMiningLogs()
|
||||||
|
|
||||||
blockTime := 5 * time.Millisecond
|
blockTime := 5 * time.Millisecond
|
||||||
client, _, ens := kit2.EnsembleMinimal(t, kit2.MockProofs())
|
client, _, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), kit2.ThroughRPC())
|
||||||
ens.InterconnectAll().BeginMining(blockTime)
|
ens.InterconnectAll().BeginMining(blockTime)
|
||||||
|
|
||||||
runMultisigTests(t, *client)
|
runMultisigTests(t, *client)
|
||||||
|
Loading…
Reference in New Issue
Block a user