Fix up tests
This commit is contained in:
parent
d540f7af72
commit
563dc8e59a
@ -205,7 +205,6 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch av {
|
||||
|
||||
case actors.Version0:
|
||||
|
@ -2,6 +2,7 @@ package market
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
@ -247,6 +248,7 @@ type publishStorageDealsReturn7 struct {
|
||||
func (r *publishStorageDealsReturn7) IsDealValid(index uint64) (bool, int, error) {
|
||||
|
||||
set, err := r.ValidDeals.IsSet(index)
|
||||
fmt.Printf("set: %t\n", set)
|
||||
if err != nil || !set {
|
||||
return false, -1, err
|
||||
}
|
||||
@ -263,6 +265,7 @@ func (r *publishStorageDealsReturn7) IsDealValid(index uint64) (bool, int, error
|
||||
if err != nil {
|
||||
return false, -1, err
|
||||
}
|
||||
fmt.Printf("outIdx: %t\n")
|
||||
return set, int(outIdx), nil
|
||||
|
||||
}
|
||||
|
8
extern/storage-sealing/currentdealinfo.go
vendored
8
extern/storage-sealing/currentdealinfo.go
vendored
@ -3,6 +3,7 @@ package sealing
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
|
||||
@ -84,6 +85,7 @@ func (mgr *CurrentDealInfoManager) dealIDFromPublishDealsMsg(ctx context.Context
|
||||
if err != nil {
|
||||
return dealID, nil, xerrors.Errorf("getting network version: %w", err)
|
||||
}
|
||||
fmt.Printf("nv: %d\n", nv)
|
||||
|
||||
retval, err := market.DecodePublishStorageDealsReturn(lookup.Receipt.Return, nv)
|
||||
if err != nil {
|
||||
@ -94,6 +96,7 @@ func (mgr *CurrentDealInfoManager) dealIDFromPublishDealsMsg(ctx context.Context
|
||||
if err != nil {
|
||||
return dealID, nil, xerrors.Errorf("looking for publish deal message %s: getting dealIDs: %w", publishCid, err)
|
||||
}
|
||||
fmt.Printf("unserialized deal ids: %v\n", dealIDs)
|
||||
|
||||
// TODO: Can we delete this? We're well past the point when we first introduced the proposals into sealing deal info
|
||||
// Previously, publish deals messages contained a single deal, and the
|
||||
@ -158,6 +161,11 @@ func (mgr *CurrentDealInfoManager) dealIDFromPublishDealsMsg(ctx context.Context
|
||||
return dealID, nil, xerrors.New("deal was invalid at publication")
|
||||
}
|
||||
|
||||
// final check against for invalid return value output
|
||||
// should not be reachable from onchain output, only pathological test cases
|
||||
if outIdx >= len(dealIDs) {
|
||||
return dealID, nil, xerrors.Errorf("invalid publish storage deals ret marking %d as valid while only returning %d valid deals in publish deal message %s", outIdx, len(dealIDs), publishCid)
|
||||
}
|
||||
return dealIDs[outIdx], lookup.TipSetTok, nil
|
||||
}
|
||||
|
||||
|
94
extern/storage-sealing/currentdealinfo_test.go
vendored
94
extern/storage-sealing/currentdealinfo_test.go
vendored
@ -8,9 +8,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-bitfield"
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
|
||||
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/xerrors"
|
||||
@ -36,6 +38,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
dummyCid, _ := cid.Parse("bafkqaaa")
|
||||
dummyCid2, _ := cid.Parse("bafkqaab")
|
||||
zeroDealID := abi.DealID(0)
|
||||
anotherDealID := abi.DealID(8)
|
||||
earlierDealID := abi.DealID(9)
|
||||
successDealID := abi.DealID(10)
|
||||
proposal := market.DealProposal{
|
||||
@ -58,6 +61,16 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
ClientCollateral: abi.NewTokenAmount(1),
|
||||
Label: "other",
|
||||
}
|
||||
anotherProposal := market.DealProposal{
|
||||
PieceCID: dummyCid2,
|
||||
PieceSize: abi.PaddedPieceSize(100),
|
||||
Client: tutils.NewActorAddr(t, "client"),
|
||||
Provider: tutils.NewActorAddr(t, "provider"),
|
||||
StoragePricePerEpoch: abi.NewTokenAmount(1),
|
||||
ProviderCollateral: abi.NewTokenAmount(1),
|
||||
ClientCollateral: abi.NewTokenAmount(1),
|
||||
Label: "another",
|
||||
}
|
||||
successDeal := &api.MarketDeal{
|
||||
Proposal: proposal,
|
||||
State: market.DealState{
|
||||
@ -72,6 +85,13 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
LastUpdatedEpoch: 2,
|
||||
},
|
||||
}
|
||||
anotherDeal := &api.MarketDeal{
|
||||
Proposal: anotherProposal,
|
||||
State: market.DealState{
|
||||
SectorStartEpoch: 1,
|
||||
LastUpdatedEpoch: 2,
|
||||
},
|
||||
}
|
||||
|
||||
type testCaseData struct {
|
||||
searchMessageLookup *MsgLookup
|
||||
@ -82,6 +102,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
expectedDealID abi.DealID
|
||||
expectedMarketDeal *api.MarketDeal
|
||||
expectedError error
|
||||
networkVersion network.Version
|
||||
}
|
||||
testCases := map[string]testCaseData{
|
||||
"deal lookup succeeds": {
|
||||
@ -89,7 +110,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturnBytes(t, []abi.DealID{successDealID}),
|
||||
Return: makePublishDealsReturnBytesOldVersion(t, []abi.DealID{successDealID}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
@ -104,7 +125,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturnBytes(t, []abi.DealID{earlierDealID, successDealID}),
|
||||
Return: makePublishDealsReturnBytesOldVersion(t, []abi.DealID{earlierDealID, successDealID}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
@ -120,7 +141,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturnBytes(t, []abi.DealID{earlierDealID}),
|
||||
Return: makePublishDealsReturnBytesOldVersion(t, []abi.DealID{earlierDealID}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
@ -130,12 +151,12 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
expectedDealID: zeroDealID,
|
||||
expectedError: xerrors.Errorf("could not find deal in publish deals message %s", dummyCid),
|
||||
},
|
||||
"deal lookup fails mismatch count of deals and return values": {
|
||||
"deal lookup handles invalid actor output with mismatched count of deals and return values": {
|
||||
publishCid: dummyCid,
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturnBytes(t, []abi.DealID{earlierDealID}),
|
||||
Return: makePublishDealsReturnBytesOldVersion(t, []abi.DealID{earlierDealID}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
@ -144,14 +165,52 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
},
|
||||
targetProposal: &proposal,
|
||||
expectedDealID: zeroDealID,
|
||||
expectedError: xerrors.Errorf("deal index 1 out of bounds of deals (len 1) in publish deals message %s", dummyCid),
|
||||
expectedError: xerrors.Errorf("invalid publish storage deals ret marking 1 as valid while only returning 1 valid deals in publish deal message %s", dummyCid),
|
||||
},
|
||||
|
||||
"deal lookup fails when deal was not valid and index exceeds output array": {
|
||||
publishCid: dummyCid,
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturn(t, []abi.DealID{earlierDealID}, []uint64{0}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
earlierDealID: earlierDeal,
|
||||
successDealID: successDeal,
|
||||
},
|
||||
targetProposal: &proposal,
|
||||
expectedDealID: zeroDealID,
|
||||
expectedError: xerrors.Errorf("deal was invalid at publication"),
|
||||
networkVersion: network.Version14,
|
||||
},
|
||||
|
||||
"deal lookup succeeds when theres a separate deal failure": {
|
||||
publishCid: dummyCid,
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturn(t, []abi.DealID{anotherDealID, successDealID}, []uint64{0, 2}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
earlierDealID: earlierDeal,
|
||||
successDealID: successDeal,
|
||||
anotherDealID: anotherDeal,
|
||||
},
|
||||
targetProposal: &proposal,
|
||||
expectedDealID: successDealID,
|
||||
expectedMarketDeal: successDeal,
|
||||
networkVersion: network.Version14,
|
||||
},
|
||||
|
||||
"deal lookup succeeds, target proposal nil, single deal in message": {
|
||||
publishCid: dummyCid,
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturnBytes(t, []abi.DealID{successDealID}),
|
||||
Return: makePublishDealsReturnBytesOldVersion(t, []abi.DealID{successDealID}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
@ -166,7 +225,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
searchMessageLookup: &MsgLookup{
|
||||
Receipt: MessageReceipt{
|
||||
ExitCode: exitcode.Ok,
|
||||
Return: makePublishDealsReturnBytes(t, []abi.DealID{earlierDealID, successDealID}),
|
||||
Return: makePublishDealsReturnBytesOldVersion(t, []abi.DealID{earlierDealID, successDealID}),
|
||||
},
|
||||
},
|
||||
marketDeals: map[abi.DealID]*api.MarketDeal{
|
||||
@ -228,6 +287,7 @@ func TestGetCurrentDealInfo(t *testing.T) {
|
||||
SearchMessageLookup: data.searchMessageLookup,
|
||||
SearchMessageErr: data.searchMessageErr,
|
||||
MarketDeals: marketDeals,
|
||||
Version: data.networkVersion,
|
||||
}
|
||||
dealInfoMgr := CurrentDealInfoManager{mockApi}
|
||||
|
||||
@ -256,6 +316,7 @@ type CurrentDealInfoMockAPI struct {
|
||||
SearchMessageErr error
|
||||
|
||||
MarketDeals map[marketDealKey]*api.MarketDeal
|
||||
Version network.Version
|
||||
}
|
||||
|
||||
func (mapi *CurrentDealInfoMockAPI) ChainGetMessage(ctx context.Context, c cid.Cid) (*types.Message, error) {
|
||||
@ -310,15 +371,28 @@ func (mapi *CurrentDealInfoMockAPI) StateSearchMsg(ctx context.Context, c cid.Ci
|
||||
}
|
||||
|
||||
func (mapi *CurrentDealInfoMockAPI) StateNetworkVersion(ctx context.Context, tok TipSetToken) (network.Version, error) {
|
||||
return network.Version0, nil
|
||||
return mapi.Version, nil
|
||||
}
|
||||
|
||||
func makePublishDealsReturnBytes(t *testing.T, dealIDs []abi.DealID) []byte {
|
||||
func makePublishDealsReturnBytesOldVersion(t *testing.T, dealIDs []abi.DealID) []byte {
|
||||
buf := new(bytes.Buffer)
|
||||
dealsReturn := market0.PublishStorageDealsReturn{
|
||||
IDs: dealIDs,
|
||||
}
|
||||
err := dealsReturn.MarshalCBOR(buf)
|
||||
require.NoError(t, err)
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func makePublishDealsReturn(t *testing.T, dealIDs []abi.DealID, validIdxs []uint64) []byte {
|
||||
buf := new(bytes.Buffer)
|
||||
dealsReturn := market7.PublishStorageDealsReturn{
|
||||
IDs: dealIDs,
|
||||
ValidDeals: bitfield.NewFromSet(validIdxs),
|
||||
}
|
||||
err := dealsReturn.MarshalCBOR(buf)
|
||||
require.NoError(t, err)
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user