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

Sometimes the test eth_getCode › eth_getCode_9 failed by accident #1579

Closed
Flouse opened this issue Nov 20, 2023 · 1 comment · Fixed by #1593
Closed

Sometimes the test eth_getCode › eth_getCode_9 failed by accident #1579

Flouse opened this issue Nov 20, 2023 · 1 comment · Fixed by #1593
Assignees
Labels
github_actions Pull requests that update GitHub Actions code t:bug Something isn't working

Comments

@Flouse
Copy link
Contributor

Flouse commented Nov 20, 2023

Examples

Current Behavior

FAIL src/eth_getCode.test.js
   eth_getCode  eth_getCode_9

    expect(received).resolves.toMatch(expected)

    Expected substring: "-32603"
    Received string:    "\"0x\""

      19 |     await currentpage.click(goto.pageIds.btnId);
      20 |     await currentpage.waitForFunction(() => document.getElementById("ret").innerText !== "");
    > 21 |     await expect(currentpage.$eval("#ret", (e) => e.innerText)).resolves.toMatch(expectedValue);
         |                                                                          ^
      22 |   },
      23 |   // get the  value
      24 |   async value(currentpage) {

      at Object.toMatch (node_modules/expect/build/index.js:166:22)
      at Object.toMatch [as check] (src/goto.js:21:74)
          at runMicrotasks (<anonymous>)
      at Object.<anonymous> (src/eth_getCode.test.js:132:5)

Expected Behavior

Test results should be deterministic

@sunchengzhu
Copy link
Collaborator

sunchengzhu commented Nov 23, 2023

behavior

After local debugging, I found that running eth_getCode_4 and eth_getCode_9 simultaneously causes this issue. (Test method: skip other test cases and only keep 4 and 9, then execute jest tests/e2e/src/eth_getCode.test.js).

troubleshooting

  1. Axon Problem Localization
    By executing the following shell script, it is observed that the eth_getCode interface behaves as expected. It does not exhibit problems when first called with the latest block height as a parameter and then immediately followed by a call with an invalid parameter.
response=$(curl -s http://localhost:8000 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}')
blockNumber=$(echo $response | jq -r '.result')

curl -X POST \
     -H "Content-Type: application/json" \
     --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "'"$blockNumber"'"],"id":1}' \
     http://localhost:8000
     
curl -X POST \
     -H "Content-Type: application/json" \
     --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", ""],"id":2}' \
     http://localhost:8000
{"jsonrpc":"2.0","result":"0x","id":1}
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params","data":"Invalid block number: missing 0x prefix at line 1 column 3"},"id":2}
  1. MetaMask Problem Localization
    I downloaded MetaMask version 10.31.0, which is the default version used in the e2e tests, and then manually entered the parameters for eth_getCode_4 and eth_getCode_9 on http://localhost:8080/eth_getCode.html. The behavior observed was as expected.

Therefore, combining points 1 and 2, we can make a preliminary judgment: Normal use of MetaMask does not cause issues; the problem may lie with the testing framework.

  1. Problem Resolution
    To facilitate the observation of the parameters passed to MetaMask during the execution of different test cases, I introduced a delay of a few seconds after each test case execution. I incidentally discovered that when there is a longer interval (about 30 seconds) between eth_getCode_4 and eth_getCode_9, the test results align with expectations. This might be because MetaMask has a bug when handling rapid, consecutive executions. By continuously adjusting the waiting time after executing eth_getCode_4, I found that 20 seconds is the threshold.
Tests:       1 failed, 8 skipped, 1 passed, 10 total
Snapshots:   0 total
Time:        19.727 s, estimated 21 s

Tests:       8 skipped, 2 passed, 10 total
Snapshots:   0 total
Time:        20.562 s

A pull request has been submitted: #1593.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update GitHub Actions code t:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants