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)
|
res, _, _, err := kit.CreateImportFile(ctx, client, rseed, piece)
|
||||||
require.NoError(t, err)
|
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)
|
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-fil-markets/storagemarket"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"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/filecoin-project/lotus/itests/kit"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -31,7 +29,7 @@ func TestOfflineDealFlow(t *testing.T) {
|
|||||||
dh := kit.NewDealHarness(t, client, miner, miner)
|
dh := kit.NewDealHarness(t, client, miner, miner)
|
||||||
|
|
||||||
// Create a random file and import on the client.
|
// 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
|
// Get the piece size and commP
|
||||||
rootCid := res.Root
|
rootCid := res.Root
|
||||||
@ -39,31 +37,18 @@ func TestOfflineDealFlow(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Log("FILE CID:", rootCid)
|
t.Log("FILE CID:", rootCid)
|
||||||
|
|
||||||
// Create a storage deal with the miner
|
dp := dh.DefaultStartDealParams()
|
||||||
maddr, err := miner.ActorAddress(ctx)
|
dp.DealStartEpoch = startEpoch
|
||||||
require.NoError(t, err)
|
dp.FastRetrieval = fastRet
|
||||||
|
// Replace with params for manual storage deal (offline deal)
|
||||||
addr, err := client.WalletDefaultAddress(ctx)
|
dp.Data = &storagemarket.DataRef{
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Manual storage deal (offline deal)
|
|
||||||
dataRef := &storagemarket.DataRef{
|
|
||||||
TransferType: storagemarket.TTManual,
|
TransferType: storagemarket.TTManual,
|
||||||
Root: rootCid,
|
Root: rootCid,
|
||||||
PieceCid: &pieceInfo.PieceCID,
|
PieceCid: &pieceInfo.PieceCID,
|
||||||
PieceSize: pieceInfo.PieceSize.Unpadded(),
|
PieceSize: pieceInfo.PieceSize.Unpadded(),
|
||||||
}
|
}
|
||||||
|
|
||||||
proposalCid, err := client.ClientStartDeal(ctx, &api.StartDealParams{
|
proposalCid := dh.StartDeal(ctx, dp)
|
||||||
Data: dataRef,
|
|
||||||
Wallet: addr,
|
|
||||||
Miner: maddr,
|
|
||||||
EpochPrice: types.NewInt(1000000),
|
|
||||||
DealStartEpoch: startEpoch,
|
|
||||||
MinBlocksDuration: uint64(build.MinDealDuration),
|
|
||||||
FastRetrieval: fastRet,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Wait for the deal to reach StorageDealCheckForAcceptance on the client
|
// Wait for the deal to reach StorageDealCheckForAcceptance on the client
|
||||||
cd, err := client.ClientGetDealInfo(ctx, *proposalCid)
|
cd, err := client.ClientGetDealInfo(ctx, *proposalCid)
|
||||||
|
@ -50,7 +50,9 @@ func TestFirstDealEnablesMining(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// now perform the deal.
|
// 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
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
@ -69,7 +69,10 @@ func TestPublishDealsBatching(t *testing.T) {
|
|||||||
upds, err := client.ClientGetDealUpdates(ctx)
|
upds, err := client.ClientGetDealUpdates(ctx)
|
||||||
require.NoError(t, err)
|
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
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
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())
|
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
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
@ -97,29 +101,28 @@ func (dh *DealHarness) MakeOnlineDeal(ctx context.Context, params MakeFullDealPa
|
|||||||
return deal, res, path
|
return deal, res, path
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartDeal starts a storage deal between the client and the miner.
|
func (dh *DealHarness) DefaultStartDealParams() api.StartDealParams {
|
||||||
func (dh *DealHarness) StartDeal(ctx context.Context, fcid cid.Cid, fastRet bool, startEpoch abi.ChainEpoch) *cid.Cid {
|
dp := api.StartDealParams{
|
||||||
maddr, err := dh.main.ActorAddress(ctx)
|
Data: &storagemarket.DataRef{TransferType: storagemarket.TTGraphsync},
|
||||||
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,
|
|
||||||
EpochPrice: types.NewInt(1000000),
|
EpochPrice: types.NewInt(1000000),
|
||||||
DealStartEpoch: startEpoch,
|
|
||||||
MinBlocksDuration: uint64(build.MinDealDuration),
|
MinBlocksDuration: uint64(build.MinDealDuration),
|
||||||
FastRetrieval: fastRet,
|
}
|
||||||
})
|
|
||||||
|
var err error
|
||||||
|
dp.Miner, err = dh.main.ActorAddress(context.Background())
|
||||||
require.NoError(dh.t, err)
|
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.
|
// WaitDealSealed waits until the deal is sealed.
|
||||||
|
Loading…
Reference in New Issue
Block a user