Skip to content
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

Fix jsonrpc payload and response types (#4743) #4761

Merged
merged 3 commits into from
Mar 13, 2022

Conversation

jdevcs
Copy link
Contributor

@jdevcs jdevcs commented Feb 8, 2022

e2e_windows were not passing in this PR so opened current PR for checks / fixes .


4743:

  • Make JsonRpcPayload's params field optional

Currently jsonrpc.js uses params: params || [] in the
toPayload function, so this type update makes the params field
optional to match.

  • Fix JsonRpcResponse type

Update id to accept string | number - this now matches the
isValidResponse function in jsonrpc.js.

Update error to accept an object with optional code, data,
and non-optional message fields to more closely match the
JSON RPC spec
and the ErrorResponse function in errors.js.

Co-authored-by: jdevcs 86780488+jdevcs@users.noreply.github.com

Description

Please include a summary of the changes and be sure to follow our Contribution Guidelines.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build and tested dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

* Make JsonRpcPayload's `params` field optional

Currently jsonrpc.js uses `params: params || []` in the
`toPayload` function, so this type update makes the `params` field
optional to match.

* Fix JsonRpcResponse type

Update `id` to accept `string | number` - this now matches the
`isValidResponse` function in `jsonrpc.js`.

Update `error` to accept an object with optional `code`, `data`,
and non-optional `message` fields to more closely match the
[JSON RPC spec](https://www.jsonrpc.org/specification#error_object)
and the `ErrorResponse` function in `errors.js`.

* Remove errant spaces

* Add PR #443 to CHANGELOG

Co-authored-by: jdevcs <86780488+jdevcs@users.noreply.github.com>
@jdevcs jdevcs added the 1.x 1.0 related issues label Feb 8, 2022
@render
Copy link

render bot commented Feb 8, 2022

Copy link
Contributor

@spacesailor24 spacesailor24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've refrained from making any changes to 1.x's types because it's considered a breaking change for those using typescript

@davidmurdoch
Copy link

@spacesailor24 The JSON RPC error property is 100% wrong in every case as is, so I think that should be fixed as no one can rely on that as it is, and if they somehow are, their runtime code is likely broken.

This is technically not a breaking change in Web3's types, as it aligns it with runtime behavior, but for Ganache to have to make the change on our side in v7 it certainly would be breaking (and wrong).

Please reconsider merging this into 1.x.

@spacesailor24
Copy link
Contributor

@spacesailor24 The JSON RPC error property is 100% wrong in every case as is, so I think that should be fixed as no one can rely on that as it is, and if they somehow are, their runtime code is likely broken.

This is technically not a breaking change in Web3's types, as it aligns it with runtime behavior, but for Ganache to have to make the change on our side in v7 it certainly would be breaking (and wrong).

Please reconsider merging this into 1.x.

@davidmurdoch Okay, yea that totally makes sense. We had a blanket policy of not making 1.x type changes, but I should've spent more time understanding this one - weird that the types were even written this way

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1975050328

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 72.688%

Totals Coverage Status
Change from base Build 1927230259: 0.0%
Covered Lines: 3383
Relevant Lines: 4397

💛 - Coveralls

@spacesailor24 spacesailor24 merged commit 5864ab4 into 1.x Mar 13, 2022
@spacesailor24 spacesailor24 deleted the junaid/jsonrpc-payload-response-types-1x-4743 branch March 13, 2022 02:13
spacesailor24 pushed a commit that referenced this pull request Mar 17, 2022
* libs update - npm audit fix

* change log update

* PRs (#4743) (#4761) were not released under 1.7.1
@jdevcs jdevcs mentioned this pull request Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants