-
Notifications
You must be signed in to change notification settings - Fork 471
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
algod: Add a sourcemap flag for compile endpoint #3938
Conversation
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.
Nice! I'm happy to see this get support in the REST API as well
if !v2.Node.Config().EnableDeveloperAPI { | ||
return ctx.String(http.StatusNotFound, "/teal/compile was not enabled in the configuration file by setting the EnableDeveloperAPI to true") | ||
} | ||
// Check if we should return the source map. | ||
sourcemapFlag := false | ||
var sourcemap logic.SourceMap |
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.
nitty but i prefer grouping multiple var declarations
var (
sourcemapFlag bool
sourcemap logic.SourcceMap
)
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.
Refactored the whole section to remove some ugly code
Co-authored-by: Ben Guidarelli <[email protected]>
data := rec.Body.Bytes() | ||
err = protocol.DecodeJSON(data, &response) | ||
require.NoError(t, err, string(data)) | ||
if params.Sourcemap != nil && *params.Sourcemap { |
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.
nit: I would make the condition expectedSourcemap != nil
, that way you aren't replicating the same logic that determines when a sourcemap should be returned or not
Also, require.Equal(t, expectedSourcemap, response.Sourcemap)
compares *logic.SourceMap
, does this pointer comparison compare the actual values?
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.
Good catch thanks!
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.
Pending tests passing, looks good to me!
Codecov Report
@@ Coverage Diff @@
## master #3938 +/- ##
=======================================
Coverage 49.79% 49.79%
=======================================
Files 409 409
Lines 69145 69155 +10
=======================================
+ Hits 34429 34437 +8
- Misses 30997 31002 +5
+ Partials 3719 3716 -3
Continue to review full report at Codecov.
|
Summary
Related to #3725:
This PR adds an optional query parameter to optionally output source maps as a JSON in the
CompileResponse
. This changes the API request and response structure to include these optional fields.Test Plan
Added test cases in the handler for optional query parameter and optional source map returned.
Tested on sandbox with following query:
curl "localhost:4001/v2/teal/compile?sourcemap=include" -H "X-Algo-API-Token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" --data-binary @simple.teal
Response: