2021-06-18 18:45:29 +00:00
|
|
|
package kit
|
2021-06-11 17:26:25 +00:00
|
|
|
|
2021-06-18 16:40:33 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
2021-06-11 17:26:25 +00:00
|
|
|
|
|
|
|
// EnsembleMinimal creates and starts an Ensemble with a single full node and a single miner.
|
|
|
|
// It does not interconnect nodes nor does it begin mining.
|
|
|
|
//
|
|
|
|
// This function supports passing both ensemble and node functional options.
|
|
|
|
// Functional options are applied to all nodes.
|
|
|
|
func EnsembleMinimal(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *Ensemble) {
|
2021-06-22 10:05:59 +00:00
|
|
|
opts = append(opts, WithAllSubsystems())
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
eopts, nopts := siftOptions(t, opts)
|
|
|
|
|
|
|
|
var (
|
|
|
|
full TestFullNode
|
|
|
|
miner TestMiner
|
|
|
|
)
|
|
|
|
ens := NewEnsemble(t, eopts...).FullNode(&full, nopts...).Miner(&miner, &full, nopts...).Start()
|
|
|
|
return &full, &miner, ens
|
|
|
|
}
|
|
|
|
|
2021-06-23 10:44:52 +00:00
|
|
|
func EnsembleWithMinerAndMarketNodes(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *TestMiner, *Ensemble) {
|
2021-06-18 16:40:33 +00:00
|
|
|
eopts, nopts := siftOptions(t, opts)
|
|
|
|
|
|
|
|
var (
|
|
|
|
fullnode TestFullNode
|
|
|
|
main, market TestMiner
|
|
|
|
)
|
|
|
|
|
2021-06-24 14:02:51 +00:00
|
|
|
mainNodeOpts := []NodeOpt{WithSubsystem(SSealing), WithSubsystem(SSectorStorage), WithSubsystem(SMining), DisableLibp2p()}
|
2021-06-18 16:40:33 +00:00
|
|
|
mainNodeOpts = append(mainNodeOpts, nopts...)
|
|
|
|
|
|
|
|
blockTime := 100 * time.Millisecond
|
|
|
|
ens := NewEnsemble(t, eopts...).FullNode(&fullnode, nopts...).Miner(&main, &fullnode, mainNodeOpts...).Start()
|
2021-06-24 14:02:51 +00:00
|
|
|
ens.BeginMining(blockTime)
|
|
|
|
//ens.InterconnectAll().BeginMining(blockTime)
|
2021-06-18 16:40:33 +00:00
|
|
|
|
|
|
|
marketNodeOpts := []NodeOpt{OwnerAddr(fullnode.DefaultKey), MainMiner(&main), WithSubsystem(SStorageMarket)}
|
|
|
|
marketNodeOpts = append(marketNodeOpts, nopts...)
|
|
|
|
|
2021-06-24 14:02:51 +00:00
|
|
|
ens.Miner(&market, &fullnode, marketNodeOpts...).Start().Connect(market, fullnode)
|
2021-06-18 16:40:33 +00:00
|
|
|
|
|
|
|
return &fullnode, &main, &market, ens
|
|
|
|
}
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
// EnsembleTwoOne creates and starts an Ensemble with two full nodes and one miner.
|
|
|
|
// It does not interconnect nodes nor does it begin mining.
|
|
|
|
//
|
|
|
|
// This function supports passing both ensemble and node functional options.
|
|
|
|
// Functional options are applied to all nodes.
|
|
|
|
func EnsembleTwoOne(t *testing.T, opts ...interface{}) (*TestFullNode, *TestFullNode, *TestMiner, *Ensemble) {
|
2021-06-22 10:05:59 +00:00
|
|
|
opts = append(opts, WithAllSubsystems())
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
eopts, nopts := siftOptions(t, opts)
|
|
|
|
|
|
|
|
var (
|
|
|
|
one, two TestFullNode
|
|
|
|
miner TestMiner
|
|
|
|
)
|
|
|
|
ens := NewEnsemble(t, eopts...).FullNode(&one, nopts...).FullNode(&two, nopts...).Miner(&miner, &one, nopts...).Start()
|
|
|
|
return &one, &two, &miner, ens
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnsembleOneTwo creates and starts an Ensemble with one full node and two miners.
|
|
|
|
// It does not interconnect nodes nor does it begin mining.
|
|
|
|
//
|
|
|
|
// This function supports passing both ensemble and node functional options.
|
|
|
|
// Functional options are applied to all nodes.
|
|
|
|
func EnsembleOneTwo(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *TestMiner, *Ensemble) {
|
2021-06-22 10:05:59 +00:00
|
|
|
opts = append(opts, WithAllSubsystems())
|
|
|
|
|
2021-06-11 17:26:25 +00:00
|
|
|
eopts, nopts := siftOptions(t, opts)
|
|
|
|
|
|
|
|
var (
|
|
|
|
full TestFullNode
|
|
|
|
one, two TestMiner
|
|
|
|
)
|
|
|
|
ens := NewEnsemble(t, eopts...).
|
|
|
|
FullNode(&full, nopts...).
|
|
|
|
Miner(&one, &full, nopts...).
|
|
|
|
Miner(&two, &full, nopts...).
|
|
|
|
Start()
|
|
|
|
|
|
|
|
return &full, &one, &two, ens
|
|
|
|
}
|
|
|
|
|
|
|
|
func siftOptions(t *testing.T, opts []interface{}) (eopts []EnsembleOpt, nopts []NodeOpt) {
|
|
|
|
for _, v := range opts {
|
|
|
|
switch o := v.(type) {
|
|
|
|
case EnsembleOpt:
|
|
|
|
eopts = append(eopts, o)
|
|
|
|
case NodeOpt:
|
|
|
|
nopts = append(nopts, o)
|
|
|
|
default:
|
|
|
|
t.Fatalf("invalid option type: %T", o)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eopts, nopts
|
|
|
|
}
|