From 44789742849be98512e730621aa9af8a6b68da5b Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Fri, 3 Jun 2022 11:51:15 -0700 Subject: [PATCH] fix(rebase): fix issues after rebase --- impl/initiating_test.go | 11 +++++------ itest/gstestdata.go | 1 - itest/integration_test.go | 4 ++-- message/message1_1prime/message.go | 6 ++---- message/message1_1prime/message_test.go | 12 ++++++------ message/message1_1prime/schema.ipldsch | 4 ++-- message/message1_1prime/transfer_message.go | 8 ++++++-- message/message1_1prime/transfer_request.go | 14 +++++++++++--- message/message1_1prime/transfer_response.go | 17 ++++++++--------- .../message1_1prime/transfer_response_test.go | 2 +- 10 files changed, 43 insertions(+), 36 deletions(-) diff --git a/impl/initiating_test.go b/impl/initiating_test.go index 1ebf6c5..f6c4f0e 100644 --- a/impl/initiating_test.go +++ b/impl/initiating_test.go @@ -334,7 +334,7 @@ func TestDataTransferInitiating(t *testing.T) { events: make(chan datatransfer.EventCode, len(verify.expectedEvents)), } ev.setup(t, dt) - h.stor = h.stor = selectorparse.CommonSelector_ExploreAllRecursively + h.stor = selectorparse.CommonSelector_ExploreAllRecursively h.voucher = testutil.NewTestTypedVoucher() h.voucherResult = testutil.NewTestTypedVoucher() require.NoError(t, err) @@ -581,11 +581,10 @@ func TestDataTransferRestartInitiating(t *testing.T) { ev.setup(t, dt) // setup voucher processing - h.stor = testutil.AllSelector() - h.voucher = testutil.NewFakeDTType() - require.NoError(t, h.dt.RegisterVoucherType(h.voucher, h.voucherValidator)) - h.voucherResult = testutil.NewFakeDTType() - err = h.dt.RegisterVoucherResultType(h.voucherResult) + h.stor = selectorparse.CommonSelector_ExploreAllRecursively + h.voucher = testutil.NewTestTypedVoucher() + require.NoError(t, h.dt.RegisterVoucherType(h.voucher.Type, h.voucherValidator)) + h.voucherResult = testutil.NewTestTypedVoucher() require.NoError(t, err) h.baseCid = testutil.GenerateCids(1)[0] diff --git a/itest/gstestdata.go b/itest/gstestdata.go index 73cb90a..e60391d 100644 --- a/itest/gstestdata.go +++ b/itest/gstestdata.go @@ -29,7 +29,6 @@ import ( "github.com/ipfs/go-unixfs/importer/balanced" ihelper "github.com/ipfs/go-unixfs/importer/helpers" "github.com/ipld/go-ipld-prime" - "github.com/ipld/go-ipld-prime/datamodel" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/protocol" diff --git a/itest/integration_test.go b/itest/integration_test.go index ab529c5..00f84cf 100644 --- a/itest/integration_test.go +++ b/itest/integration_test.go @@ -947,10 +947,10 @@ func TestAutoRestartAfterBouncingInitiator(t *testing.T) { var chid datatransfer.ChannelID if isPush { // Open a push channel - chid, err = initiator.OpenPushDataChannel(ctx, responderHost.ID(), &voucher, rootCid, gsData.AllSelector) + chid, err = initiator.OpenPushDataChannel(ctx, responderHost.ID(), voucher, rootCid, selectorparse.CommonSelector_ExploreAllRecursively) } else { // Open a pull channel - chid, err = initiator.OpenPullDataChannel(ctx, responderHost.ID(), &voucher, rootCid, gsData.AllSelector) + chid, err = initiator.OpenPullDataChannel(ctx, responderHost.ID(), voucher, rootCid, selectorparse.CommonSelector_ExploreAllRecursively) } require.NoError(t, err) diff --git a/message/message1_1prime/message.go b/message/message1_1prime/message.go index d87c008..75302e4 100644 --- a/message/message1_1prime/message.go +++ b/message/message1_1prime/message.go @@ -214,13 +214,11 @@ func fromMessage(tresp *TransferMessage1_1) (datatransfer.Message, error) { // FromNetWrraped can read a network stream to deserialize a message + transport ID func FromNetWrapped(r io.Reader) (datatransfer.TransportID, datatransfer.Message, error) { - builder := Prototype.WrappedTransferMessage.Representation().NewBuilder() - err := dagcbor.Decode(builder, r) + tm, err := ipldutils.FromReader(r, &WrappedTransferMessage1_1{}) if err != nil { return "", nil, err } - node := builder.Build() - wtresp := bindnode.Unwrap(node).(*WrappedTransferMessage1_1) + wtresp := tm.(*WrappedTransferMessage1_1) msg, err := fromMessage(&wtresp.Message) return datatransfer.TransportID(wtresp.TransportID), msg, err } diff --git a/message/message1_1prime/message_test.go b/message/message1_1prime/message_test.go index dc9575e..bc1cd84 100644 --- a/message/message1_1prime/message_test.go +++ b/message/message1_1prime/message_test.go @@ -515,9 +515,9 @@ func TestToNetFromNetEquivalency(t *testing.T) { isPull := false id := datatransfer.TransferID(rand.Int31()) accepted := false - voucher := testutil.NewFakeDTType() - voucherResult := testutil.NewFakeDTType() - request, err := message1_1.NewRequest(id, false, isPull, voucher.Type(), voucher, baseCid, selector) + voucher := testutil.NewTestTypedVoucher() + voucherResult := testutil.NewTestTypedVoucher() + request, err := message1_1.NewRequest(id, false, isPull, &voucher, baseCid, selector) require.NoError(t, err) wrequest := request.WrappedForTransport(transportID) buf := new(bytes.Buffer) @@ -536,10 +536,10 @@ func TestToNetFromNetEquivalency(t *testing.T) { require.Equal(t, deserializedRequest.IsPull(), request.IsPull()) require.Equal(t, deserializedRequest.IsRequest(), request.IsRequest()) require.Equal(t, deserializedRequest.BaseCid(), request.BaseCid()) - testutil.AssertEqualFakeDTVoucher(t, request, deserializedRequest) + testutil.AssertEqualTestVoucher(t, request, deserializedRequest) testutil.AssertEqualSelector(t, request, deserializedRequest) - response, err := message1_1.NewResponse(id, accepted, false, voucherResult.Type(), voucherResult) + response, err := message1_1.NewResponse(id, accepted, false, &voucherResult) require.NoError(t, err) wresponse := response.WrappedForTransport(transportID) err = wresponse.ToNet(buf) @@ -556,7 +556,7 @@ func TestToNetFromNetEquivalency(t *testing.T) { require.Equal(t, deserializedResponse.IsRequest(), response.IsRequest()) require.Equal(t, deserializedResponse.IsUpdate(), response.IsUpdate()) require.Equal(t, deserializedResponse.IsPaused(), response.IsPaused()) - testutil.AssertEqualFakeDTVoucherResult(t, response, deserializedResponse) + testutil.AssertEqualTestVoucherResult(t, response, deserializedResponse) request = message1_1.CancelRequest(id) wrequest = request.WrappedForTransport(transportID) diff --git a/message/message1_1prime/schema.ipldsch b/message/message1_1prime/schema.ipldsch index b0ef373..06ed207 100644 --- a/message/message1_1prime/schema.ipldsch +++ b/message/message1_1prime/schema.ipldsch @@ -37,7 +37,7 @@ type TransferMessage1_1 struct { Response nullable TransferResponse } -type WrappedTransferMessage struct { +type WrappedTransferMessage1_1 struct { TransportID TransportID (rename "ID") - Message TransferMessage (rename "Msg") + Message TransferMessage1_1 (rename "Msg") } \ No newline at end of file diff --git a/message/message1_1prime/transfer_message.go b/message/message1_1prime/transfer_message.go index a9156f3..a23a62a 100644 --- a/message/message1_1prime/transfer_message.go +++ b/message/message1_1prime/transfer_message.go @@ -63,6 +63,10 @@ type WrappedTransferMessage1_1 struct { Message TransferMessage1_1 } -func (wtm *WrappedTransferMessage1_1) toIPLD() schema.TypedNode { - return bindnode.Wrap(&wtm, Prototype.WrappedTransferMessage.Type()) +func (wtm *WrappedTransferMessage1_1) BindnodeSchema() string { + return string(embedSchema) +} + +func (wtm *WrappedTransferMessage1_1) toIPLD() (schema.TypedNode, error) { + return ipldutils.ToNode(wtm) } diff --git a/message/message1_1prime/transfer_request.go b/message/message1_1prime/transfer_request.go index b9bfded..2a92f93 100644 --- a/message/message1_1prime/transfer_request.go +++ b/message/message1_1prime/transfer_request.go @@ -174,7 +174,7 @@ type WrappedTransferRequest1_1 struct { TransportID string } -func (trsp *WrappedTransferRequest1_1) toIPLD() schema.TypedNode { +func (trsp *WrappedTransferRequest1_1) toIPLD() (schema.TypedNode, error) { msg := WrappedTransferMessage1_1{ TransportID: trsp.TransportID, Message: TransferMessage1_1{ @@ -187,9 +187,17 @@ func (trsp *WrappedTransferRequest1_1) toIPLD() schema.TypedNode { } func (trq *WrappedTransferRequest1_1) ToIPLD() (datamodel.Node, error) { - return trq.toIPLD().Representation(), nil + msg, err := trq.toIPLD() + if err != nil { + return nil, err + } + return msg.Representation(), nil } func (trq *WrappedTransferRequest1_1) ToNet(w io.Writer) error { - return dagcbor.Encode(trq.toIPLD().Representation(), w) + i, err := trq.toIPLD() + if err != nil { + return err + } + return ipldutils.NodeToWriter(i, w) } diff --git a/message/message1_1prime/transfer_response.go b/message/message1_1prime/transfer_response.go index f4b5fa4..bf9c9dc 100644 --- a/message/message1_1prime/transfer_response.go +++ b/message/message1_1prime/transfer_response.go @@ -96,7 +96,7 @@ func (trsp *TransferResponse1_1) MessageForVersion(version datatransfer.MessageV } func (trsp *TransferResponse1_1) WrappedForTransport(transportID datatransfer.TransportID) datatransfer.Message { - return &WrappedTransferRepsponse1_1{trsp, string(transportID)} + return &WrappedTransferResponse1_1{trsp, string(transportID)} } func (trsp *TransferResponse1_1) toIPLD() (schema.TypedNode, error) { msg := TransferMessage1_1{ @@ -124,14 +124,14 @@ func (trsp *TransferResponse1_1) ToNet(w io.Writer) error { return ipldutils.NodeToWriter(i, w) } -// WrappedTransferRepsponse1_1 is used to serialize a response along with a +// WrappedTransferResponse1_1 is used to serialize a response along with a // transport id -type WrappedTransferRepsponse1_1 struct { +type WrappedTransferResponse1_1 struct { *TransferResponse1_1 TransportID string } -func (trsp *WrappedTransferRepsponse1_1) toIPLD() (schema.TypedNode, error) { +func (trsp *WrappedTransferResponse1_1) toIPLD() (schema.TypedNode, error) { msg := WrappedTransferMessage1_1{ TransportID: trsp.TransportID, Message: TransferMessage1_1{ @@ -143,19 +143,18 @@ func (trsp *WrappedTransferRepsponse1_1) toIPLD() (schema.TypedNode, error) { return msg.toIPLD() } -func (trq *WrappedTransferRepsponse1_1) ToIPLD() (datamodel.Node, error) { +func (trsp *WrappedTransferResponse1_1) ToIPLD() (datamodel.Node, error) { msg, err := trsp.toIPLD() if err != nil { - return err + return nil, err } return msg.Representation(), nil } -func (trq *WrappedTransferRepsponse1_1) ToNet(w io.Writer) error { +func (trsp *WrappedTransferResponse1_1) ToNet(w io.Writer) error { msg, err := trsp.toIPLD() if err != nil { return err } - return ipldutils.NodeToWriter(i, w) + return ipldutils.NodeToWriter(msg, w) } - diff --git a/message/message1_1prime/transfer_response_test.go b/message/message1_1prime/transfer_response_test.go index 1702ee5..f29773b 100644 --- a/message/message1_1prime/transfer_response_test.go +++ b/message/message1_1prime/transfer_response_test.go @@ -29,7 +29,7 @@ func TestResponseMessageForVersion(t *testing.T) { require.True(t, resp.IsValidationResult()) wrappedOut := out.WrappedForTransport(datatransfer.LegacyTransportID) - require.Equal(t, &message1_1.WrappedTransferRepsponse1_1{ + require.Equal(t, &message1_1.WrappedTransferResponse1_1{ TransferResponse1_1: response.(*message1_1.TransferResponse1_1), TransportID: string(datatransfer.LegacyTransportID), }, wrappedOut)