Rewire itest's StartDeal to take the full API struct
This allows one to use the harness for much more versatile deal conditions
This commit is contained in:
parent
f09c4733ad
commit
2edf7fd25b
@ -90,7 +90,11 @@ func TestBatchDealInput(t *testing.T) {
|
||||
res, _, _, err := kit.CreateImportFile(ctx, client, rseed, piece)
|
||||
require.NoError(t, err)
|
||||
|
||||
deal := dh.StartDeal(ctx, res.Root, false, dealStartEpoch)
|
||||
dp := dh.DefaultStartDealParams()
|
||||
dp.Data.Root = res.Root
|
||||
dp.DealStartEpoch = dealStartEpoch
|
||||
|
||||
deal := dh.StartDeal(ctx, dp)
|
||||
dh.WaitDealSealed(ctx, deal, false, true, checkNoPadding)
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,6 @@ import (
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/itests/kit"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@ -31,7 +29,7 @@ func TestOfflineDealFlow(t *testing.T) {
|
||||
dh := kit.NewDealHarness(t, client, miner, miner)
|
||||
|
||||
// Create a random file and import on the client.
|
||||
res, inFile := client.CreateImportFile(ctx, 1, 0)
|
||||
res, inFile := client.CreateImportFile(ctx, 1, 200)
|
||||
|
||||
// Get the piece size and commP
|
||||
rootCid := res.Root
|
||||
@ -39,31 +37,18 @@ func TestOfflineDealFlow(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
t.Log("FILE CID:", rootCid)
|
||||
|
||||
// Create a storage deal with the miner
|
||||
maddr, err := miner.ActorAddress(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
addr, err := client.WalletDefaultAddress(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Manual storage deal (offline deal)
|
||||
dataRef := &storagemarket.DataRef{
|
||||
dp := dh.DefaultStartDealParams()
|
||||
dp.DealStartEpoch = startEpoch
|
||||
dp.FastRetrieval = fastRet
|
||||
// Replace with params for manual storage deal (offline deal)
|
||||
dp.Data = &storagemarket.DataRef{
|
||||
TransferType: storagemarket.TTManual,
|
||||
Root: rootCid,
|
||||
PieceCid: &pieceInfo.PieceCID,
|
||||
PieceSize: pieceInfo.PieceSize.Unpadded(),
|
||||
}
|
||||
|
||||
proposalCid, err := client.ClientStartDeal(ctx, &api.StartDealParams{
|
||||
Data: dataRef,
|
||||
Wallet: addr,
|
||||
Miner: maddr,
|
||||
EpochPrice: types.NewInt(1000000),
|
||||
DealStartEpoch: startEpoch,
|
||||
MinBlocksDuration: uint64(build.MinDealDuration),
|
||||
FastRetrieval: fastRet,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
proposalCid := dh.StartDeal(ctx, dp)
|
||||
|
||||
// Wait for the deal to reach StorageDealCheckForAcceptance on the client
|
||||
cd, err := client.ClientGetDealInfo(ctx, *proposalCid)
|
||||
|
@ -50,7 +50,9 @@ func TestFirstDealEnablesMining(t *testing.T) {
|
||||
}()
|
||||
|
||||
// now perform the deal.
|
||||
deal := dh.StartDeal(ctx, ref.Root, false, 0)
|
||||
dp := dh.DefaultStartDealParams()
|
||||
dp.Data.Root = ref.Root
|
||||
deal := dh.StartDeal(ctx, dp)
|
||||
|
||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||
time.Sleep(time.Second)
|
||||
|
@ -69,7 +69,10 @@ func TestPublishDealsBatching(t *testing.T) {
|
||||
upds, err := client.ClientGetDealUpdates(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
dh.StartDeal(ctx, res.Root, false, startEpoch)
|
||||
dp := dh.DefaultStartDealParams()
|
||||
dp.Data.Root = res.Root
|
||||
dp.DealStartEpoch = startEpoch
|
||||
dh.StartDeal(ctx, dp)
|
||||
|
||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||
time.Sleep(time.Second)
|
||||
|
@ -88,7 +88,11 @@ func (dh *DealHarness) MakeOnlineDeal(ctx context.Context, params MakeFullDealPa
|
||||
dh.t.Logf("deal-making continuing; current height is %d", ts.Height())
|
||||
}
|
||||
|
||||
deal = dh.StartDeal(ctx, res.Root, params.FastRet, params.StartEpoch)
|
||||
dp := dh.DefaultStartDealParams()
|
||||
dp.Data.Root = res.Root
|
||||
dp.DealStartEpoch = params.StartEpoch
|
||||
dp.FastRetrieval = params.FastRet
|
||||
deal = dh.StartDeal(ctx, dp)
|
||||
|
||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||
time.Sleep(time.Second)
|
||||
@ -97,29 +101,28 @@ func (dh *DealHarness) MakeOnlineDeal(ctx context.Context, params MakeFullDealPa
|
||||
return deal, res, path
|
||||
}
|
||||
|
||||
// StartDeal starts a storage deal between the client and the miner.
|
||||
func (dh *DealHarness) StartDeal(ctx context.Context, fcid cid.Cid, fastRet bool, startEpoch abi.ChainEpoch) *cid.Cid {
|
||||
maddr, err := dh.main.ActorAddress(ctx)
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
addr, err := dh.client.WalletDefaultAddress(ctx)
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
deal, err := dh.client.ClientStartDeal(ctx, &api.StartDealParams{
|
||||
Data: &storagemarket.DataRef{
|
||||
TransferType: storagemarket.TTGraphsync,
|
||||
Root: fcid,
|
||||
},
|
||||
Wallet: addr,
|
||||
Miner: maddr,
|
||||
func (dh *DealHarness) DefaultStartDealParams() api.StartDealParams {
|
||||
dp := api.StartDealParams{
|
||||
Data: &storagemarket.DataRef{TransferType: storagemarket.TTGraphsync},
|
||||
EpochPrice: types.NewInt(1000000),
|
||||
DealStartEpoch: startEpoch,
|
||||
MinBlocksDuration: uint64(build.MinDealDuration),
|
||||
FastRetrieval: fastRet,
|
||||
})
|
||||
}
|
||||
|
||||
var err error
|
||||
dp.Miner, err = dh.main.ActorAddress(context.Background())
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
return deal
|
||||
dp.Wallet, err = dh.client.WalletDefaultAddress(context.Background())
|
||||
require.NoError(dh.t, err)
|
||||
|
||||
return dp
|
||||
}
|
||||
|
||||
// StartDeal starts a storage deal between the client and the miner.
|
||||
func (dh *DealHarness) StartDeal(ctx context.Context, dealParams api.StartDealParams) *cid.Cid {
|
||||
dealProposalCid, err := dh.client.ClientStartDeal(ctx, &dealParams)
|
||||
require.NoError(dh.t, err)
|
||||
return dealProposalCid
|
||||
}
|
||||
|
||||
// WaitDealSealed waits until the deal is sealed.
|
||||
|
Loading…
Reference in New Issue
Block a user