deals tests: refactor/simplify TestDealMining; now TestFirstDealEnablesMining.
This commit is contained in:
parent
329970934a
commit
4f2aaa54d2
@ -48,7 +48,7 @@ func (ts *apiSuite) testVersion(t *testing.T) {
|
||||
lapi.RunningNodeType = lapi.NodeUnknown
|
||||
})
|
||||
|
||||
full, _, _ := kit.EnsembleMinimum(t, ts.opts...)
|
||||
full, _, _ := kit.EnsembleMinimal(t, ts.opts...)
|
||||
|
||||
v, err := full.Version(context.Background())
|
||||
require.NoError(t, err)
|
||||
@ -61,7 +61,7 @@ func (ts *apiSuite) testVersion(t *testing.T) {
|
||||
func (ts *apiSuite) testID(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
full, _, _ := kit.EnsembleMinimum(t, ts.opts...)
|
||||
full, _, _ := kit.EnsembleMinimal(t, ts.opts...)
|
||||
|
||||
id, err := full.ID(ctx)
|
||||
if err != nil {
|
||||
@ -73,7 +73,7 @@ func (ts *apiSuite) testID(t *testing.T) {
|
||||
func (ts *apiSuite) testConnectTwo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
one, two, _, ens := kit.EnsembleTwo(t, ts.opts...)
|
||||
one, two, _, ens := kit.EnsembleTwoOne(t, ts.opts...)
|
||||
|
||||
p, err := one.NetPeers(ctx)
|
||||
require.NoError(t, err)
|
||||
@ -97,7 +97,7 @@ func (ts *apiSuite) testConnectTwo(t *testing.T) {
|
||||
func (ts *apiSuite) testSearchMsg(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
full, _, ens := kit.EnsembleMinimum(t, ts.opts...)
|
||||
full, _, ens := kit.EnsembleMinimal(t, ts.opts...)
|
||||
|
||||
senderAddr, err := full.WalletDefaultAddress(ctx)
|
||||
require.NoError(t, err)
|
||||
@ -127,7 +127,7 @@ func (ts *apiSuite) testSearchMsg(t *testing.T) {
|
||||
func (ts *apiSuite) testMining(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
full, miner, _ := kit.EnsembleMinimum(t, ts.opts...)
|
||||
full, miner, _ := kit.EnsembleMinimal(t, ts.opts...)
|
||||
|
||||
newHeads, err := full.ChainNotify(ctx)
|
||||
require.NoError(t, err)
|
||||
@ -170,7 +170,7 @@ func (ts *apiSuite) testMiningReal(t *testing.T) {
|
||||
func (ts *apiSuite) testNonGenesisMiner(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
full, genesisMiner, ens := kit.EnsembleMinimum(t, ts.opts...)
|
||||
full, genesisMiner, ens := kit.EnsembleMinimal(t, ts.opts...)
|
||||
|
||||
ens.BeginMining(4 * time.Millisecond)
|
||||
|
||||
|
@ -3,11 +3,9 @@ package itests
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
@ -92,14 +90,11 @@ func TestPublishDealsBatching(t *testing.T) {
|
||||
}),
|
||||
)
|
||||
|
||||
client, miner, ens := kit.EnsembleMinimum(t, kit.MockProofs(), kit.ExtraNodeOpts(opts))
|
||||
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ExtraNodeOpts(opts))
|
||||
ens.InterconnectAll().BeginMining(10 * time.Millisecond)
|
||||
|
||||
dh := kit.NewDealHarness(t, client, miner)
|
||||
|
||||
fmt.Println("***********************")
|
||||
spew.Dump(client.NetPeers(context.Background()))
|
||||
|
||||
// Starts a deal and waits until it's published
|
||||
runDealTillPublish := func(rseed int) {
|
||||
res, _, _, err := kit.CreateImportFile(ctx, client, rseed, 0)
|
||||
@ -168,135 +163,70 @@ func TestPublishDealsBatching(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// func TestDealMining(t *testing.T) {
|
||||
// // test making a deal with a fresh miner, and see if it starts to mine.
|
||||
// if testing.Short() {
|
||||
// t.Skip("skipping test in short mode")
|
||||
// }
|
||||
//
|
||||
// kit.QuietMiningLogs()
|
||||
//
|
||||
// b := kit.MockMinerBuilder
|
||||
// blocktime := 50 * time.Millisecond
|
||||
//
|
||||
// ctx := context.Background()
|
||||
// fulls, miners := b(t,
|
||||
// kit.OneFull,
|
||||
// []kit.StorageMiner{
|
||||
// {Full: 0, Preseal: kit.PresealGenesis},
|
||||
// {Full: 0, Preseal: 0}, // TODO: Add support for miners on non-first full node
|
||||
// })
|
||||
// client := fulls[0].FullNode.(*impl.FullNodeAPI)
|
||||
// genesisMiner := miners[0]
|
||||
// provider := miners[1]
|
||||
//
|
||||
// addrinfo, err := client.NetAddrsListen(ctx)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
//
|
||||
// if err := provider.NetConnect(ctx, addrinfo); err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
//
|
||||
// if err := genesisMiner.NetConnect(ctx, addrinfo); err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
//
|
||||
// time.Sleep(time.Second)
|
||||
//
|
||||
// data := make([]byte, 600)
|
||||
// rand.New(rand.NewSource(5)).Read(data)
|
||||
//
|
||||
// r := bytes.NewReader(data)
|
||||
// fcid, err := client.ClientImportLocal(ctx, r)
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
//
|
||||
// fmt.Println("FILE CID: ", fcid)
|
||||
//
|
||||
// var mine int32 = 1
|
||||
// done := make(chan struct{})
|
||||
// minedTwo := make(chan struct{})
|
||||
//
|
||||
// m2addr, err := miners[1].ActorAddress(context.TODO())
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
//
|
||||
// go func() {
|
||||
// defer close(done)
|
||||
//
|
||||
// complChan := minedTwo
|
||||
// for atomic.LoadInt32(&mine) != 0 {
|
||||
// wait := make(chan int)
|
||||
// mdone := func(mined bool, _ abi.ChainEpoch, err error) {
|
||||
// n := 0
|
||||
// if mined {
|
||||
// n = 1
|
||||
// }
|
||||
// wait <- n
|
||||
// }
|
||||
//
|
||||
// if err := miners[0].MineOne(ctx, miner.MineReq{Done: mdone}); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
//
|
||||
// if err := miners[1].MineOne(ctx, miner.MineReq{Done: mdone}); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
//
|
||||
// expect := <-wait
|
||||
// expect += <-wait
|
||||
//
|
||||
// time.Sleep(blocktime)
|
||||
// if expect == 0 {
|
||||
// // null block
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// var nodeOneMined bool
|
||||
// for _, node := range miners {
|
||||
// mb, err := node.MiningBase(ctx)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// for _, b := range mb.Blocks() {
|
||||
// if b.Miner == m2addr {
|
||||
// nodeOneMined = true
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// if nodeOneMined && complChan != nil {
|
||||
// close(complChan)
|
||||
// complChan = nil
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }()
|
||||
//
|
||||
// dh := kit.NewDealHarness(t, client, provider)
|
||||
//
|
||||
// deal := dh.StartDeal(ctx, fcid, false, 0)
|
||||
//
|
||||
// // TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||
// time.Sleep(time.Second)
|
||||
//
|
||||
// dh.WaitDealSealed(ctx, deal, false, false, nil)
|
||||
//
|
||||
// <-minedTwo
|
||||
//
|
||||
// atomic.StoreInt32(&mine, 0)
|
||||
// fmt.Println("shutting down mining")
|
||||
// <-done
|
||||
// }
|
||||
func TestFirstDealEnablesMining(t *testing.T) {
|
||||
// test making a deal with a fresh miner, and see if it starts to mine.
|
||||
if testing.Short() {
|
||||
t.Skip("skipping test in short mode")
|
||||
}
|
||||
|
||||
kit.QuietMiningLogs()
|
||||
|
||||
var (
|
||||
client kit.TestFullNode
|
||||
genMiner kit.TestMiner // bootstrap
|
||||
provider kit.TestMiner // no sectors, will need to create one
|
||||
)
|
||||
|
||||
ens := kit.NewEnsemble(t)
|
||||
ens.FullNode(&client, kit.MockProofs())
|
||||
ens.Miner(&genMiner, &client, kit.MockProofs())
|
||||
ens.Miner(&provider, &client, kit.MockProofs(), kit.PresealSectors(0))
|
||||
ens.Start().InterconnectAll().BeginMining(50 * time.Millisecond)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
dh := kit.NewDealHarness(t, client, &provider)
|
||||
|
||||
ref, _, _, err := kit.CreateImportFile(ctx, client, 5, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Log("FILE CID:", ref.Root)
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// start a goroutine to monitor head changes from the client
|
||||
// once the provider has mined a block, thanks to the power acquired from the deal,
|
||||
// we pass the test.
|
||||
providerMined := make(chan struct{})
|
||||
heads, err := client.ChainNotify(ctx)
|
||||
go func() {
|
||||
for chg := range heads {
|
||||
for _, c := range chg {
|
||||
if c.Type != "apply" {
|
||||
continue
|
||||
}
|
||||
for _, b := range c.Val.Blocks() {
|
||||
if b.Miner == provider.ActorAddr {
|
||||
close(providerMined)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// now perform the deal.
|
||||
deal := dh.StartDeal(ctx, ref.Root, false, 0)
|
||||
|
||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||
time.Sleep(time.Second)
|
||||
|
||||
dh.WaitDealSealed(ctx, deal, false, false, nil)
|
||||
|
||||
<-providerMined
|
||||
}
|
||||
|
||||
//
|
||||
// func TestOfflineDealFlow(t *testing.T) {
|
||||
// blocktime := 10 * time.Millisecond
|
||||
@ -390,7 +320,7 @@ func TestPublishDealsBatching(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
// func runFullDealCycles(t *testing.T, n int, b kit.APIBuilder, blocktime time.Duration, carExport, fastRet bool, startEpoch abi.ChainEpoch) {
|
||||
// full, _, ens := kit.EnsembleMinimum(t)
|
||||
// full, _, ens := kit.EnsembleMinimal(t)
|
||||
// ens.BeginMining()
|
||||
// dh := kit.NewDealHarness(t, client, miner)
|
||||
//
|
||||
|
@ -123,9 +123,11 @@ type NodeOpts struct {
|
||||
extraNodeOpts []node.Option
|
||||
}
|
||||
|
||||
const DefaultPresealsPerBootstrapMiner = 2
|
||||
|
||||
var DefaultNodeOpts = NodeOpts{
|
||||
balance: big.Mul(big.NewInt(100000000), types.NewInt(build.FilecoinPrecision)),
|
||||
sectors: 2,
|
||||
sectors: DefaultPresealsPerBootstrapMiner,
|
||||
}
|
||||
|
||||
type NodeOpt func(opts *NodeOpts) error
|
||||
@ -215,7 +217,7 @@ func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble {
|
||||
n.genesis.accounts = append(n.genesis.accounts, genacc)
|
||||
}
|
||||
|
||||
*full = TestFullNode{options: options, DefaultKey: key}
|
||||
*full = TestFullNode{t: n.t, options: options, DefaultKey: key}
|
||||
n.inactive.fullnodes = append(n.inactive.fullnodes, full)
|
||||
return n
|
||||
}
|
||||
@ -280,6 +282,7 @@ func (n *Ensemble) Miner(miner *TestMiner, full *TestFullNode, opts ...NodeOpt)
|
||||
}
|
||||
|
||||
*miner = TestMiner{
|
||||
t: n.t,
|
||||
ActorAddr: actorAddr,
|
||||
OwnerKey: ownerKey,
|
||||
FullNode: full,
|
||||
|
@ -2,7 +2,9 @@ package kit
|
||||
|
||||
import "testing"
|
||||
|
||||
func EnsembleMinimum(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestMiner, *Ensemble) {
|
||||
// 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.
|
||||
func EnsembleMinimal(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestMiner, *Ensemble) {
|
||||
var (
|
||||
full TestFullNode
|
||||
miner TestMiner
|
||||
@ -11,7 +13,9 @@ func EnsembleMinimum(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestMiner,
|
||||
return &full, &miner, ensemble
|
||||
}
|
||||
|
||||
func EnsembleTwo(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestFullNode, *TestMiner, *Ensemble) {
|
||||
// EnsembleTwoOne creates and starts an ensemble with two full nodes and one miner.
|
||||
// It does not interconnect nodes nor does it begin mining.
|
||||
func EnsembleTwoOne(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestFullNode, *TestMiner, *Ensemble) {
|
||||
var (
|
||||
one, two TestFullNode
|
||||
miner TestMiner
|
||||
@ -19,3 +23,19 @@ func EnsembleTwo(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestFullNode, *
|
||||
ensemble := NewEnsemble(t).FullNode(&one, opts...).FullNode(&two, opts...).Miner(&miner, &one, opts...).Start()
|
||||
return &one, &two, &miner, ensemble
|
||||
}
|
||||
|
||||
// EnsembleOneTwo creates and starts an ensemble with one full node and two miners.
|
||||
// It does not interconnect nodes nor does it begin mining.
|
||||
func EnsembleOneTwo(t *testing.T, opts ...NodeOpt) (*TestFullNode, *TestMiner, *TestMiner, *Ensemble) {
|
||||
var (
|
||||
full TestFullNode
|
||||
one, two TestMiner
|
||||
)
|
||||
ensemble := NewEnsemble(t).
|
||||
FullNode(&full, opts...).
|
||||
Miner(&one, &full, opts...).
|
||||
Miner(&two, &full, opts...).
|
||||
Start()
|
||||
|
||||
return &full, &one, &two, ensemble
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user