|
| 1 | +package lp2pimpl |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "github.com/filecoin-project/boost/storagemarket/types" |
| 6 | + "github.com/filecoin-project/boost/testutil" |
| 7 | + "github.com/filecoin-project/go-address" |
| 8 | + "github.com/filecoin-project/go-state-types/abi" |
| 9 | + "github.com/filecoin-project/go-state-types/builtin/v9/market" |
| 10 | + "github.com/filecoin-project/go-state-types/crypto" |
| 11 | + "github.com/google/uuid" |
| 12 | + "github.com/stretchr/testify/require" |
| 13 | + "testing" |
| 14 | +) |
| 15 | + |
| 16 | +// TestDealParamsMissingFields verifies that when the client sends a v1.2.0 |
| 17 | +// DealParams struct, the server unmarshalls it into a v1.2.1 DealParams struct |
| 18 | +// with all missing boolean fields set to false. |
| 19 | +func TestDealParamsMissingFields(t *testing.T) { |
| 20 | + label, err := market.NewLabelFromString("label") |
| 21 | + require.NoError(t, err) |
| 22 | + dpv120 := types.DealParamsV120{ |
| 23 | + DealUUID: uuid.New(), |
| 24 | + IsOffline: false, |
| 25 | + ClientDealProposal: market.ClientDealProposal{ |
| 26 | + Proposal: market.DealProposal{ |
| 27 | + PieceCID: testutil.GenerateCid(), |
| 28 | + Client: address.TestAddress, |
| 29 | + Provider: address.TestAddress2, |
| 30 | + Label: label, |
| 31 | + StoragePricePerEpoch: abi.NewTokenAmount(1), |
| 32 | + ProviderCollateral: abi.NewTokenAmount(2), |
| 33 | + ClientCollateral: abi.NewTokenAmount(3), |
| 34 | + }, |
| 35 | + ClientSignature: crypto.Signature{ |
| 36 | + Type: crypto.SigTypeSecp256k1, |
| 37 | + Data: []byte("sig"), |
| 38 | + }, |
| 39 | + }, |
| 40 | + DealDataRoot: testutil.GenerateCid(), |
| 41 | + Transfer: types.Transfer{ |
| 42 | + Type: "http", |
| 43 | + ClientID: "1234", |
| 44 | + Params: []byte("params"), |
| 45 | + Size: 5678, |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + var buff bytes.Buffer |
| 50 | + err = dpv120.MarshalCBOR(&buff) |
| 51 | + require.NoError(t, err) |
| 52 | + |
| 53 | + var dpv121 types.DealParams |
| 54 | + err = dpv121.UnmarshalCBOR(&buff) |
| 55 | + require.NoError(t, err) |
| 56 | + |
| 57 | + // Expect all fields present in both v1.2.0 and v1.2.1 to match |
| 58 | + require.Equal(t, dpv120.DealUUID, dpv121.DealUUID) |
| 59 | + require.Equal(t, dpv120.IsOffline, dpv121.IsOffline) |
| 60 | + require.Equal(t, dpv120.ClientDealProposal, dpv121.ClientDealProposal) |
| 61 | + require.Equal(t, dpv120.DealDataRoot, dpv121.DealDataRoot) |
| 62 | + require.Equal(t, dpv120.Transfer, dpv121.Transfer) |
| 63 | + |
| 64 | + // Expect all boolean fields not present in v1.2.0 to be false |
| 65 | + // in v1.2.1 |
| 66 | + require.False(t, dpv121.SkipIPNIAnnounce) |
| 67 | + require.False(t, dpv121.RemoveUnsealedCopy) |
| 68 | +} |
0 commit comments