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 JSON-RPC response validation #2862

Merged
merged 6 commits into from
Jun 3, 2019

Conversation

JunichiSugiura
Copy link

Description

Fixed the send method on Web3EthereumProvider to return response result, not response object itself otherwise GetAccountsMethod.js#L47 throws an error.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Enhancement

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 warnings.
  • I have updated or added types for all modules I've changed
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run test in the root folder with success and extended the tests if necessary.
  • I ran npm run build in the root folder and tested it in the browser and with node.
  • I ran npm run dtslint in the root folder and tested that all my types are correct
  • I have tested my code on an ethereum test network.

@coveralls
Copy link

coveralls commented Jun 1, 2019

Coverage Status

Coverage decreased (-0.003%) to 95.862% when pulling 7929596 on LukeSugiura:hotfix/eip1193-provider-result into caa9410 on ethereum:1.0.

@JunichiSugiura
Copy link
Author

I’ve been reading through the API described in EIP1193 and become skeptical about my fix above. The example showed here seems like the provider’s send method only returns the JSON-RPC response result.

In this case, the current return value from Web3EthereumProvider.send method seems right but the validation method needs to be changed to something like below.

// Web3EthereumProvider.js
...
async send (method, parameters) {
    let response;
    try {
        response = await this.connection.send(method, parameters);
    } catch (error) {
        throw new Error(`Node error: ${error.message}`);
    }

    if (response === undefined) {
        throw new Error(`Validation error: Undefined JSON-RPC result`);
    }

    return response;
}
...

@nivida Could you verify this approach, please?

@JunichiSugiura JunichiSugiura changed the title Fix response from Web3EthereumProvider send Fix JSON-RPC response validation Jun 1, 2019

if (validationResult instanceof Error) {
throw validationResult;
if (result === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check isn't required :)

Copy link
Author

Choose a reason for hiding this comment

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

fix: 747554b

@nivida nivida added Bug Addressing a bug In Progress Currently being worked on labels Jun 2, 2019
@JunichiSugiura JunichiSugiura force-pushed the hotfix/eip1193-provider-result branch from bdcca21 to 747554b Compare June 3, 2019 11:06
@JunichiSugiura
Copy link
Author

@nivida Undefined check is now removed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants