Merge branch 'raulk/itests-refactor-kit' into refactor/itest-wdpost
This commit is contained in:
commit
21848054d7
@ -239,23 +239,10 @@ func TestFirstDealEnablesMining(t *testing.T) {
|
|||||||
// once the provider has mined a block, thanks to the power acquired from the deal,
|
// once the provider has mined a block, thanks to the power acquired from the deal,
|
||||||
// we pass the test.
|
// we pass the test.
|
||||||
providerMined := make(chan struct{})
|
providerMined := make(chan struct{})
|
||||||
heads, err := client.ChainNotify(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for chg := range heads {
|
_ = client.WaitTillChain(ctx, kit2.BlockMinedBy(provider.ActorAddr))
|
||||||
for _, c := range chg {
|
|
||||||
if c.Type != "apply" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, b := range c.Val.Blocks() {
|
|
||||||
if b.Miner == provider.ActorAddr {
|
|
||||||
close(providerMined)
|
close(providerMined)
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// now perform the deal.
|
// now perform the deal.
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package kit2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func WaitTillChainHeight(ctx context.Context, t *testing.T, node *TestFullNode, blocktime time.Duration, height int) abi.ChainEpoch {
|
|
||||||
for {
|
|
||||||
h, err := node.ChainHead(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
if h.Height() > abi.ChainEpoch(height) {
|
|
||||||
return h.Height()
|
|
||||||
}
|
|
||||||
time.Sleep(blocktime)
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,8 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/api/v1api"
|
"github.com/filecoin-project/lotus/api/v1api"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -33,3 +36,50 @@ func (f *TestFullNode) CreateImportFile(ctx context.Context, rseed int, size int
|
|||||||
require.NoError(f.t, err)
|
require.NoError(f.t, err)
|
||||||
return res, path
|
return res, path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitTillChain waits until a specified chain condition is met. It returns
|
||||||
|
// the first tipset where the condition is met.
|
||||||
|
func (f *TestFullNode) WaitTillChain(ctx context.Context, pred ChainPredicate) *types.TipSet {
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
heads, err := f.ChainNotify(ctx)
|
||||||
|
require.NoError(f.t, err)
|
||||||
|
|
||||||
|
for chg := range heads {
|
||||||
|
for _, c := range chg {
|
||||||
|
if c.Type != "apply" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ts := c.Val; pred(ts) {
|
||||||
|
return ts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.Fail(f.t, "chain condition not met")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChainPredicate encapsulates a chain condition.
|
||||||
|
type ChainPredicate func(set *types.TipSet) bool
|
||||||
|
|
||||||
|
// HeightAtLeast returns a ChainPredicate that is satisfied when the chain
|
||||||
|
// height is equal or higher to the target.
|
||||||
|
func HeightAtLeast(target abi.ChainEpoch) ChainPredicate {
|
||||||
|
return func(ts *types.TipSet) bool {
|
||||||
|
return ts.Height() >= target
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlockMinedBy returns a ChainPredicate that is satisfied when we observe the
|
||||||
|
// first block mined by the specified miner.
|
||||||
|
func BlockMinedBy(miner address.Address) ChainPredicate {
|
||||||
|
return func(ts *types.TipSet) bool {
|
||||||
|
for _, b := range ts.Blocks() {
|
||||||
|
if b.Miner == miner {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -58,7 +58,7 @@ func TestPledgeBatching(t *testing.T) {
|
|||||||
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
|
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
|
||||||
ens.InterconnectAll().BeginMining(blockTime)
|
ens.InterconnectAll().BeginMining(blockTime)
|
||||||
|
|
||||||
kit2.WaitTillChainHeight(ctx, t, client, blockTime, 10)
|
client.WaitTillChain(ctx, kit2.HeightAtLeast(10))
|
||||||
|
|
||||||
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ func TestPledgeBeforeNv13(t *testing.T) {
|
|||||||
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
|
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
|
||||||
ens.InterconnectAll().BeginMining(blocktime)
|
ens.InterconnectAll().BeginMining(blocktime)
|
||||||
|
|
||||||
kit2.WaitTillChainHeight(ctx, t, client, blocktime, 10)
|
client.WaitTillChain(ctx, kit2.HeightAtLeast(10))
|
||||||
|
|
||||||
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ func TestTerminate(t *testing.T) {
|
|||||||
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
|
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
|
||||||
t.Logf("End for head.Height > %d", waitUntil)
|
t.Logf("End for head.Height > %d", waitUntil)
|
||||||
|
|
||||||
height := kit2.WaitTillChainHeight(ctx, t, client, blocktime, int(waitUntil))
|
ts := client.WaitTillChain(ctx, kit2.HeightAtLeast(waitUntil))
|
||||||
t.Logf("Now head.Height = %d", height)
|
t.Logf("Now head.Height = %d", ts.Height())
|
||||||
}
|
}
|
||||||
|
|
||||||
nSectors++
|
nSectors++
|
||||||
@ -140,8 +140,8 @@ loop:
|
|||||||
|
|
||||||
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
|
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
|
||||||
t.Logf("End for head.Height > %d", waitUntil)
|
t.Logf("End for head.Height > %d", waitUntil)
|
||||||
height := kit2.WaitTillChainHeight(ctx, t, client, blocktime, int(waitUntil))
|
ts := client.WaitTillChain(ctx, kit2.HeightAtLeast(waitUntil))
|
||||||
t.Logf("Now head.Height = %d", height)
|
t.Logf("Now head.Height = %d", ts.Height())
|
||||||
|
|
||||||
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user