2020-07-01 16:29:09 +00:00
|
|
|
package testkit
|
2020-06-30 22:02:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
)
|
|
|
|
|
2020-07-01 16:29:09 +00:00
|
|
|
func StartDeal(ctx context.Context, minerActorAddr address.Address, client api.FullNode, fcid cid.Cid) *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{
|
|
|
|
Data: &storagemarket.DataRef{Root: fcid},
|
|
|
|
Wallet: addr,
|
|
|
|
Miner: minerActorAddr,
|
|
|
|
EpochPrice: types.NewInt(1000000),
|
|
|
|
MinBlocksDuration: 1000,
|
|
|
|
})
|
|
|
|
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-06-30 22:02:01 +00:00
|
|
|
loop:
|
|
|
|
for {
|
|
|
|
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)
|
|
|
|
break loop
|
|
|
|
}
|
|
|
|
t.RecordMessage("deal state: %s", storagemarket.DealStates[di.State])
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
}
|