-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Query Protocol to Spec V0 #25
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
786b28a
feat(retrieval): add network abstraction skeleton
shannonwells ae002e4
feat(retrievalmarket): upgrade query protocol to spec v0
hannahhoward 9224620
fix(retrievalmarket): fix lint errors
hannahhoward 6078ca1
updates after rebase
shannonwells 8f154a6
some updates after rebase with master
shannonwells cc8e97f
fix tests/breakages
shannonwells 6c94789
fix test
shannonwells 8a238c4
updates after repo rename & rebase with master
shannonwells File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package retrievalimpl_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/ipfs/go-datastore" | ||
dss "github.com/ipfs/go-datastore/sync" | ||
bstore "github.com/ipfs/go-ipfs-blockstore" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/filecoin-project/go-fil-markets/retrievalmarket" | ||
retrievalimpl "github.com/filecoin-project/go-fil-markets/retrievalmarket/impl" | ||
"github.com/filecoin-project/go-fil-markets/retrievalmarket/network" | ||
rmnet "github.com/filecoin-project/go-fil-markets/retrievalmarket/network" | ||
"github.com/filecoin-project/go-fil-markets/shared/tokenamount" | ||
"github.com/filecoin-project/go-fil-markets/shared/types" | ||
tut "github.com/filecoin-project/go-fil-markets/shared_testutil" | ||
) | ||
|
||
func TestClient_Query(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
bs := bstore.NewBlockstore(dss.MutexWrap(datastore.NewMapDatastore())) | ||
|
||
pcid := []byte(string("applesauce")) | ||
expectedPeer := peer.ID("somevalue") | ||
rpeer := retrievalmarket.RetrievalPeer{ | ||
Address: address.TestAddress2, | ||
ID: expectedPeer, | ||
} | ||
|
||
expectedQuery := retrievalmarket.Query{ | ||
PieceCID: pcid, | ||
} | ||
|
||
expectedQueryResponse := retrievalmarket.QueryResponse{ | ||
Status: retrievalmarket.QueryResponseAvailable, | ||
Size: 1234, | ||
PaymentAddress: address.TestAddress, | ||
MinPricePerByte: tokenamount.FromInt(5678), | ||
MaxPaymentInterval: 4321, | ||
MaxPaymentIntervalIncrease: 0, | ||
} | ||
|
||
t.Run("it works", func(t *testing.T) { | ||
var qsb tut.QueryStreamBuilder = func(p peer.ID) (rmnet.RetrievalQueryStream, error) { | ||
return tut.NewTestRetrievalQueryStream(tut.TestQueryStreamParams{ | ||
Writer: tut.ExpectQueryWriter(t, expectedQuery, "queries should match"), | ||
RespReader: tut.StubbedQueryResponseReader(expectedQueryResponse), | ||
}), nil | ||
} | ||
net := tut.NewTestRetrievalMarketNetwork(tut.TestNetworkParams{ | ||
QueryStreamBuilder: tut.ExpectPeerOnQueryStreamBuilder(t, expectedPeer, qsb, "Peers should match"), | ||
}) | ||
c := retrievalimpl.NewClient(net, bs, &testRetrievalNode{}) | ||
|
||
resp, err := c.Query(ctx, rpeer, pcid, retrievalmarket.QueryParams{}) | ||
require.NoError(t, err) | ||
assert.NotNil(t, resp) | ||
assert.Equal(t, expectedQueryResponse, resp) | ||
}) | ||
|
||
t.Run("when the stream returns error, returns error", func(t *testing.T) { | ||
net := tut.NewTestRetrievalMarketNetwork(tut.TestNetworkParams{ | ||
QueryStreamBuilder: tut.FailNewQueryStream, | ||
}) | ||
c := retrievalimpl.NewClient(net, bs, &testRetrievalNode{}) | ||
|
||
_, err := c.Query(ctx, rpeer, pcid, retrievalmarket.QueryParams{}) | ||
assert.EqualError(t, err, "new query stream failed") | ||
}) | ||
|
||
t.Run("when WriteQuery fails, returns error", func(t *testing.T) { | ||
|
||
qsbuilder := func(p peer.ID) (network.RetrievalQueryStream, error) { | ||
newStream := tut.NewTestRetrievalQueryStream(tut.TestQueryStreamParams{ | ||
PeerID: p, | ||
Writer: tut.FailQueryWriter, | ||
}) | ||
return newStream, nil | ||
} | ||
|
||
net := tut.NewTestRetrievalMarketNetwork(tut.TestNetworkParams{ | ||
QueryStreamBuilder: qsbuilder, | ||
}) | ||
c := retrievalimpl.NewClient(net, bs, &testRetrievalNode{}) | ||
|
||
statusCode, err := c.Query(ctx, rpeer, pcid, retrievalmarket.QueryParams{}) | ||
assert.EqualError(t, err, "write query failed") | ||
assert.Equal(t, retrievalmarket.QueryResponseUndefined, statusCode) | ||
}) | ||
|
||
t.Run("when ReadQueryResponse fails, returns error", func(t *testing.T) { | ||
qsbuilder := func(p peer.ID) (network.RetrievalQueryStream, error) { | ||
newStream := tut.NewTestRetrievalQueryStream(tut.TestQueryStreamParams{ | ||
PeerID: p, | ||
RespReader: tut.FailResponseReader, | ||
}) | ||
return newStream, nil | ||
} | ||
net := tut.NewTestRetrievalMarketNetwork(tut.TestNetworkParams{ | ||
QueryStreamBuilder: qsbuilder, | ||
}) | ||
c := retrievalimpl.NewClient(net, bs, &testRetrievalNode{}) | ||
|
||
statusCode, err := c.Query(ctx, rpeer, pcid, retrievalmarket.QueryParams{}) | ||
assert.EqualError(t, err, "query response failed") | ||
assert.Equal(t, retrievalmarket.QueryResponseUndefined, statusCode) | ||
}) | ||
} | ||
|
||
type testRetrievalNode struct { | ||
} | ||
|
||
func (t *testRetrievalNode) GetOrCreatePaymentChannel(ctx context.Context, clientAddress address.Address, minerAddress address.Address, clientFundsAvailable tokenamount.TokenAmount) (address.Address, error) { | ||
return address.Address{}, nil | ||
} | ||
|
||
func (t *testRetrievalNode) AllocateLane(paymentChannel address.Address) (uint64, error) { | ||
return 0, nil | ||
} | ||
|
||
func (t *testRetrievalNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount tokenamount.TokenAmount, lane uint64) (*types.SignedVoucher, error) { | ||
return nil, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same re: commented out code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not delete in this case -- it's the whole old implementation -- need it for reference