axonweb3 / axon

Axon is a Layer 2 framework of CKB with native cross-chain and interoperability.
https://axonweb3.io
MIT License
65 stars 39 forks source link

Sometimes the test `eth_getCode › eth_getCode_9` failed by accident #1579

Closed Flouse closed 11 months ago

Flouse commented 11 months ago

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 commented 11 months ago

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

``` json
{"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: https://github.com/axonweb3/axon/pull/1593.