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