move the gateway test to itests package.

This commit is contained in:
Raúl Kripalani 2021-05-19 17:14:14 +01:00
parent 6f4349064a
commit 2a70ff96bf
5 changed files with 44 additions and 42 deletions

View File

@ -5,7 +5,6 @@ import (
"net" "net"
"net/http" "net/http"
"os" "os"
"time"
"contrib.go.opencensus.io/exporter/prometheus" "contrib.go.opencensus.io/exporter/prometheus"
"github.com/filecoin-project/go-jsonrpc" "github.com/filecoin-project/go-jsonrpc"
@ -31,11 +30,6 @@ import (
var log = logging.Logger("gateway") var log = logging.Logger("gateway")
const (
DefautLookbackCap = time.Hour * 24
DefaultStateWaitLookbackLimit = abi.ChainEpoch(20)
)
func main() { func main() {
lotuslog.SetupLogLevels() lotuslog.SetupLogLevels()
@ -81,12 +75,12 @@ var runCmd = &cli.Command{
&cli.DurationFlag{ &cli.DurationFlag{
Name: "api-max-lookback", Name: "api-max-lookback",
Usage: "maximum duration allowable for tipset lookbacks", Usage: "maximum duration allowable for tipset lookbacks",
Value: DefautLookbackCap, Value: gateway.DefautLookbackCap,
}, },
&cli.Int64Flag{ &cli.Int64Flag{
Name: "api-wait-lookback-limit", Name: "api-wait-lookback-limit",
Usage: "maximum number of blocks to search back through for message inclusion", Usage: "maximum number of blocks to search back through for message inclusion",
Value: int64(DefaultStateWaitLookbackLimit), Value: int64(gateway.DefaultStateWaitLookbackLimit),
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {

View File

@ -22,6 +22,11 @@ import (
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
) )
const (
DefautLookbackCap = time.Hour * 24
DefaultStateWaitLookbackLimit = abi.ChainEpoch(20)
)
// TargetAPI defines the API methods that the Node depends on // TargetAPI defines the API methods that the Node depends on
// (to make it easy to mock for tests) // (to make it easy to mock for tests)
type TargetAPI interface { type TargetAPI interface {

View File

@ -1,4 +1,4 @@
package main package itests
import ( import (
"bytes" "bytes"
@ -8,30 +8,28 @@ import (
"testing" "testing"
"time" "time"
"github.com/filecoin-project/lotus/cli"
clitest "github.com/filecoin-project/lotus/cli/test"
"github.com/filecoin-project/lotus/gateway"
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-jsonrpc" "github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"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/api/test"
"github.com/filecoin-project/lotus/api/v0api" "github.com/filecoin-project/lotus/api/v0api"
"github.com/filecoin-project/lotus/api/v1api" "github.com/filecoin-project/lotus/api/v1api"
"github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/actors/policy"
"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/gateway"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node"
builder "github.com/filecoin-project/lotus/node/test"
init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init"
multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig"
) )
func init() { func init() {
@ -44,11 +42,11 @@ 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 TestWalletMsig(t *testing.T) { func TestWalletMsig(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs() kit.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
nodes := startNodes(ctx, t, blocktime, DefautLookbackCap, DefaultStateWaitLookbackLimit) nodes := startNodes(ctx, t, blocktime, gateway.DefautLookbackCap, gateway.DefaultStateWaitLookbackLimit)
defer nodes.closer() defer nodes.closer()
lite := nodes.lite lite := nodes.lite
@ -178,49 +176,49 @@ func TestWalletMsig(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 TestMsigCLI(t *testing.T) { func TestMsigCLI(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs() kit.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
nodes := startNodesWithFunds(ctx, t, blocktime, DefautLookbackCap, DefaultStateWaitLookbackLimit) nodes := startNodesWithFunds(ctx, t, blocktime, gateway.DefautLookbackCap, gateway.DefaultStateWaitLookbackLimit)
defer nodes.closer() defer nodes.closer()
lite := nodes.lite lite := nodes.lite
clitest.RunMultisigTest(t, cli.Commands, lite) runMultisigTests(t, lite)
} }
func TestDealFlow(t *testing.T) { func TestDealFlow(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs() kit.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
nodes := startNodesWithFunds(ctx, t, blocktime, DefautLookbackCap, DefaultStateWaitLookbackLimit) nodes := startNodesWithFunds(ctx, t, blocktime, gateway.DefautLookbackCap, gateway.DefaultStateWaitLookbackLimit)
defer nodes.closer() defer nodes.closer()
// For these tests where the block time is artificially short, just use // For these tests where the block time is artificially short, just use
// a deal start epoch that is guaranteed to be far enough in the future // a deal start epoch that is guaranteed to be far enough in the future
// 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)
test.MakeDeal(t, ctx, 6, nodes.lite, nodes.miner, false, false, dealStartEpoch) kit.MakeDeal(t, ctx, 6, nodes.lite, nodes.miner, false, false, dealStartEpoch)
} }
func TestCLIDealFlow(t *testing.T) { func TestCLIDealFlow(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1") _ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs() kit.QuietMiningLogs()
blocktime := 5 * time.Millisecond blocktime := 5 * time.Millisecond
ctx := context.Background() ctx := context.Background()
nodes := startNodesWithFunds(ctx, t, blocktime, DefautLookbackCap, DefaultStateWaitLookbackLimit) nodes := startNodesWithFunds(ctx, t, blocktime, gateway.DefautLookbackCap, gateway.DefaultStateWaitLookbackLimit)
defer nodes.closer() defer nodes.closer()
clitest.RunClientTest(t, cli.Commands, nodes.lite) kit.RunClientTest(t, cli.Commands, nodes.lite)
} }
type testNodes struct { type testNodes struct {
lite test.TestNode lite kit.TestFullNode
full test.TestNode full kit.TestFullNode
miner test.TestStorageNode miner kit.TestMiner
closer jsonrpc.ClientCloser closer jsonrpc.ClientCloser
} }
@ -263,16 +261,16 @@ func startNodes(
// - Connect lite node -> gateway server -> full node // - Connect lite node -> gateway server -> full node
opts := append( opts := append(
// Full node // Full node
test.OneFull, kit.OneFull,
// Lite node // Lite node
test.FullNodeOpts{ kit.FullNodeOpts{
Lite: true, Lite: true,
Opts: func(nodes []test.TestNode) node.Option { 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
gapiImpl := gateway.NewNode(fullNode, lookbackCap, stateWaitLookbackLimit) gapiImpl := gateway.NewNode(fullNode, lookbackCap, stateWaitLookbackLimit)
_, addr, err := builder.CreateRPCServer(t, map[string]interface{}{ _, addr, err := kit.CreateRPCServer(t, map[string]interface{}{
"/rpc/v1": gapiImpl, "/rpc/v1": gapiImpl,
"/rpc/v0": api.Wrap(new(v1api.FullNodeStruct), new(v0api.WrapperV1Full), gapiImpl), "/rpc/v0": api.Wrap(new(v1api.FullNodeStruct), new(v0api.WrapperV1Full), gapiImpl),
}) })
@ -288,7 +286,7 @@ func startNodes(
}, },
}, },
) )
n, sn := builder.RPCMockSbBuilder(t, opts, test.OneMiner) n, sn := kit.RPCMockSbBuilder(t, opts, kit.OneMiner)
full := n[0] full := n[0]
lite := n[1] lite := n[1]
@ -310,14 +308,14 @@ func startNodes(
require.NoError(t, err) require.NoError(t, err)
// Start mining blocks // Start mining blocks
bm := test.NewBlockMiner(ctx, t, miner, blocktime) bm := kit.NewBlockMiner(t, miner)
bm.MineBlocks() bm.MineBlocks(ctx, blocktime)
t.Cleanup(bm.Stop) 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 test.TestNode, fromAddr address.Address, toAddr address.Address, amt types.BigInt) error { func sendFunds(ctx context.Context, fromNode kit.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,

View File

@ -93,7 +93,7 @@ func (bm *BlockMiner) MineUntilBlock(ctx context.Context, fn TestFullNode, cb fu
break break
} }
require.Equal(bm.t, i, nloops-1, "block never managed to sync to node") require.NotEqual(bm.t, i, nloops-1, "block never managed to sync to node")
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)
} }

View File

@ -25,7 +25,12 @@ func TestMultisig(t *testing.T) {
ctx := context.Background() ctx := context.Background()
clientNode, _ := kit.StartOneNodeOneMiner(ctx, t, blocktime) clientNode, _ := kit.StartOneNodeOneMiner(ctx, t, blocktime)
runMultisigTests(t, clientNode)
}
func runMultisigTests(t *testing.T, clientNode kit.TestFullNode) {
// Create mock CLI // Create mock CLI
ctx := context.Background()
mockCLI := kit.NewMockCLI(ctx, t, cli.Commands) mockCLI := kit.NewMockCLI(ctx, t, cli.Commands)
clientCLI := mockCLI.Client(clientNode.ListenAddr) clientCLI := mockCLI.Client(clientNode.ListenAddr)