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

Conversation

MicaiahReid
Copy link

@MicaiahReid MicaiahReid commented Jan 28, 2022

Description

The new Ganache v7 release is not compatible with Web3 as a provider due to some typing issues. We think this is an issue with some of Ganache's and some of Web3's types. This PR fixes the Web3 types.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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.

Currently jsonrpc.js uses `params: params || []` in the
`toPayload` function, so this type update makes the `params` field
optional to match.
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`.
@MicaiahReid MicaiahReid changed the title Fix jsonrpc types Fix jsonrpc payload and response types Jan 28, 2022
@MicaiahReid MicaiahReid marked this pull request as ready for review January 28, 2022 20:25
@jdevcs jdevcs added the 1.x 1.0 related issues label Jan 31, 2022
@coveralls
Copy link

coveralls commented Jan 31, 2022

Pull Request Test Coverage Report for Build 1784172171

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 429 unchanged lines in 7 files lost coverage.
  • Overall coverage decreased (-2.3%) to 72.71%

Files with Coverage Reduction New Missed Lines %
packages/web3-core-requestmanager/src/jsonrpc.js 1 88.0%
packages/web3-core-helpers/src/formatters.js 25 81.07%
packages/web3-core-helpers/src/errors.js 31 4.41%
packages/web3-utils/src/soliditySha3.js 55 5.13%
packages/web3-utils/src/index.js 62 29.31%
packages/web3-utils/src/utils.js 92 12.86%
packages/web3-eth-accounts/src/index.js 163 23.77%
Totals Coverage Status
Change from base Build 1782159682: -2.3%
Covered Lines: 3385
Relevant Lines: 4399

💛 - Coveralls

@jdevcs jdevcs changed the base branch from 1.x to junaid/jsonrpc-payload-response-types-1x-4743 February 8, 2022 18:58
@jdevcs
Copy link
Contributor

jdevcs commented Feb 8, 2022

e2e_windows not passing in this PR so merging this into my branch for checks / fixes there first.

@jdevcs jdevcs merged commit 63b5e62 into web3:junaid/jsonrpc-payload-response-types-1x-4743 Feb 8, 2022
spacesailor24 added a commit that referenced this pull request Mar 13, 2022
* Fix jsonrpc payload and response types (#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](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>

* changelog update

Co-authored-by: Micaiah Reid <micaiahreid@gmail.com>
Co-authored-by: Wyatt Barnes <me@wyatt.email>
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

4 participants