This commit is contained in:
Raúl Kripalani 2021-05-17 13:28:09 +01:00
parent 625b18771d
commit c46d4ae529
22 changed files with 95 additions and 95 deletions

View File

@ -1,22 +0,0 @@
package cli
import (
"context"
"os"
"testing"
"time"
clitest "github.com/filecoin-project/lotus/cli/test"
)
// TestClient does a basic test to exercise the client CLI
// commands
func TestClient(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
blocktime := 5 * time.Millisecond
ctx := context.Background()
clientNode, _ := clitest.StartOneNodeOneMiner(ctx, t, blocktime)
clitest.RunClientTest(t, Commands, clientNode)
}

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"
@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/lotus/miner"
)
// BlockMiner is a utility that makes a test miner mine blocks on a timer.
type BlockMiner struct {
ctx context.Context
t *testing.T

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"
@ -24,12 +24,12 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) {
} {
height := height // make linters happy by copying
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
testCCUpgrade(t, b, blocktime, height)
runTestCCUpgrade(t, b, blocktime, height)
})
}
}
func testCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, upgradeHeight abi.ChainEpoch) {
func runTestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, upgradeHeight abi.ChainEpoch) {
ctx := context.Background()
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(upgradeHeight)}, OneMiner)
client := n[0].FullNode.(*impl.FullNodeAPI)

21
itests/cliclient_test.go Normal file
View File

@ -0,0 +1,21 @@
package itests
import (
"context"
"os"
"testing"
"time"
"github.com/filecoin-project/lotus/cli"
)
// TestClient does a basic test to exercise the client CLI commands.
func TestClient(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1")
QuietMiningLogs()
blocktime := 5 * time.Millisecond
ctx := context.Background()
clientNode, _ := StartOneNodeOneMiner(ctx, t, blocktime)
RunClientTest(t, cli.Commands, clientNode)
}

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"
@ -13,7 +13,6 @@ import (
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api/test"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/v2/actors/builtin"
@ -22,7 +21,7 @@ import (
)
// RunClientTest exercises some of the client CLI commands
func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode) {
func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode TestNode) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
@ -44,7 +43,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
// Create a deal (non-interactive)
// client deal --start-epoch=<start epoch> <cid> <miner addr> 1000000attofil <duration>
res, _, err := test.CreateClientFile(ctx, clientNode, 1)
res, _, err := CreateClientFile(ctx, clientNode, 1)
require.NoError(t, err)
startEpoch := fmt.Sprintf("--start-epoch=%d", 2<<12)
dataCid := res.Root
@ -60,7 +59,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode test.TestNode)
// <miner addr>
// "no" (verified client)
// "yes" (confirm deal)
res, _, err = test.CreateClientFile(ctx, clientNode, 2)
res, _, err = CreateClientFile(ctx, clientNode, 2)
require.NoError(t, err)
dataCid2 := res.Root
duration = fmt.Sprintf("%d", build.MinDealDuration/builtin.EpochsInDay)

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"bytes"

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"bytes"

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"bytes"

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"bytes"

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"

View File

