2020-07-01 16:29:09 +00:00
|
|
|
package testkit
|
2020-06-30 22:02:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
2020-09-16 10:51:23 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-06-30 22:02:01 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/ipfs/go-cid"
|
2020-07-27 11:57:01 +00:00
|
|
|
|
|
|
|
tstats "github.com/filecoin-project/lotus/tools/stats"
|
2020-06-30 22:02:01 +00:00
|
|
|
)
|
|
|
|
|
2020-07-27 11:57:01 +00:00
|
|
|
func StartDeal(ctx context.Context, minerActorAddr address.Address, client api.FullNode, fcid cid.Cid, fastRetrieval bool) *cid.Cid {
|
2020-06-30 22:02:01 +00:00
|
|
|
addr, err := client.WalletDefaultAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deal, err := client.ClientStartDeal(ctx, &api.StartDealParams{
|
2020-07-30 14:22:43 +00:00
|
|
|
Data: &storagemarket.DataRef{
|
|
|
|
TransferType: storagemarket.TTGraphsync,
|
|
|
|
Root: fcid,
|
|
|
|
},
|
2020-06-30 22:02:01 +00:00
|
|
|
Wallet: addr,
|
|
|
|
Miner: minerActorAddr,
|
2020-10-11 10:38:59 +00:00
|
|
|
EpochPrice: types.NewInt(1000),
|
2020-07-30 14:22:43 +00:00
|
|
|
MinBlocksDuration: 640000,
|
2020-10-06 14:40:23 +00:00
|
|
|
DealStartEpoch: 200,
|
2020-07-27 11:57:01 +00:00
|
|
|
FastRetrieval: fastRetrieval,
|
2020-06-30 22:02:01 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return deal
|
|
|
|
}
|
|
|
|
|
2020-07-01 16:29:09 +00:00
|
|
|
func WaitDealSealed(t *TestEnvironment, ctx context.Context, client api.FullNode, deal *cid.Cid) {
|
2020-07-27 11:57:01 +00:00
|
|
|
height := 0
|
|
|
|
headlag := 3
|
|
|
|
|
|
|
|
cctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
tipsetsCh, err := tstats.GetTips(cctx, client, abi.ChainEpoch(height), headlag)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for tipset := range tipsetsCh {
|
|
|
|
t.RecordMessage("got tipset: height %d", tipset.Height())
|
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
di, err := client.ClientGetDealInfo(ctx, *deal)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
switch di.State {
|
|
|
|
case storagemarket.StorageDealProposalRejected:
|
|
|
|
panic("deal rejected")
|
|
|
|
case storagemarket.StorageDealFailing:
|
|
|
|
panic("deal failed")
|
|
|
|
case storagemarket.StorageDealError:
|
|
|
|
panic(fmt.Sprintf("deal errored %s", di.Message))
|
|
|
|
case storagemarket.StorageDealActive:
|
|
|
|
t.RecordMessage("completed deal: %s", di)
|
2020-07-27 11:57:01 +00:00
|
|
|
return
|
2020-06-30 22:02:01 +00:00
|
|
|
}
|
2020-07-27 11:57:01 +00:00
|
|
|
|
2020-06-30 22:02:01 +00:00
|
|
|
t.RecordMessage("deal state: %s", storagemarket.DealStates[di.State])
|
|
|
|
}
|
|
|
|
}
|