refactor: ccupgrade test

This commit is contained in:
Dirk McCormick 2021-06-14 11:50:40 +02:00
parent c27f3deadd
commit 803a3df6b4
2 changed files with 49 additions and 42 deletions

View File

@ -3,62 +3,67 @@ package itests
import (
"context"
"fmt"
"sync/atomic"
"testing"
"time"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/itests/kit2"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/impl"
)
func TestCCUpgrade(t *testing.T) {
kit.QuietMiningLogs()
kit2.QuietMiningLogs()
for _, height := range []abi.ChainEpoch{
-1, // before
162, // while sealing
530, // after upgrade deal
5000, // after
-1, // before
//162, // while sealing
//530, // after upgrade deal
//5000, // after
} {
height := height // make linters happy by copying
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()
n, sn := b(t, []kit.FullNodeOpts{kit.FullNodeWithLatestActorsAt(upgradeHeight)}, kit.OneMiner)
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]
blockTime := 5 * time.Millisecond
addrinfo, err := client.NetAddrsListen(ctx)
if err != nil {
t.Fatal(err)
}
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), kit2.LatestActorsAt(upgradeHeight))
ens.InterconnectAll().BeginMining(blockTime)
if err := miner.NetConnect(ctx, addrinfo); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)
//b := kit.MockMinerBuilder
//n, sn := b(t, []kit.FullNodeOpts{kit.FullNodeWithLatestActorsAt(upgradeHeight)}, kit.OneMiner)
//client := n[0].FullNode.(*impl.FullNodeAPI)
//miner := sn[0]
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)
}
}
}()
//addrinfo, err := client.NetAddrsListen(ctx)
//if err != nil {
// t.Fatal(err)
//}
//
//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)
if err != nil {
@ -68,7 +73,7 @@ func runTestCCUpgrade(t *testing.T, b kit.APIBuilder, blocktime time.Duration, u
CC := abi.SectorNumber(kit.GenesisPreseals + 1)
Upgraded := CC + 1
kit.PledgeSectors(t, ctx, miner, 1, 0, nil)
miner.PledgeSectors(ctx, 1, 0, nil)
sl, err := miner.SectorsList(ctx)
if err != nil {
@ -92,9 +97,9 @@ func runTestCCUpgrade(t *testing.T, b kit.APIBuilder, blocktime time.Duration, u
t.Fatal(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
@ -123,10 +128,6 @@ func runTestCCUpgrade(t *testing.T, b kit.APIBuilder, blocktime time.Duration, u
}
t.Log("waiting for sector to expire")
// 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
}

View File

@ -7,12 +7,12 @@ import (
"github.com/filecoin-project/lotus/node"
)
func LatestActorsAt(upgradeHeight abi.ChainEpoch) node.Option {
func LatestActorsAt(upgradeHeight abi.ChainEpoch) NodeOpt {
// Attention: Update this when introducing new actor versions or your tests will be sad
return NetworkUpgradeAt(network.Version13, upgradeHeight)
}
func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) node.Option {
func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) NodeOpt {
fullSchedule := stmgr.UpgradeSchedule{{
// prepare for upgrade.
Network: network.Version9,
@ -45,7 +45,13 @@ func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) nod
schedule[len(schedule)-1].Height = upgradeHeight
}
return node.Override(new(stmgr.UpgradeSchedule), schedule)
return func(opts *nodeOpts) error {
opts.extraNodeOpts = []node.Option{
node.Override(new(stmgr.UpgradeSchedule), schedule),
}
return nil
}
//return node.Override(new(stmgr.UpgradeSchedule), schedule)
}
func SDRUpgradeAt(calico, persian abi.ChainEpoch) node.Option {