2021-05-18 21:01:10 +00:00
|
|
|
package kit
|
2019-06-29 09:19:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2020-08-13 20:37:09 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-10-08 10:21:15 +00:00
|
|
|
"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-23 12:29:46 +00:00
|
|
|
|
2021-04-05 19:34:03 +00:00
|
|
|
lapi "github.com/filecoin-project/lotus/api"
|
2021-04-27 06:13:49 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v1api"
|
2021-04-23 12:29:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2020-07-28 16:16:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/miner"
|
2020-10-01 22:26:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/node"
|
2019-06-29 09:19:06 +00:00
|
|
|
)
|
|
|
|
|
2021-05-21 19:39:41 +00:00
|
|
|
type MinerBuilder func(context.Context, *testing.T, abi.RegisteredSealProof, address.Address) TestMiner
|
2021-04-23 12:29:46 +00:00
|
|
|
|
2021-05-19 10:47:37 +00:00
|
|
|
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-04-23 12:29:46 +00:00
|
|
|
|
2021-05-21 19:39:41 +00:00
|
|
|
Stb MinerBuilder
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 10:47:37 +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 18:11:55 +00:00
|
|
|
|
2020-06-01 12:49:48 +00:00
|
|
|
const GenesisPreseals = 2
|
2020-04-23 17:50:52 +00:00
|
|
|
|
2021-04-23 12:29:46 +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
|
|
|
|
}
|
|
|
|
|
2021-05-19 10:47:37 +00:00
|
|
|
type OptionGenerator func([]TestFullNode) node.Option
|
2020-10-07 09:26:15 +00:00
|
|
|
|
2020-10-08 09:24:31 +00:00
|
|
|
// 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
|
|
|
//
|
2020-10-08 09:24:31 +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
|
2021-05-19 10:47:37 +00:00
|
|
|
type APIBuilder func(t *testing.T, full []FullNodeOpts, storage []StorageMiner) ([]TestFullNode, []TestMiner)
|
2019-06-29 09:19:06 +00:00
|
|
|
|
2020-10-08 09:24:31 +00:00
|
|
|
func DefaultFullOpts(nFull int) []FullNodeOpts {
|
|
|
|
full := make([]FullNodeOpts, nFull)
|
2020-10-07 09:26:15 +00:00
|
|
|
for i := range full {
|
2020-10-08 09:24:31 +00:00
|
|
|
full[i] = FullNodeOpts{
|
2021-05-19 10:47:37 +00:00
|
|
|
Opts: func(nodes []TestFullNode) node.Option {
|
2020-10-08 09:24:31 +00:00
|
|
|
return node.Options()
|
|
|
|
},
|
2020-10-07 09:26:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return full
|
|
|
|
}
|
|
|
|
|
2020-08-13 20:37:09 +00:00
|
|
|
var OneMiner = []StorageMiner{{Full: 0, Preseal: PresealGenesis}}
|
2020-10-07 09:26:15 +00:00
|
|
|
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 {
|
2021-06-07 22:17:44 +00:00
|
|
|
// 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
|
2021-04-23 12:29:46 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 10:21:15 +00:00
|
|
|
return FullNodeOpts{
|
2021-05-19 10:47:37 +00:00
|
|
|
Opts: func(nodes []TestFullNode) node.Option {
|
2021-06-07 22:17:44 +00:00
|
|
|
return node.Override(new(stmgr.UpgradeSchedule), schedule)
|
2020-10-08 10:21:15 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 22:43:27 +00:00
|
|
|
var FullNodeWithSDRAt = func(calico, persian abi.ChainEpoch) FullNodeOpts {
|
2020-11-06 18:01:09 +00:00
|
|
|
return FullNodeOpts{
|
2021-05-19 10:47:37 +00:00
|
|
|
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,
|
2020-11-12 22:43:27 +00:00
|
|
|
Height: calico,
|
2020-11-06 18:01:09 +00:00
|
|
|
Migration: stmgr.UpgradeCalico,
|
2020-11-12 22:43:27 +00:00
|
|
|
}, {
|
|
|
|
Network: network.Version8,
|
|
|
|
Height: persian,
|
2020-11-06 18:01:09 +00:00
|
|
|
}})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 23:52:13 +00:00
|
|
|
var MineNext = miner.MineReq{
|
|
|
|
InjectNulls: 0,
|
|
|
|
Done: func(bool, abi.ChainEpoch, error) {},
|
|
|
|
}
|