-
Notifications
You must be signed in to change notification settings - Fork 503
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
Add Trades endpoint in Go SDK #408
Conversation
http://localhost:8000/accounts/GBTYBQW5GLRSYMT4OJQGVAIH5KBIE5ITEWIVDZHVHIZT7XSKU6DLB6QI/payments?cursor=-213&order=asc&limit=2 ``` { "type": "https://stellar.org/horizon-errors/bad_request", "title": "Bad Request", "status": 400, "detail": "The request you sent was invalid in some way", "extras": { "invalid_field": "cursor", "reason": "the cursor -213 is a negative number: " } } ```
https://www.stellar.org/developers/horizon/reference/endpoints/trades.html http://localhost:8000/trades?limit=3&order=desc&base_asset_type=native&counter_asset_code=SLT&counter_asset_issuer=GCKA6K5PCQ6PNF5RQBF7PQDJWRHO6UOGFMRLK3DYHDOI244V47XKQ4GP&counter_asset_type=credit_alphanum4
offerID int64, | ||
resolution int64, | ||
params ...interface{}, | ||
) (tradesPage TradesPage, err error) |
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.
We should probably create code-style guide for our Go code.
clients/horizon/mocks.go
Outdated
resolution int64, | ||
params ...interface{}, | ||
) (tradesPage TradesPage, err error) { | ||
a := m.Called(baseAsset, counterAsset, offerID, resolution, params) |
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.
Should be params...
. Right now, for the following params
: ["a", "b", "c"]
will call:
m.Called(baseAsset, counterAsset, offerID, resolution, ["a", "b", "c"])
instead of:
m.Called(baseAsset, counterAsset, offerID, resolution, "a", "b", "c")
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 you mean this?
a := m.Called(baseAsset, counterAsset, offerID, resolution, params...)
I won't get this compiled.
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.
What errors are you getting? It should work.
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.
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.
OK, I pulled your code and it seems we're falling into golang/go#18605.
The only possible workaround is to do it like:
args := []interface{}{baseAsset, counterAsset, offerID, resolution}
args = append(args, params...)
a := m.Called(args...)
return a.Get(0).(TradesPage), a.Error(1)
which looks strange but works as expected (allows mocking params
properly).
Is the test you've listed in your comment above checked in? @michaelran16 |
Thanks, @bartekn! I started writing Go since last week, so I was assuming lots of styling guide from Java, which I then realize shouldn't be the case. If there's no guide now, I will refer to this for now: |
@nikhilsaraf No the test code is an external project, calling horizon go API, thus not checked in. |
No worries. I think the best solution is to connect Would be great to have tests for a new method. Check |
+1 on the test. they should be part of the project and checked in, that way we can run them as part of the build. |
@bartekn and @nikhilsaraf |
clients/horizon/main_test.go
Outdated
@@ -266,6 +266,80 @@ var _ = Describe("Horizon", func() { | |||
}) | |||
}) | |||
|
|||
Describe("LoadTrades", func() { |
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.
Please do not add tests using gingko. As mentioned previously in slack, we should be writing our tests using the standard library's testing
package and testify.
@nullstyle I think this PR is good to go, the testing code I move to a different discussion thread: #421 |
@michaelran16 You misunderstood me: I didn't mean that you should remove the test code. I meant that you should be porting that test code into our most modern convention for go tests: the standard test library and testify. We are doing this work such that we can remove goconvey, gingko, and gomega from our list of dependencies. |
Whoops! I see your comment now. nvm. |
replaced with #428 |
As titled, add a new function LoadTrades()
Testing:
Result