2021-05-18 20:32:10 +00:00
|
|
|
package itests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
2021-05-18 21:01:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2021-05-18 20:32:10 +00:00
|
|
|
bminer "github.com/filecoin-project/lotus/miner"
|
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPledgeSectors(t *testing.T) {
|
2021-05-18 21:01:10 +00:00
|
|
|
kit.QuietMiningLogs()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
t.Run("1", func(t *testing.T) {
|
2021-05-18 21:01:10 +00:00
|
|
|
runPledgeSectorTest(t, kit.MockSbBuilder, 50*time.Millisecond, 1)
|
2021-05-18 20:32:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("100", func(t *testing.T) {
|
2021-05-18 21:01:10 +00:00
|
|
|
runPledgeSectorTest(t, kit.MockSbBuilder, 50*time.Millisecond, 100)
|
2021-05-18 20:32:10 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("1000", func(t *testing.T) {
|
|
|
|
if testing.Short() { // takes ~16s
|
|
|
|
t.Skip("skipping test in short mode")
|
|
|
|
}
|
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
runPledgeSectorTest(t, kit.MockSbBuilder, 50*time.Millisecond, 1000)
|
2021-05-18 20:32:10 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
func runPledgeSectorTest(t *testing.T, b kit.APIBuilder, blocktime time.Duration, nSectors int) {
|
2021-05-18 20:32:10 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
n, sn := b(t, kit.OneFull, kit.OneMiner)
|
2021-05-18 20:32:10 +00:00
|
|
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
|
|
|
miner := sn[0]
|
|
|
|
|
|
|
|
addrinfo, err := client.NetAddrsListen(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
mine := int64(1)
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for atomic.LoadInt64(&mine) != 0 {
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
|
|
|
|
|
|
|
}}); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
kit.PledgeSectors(t, ctx, miner, nSectors, 0, nil)
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
atomic.StoreInt64(&mine, 0)
|
|
|
|
<-done
|
|
|
|
}
|