@ -1,4 +1,4 @@
package cli
package itests
import (
"context"
@ -6,17 +6,17 @@ import (
"testing"
"time"
clitest "github.com/filecoin-project/lotus/cli/test"
"github.com/filecoin-project/lotus/cli"
)
// TestMultisig does a basic test to exercise the multisig CLI
// commands
func TestMultisig(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
QuietMiningLogs()
blocktime := 5 * time.Millisecond
ctx := context.Background()
clientNode, _ := clitest.StartOneNodeOneMiner(ctx, t, blocktime)
clitest.RunMultisigTest(t, Commands, clientNode)
clientNode, _ := StartOneNodeOneMiner(ctx, t, blocktime)
RunMultisigTest(t, cli.Commands, clientNode)
}

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"
@ -13,8 +13,8 @@ import (
test2 "github.com/filecoin-project/lotus/node/test"
)
func StartOneNodeOneMiner(ctx context.Context, t *testing.T, blocktime time.Duration) (test.TestNode, address.Address) {
n, sn := test2.RPCMockSbBuilder(t, test.OneFull, test.OneMiner)
func StartOneNodeOneMiner(ctx context.Context, t *testing.T, blocktime time.Duration) (TestNode, address.Address) {
n, sn := RPCMockSbBuilder(t, OneFull, OneMiner)
full := n[0]
miner := sn[0]
@ -30,7 +30,7 @@ func StartOneNodeOneMiner(ctx context.Context, t *testing.T, blocktime time.Dura
}
// Start mining blocks
bm := test.NewBlockMiner(ctx, t, miner, blocktime)
bm := NewBlockMiner(ctx, t, miner, blocktime)
bm.MineBlocks()
t.Cleanup(bm.Stop)
@ -44,8 +44,8 @@ func StartOneNodeOneMiner(ctx context.Context, t *testing.T, blocktime time.Dura
return full, fullAddr
}
func StartTwoNodesOneMiner(ctx context.Context, t *testing.T, blocktime time.Duration) ([]test.TestNode, []address.Address) {
n, sn := test2.RPCMockSbBuilder(t, test.TwoFull, test.OneMiner)
func StartTwoNodesOneMiner(ctx context.Context, t *testing.T, blocktime time.Duration) ([]TestNode, []address.Address) {
n, sn := RPCMockSbBuilder(t, TwoFull, OneMiner)
fullNode1 := n[0]
fullNode2 := n[1]

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"bytes"
@ -23,7 +23,6 @@ import (
"github.com/filecoin-project/go-storedcounter"
"github.com/filecoin-project/lotus/api"
"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/v1api"
"github.com/filecoin-project/lotus/build"
@ -65,7 +64,7 @@ func init() {
messagepool.HeadChangeCoalesceMergeInterval = 100 * time.Nanosecond
}
func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd test.TestNode, mn mocknet.Mocknet, opts node.Option) test.TestStorageNode {
func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Address, act address.Address, pk crypto.PrivKey, tnd TestNode, mn mocknet.Mocknet, opts node.Option) TestStorageNode {
r := repo.NewMemory(nil)
lr, err := r.Lock(repo.StorageMiner)
@ -89,7 +88,7 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr
require.NoError(t, err)
nic := storedcounter.New(ds, datastore.NewKey(modules.StorageCounterDSPrefix))
for i := 0; i < test.GenesisPreseals; i++ {
for i := 0; i < GenesisPreseals; i++ {
_, err := nic.Next()
require.NoError(t, err)
}
@ -154,11 +153,11 @@ func CreateTestStorageNode(ctx context.Context, t *testing.T, waddr address.Addr
}
}
return test.TestStorageNode{StorageMiner: minerapi, MineOne: mineOne, Stop: stop}
return TestStorageNode{StorageMiner: minerapi, MineOne: mineOne, Stop: stop}
}
func storageBuilder(parentNode test.TestNode, mn mocknet.Mocknet, opts node.Option) test.StorageBuilder {
return func(ctx context.Context, t *testing.T, spt abi.RegisteredSealProof, owner address.Address) test.TestStorageNode {
func storageBuilder(parentNode TestNode, mn mocknet.Mocknet, opts node.Option) StorageBuilder {
return func(ctx context.Context, t *testing.T, spt abi.RegisteredSealProof, owner address.Address) TestStorageNode {
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)
@ -200,30 +199,30 @@ func storageBuilder(parentNode test.TestNode, mn mocknet.Mocknet, opts node.Opti
}
}
func Builder(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
func Builder(t *testing.T, fullOpts []FullNodeOpts, storage []StorageMiner) ([]TestNode, []TestStorageNode) {
return mockBuilderOpts(t, fullOpts, storage, false)
}
func MockSbBuilder(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
func MockSbBuilder(t *testing.T, fullOpts []FullNodeOpts, storage []StorageMiner) ([]TestNode, []TestStorageNode) {
return mockSbBuilderOpts(t, fullOpts, storage, false)
}
func RPCBuilder(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
func RPCBuilder(t *testing.T, fullOpts []FullNodeOpts, storage []StorageMiner) ([]TestNode, []TestStorageNode) {
return mockBuilderOpts(t, fullOpts, storage, true)
}
func RPCMockSbBuilder(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner) ([]test.TestNode, []test.TestStorageNode) {
func RPCMockSbBuilder(t *testing.T, fullOpts []FullNodeOpts, storage []StorageMiner) ([]TestNode, []TestStorageNode) {
return mockSbBuilderOpts(t, fullOpts, storage, true)
}
func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner, rpc bool) ([]test.TestNode, []test.TestStorageNode) {
func mockBuilderOpts(t *testing.T, fullOpts []FullNodeOpts, storage []StorageMiner, rpc bool) ([]TestNode, []TestStorageNode) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
mn := mocknet.New(ctx)
fulls := make([]test.TestNode, len(fullOpts))
storers := make([]test.TestStorageNode, len(storage))
fulls := make([]TestNode, len(fullOpts))
storers := make([]TestStorageNode, len(storage))
pk, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)
@ -254,7 +253,7 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
if err != nil {
t.Fatal(err)
}
genm, k, err := seed.PreSeal(maddr, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, test.GenesisPreseals, tdir, []byte("make genesis mem random"), nil, true)
genm, k, err := seed.PreSeal(maddr, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, GenesisPreseals, tdir, []byte("make genesis mem random"), nil, true)
if err != nil {
t.Fatal(err)
}
@ -366,12 +365,12 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
var wait sync.Mutex
wait.Lock()
test.MineUntilBlock(ctx, t, fulls[0], storers[0], func(epoch abi.ChainEpoch) {
MineUntilBlock(ctx, t, fulls[0], storers[0], func(epoch abi.ChainEpoch) {
wait.Unlock()
})
wait.Lock()
test.MineUntilBlock(ctx, t, fulls[0], storers[0], func(epoch abi.ChainEpoch) {
MineUntilBlock(ctx, t, fulls[0], storers[0], func(epoch abi.ChainEpoch) {
wait.Unlock()
})
wait.Lock()
@ -380,14 +379,14 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.
return fulls, storers
}
func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test.StorageMiner, rpc bool) ([]test.TestNode, []test.TestStorageNode) {
func mockSbBuilderOpts(t *testing.T, fullOpts []FullNodeOpts, storage []StorageMiner, rpc bool) ([]TestNode, []TestStorageNode) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
mn := mocknet.New(ctx)
fulls := make([]test.TestNode, len(fullOpts))
storers := make([]test.TestStorageNode, len(storage))
fulls := make([]TestNode, len(fullOpts))
storers := make([]TestStorageNode, len(storage))
var genbuf bytes.Buffer
@ -406,8 +405,8 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes
}
preseals := storage[i].Preseal
if preseals == test.PresealGenesis {
preseals = test.GenesisPreseals
if preseals == PresealGenesis {
preseals = GenesisPreseals
}
genm, k, err := mockstorage.PreSeal(abi.RegisteredSealProof_StackedDrg2KiBV1, maddr, preseals)
@ -545,11 +544,11 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes
var wait sync.Mutex
wait.Lock()
test.MineUntilBlock(ctx, t, fulls[0], storers[0], func(abi.ChainEpoch) {
MineUntilBlock(ctx, t, fulls[0], storers[0], func(abi.ChainEpoch) {
wait.Unlock()
})
wait.Lock()
test.MineUntilBlock(ctx, t, fulls[0], storers[0], func(abi.ChainEpoch) {
MineUntilBlock(ctx, t, fulls[0], storers[0], func(abi.ChainEpoch) {
wait.Unlock()
})
wait.Lock()
@ -558,7 +557,7 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes
return fulls, storers
}
func fullRpc(t *testing.T, nd test.TestNode) test.TestNode {
func fullRpc(t *testing.T, nd TestNode) TestNode {
ma, listenAddr, err := CreateRPCServer(t, map[string]interface{}{
"/rpc/v1": nd,
"/rpc/v0": &v0api.WrapperV1Full{FullNode: nd},
@ -566,7 +565,7 @@ func fullRpc(t *testing.T, nd test.TestNode) test.TestNode {
require.NoError(t, err)
var stop func()
var full test.TestNode
var full TestNode
full.FullNode, stop, err = client.NewFullNodeRPCV1(context.Background(), listenAddr+"/rpc/v1", nil)
require.NoError(t, err)
t.Cleanup(stop)
@ -575,14 +574,14 @@ func fullRpc(t *testing.T, nd test.TestNode) test.TestNode {
return full
}
func storerRpc(t *testing.T, nd test.TestStorageNode) test.TestStorageNode {
func storerRpc(t *testing.T, nd TestStorageNode) TestStorageNode {
ma, listenAddr, err := CreateRPCServer(t, map[string]interface{}{
"/rpc/v0": nd,
})
require.NoError(t, err)
var stop func()
var storer test.TestStorageNode
var storer TestStorageNode
storer.StorageMiner, stop, err = client.NewStorageMinerRPCV0(context.Background(), listenAddr+"/rpc/v0", nil)
require.NoError(t, err)
t.Cleanup(stop)
@ -599,7 +598,7 @@ func CreateRPCServer(t *testing.T, handlers map[string]interface{}) (multiaddr.M
rpcServer.Register("Filecoin", handler)
m.Handle(path, rpcServer)
}
testServ := httptest.NewServer(m) // todo: close
testServ := httpNewServer(m) // todo: close
t.Cleanup(testServ.Close)
t.Cleanup(testServ.CloseClientConnections)

View File

@ -1,4 +1,4 @@
package node_test
package itests_test
import (
"os"
@ -183,7 +183,7 @@ func TestWindowedPost(t *testing.T) {
logging.SetLogLevel("sub", "ERROR")
logging.SetLogLevel("storageminer", "ERROR")
test.TestWindowPost(t, builder.MockSbBuilder, 2*time.Millisecond, 10)
TestWindowPost(t, builder.MockSbBuilder, 2*time.Millisecond, 10)
}
func TestTerminate(t *testing.T) {
@ -197,7 +197,7 @@ func TestTerminate(t *testing.T) {
logging.SetLogLevel("sub", "ERROR")
logging.SetLogLevel("storageminer", "ERROR")
test.TestTerminate(t, builder.MockSbBuilder, 2*time.Millisecond)
TestTerminate(t, builder.MockSbBuilder, 2*time.Millisecond)
}
func TestCCUpgrade(t *testing.T) {

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"

View File

@ -1,4 +1,4 @@
package cli
package itests
import (
"context"
@ -10,6 +10,7 @@ import (
"testing"
"time"
"github.com/filecoin-project/lotus/cli"
clitest "github.com/filecoin-project/lotus/cli/test"
"github.com/filecoin-project/go-address"
@ -37,18 +38,18 @@ func init() {
// commands
func TestPaymentChannels(t *testing.T) {
_ = os.Setenv("BELLMAN_NO_GPU", "1")
clitest.QuietMiningLogs()
QuietMiningLogs()
blocktime := 5 * time.Millisecond
ctx := context.Background()
nodes, addrs := clitest.StartTwoNodesOneMiner(ctx, t, blocktime)
nodes, addrs := StartTwoNodesOneMiner(ctx, t, blocktime)
paymentCreator := nodes[0]
paymentReceiver := nodes[1]
creatorAddr := addrs[0]
receiverAddr := addrs[1]
// Create mock CLI
mockCLI := clitest.NewMockCLI(ctx, t, Commands)
mockCLI := NewMockCLI(ctx, t, cli.Commands)
creatorCLI := mockCLI.Client(paymentCreator.ListenAddr)
receiverCLI := mockCLI.Client(paymentReceiver.ListenAddr)

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"

View File

@ -1,4 +1,4 @@
package test
package itests
import "github.com/ipfs/go-log/v2"

View File

@ -1,4 +1,4 @@
package test
package itests
import (
"context"

View File

@ -1,12 +1,11 @@
package test
package itests
import (
"context"
"fmt"
"sort"
"sync/atomic"
"strings"
"sync/atomic"
"testing"
"time"

View File

@ -5,7 +5,7 @@ import (
"time"
"github.com/filecoin-project/go-state-types/abi"
xerrors "golang.org/x/xerrors"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/big"
"github.com/ipfs/go-cid"
@ -13,7 +13,7 @@ import (
"github.com/libp2p/go-libp2p-core/host"
inet "github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
protocol "github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-core/protocol"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/lotus/build"
@ -23,6 +23,8 @@ import (
"github.com/filecoin-project/lotus/lib/peermgr"
)
// TODO(TEST): missing test coverage.
const ProtocolID = "/fil/hello/1.0.0"
var log = logging.Logger("hello")
@ -33,12 +35,14 @@ type HelloMessage struct {
HeaviestTipSetWeight big.Int
GenesisHash cid.Cid
}
type LatencyMessage struct {
TArrival int64
TSent int64
}
type NewStreamFunc func(context.Context, peer.ID, ...protocol.ID) (inet.Stream, error)
type Service struct {
h host.Host
@ -62,7 +66,6 @@ func NewHelloService(h host.Host, cs *store.ChainStore, syncer *chain.Syncer, pm
}
func (hs *Service) HandleStream(s inet.Stream) {
var hmsg HelloMessage
if err := cborutil.ReadCborRPC(s, &hmsg); err != nil {
log.Infow("failed to read hello message, disconnecting", "error", err)
@ -121,7 +124,6 @@ func (hs *Service) HandleStream(s inet.Stream) {
log.Debugf("Got new tipset through Hello: %s from %s", ts.Cids(), s.Conn().RemotePeer())
hs.syncer.InformNewHead(s.Conn().RemotePeer(), ts)
}
}
func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {