Merge pull request #6470 from filecoin-project/refactor/ccupgrade-test
This commit is contained in:
commit
30148477a7
@ -3,21 +3,19 @@ package itests
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync/atomic"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/itests/kit"
|
"github.com/filecoin-project/lotus/itests/kit2"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/node/impl"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCCUpgrade(t *testing.T) {
|
func TestCCUpgrade(t *testing.T) {
|
||||||
kit.QuietMiningLogs()
|
kit2.QuietMiningLogs()
|
||||||
|
|
||||||
for _, height := range []abi.ChainEpoch{
|
for _, height := range []abi.ChainEpoch{
|
||||||
-1, // before
|
-1, // before
|
||||||
@ -27,60 +25,33 @@ func TestCCUpgrade(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
height := height // make linters happy by copying
|
height := height // make linters happy by copying
|
||||||
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
|
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
|
||||||
runTestCCUpgrade(t, kit.MockMinerBuilder, 5*time.Millisecond, height)
|
runTestCCUpgrade(t, height)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTestCCUpgrade(t *testing.T, b kit.APIBuilder, blocktime time.Duration, upgradeHeight abi.ChainEpoch) {
|
func runTestCCUpgrade(t *testing.T, upgradeHeight abi.ChainEpoch) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
n, sn := b(t, []kit.FullNodeOpts{kit.FullNodeWithLatestActorsAt(upgradeHeight)}, kit.OneMiner)
|
blockTime := 5 * time.Millisecond
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
|
||||||
miner := sn[0]
|
|
||||||
|
|
||||||
addrinfo, err := client.NetAddrsListen(ctx)
|
opts := kit2.ConstructorOpts(kit2.LatestActorsAt(upgradeHeight))
|
||||||
if err != nil {
|
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
|
||||||
t.Fatal(err)
|
ens.InterconnectAll().BeginMining(blockTime)
|
||||||
}
|
|
||||||
|
|
||||||
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
mine := int64(1)
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer close(done)
|
|
||||||
for atomic.LoadInt64(&mine) == 1 {
|
|
||||||
time.Sleep(blocktime)
|
|
||||||
if err := sn[0].MineOne(ctx, kit.MineNext); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
maddr, err := miner.ActorAddress(ctx)
|
maddr, err := miner.ActorAddress(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
CC := abi.SectorNumber(kit.GenesisPreseals + 1)
|
CC := abi.SectorNumber(kit2.DefaultPresealsPerBootstrapMiner + 1)
|
||||||
Upgraded := CC + 1
|
Upgraded := CC + 1
|
||||||
|
|
||||||
kit.PledgeSectors(t, ctx, miner, 1, 0, nil)
|
miner.PledgeSectors(ctx, 1, 0, nil)
|
||||||
|
|
||||||
sl, err := miner.SectorsList(ctx)
|
sl, err := miner.SectorsList(ctx)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
require.Len(t, sl, 1, "expected 1 sector")
|
||||||
}
|
require.Equal(t, CC, sl[0], "unexpected sector number")
|
||||||
if len(sl) != 1 {
|
|
||||||
t.Fatal("expected 1 sector")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sl[0] != CC {
|
|
||||||
t.Fatal("bad")
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
si, err := client.StateSectorGetInfo(ctx, maddr, CC, types.EmptyTSK)
|
si, err := client.StateSectorGetInfo(ctx, maddr, CC, types.EmptyTSK)
|
||||||
@ -88,13 +59,12 @@ func runTestCCUpgrade(t *testing.T, b kit.APIBuilder, blocktime time.Duration, u
|
|||||||
require.Less(t, 50000, int(si.Expiration))
|
require.Less(t, 50000, int(si.Expiration))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := miner.SectorMarkForUpgrade(ctx, sl[0]); err != nil {
|
err = miner.SectorMarkForUpgrade(ctx, sl[0])
|
||||||
t.Fatal(err)
|
require.NoError(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
dh := kit.NewDealHarness(t, client, miner)
|
dh := kit2.NewDealHarness(t, client, miner)
|
||||||
|
|
||||||
dh.MakeFullDeal(context.Background(), 6, false, false, 0)
|
dh.MakeOnlineDeal(context.Background(), 6, false, 0)
|
||||||
|
|
||||||
// Validate upgrade
|
// Validate upgrade
|
||||||
|
|
||||||
@ -123,10 +93,6 @@ func runTestCCUpgrade(t *testing.T, b kit.APIBuilder, blocktime time.Duration, u
|
|||||||
}
|
}
|
||||||
t.Log("waiting for sector to expire")
|
t.Log("waiting for sector to expire")
|
||||||
// wait one deadline per loop.
|
// wait one deadline per loop.
|
||||||
time.Sleep(time.Duration(dlInfo.WPoStChallengeWindow) * blocktime)
|
time.Sleep(time.Duration(dlInfo.WPoStChallengeWindow) * blockTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("shutting down mining")
|
|
||||||
atomic.AddInt64(&mine, -1)
|
|
||||||
<-done
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user