lotus/itests/kit/nodes.go

154 lines
4.0 KiB
Go
Raw Normal View History

2021-05-18 21:01:10 +00:00
package kit
import (
"context"
"testing"
2020-08-13 20:37:09 +00:00
"github.com/multiformats/go-multiaddr"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
2020-10-12 06:31:23 +00:00
"github.com/filecoin-project/go-state-types/network"
2021-04-05 19:34:03 +00:00
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/v1api"
"github.com/filecoin-project/lotus/chain/stmgr"
2020-07-28 16:16:46 +00:00
"github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/lotus/node"
)
2021-05-21 19:39:41 +00:00
type MinerBuilder func(context.Context, *testing.T, abi.RegisteredSealProof, address.Address) TestMiner
type TestFullNode struct {
2021-04-05 17:56:53 +00:00
v1api.FullNode
2020-08-13 20:37:09 +00:00
// ListenAddr is the address on which an API server is listening, if an
// API server is created for this Node
ListenAddr multiaddr.Multiaddr
2021-05-21 19:39:41 +00:00
Stb MinerBuilder
2019-09-23 15:27:30 +00:00
}
type TestMiner struct {
2021-04-05 19:34:03 +00:00
lapi.StorageMiner
2020-08-13 20:37:09 +00:00
// ListenAddr is the address on which an API server is listening, if an
// API server is created for this Node
ListenAddr multiaddr.Multiaddr
2019-11-30 23:17:50 +00:00
2020-07-28 16:16:46 +00:00
MineOne func(context.Context, miner.MineReq) error
2021-01-22 03:48:34 +00:00
Stop func(context.Context) error
2019-09-23 15:27:30 +00:00
}
2020-04-23 17:50:52 +00:00
var PresealGenesis = -1
2020-06-01 12:49:48 +00:00
const GenesisPreseals = 2
2020-04-23 17:50:52 +00:00
const TestSpt = abi.RegisteredSealProof_StackedDrg2KiBV1_1
2021-05-18 21:01:10 +00:00
// Options for setting up a mock storage Miner
2020-04-23 17:50:52 +00:00
type StorageMiner struct {
Full int
2021-01-08 15:28:38 +00:00
Opts node.Option
2020-04-23 17:50:52 +00:00
Preseal int
}
type OptionGenerator func([]TestFullNode) node.Option
// Options for setting up a mock full node
type FullNodeOpts struct {
Lite bool // run node in "lite" mode
Opts OptionGenerator // generate dependency injection options
}
2019-07-02 13:05:43 +00:00
// APIBuilder is a function which is invoked in test suite to provide
// test nodes and networks
2019-09-23 15:27:30 +00:00
//
// fullOpts array defines options for each full node
2019-09-23 15:27:30 +00:00
// storage array defines storage nodes, numbers in the array specify full node
// index the storage node 'belongs' to
type APIBuilder func(t *testing.T, full []FullNodeOpts, storage []StorageMiner) ([]TestFullNode, []TestMiner)
func DefaultFullOpts(nFull int) []FullNodeOpts {
full := make([]FullNodeOpts, nFull)
for i := range full {
full[i] = FullNodeOpts{
Opts: func(nodes []TestFullNode) node.Option {
return node.Options()
},
}
}
return full
}
2020-08-13 20:37:09 +00:00
var OneMiner = []StorageMiner{{Full: 0, Preseal: PresealGenesis}}
var OneFull = DefaultFullOpts(1)
var TwoFull = DefaultFullOpts(2)
2020-04-23 17:50:52 +00:00
2021-04-30 16:43:06 +00:00
var FullNodeWithLatestActorsAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts {
// Attention: Update this when introducing new actor versions or your tests will be sad
return FullNodeWithNetworkUpgradeAt(network.Version13, upgradeHeight)
}
var FullNodeWithNetworkUpgradeAt = func(version network.Version, upgradeHeight abi.ChainEpoch) FullNodeOpts {
fullSchedule := stmgr.UpgradeSchedule{{
// prepare for upgrade.
Network: network.Version9,
Height: 1,
Migration: stmgr.UpgradeActorsV2,
}, {
Network: network.Version10,
Height: 2,
Migration: stmgr.UpgradeActorsV3,
}, {
Network: network.Version12,
Height: 3,
Migration: stmgr.UpgradeActorsV4,
}, {
Network: network.Version13,
Height: 4,
Migration: stmgr.UpgradeActorsV5,
}}
schedule := stmgr.UpgradeSchedule{}
for _, upgrade := range fullSchedule {
if upgrade.Network > version {
break
}
schedule = append(schedule, upgrade)
}
if upgradeHeight > 0 {
schedule[len(schedule)-1].Height = upgradeHeight
}
return FullNodeOpts{
Opts: func(nodes []TestFullNode) node.Option {
return node.Override(new(stmgr.UpgradeSchedule), schedule)
},
}
}
var FullNodeWithSDRAt = func(calico, persian abi.ChainEpoch) FullNodeOpts {
2020-11-06 18:01:09 +00:00
return FullNodeOpts{
Opts: func(nodes []TestFullNode) node.Option {
2020-11-06 18:01:09 +00:00
return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{
Network: network.Version6,
Height: 1,
Migration: stmgr.UpgradeActorsV2,
}, {
Network: network.Version7,
Height: calico,
2020-11-06 18:01:09 +00:00
Migration: stmgr.UpgradeCalico,
}, {
Network: network.Version8,
Height: persian,
2020-11-06 18:01:09 +00:00
}})
},
}
}
var MineNext = miner.MineReq{
InjectNulls: 0,
Done: func(bool, abi.ChainEpoch, error) {},
}