2021-12-10 15:08:25 +00:00
//stm: #unit
2021-08-18 10:43:44 +00:00
package sealing_test
import (
"bytes"
"context"
"testing"
"github.com/golang/mock/gomock"
"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/exitcode"
2022-06-14 15:00:51 +00:00
"github.com/filecoin-project/go-state-types/network"
2022-06-15 10:06:22 +00:00
"github.com/filecoin-project/go-statemachine"
2022-06-14 15:00:51 +00:00
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
2021-08-18 10:43:44 +00:00
api2 "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
2022-06-16 11:15:49 +00:00
"github.com/filecoin-project/lotus/chain/types"
2022-06-14 18:31:17 +00:00
pipeline "github.com/filecoin-project/lotus/storage/pipeline"
2022-06-15 10:06:22 +00:00
"github.com/filecoin-project/lotus/storage/pipeline/mocks"
2021-08-18 10:43:44 +00:00
)
func TestStateRecoverDealIDs ( t * testing . T ) {
2021-12-08 17:11:19 +00:00
t . Skip ( "Bring this back when we can correctly mock a state machine context: Issue #7867" )
2021-08-18 10:43:44 +00:00
mockCtrl := gomock . NewController ( t )
defer mockCtrl . Finish ( )
ctx := context . Background ( )
2022-06-14 18:03:38 +00:00
api := mocks . NewMockSealingAPI ( mockCtrl )
2021-08-18 10:43:44 +00:00
2022-06-14 18:31:17 +00:00
fakeSealing := & pipeline . Sealing {
2021-08-18 10:43:44 +00:00
Api : api ,
2022-06-14 18:31:17 +00:00
DealInfo : & pipeline . CurrentDealInfoManager { CDAPI : api } ,
2021-08-18 10:43:44 +00:00
}
2022-06-14 18:03:38 +00:00
sctx := mocks . NewMockContext ( mockCtrl )
2021-08-18 10:43:44 +00:00
sctx . EXPECT ( ) . Context ( ) . AnyTimes ( ) . Return ( ctx )
2021-12-08 17:11:19 +00:00
api . EXPECT ( ) . ChainHead ( ctx ) . Times ( 2 ) . Return ( nil , abi . ChainEpoch ( 10 ) , nil )
2021-08-18 10:43:44 +00:00
var dealId abi . DealID = 12
dealProposal := market . DealProposal {
PieceCID : idCid ( "newPieceCID" ) ,
}
2021-12-10 15:08:25 +00:00
//stm: @CHAIN_STATE_MARKET_STORAGE_DEAL_001, @CHAIN_STATE_NETWORK_VERSION_001
2022-06-16 12:00:37 +00:00
api . EXPECT ( ) . StateMarketStorageDeal ( ctx , dealId , nil ) . Return ( & api2 . MarketDeal { Proposal : dealProposal } , nil )
2021-08-18 10:43:44 +00:00
pc := idCid ( "publishCID" )
// expect GetCurrentDealInfo
{
2022-06-16 10:47:19 +00:00
api . EXPECT ( ) . StateSearchMsg ( ctx , gomock . Any ( ) , pc , gomock . Any ( ) , gomock . Any ( ) ) . Return ( & api2 . MsgLookup {
Receipt : types . MessageReceipt {
2021-08-18 10:43:44 +00:00
ExitCode : exitcode . Ok ,
2021-09-29 20:16:19 +00:00
Return : cborRet ( & market0 . PublishStorageDealsReturn {
2021-08-18 10:43:44 +00:00
IDs : [ ] abi . DealID { dealId } ,
} ) ,
} ,
} , nil )
2021-09-30 00:44:27 +00:00
api . EXPECT ( ) . StateNetworkVersion ( ctx , nil ) . Return ( network . Version0 , nil )
2021-08-18 10:43:44 +00:00
api . EXPECT ( ) . StateMarketStorageDeal ( ctx , dealId , nil ) . Return ( & api2 . MarketDeal {
Proposal : dealProposal ,
} , nil )
}
2022-06-14 18:31:17 +00:00
sctx . EXPECT ( ) . Send ( pipeline . SectorRemove { } ) . Return ( nil )
2021-08-18 10:43:44 +00:00
2021-12-08 17:11:19 +00:00
// TODO sctx should satisfy an interface so it can be useable for mocking. This will fail because we are passing in an empty context now to get this to build.
// https://github.com/filecoin-project/lotus/issues/7867
2022-06-14 18:31:17 +00:00
err := fakeSealing . HandleRecoverDealIDs ( statemachine . Context { } , pipeline . SectorInfo {
Pieces : [ ] pipeline . Piece {
2021-08-18 10:43:44 +00:00
{
DealInfo : & api2 . PieceDealInfo {
DealID : dealId ,
PublishCid : & pc ,
} ,
Piece : abi . PieceInfo {
PieceCID : idCid ( "oldPieceCID" ) ,
} ,
} ,
} ,
} )
require . NoError ( t , err )
}
func idCid ( str string ) cid . Cid {
builder := cid . V1Builder { Codec : cid . Raw , MhType : mh . IDENTITY }
c , err := builder . Sum ( [ ] byte ( str ) )
if err != nil {
panic ( err )
}
return c
}
func cborRet ( v cbor . Marshaler ) [ ] byte {
var buf bytes . Buffer
if err := v . MarshalCBOR ( & buf ) ; err != nil {
panic ( err )
}
return buf . Bytes ( )
}