This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed bestQuote, fastestQuote, implemented slice return from …
…policyQuote and feeQuote (#11)
- Loading branch information
1 parent
7596179
commit 3d7f23c
Showing
17 changed files
with
385 additions
and
460 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
149 changes: 149 additions & 0 deletions
149
broadcast/internal/acceptance_tests/arc_fee_quote_test.go
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,149 @@ | ||
package acceptancetests | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/bitcoin-sv/go-broadcast-client/broadcast" | ||
broadcast_client "github.com/bitcoin-sv/go-broadcast-client/broadcast/broadcast-client" | ||
"github.com/bitcoin-sv/go-broadcast-client/broadcast/internal/arc" | ||
) | ||
|
||
var firstSuccessfulFeeQuoteResponse = ` | ||
{ | ||
"policy": { | ||
"maxscriptsizepolicy": 100000000, | ||
"maxtxsigopscountspolicy": 4294967295, | ||
"maxtxsizepolicy": 100000000, | ||
"miningFee": { | ||
"bytes": 1000, | ||
"satoshis": 1 | ||
} | ||
}, | ||
"timestamp": "2023-08-10T13:49:07.308687569Z" | ||
} | ||
` | ||
|
||
var secondSuccessfulFeeQuoteResponse = ` | ||
{ | ||
"policy": { | ||
"maxscriptsizepolicy": 100000000, | ||
"maxtxsigopscountspolicy": 4294967295, | ||
"maxtxsizepolicy": 100000000, | ||
"miningFee": { | ||
"bytes": 1000, | ||
"satoshis": 2 | ||
} | ||
}, | ||
"timestamp": "2023-08-10T13:49:07.308687569Z" | ||
} | ||
` | ||
|
||
func TestFeeQuote(t *testing.T) { | ||
t.Run("Should successfully query from multiple ArcClients", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc2-api-url", Token: "arc2-token"}). | ||
Build() | ||
|
||
httpResponse1 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(firstSuccessfulFeeQuoteResponse)), | ||
} | ||
httpResponse2 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(secondSuccessfulFeeQuoteResponse)), | ||
} | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse1, nil). | ||
Once() | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse2, nil). | ||
Once() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.NoError(t, err) | ||
assert.NotNil(t, result) | ||
}) | ||
|
||
t.Run("Should return error if all ArcClients return errors", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc2-api-url", Token: "arc2-token"}). | ||
Build() | ||
|
||
httpResponse := &http.Response{} | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse, errors.New("http error")). | ||
Twice() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.Error(t, err) | ||
assert.Nil(t, result) | ||
assert.EqualError(t, err, broadcast.ErrNoMinerResponse.Error()) | ||
}) | ||
|
||
t.Run("Should successfully query from single ArcClient", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
Build() | ||
|
||
httpResponse1 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(firstSuccessfulFeeQuoteResponse)), | ||
} | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse1, nil). | ||
Once() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.NoError(t, err) | ||
assert.NotNil(t, result) | ||
}) | ||
|
||
t.Run("Should return error if single ArcClient returns error", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
httpResponse := &http.Response{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
Build() | ||
|
||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse, errors.New("http error")). | ||
Once() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.Error(t, err) | ||
assert.Nil(t, result) | ||
}) | ||
} |
149 changes: 149 additions & 0 deletions
149
broadcast/internal/acceptance_tests/arc_policy_quote_test.go
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,149 @@ | ||
package acceptancetests | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/bitcoin-sv/go-broadcast-client/broadcast" | ||
broadcast_client "github.com/bitcoin-sv/go-broadcast-client/broadcast/broadcast-client" | ||
"github.com/bitcoin-sv/go-broadcast-client/broadcast/internal/arc" | ||
) | ||
|
||
var firstSuccessfulPolicyResponse = ` | ||
{ | ||
"policy": { | ||
"maxscriptsizepolicy": 100000000, | ||
"maxtxsigopscountspolicy": 4294967295, | ||
"maxtxsizepolicy": 100000000, | ||
"miningFee": { | ||
"bytes": 1000, | ||
"satoshis": 1 | ||
} | ||
}, | ||
"timestamp": "2023-08-10T13:49:07.308687569Z" | ||
} | ||
` | ||
|
||
var secondSuccessfulPolicyResponse = ` | ||
{ | ||
"policy": { | ||
"maxscriptsizepolicy": 100000000, | ||
"maxtxsigopscountspolicy": 4294967295, | ||
"maxtxsizepolicy": 100000000, | ||
"miningFee": { | ||
"bytes": 1000, | ||
"satoshis": 2 | ||
} | ||
}, | ||
"timestamp": "2023-08-10T13:49:07.308687569Z" | ||
} | ||
` | ||
|
||
func TestPolicyQuote(t *testing.T) { | ||
t.Run("Should successfully query from multiple ArcClients", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc2-api-url", Token: "arc2-token"}). | ||
Build() | ||
|
||
httpResponse1 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(firstSuccessfulPolicyResponse)), | ||
} | ||
httpResponse2 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(secondSuccessfulPolicyResponse)), | ||
} | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse1, nil). | ||
Once() | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse2, nil). | ||
Once() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.NoError(t, err) | ||
assert.NotNil(t, result) | ||
}) | ||
|
||
t.Run("Should return error if all ArcClients return errors", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc2-api-url", Token: "arc2-token"}). | ||
Build() | ||
|
||
httpResponse := &http.Response{} | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse, errors.New("http error")). | ||
Twice() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.Error(t, err) | ||
assert.Nil(t, result) | ||
assert.EqualError(t, err, broadcast.ErrNoMinerResponse.Error()) | ||
}) | ||
|
||
t.Run("Should successfully query from single ArcClient", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
Build() | ||
|
||
httpResponse1 := &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: io.NopCloser(strings.NewReader(firstSuccessfulPolicyResponse)), | ||
} | ||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse1, nil). | ||
Once() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.NoError(t, err) | ||
assert.NotNil(t, result) | ||
}) | ||
|
||
t.Run("Should return error if single ArcClient returns error", func(t *testing.T) { | ||
// given | ||
httpClientMock := &arc.MockHttpClient{} | ||
httpResponse := &http.Response{} | ||
broadcaster := broadcast_client.Builder(). | ||
WithHttpClient(httpClientMock). | ||
WithArc(broadcast_client.ArcClientConfig{APIUrl: "http://arc1-api-url", Token: "arc1-token"}). | ||
Build() | ||
|
||
httpClientMock.On("DoRequest", mock.Anything, mock.Anything). | ||
Return(httpResponse, errors.New("http error")). | ||
Once() | ||
|
||
// when | ||
result, err := broadcaster.GetPolicyQuote(context.Background()) | ||
|
||
// then | ||
assert.Error(t, err) | ||
assert.Nil(t, result) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.