From 7a8bda42c65dae324a226afca284d62f5a602776 Mon Sep 17 00:00:00 2001 From: shannonwells Date: Tue, 21 Jan 2020 14:06:27 -0800 Subject: [PATCH 1/6] < 1 block file retrieval test --- retrievalmarket/impl/integration_test.go | 207 ++++++++++++----------- 1 file changed, 111 insertions(+), 96 deletions(-) diff --git a/retrievalmarket/impl/integration_test.go b/retrievalmarket/impl/integration_test.go index 72231a1f..75159ca5 100644 --- a/retrievalmarket/impl/integration_test.go +++ b/retrievalmarket/impl/integration_test.go @@ -106,119 +106,134 @@ func TestClientCanMakeDealWithProvider(t *testing.T) { // pieceLink := testData.LoadUnixFSFile(t, "lorem_big.txt", true) // fileSize := uint64(89359) - pieceLink := testData.LoadUnixFSFile(t, "lorem.txt", true) - fileSize := uint64(19000) - - pieceCID := []byte("pieceCID") - providerPaymentAddr, err := address.NewIDAddress(rand.Uint64()) - require.NoError(t, err) - paymentInterval := uint64(10000) - paymentIntervalIncrease := uint64(1000) - pricePerByte := tokenamount.FromInt(1000) - - expectedQR := retrievalmarket.QueryResponse{ - Size: 1024, - PaymentAddress: providerPaymentAddr, - MinPricePerByte: pricePerByte, - MaxPaymentInterval: paymentInterval, - MaxPaymentIntervalIncrease: paymentIntervalIncrease, + testCases := []struct { + name string + filename string + filesize uint64 + }{ + { name: "1 block file retrieval succeeds", + filename: "lorem_under_1_block.txt", + filesize: 410}, + { name: "multi-block file retrieval succeeds", + filename: "lorem.txt", + filesize: 19000}, } - - providerNode := setupProvider(t, testData, pieceCID, expectedQR, providerPaymentAddr ) - - retrievalPeer := &retrievalmarket.RetrievalPeer{Address: providerPaymentAddr, ID: testData.Host2.ID(),} - - expectedVoucher := tut.MakeTestSignedVoucher() - - // just make sure there is enough to cover the transfer - expectedTotal := tokenamount.Mul(pricePerByte, tokenamount.FromInt(fileSize*2)) - - // this is just pulled from the actual answer so the expected keys in the test node match up. - // later we compare the voucher values. - expectedVoucher.Amount = tokenamount.FromInt(10136000) - proof := []byte("") - require.NoError(t, providerNode.ExpectVoucher(clientPaymentChannel, expectedVoucher, proof, expectedVoucher.Amount, expectedVoucher.Amount, nil)) - - // ------- SET UP CLIENT - nw1 := rmnet.NewFromLibp2pHost(testData.Host1) - - createdChan, newLaneAddr, createdVoucher, client := setupClient(clientPaymentChannel, expectedVoucher, nw1, testData) - - dealStateChan := make(chan retrievalmarket.ClientDealState) - client.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) { - switch event { - case retrievalmarket.ClientEventComplete: - dealStateChan <- state - case retrievalmarket.ClientEventError: - msg := ` + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T){ + pieceLink := testData.LoadUnixFSFile(t, testCase.filename, true) + pieceCID := []byte("pieceCID") + providerPaymentAddr, err := address.NewIDAddress(rand.Uint64()) + require.NoError(t, err) + paymentInterval := uint64(10000) + paymentIntervalIncrease := uint64(1000) + pricePerByte := tokenamount.FromInt(1000) + + expectedQR := retrievalmarket.QueryResponse{ + Size: 1024, + PaymentAddress: providerPaymentAddr, + MinPricePerByte: pricePerByte, + MaxPaymentInterval: paymentInterval, + MaxPaymentIntervalIncrease: paymentIntervalIncrease, + } + + providerNode := setupProvider(t, testData, pieceCID, expectedQR, providerPaymentAddr) + + retrievalPeer := &retrievalmarket.RetrievalPeer{Address: providerPaymentAddr, ID: testData.Host2.ID(),} + + expectedVoucher := tut.MakeTestSignedVoucher() + + // just make sure there is enough to cover the transfer + expectedTotal := tokenamount.Mul(pricePerByte, tokenamount.FromInt(testCase.filesize*2)) + + // this is just pulled from the actual answer so the expected keys in the test node match up. + // later we compare the voucher values. + expectedVoucher.Amount = tokenamount.FromInt(10136000) + proof := []byte("") + require.NoError(t, providerNode.ExpectVoucher(clientPaymentChannel, expectedVoucher, proof, expectedVoucher.Amount, expectedVoucher.Amount, nil)) + + // ------- SET UP CLIENT + nw1 := rmnet.NewFromLibp2pHost(testData.Host1) + + createdChan, newLaneAddr, createdVoucher, client := setupClient(clientPaymentChannel, expectedVoucher, nw1, testData) + + dealStateChan := make(chan retrievalmarket.ClientDealState) + client.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) { + switch event { + case retrievalmarket.ClientEventComplete: + dealStateChan <- state + case retrievalmarket.ClientEventError: + msg := ` Status: %d TotalReceived: %d BytesPaidFor: %d CurrentInterval: %d TotalFunds: %s ` - t.Logf(msg, state.Status, state.TotalReceived, state.BytesPaidFor, state.CurrentInterval,state.TotalFunds.String(),) - } - }) - - // **** Send the query for the Piece - // set up retrieval params - resp, err := client.Query(bgCtx, *retrievalPeer, pieceCID, retrievalmarket.QueryParams{}) - require.NoError(t, err) - require.Equal(t, retrievalmarket.QueryResponseAvailable, resp.Status) - - c, ok := pieceLink.(cidlink.Link) - require.True(t, ok) - payloadCID := c.Cid - - rmParams := retrievalmarket.Params{ - PricePerByte: pricePerByte, - PaymentInterval: paymentInterval, - PaymentIntervalIncrease: paymentIntervalIncrease, - PayloadCID: payloadCID, + t.Logf(msg, state.Status, state.TotalReceived, state.BytesPaidFor, state.CurrentInterval, state.TotalFunds.String(), ) + } + }) + + // **** Send the query for the Piece + // set up retrieval params + resp, err := client.Query(bgCtx, *retrievalPeer, pieceCID, retrievalmarket.QueryParams{}) + require.NoError(t, err) + require.Equal(t, retrievalmarket.QueryResponseAvailable, resp.Status) + + c, ok := pieceLink.(cidlink.Link) + require.True(t, ok) + payloadCID := c.Cid + + rmParams := retrievalmarket.Params{ + PricePerByte: pricePerByte, + PaymentInterval: paymentInterval, + PaymentIntervalIncrease: paymentIntervalIncrease, + PayloadCID: payloadCID, + } + + // *** Retrieve the piece + did := client.Retrieve(bgCtx, pieceCID, rmParams, expectedTotal, retrievalPeer.ID, clientPaymentChannel, retrievalPeer.Address) + assert.Equal(t, did, retrievalmarket.DealID(1)) + + ctx, cancel := context.WithTimeout(bgCtx, 20*time.Second) + defer cancel() + + var dealState retrievalmarket.ClientDealState + select { + case <-ctx.Done(): + t.Error("deal never completed") + t.FailNow() + case dealState = <-dealStateChan: + } + assert.Equal(t, dealState.Lane, expectedVoucher.Lane) + require.NotNil(t, createdChan) + require.Equal(t, expectedTotal, createdChan.amt) + require.Equal(t, clientPaymentChannel, *newLaneAddr) + // verify that the voucher was saved/seen by the client with correct values + require.NotNil(t, createdVoucher) + assert.True(t, createdVoucher.Equals(expectedVoucher)) + // // verify that the provider saved the same voucher values + providerNode.VerifyExpectations(t) + testData.VerifyFileTransferred(t, pieceLink, false) + }) } - // *** Retrieve the piece - did := client.Retrieve(bgCtx, pieceCID, rmParams, expectedTotal, retrievalPeer.ID, clientPaymentChannel, retrievalPeer.Address) - assert.Equal(t, did, retrievalmarket.DealID(1)) - - ctx , cancel := context.WithTimeout(bgCtx, 20*time.Second) - defer cancel() - - var dealState retrievalmarket.ClientDealState - select { - case <- ctx.Done(): - t.Error("deal never completed") - t.FailNow() - case dealState = <- dealStateChan: - } - assert.Equal(t, dealState.Lane, expectedVoucher.Lane) - require.NotNil(t, createdChan) - require.Equal(t, expectedTotal, createdChan.amt) - require.Equal(t, clientPaymentChannel, *newLaneAddr) - // verify that the voucher was saved/seen by the client with correct values - require.NotNil(t, createdVoucher) - assert.True(t, createdVoucher.Equals(expectedVoucher)) - // // verify that the provider saved the same voucher values - providerNode.VerifyExpectations(t) - testData.VerifyFileTransferred(t, pieceLink, false) } func setupClient( - clientPaymentChannel address.Address, - expectedVoucher *types.SignedVoucher, - nw1 rmnet.RetrievalMarketNetwork, - testData *tut.Libp2pTestData) ( *pmtChan, - *address.Address, - *types.SignedVoucher, - retrievalmarket.RetrievalClient) { - var createdChan pmtChan + clientPaymentChannel address.Address, + expectedVoucher *types.SignedVoucher, + nw1 rmnet.RetrievalMarketNetwork, + testData *tut.Libp2pTestData) (*pmtChan, + *address.Address, + *types.SignedVoucher, + retrievalmarket.RetrievalClient) { + var createdChan pmtChan paymentChannelRecorder := func(client, miner address.Address, amt tokenamount.TokenAmount) { createdChan = pmtChan{client, miner, amt} } - var newLaneAddr address.Address + var newLaneAddr address.Address laneRecorder := func(paymentChannel address.Address) { newLaneAddr = paymentChannel } From 11af02f92426db0f81a1672cfac9ad1a1dbe2e2a Mon Sep 17 00:00:00 2001 From: shannonwells Date: Tue, 21 Jan 2020 14:41:53 -0800 Subject: [PATCH 2/6] parameterize the voucher amount so the key lookup succeeds for the test provider node --- retrievalmarket/impl/integration_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/retrievalmarket/impl/integration_test.go b/retrievalmarket/impl/integration_test.go index 75159ca5..89874f7c 100644 --- a/retrievalmarket/impl/integration_test.go +++ b/retrievalmarket/impl/integration_test.go @@ -111,13 +111,16 @@ func TestClientCanMakeDealWithProvider(t *testing.T) { name string filename string filesize uint64 + voucherAmt tokenamount.TokenAmount }{ { name: "1 block file retrieval succeeds", filename: "lorem_under_1_block.txt", - filesize: 410}, + filesize: 410, + voucherAmt: tokenamount.FromInt(410000)}, { name: "multi-block file retrieval succeeds", filename: "lorem.txt", - filesize: 19000}, + filesize: 19000, + voucherAmt: tokenamount.FromInt(10136000)}, } for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T){ @@ -148,9 +151,8 @@ func TestClientCanMakeDealWithProvider(t *testing.T) { // this is just pulled from the actual answer so the expected keys in the test node match up. // later we compare the voucher values. - expectedVoucher.Amount = tokenamount.FromInt(10136000) proof := []byte("") - require.NoError(t, providerNode.ExpectVoucher(clientPaymentChannel, expectedVoucher, proof, expectedVoucher.Amount, expectedVoucher.Amount, nil)) + require.NoError(t, providerNode.ExpectVoucher(clientPaymentChannel, expectedVoucher, proof, testCase.voucherAmt, testCase.voucherAmt, nil)) // ------- SET UP CLIENT nw1 := rmnet.NewFromLibp2pHost(testData.Host1) From e99f28062b12bedd5021fc0454596ab7d3157539 Mon Sep 17 00:00:00 2001 From: shannonwells Date: Tue, 21 Jan 2020 16:00:12 -0800 Subject: [PATCH 3/6] add a provider subscriber and use a channel to check that the provider sees the completed deal --- go.mod | 1 + go.sum | 2 + .../impl/clientstates/client_states.go | 9 +- retrievalmarket/impl/integration_test.go | 104 +++++++++++------- .../impl/providerstates/provider_states.go | 6 +- .../testnodes/test_retrieval_provider_node.go | 9 +- 6 files changed, 86 insertions(+), 45 deletions(-) diff --git a/go.mod b/go.mod index 20d74643..ee3c89ae 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/ipfs/go-ipfs-files v0.0.4 github.com/ipfs/go-ipld-cbor v0.0.3 github.com/ipfs/go-ipld-format v0.0.2 + github.com/ipfs/go-log v1.0.1 github.com/ipfs/go-log/v2 v2.0.1 github.com/ipfs/go-merkledag v0.2.4 github.com/ipfs/go-unixfs v0.2.2-0.20190827150610-868af2e9e5cb diff --git a/go.sum b/go.sum index 3951c7de..8e638da3 100644 --- a/go.sum +++ b/go.sum @@ -200,6 +200,8 @@ github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.0 h1:BW3LQIiZzpNyolt84yvKNCd3FU+AK4VDw1hnHR+1aiI= github.com/ipfs/go-log v1.0.0/go.mod h1:JO7RzlMK6rA+CIxFMLOuB6Wf5b81GDiKElL7UPSIKjA= +github.com/ipfs/go-log v1.0.1 h1:5lIEEOQTk/vd1WuPFBRqz2mcp+5G1fMVcW+Ib/H5Hfo= +github.com/ipfs/go-log v1.0.1/go.mod h1:HuWlQttfN6FWNHRhlY5yMk/lW7evQC0HHGOxEwMRR8I= github.com/ipfs/go-log/v2 v2.0.1 h1:mnR9XFltezAtO8A6tj5U7nKkRzhEQNEw/wT11U2HhPM= github.com/ipfs/go-log/v2 v2.0.1/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0= github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= diff --git a/retrievalmarket/impl/clientstates/client_states.go b/retrievalmarket/impl/clientstates/client_states.go index bfff0b75..c88931d1 100644 --- a/retrievalmarket/impl/clientstates/client_states.go +++ b/retrievalmarket/impl/clientstates/client_states.go @@ -4,13 +4,16 @@ import ( "context" "fmt" + logging "github.com/ipfs/go-log" + "golang.org/x/xerrors" + rm "github.com/filecoin-project/go-fil-markets/retrievalmarket" rmnet "github.com/filecoin-project/go-fil-markets/retrievalmarket/network" "github.com/filecoin-project/go-fil-markets/shared/tokenamount" - - "golang.org/x/xerrors" ) +var log = logging.Logger("ClientStates") + // ClientDealEnvironment is a bridge to the environment a client deal is executing in type ClientDealEnvironment interface { Node() rm.RetrievalClientNode @@ -89,7 +92,7 @@ func ProcessPaymentRequested(ctx context.Context, environment ClientDealEnvironm } // check that totalReceived - bytesPaidFor >= currentInterval, or fail - if (deal.TotalReceived-deal.BytesPaidFor < deal.CurrentInterval) && deal.Status != rm.DealStatusFundsNeededLastPayment{ + if (deal.TotalReceived-deal.BytesPaidFor < deal.CurrentInterval) && deal.Status != rm.DealStatusFundsNeededLastPayment { return errorFunc(xerrors.New("not enough bytes received between payment request")) } diff --git a/retrievalmarket/impl/integration_test.go b/retrievalmarket/impl/integration_test.go index 89874f7c..aef822fb 100644 --- a/retrievalmarket/impl/integration_test.go +++ b/retrievalmarket/impl/integration_test.go @@ -8,7 +8,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-data-transfer/testutil" - "github.com/ipfs/go-log/v2" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -92,7 +91,6 @@ func requireSetupTestClientAndProvider(bgCtx context.Context, t *testing.T, payC } func TestClientCanMakeDealWithProvider(t *testing.T) { - log.SetDebugLogging() bgCtx := context.Background() clientPaymentChannel, err := address.NewIDAddress(rand.Uint64()) require.NoError(t, err) @@ -101,30 +99,27 @@ func TestClientCanMakeDealWithProvider(t *testing.T) { // -------- SET UP PROVIDER - // Inject a unixFS file on the provider side to its blockstore - // obtained via `ls -laf` on this file - - // pieceLink := testData.LoadUnixFSFile(t, "lorem_big.txt", true) - // fileSize := uint64(89359) - testCases := []struct { - name string - filename string - filesize uint64 - voucherAmt tokenamount.TokenAmount + name string + filename string + filesize uint64 + voucherAmts []tokenamount.TokenAmount }{ - { name: "1 block file retrieval succeeds", - filename: "lorem_under_1_block.txt", - filesize: 410, - voucherAmt: tokenamount.FromInt(410000)}, - { name: "multi-block file retrieval succeeds", - filename: "lorem.txt", - filesize: 19000, - voucherAmt: tokenamount.FromInt(10136000)}, + {name: "1 block file retrieval succeeds", + filename: "lorem_under_1_block.txt", + filesize: 410, + voucherAmts: []tokenamount.TokenAmount{tokenamount.FromInt(410000)}}, + {name: "multi-block file retrieval succeeds", + filename: "lorem.txt", + filesize: 19000, + voucherAmts: []tokenamount.TokenAmount{tokenamount.FromInt(10136000), tokenamount.FromInt(9784000)}}, } for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T){ + t.Run(testCase.name, func(t *testing.T) { + // Inject a unixFS file on the provider side to its blockstore + // obtained via `ls -laf` on this file pieceLink := testData.LoadUnixFSFile(t, testCase.filename, true) + pieceCID := []byte("pieceCID") providerPaymentAddr, err := address.NewIDAddress(rand.Uint64()) require.NoError(t, err) @@ -140,7 +135,7 @@ func TestClientCanMakeDealWithProvider(t *testing.T) { MaxPaymentIntervalIncrease: paymentIntervalIncrease, } - providerNode := setupProvider(t, testData, pieceCID, expectedQR, providerPaymentAddr) + providerNode, provider := setupProvider(t, testData, pieceCID, expectedQR, providerPaymentAddr) retrievalPeer := &retrievalmarket.RetrievalPeer{Address: providerPaymentAddr, ID: testData.Host2.ID(),} @@ -149,33 +144,52 @@ func TestClientCanMakeDealWithProvider(t *testing.T) { // just make sure there is enough to cover the transfer expectedTotal := tokenamount.Mul(pricePerByte, tokenamount.FromInt(testCase.filesize*2)) - // this is just pulled from the actual answer so the expected keys in the test node match up. - // later we compare the voucher values. + // voucherAmts are pulled from the actual answer so the expected keys in the test node match up. + // later we compare the voucher values. The last voucherAmt is a remainder proof := []byte("") - require.NoError(t, providerNode.ExpectVoucher(clientPaymentChannel, expectedVoucher, proof, testCase.voucherAmt, testCase.voucherAmt, nil)) + for _, voucherAmt := range testCase.voucherAmts { + require.NoError(t, providerNode.ExpectVoucher(clientPaymentChannel, expectedVoucher, proof, voucherAmt, voucherAmt, nil)) + } // ------- SET UP CLIENT nw1 := rmnet.NewFromLibp2pHost(testData.Host1) createdChan, newLaneAddr, createdVoucher, client := setupClient(clientPaymentChannel, expectedVoucher, nw1, testData) - dealStateChan := make(chan retrievalmarket.ClientDealState) + clientDealStateChan := make(chan retrievalmarket.ClientDealState) client.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) { switch event { case retrievalmarket.ClientEventComplete: - dealStateChan <- state + clientDealStateChan <- state case retrievalmarket.ClientEventError: msg := ` -Status: %d -TotalReceived: %d -BytesPaidFor: %d +Status: %d +TotalReceived: %d +BytesPaidFor: %d CurrentInterval: %d -TotalFunds: %s +TotalFunds: %s ` t.Logf(msg, state.Status, state.TotalReceived, state.BytesPaidFor, state.CurrentInterval, state.TotalFunds.String(), ) } }) + providerDealStateChan := make(chan retrievalmarket.ProviderDealState) + provider.SubscribeToEvents(func(event retrievalmarket.ProviderEvent, state retrievalmarket.ProviderDealState) { + switch event { + case retrievalmarket.ProviderEventComplete: + providerDealStateChan <- state + case retrievalmarket.ProviderEventError: + msg := ` +Status: %d +TotalSent: %d +FundsReceived: %s +Message: %s +CurrentInterval: %d +` + t.Logf(msg, state.Status, state.TotalSent, state.FundsReceived.String(), state.Message, state.CurrentInterval) + } + }) + // **** Send the query for the Piece // set up retrieval params resp, err := client.Query(bgCtx, *retrievalPeer, pieceCID, retrievalmarket.QueryParams{}) @@ -197,24 +211,38 @@ TotalFunds: %s did := client.Retrieve(bgCtx, pieceCID, rmParams, expectedTotal, retrievalPeer.ID, clientPaymentChannel, retrievalPeer.Address) assert.Equal(t, did, retrievalmarket.DealID(1)) - ctx, cancel := context.WithTimeout(bgCtx, 20*time.Second) + ctx, cancel := context.WithTimeout(bgCtx, 10*time.Second) defer cancel() - var dealState retrievalmarket.ClientDealState + // verify that client subscribers will be notified of state changes + var clientDealState retrievalmarket.ClientDealState select { case <-ctx.Done(): t.Error("deal never completed") t.FailNow() - case dealState = <-dealStateChan: + case clientDealState = <-clientDealStateChan: } - assert.Equal(t, dealState.Lane, expectedVoucher.Lane) + assert.Equal(t, clientDealState.Lane, expectedVoucher.Lane) require.NotNil(t, createdChan) require.Equal(t, expectedTotal, createdChan.amt) require.Equal(t, clientPaymentChannel, *newLaneAddr) // verify that the voucher was saved/seen by the client with correct values require.NotNil(t, createdVoucher) assert.True(t, createdVoucher.Equals(expectedVoucher)) - // // verify that the provider saved the same voucher values + + ctx, cancel = context.WithTimeout(bgCtx, 10*time.Second) + defer cancel() + var providerDealState retrievalmarket.ProviderDealState + select { + case <-ctx.Done(): + t.Error("provider never saw completed deal") + t.FailNow() + case providerDealState = <- providerDealStateChan: + } + + require.Equal(t, retrievalmarket.DealStatusCompleted, providerDealState.Status) + + // verify that the provider saved the same voucher values providerNode.VerifyExpectations(t) testData.VerifyFileTransferred(t, pieceLink, false) }) @@ -256,7 +284,7 @@ func setupClient( return &createdChan, &newLaneAddr, &createdVoucher, client } -func setupProvider(t *testing.T, testData *tut.Libp2pTestData, pieceCID []byte, expectedQR retrievalmarket.QueryResponse, providerPaymentAddr address.Address) *testnodes.TestRetrievalProviderNode { +func setupProvider(t *testing.T, testData *tut.Libp2pTestData, pieceCID []byte, expectedQR retrievalmarket.QueryResponse, providerPaymentAddr address.Address) (*testnodes.TestRetrievalProviderNode, retrievalmarket.RetrievalProvider) { nw2 := rmnet.NewFromLibp2pHost(testData.Host2) providerNode := testnodes.NewTestRetrievalProviderNode() providerNode.SetBlockstore(testData.Bs2) @@ -265,7 +293,7 @@ func setupProvider(t *testing.T, testData *tut.Libp2pTestData, pieceCID []byte, provider.SetPaymentInterval(expectedQR.MaxPaymentInterval, expectedQR.MaxPaymentIntervalIncrease) provider.SetPricePerByte(expectedQR.MinPricePerByte) require.NoError(t, provider.Start()) - return providerNode + return providerNode, provider } type pmtChan struct { diff --git a/retrievalmarket/impl/providerstates/provider_states.go b/retrievalmarket/impl/providerstates/provider_states.go index 218aac1c..722989af 100644 --- a/retrievalmarket/impl/providerstates/provider_states.go +++ b/retrievalmarket/impl/providerstates/provider_states.go @@ -3,12 +3,16 @@ package providerstates import ( "context" + logging "github.com/ipfs/go-log" + "golang.org/x/xerrors" + rm "github.com/filecoin-project/go-fil-markets/retrievalmarket" rmnet "github.com/filecoin-project/go-fil-markets/retrievalmarket/network" "github.com/filecoin-project/go-fil-markets/shared/tokenamount" - "golang.org/x/xerrors" ) +var log = logging.Logger("ProviderStates") + // ProviderDealEnvironment is a bridge to the environment a provider deal is executing in type ProviderDealEnvironment interface { Node() rm.RetrievalProviderNode diff --git a/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go b/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go index 18fe56d4..f286cef6 100644 --- a/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go +++ b/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-address" blockstore "github.com/ipfs/go-ipfs-blockstore" + logging "github.com/ipfs/go-log" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-fil-markets/retrievalmarket" @@ -14,6 +15,7 @@ import ( "github.com/filecoin-project/go-fil-markets/shared/types" ) +var log = logging.Logger("TestRetrievalProviderNode") type TestRetrievalProviderNodeParams struct { /* PayCh address.Address PayChErr error @@ -42,7 +44,7 @@ type TestRetrievalProviderNode struct { receivedPiecesSizes map[string]struct{} receivedMissingPieces map[string]struct{} expectedVouchers map[expectedVoucherKey]voucherResult - receivedVouchers map[expectedVoucherKey]struct{} + receivedVouchers map[expectedVoucherKey]bool } var _ retrievalmarket.RetrievalProviderNode = &TestRetrievalProviderNode{} @@ -54,7 +56,7 @@ func NewTestRetrievalProviderNode() *TestRetrievalProviderNode { receivedPiecesSizes: make(map[string]struct{}), receivedMissingPieces: make(map[string]struct{}), expectedVouchers: make(map[expectedVoucherKey]voucherResult), - receivedVouchers: make(map[expectedVoucherKey]struct{}), + receivedVouchers: make(map[expectedVoucherKey]bool), } } @@ -100,13 +102,14 @@ func (trpn *TestRetrievalProviderNode) SavePaymentVoucher( voucher *types.SignedVoucher, proof []byte, expectedAmount tokenamount.TokenAmount) (tokenamount.TokenAmount, error) { + key, err := trpn.toExpectedVoucherKey(paymentChannel, voucher, proof, expectedAmount) if err != nil { return tokenamount.Empty, err } result, ok := trpn.expectedVouchers[key] if ok { - trpn.receivedVouchers[key] = struct{}{} + trpn.receivedVouchers[key] = true return result.amount, result.err } return tokenamount.Empty, errors.New("SavePaymentVoucher failed") From 2390a7fe562cd20e2ba349b5d42ae88f190b9c74 Mon Sep 17 00:00:00 2001 From: shannonwells Date: Tue, 21 Jan 2020 16:45:57 -0800 Subject: [PATCH 4/6] please the linter --- retrievalmarket/impl/clientstates/client_states.go | 3 --- retrievalmarket/impl/providerstates/provider_states.go | 3 --- retrievalmarket/impl/testnodes/test_retrieval_provider_node.go | 2 -- 3 files changed, 8 deletions(-) diff --git a/retrievalmarket/impl/clientstates/client_states.go b/retrievalmarket/impl/clientstates/client_states.go index c88931d1..db4fc573 100644 --- a/retrievalmarket/impl/clientstates/client_states.go +++ b/retrievalmarket/impl/clientstates/client_states.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - logging "github.com/ipfs/go-log" "golang.org/x/xerrors" rm "github.com/filecoin-project/go-fil-markets/retrievalmarket" @@ -12,8 +11,6 @@ import ( "github.com/filecoin-project/go-fil-markets/shared/tokenamount" ) -var log = logging.Logger("ClientStates") - // ClientDealEnvironment is a bridge to the environment a client deal is executing in type ClientDealEnvironment interface { Node() rm.RetrievalClientNode diff --git a/retrievalmarket/impl/providerstates/provider_states.go b/retrievalmarket/impl/providerstates/provider_states.go index 722989af..51c4befa 100644 --- a/retrievalmarket/impl/providerstates/provider_states.go +++ b/retrievalmarket/impl/providerstates/provider_states.go @@ -3,7 +3,6 @@ package providerstates import ( "context" - logging "github.com/ipfs/go-log" "golang.org/x/xerrors" rm "github.com/filecoin-project/go-fil-markets/retrievalmarket" @@ -11,8 +10,6 @@ import ( "github.com/filecoin-project/go-fil-markets/shared/tokenamount" ) -var log = logging.Logger("ProviderStates") - // ProviderDealEnvironment is a bridge to the environment a provider deal is executing in type ProviderDealEnvironment interface { Node() rm.RetrievalProviderNode diff --git a/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go b/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go index f286cef6..1f640457 100644 --- a/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go +++ b/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go @@ -7,7 +7,6 @@ import ( "github.com/filecoin-project/go-address" blockstore "github.com/ipfs/go-ipfs-blockstore" - logging "github.com/ipfs/go-log" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-fil-markets/retrievalmarket" @@ -15,7 +14,6 @@ import ( "github.com/filecoin-project/go-fil-markets/shared/types" ) -var log = logging.Logger("TestRetrievalProviderNode") type TestRetrievalProviderNodeParams struct { /* PayCh address.Address PayChErr error From e357ee363b97359e50e5f10cafa237aaad626a84 Mon Sep 17 00:00:00 2001 From: shannonwells Date: Tue, 21 Jan 2020 16:49:54 -0800 Subject: [PATCH 5/6] mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ee3c89ae..cec6b50b 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/ipfs/go-ipfs-files v0.0.4 github.com/ipfs/go-ipld-cbor v0.0.3 github.com/ipfs/go-ipld-format v0.0.2 - github.com/ipfs/go-log v1.0.1 + github.com/ipfs/go-log v1.0.1 // indirect github.com/ipfs/go-log/v2 v2.0.1 github.com/ipfs/go-merkledag v0.2.4 github.com/ipfs/go-unixfs v0.2.2-0.20190827150610-868af2e9e5cb From 1e8aae8a1ac775ee968b3f70a84d307893ff3f3b Mon Sep 17 00:00:00 2001 From: shannonwells Date: Tue, 21 Jan 2020 17:19:05 -0800 Subject: [PATCH 6/6] reduce PR footprint --- go.mod | 1 - go.sum | 2 -- .../impl/testnodes/test_retrieval_provider_node.go | 7 +++---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index cec6b50b..20d74643 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/ipfs/go-ipfs-files v0.0.4 github.com/ipfs/go-ipld-cbor v0.0.3 github.com/ipfs/go-ipld-format v0.0.2 - github.com/ipfs/go-log v1.0.1 // indirect github.com/ipfs/go-log/v2 v2.0.1 github.com/ipfs/go-merkledag v0.2.4 github.com/ipfs/go-unixfs v0.2.2-0.20190827150610-868af2e9e5cb diff --git a/go.sum b/go.sum index 8e638da3..3951c7de 100644 --- a/go.sum +++ b/go.sum @@ -200,8 +200,6 @@ github.com/ipfs/go-ipld-format v0.0.2/go.mod h1:4B6+FM2u9OJ9zCV+kSbgFAZlOrv1Hqbf github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.0 h1:BW3LQIiZzpNyolt84yvKNCd3FU+AK4VDw1hnHR+1aiI= github.com/ipfs/go-log v1.0.0/go.mod h1:JO7RzlMK6rA+CIxFMLOuB6Wf5b81GDiKElL7UPSIKjA= -github.com/ipfs/go-log v1.0.1 h1:5lIEEOQTk/vd1WuPFBRqz2mcp+5G1fMVcW+Ib/H5Hfo= -github.com/ipfs/go-log v1.0.1/go.mod h1:HuWlQttfN6FWNHRhlY5yMk/lW7evQC0HHGOxEwMRR8I= github.com/ipfs/go-log/v2 v2.0.1 h1:mnR9XFltezAtO8A6tj5U7nKkRzhEQNEw/wT11U2HhPM= github.com/ipfs/go-log/v2 v2.0.1/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0= github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= diff --git a/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go b/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go index 1f640457..18fe56d4 100644 --- a/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go +++ b/retrievalmarket/impl/testnodes/test_retrieval_provider_node.go @@ -42,7 +42,7 @@ type TestRetrievalProviderNode struct { receivedPiecesSizes map[string]struct{} receivedMissingPieces map[string]struct{} expectedVouchers map[expectedVoucherKey]voucherResult - receivedVouchers map[expectedVoucherKey]bool + receivedVouchers map[expectedVoucherKey]struct{} } var _ retrievalmarket.RetrievalProviderNode = &TestRetrievalProviderNode{} @@ -54,7 +54,7 @@ func NewTestRetrievalProviderNode() *TestRetrievalProviderNode { receivedPiecesSizes: make(map[string]struct{}), receivedMissingPieces: make(map[string]struct{}), expectedVouchers: make(map[expectedVoucherKey]voucherResult), - receivedVouchers: make(map[expectedVoucherKey]bool), + receivedVouchers: make(map[expectedVoucherKey]struct{}), } } @@ -100,14 +100,13 @@ func (trpn *TestRetrievalProviderNode) SavePaymentVoucher( voucher *types.SignedVoucher, proof []byte, expectedAmount tokenamount.TokenAmount) (tokenamount.TokenAmount, error) { - key, err := trpn.toExpectedVoucherKey(paymentChannel, voucher, proof, expectedAmount) if err != nil { return tokenamount.Empty, err } result, ok := trpn.expectedVouchers[key] if ok { - trpn.receivedVouchers[key] = true + trpn.receivedVouchers[key] = struct{}{} return result.amount, result.err } return tokenamount.Empty, errors.New("SavePaymentVoucher failed")