iotex-core icon indicating copy to clipboard operation
iotex-core copied to clipboard

[api] fix revert custom errors and returns the correct revert message…

Open millken opened this issue 2 years ago • 2 comments

Description

Returns the correct json when the contract call contains a custom revert error

The PR needs to add a new HF height config in genesis.yaml , pls confirm it when deploying.

fix before

$ curl -X POST http://127.0.0.1:15014/ -H "Content-Type:application/json" \
            --data "{\"id\":2248897981,\"jsonrpc\":\"2.0\",\"method\":\"eth_estimateGas\",\"params\":[{\"from\":\"0x4f2f741648699c1dc0ad8352e937057cd7e66bd7\",\"to\":\"0x3f5f75147437c8354d1ff31ece231ba29be90f65\",\"data\":\"0xa6b206bf0000000000000000000000000000000000000000000000000000000000000000\",\"value\":\"0x0\",\"type\":\"0x1\"}]}"

{"jsonrpc":"2.0","id":2248897981,"error":{"code":13,"message":"execution simulation failed: status = 106"}}


$ curl -X POST http://127.0.0.1:15014/ -H "Content-Type:application/json" \
            --data '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"data":"0xa6b206bf0000000000000000000000000000000000000000000000000000000000000000","to":"0x3F5f75147437C8354d1fF31EcE231BA29bE90f65","gas":"0x2faf080"},"latest"]}'
{"jsonrpc":"2.0","id":1,"result":"0x1bd9aa400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000001456616c75652063616e6e6f74206265207a65726f000000000000000000000000"}

after fix

$ curl -X POST http://127.0.0.1:15014/ -H "Content-Type:application/json" \
            --data "{\"id\":2248897981,\"jsonrpc\":\"2.0\",\"method\":\"eth_estimateGas\",\"params\":[{\"from\":\"0x4f2f741648699c1dc0ad8352e937057cd7e66bd7\",\"to\":\"0x3f5f75147437c8354d1ff31ece231ba29be90f65\",\"data\":\"0xa6b206bf0000000000000000000000000000000000000000000000000000000000000000\",\"value\":\"0x0\",\"type\":\"0x1\"}]}"

{"jsonrpc":"2.0","id":2248897981,"error":{"code":3,"message":"execution reverted","data":"0x1bd9aa400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000001456616c75652063616e6e6f74206265207a65726f000000000000000000000000"}}

$ curl -X POST http://127.0.0.1:15014/ -H "Content-Type:application/json" \
            --data '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"data":"0xa6b206bf0000000000000000000000000000000000000000000000000000000000000000","to":"0x3F5f75147437C8354d1fF31EcE231BA29bE90f65","gas":"0x2faf080"},"latest"]}'

{"jsonrpc":"2.0","id":1,"error":{"code":3,"message":"execution reverted","data":"0x1bd9aa400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000001456616c75652063616e6e6f74206265207a65726f000000000000000000000000"}}

The fixed API response is the same as geth

Fixes #3919

Type of change

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [x] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my 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
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

millken avatar Aug 16 '23 08:08 millken

Codecov Report

Merging #3923 (423fa39) into master (e1f0636) will increase coverage by 0.60%. Report is 84 commits behind head on master. The diff coverage is 73.21%.

:exclamation: Current head 423fa39 differs from pull request most recent head 94fac1a. Consider uploading reports for the commit 94fac1a to get more accurate results

@@            Coverage Diff             @@
##           master    #3923      +/-   ##
==========================================
+ Coverage   75.38%   75.98%   +0.60%     
==========================================
  Files         303      329      +26     
  Lines       25923    27965    +2042     
==========================================
+ Hits        19541    21250    +1709     
- Misses       5360     5622     +262     
- Partials     1022     1093      +71     
Files Changed Coverage Δ
action/protocol/execution/evm/evm.go 42.58% <0.00%> (-3.89%) :arrow_down:
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/poll/consortium.go 0.00% <0.00%> (ø)
action/protocol/poll/staking_committee.go 43.85% <0.00%> (ø)
...tion/protocol/staking/contractstake_bucket_type.go 0.00% <0.00%> (ø)
action/receipt.go 82.17% <ø> (ø)
api/grpcserver.go 86.40% <0.00%> (ø)
api/loglistener.go 25.00% <0.00%> (ø)
api/web3server_marshal.go 93.68% <ø> (+0.47%) :arrow_up:
api/websocket.go 4.10% <0.00%> (-1.07%) :arrow_down:
... and 66 more

... and 5 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Aug 16 '23 08:08 codecov[bot]

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Aug 31 '23 02:08 sonarqubecloud[bot]