Skip to content

Fix flaky test "eth_getBalance" with block number in the last 15 minutes for account that has performed contract deploys/calls #3666

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

Open
acuarica opened this issue Apr 10, 2025 · 0 comments

Comments

@acuarica
Copy link
Contributor

acuarica commented Apr 10, 2025

The following server release test fails intermittently causing flakiness in our test suite.

$
[...]
  0 passing (1m)
  1 failing

  1) RPC Server Acceptance Tests
       Acceptance tests
         @api-batch-2 RPC Server Acceptance Tests
           eth_getBalance
             @release should execute "eth_getBalance" with block number in the last 15 minutes for account that has performed contract deploys/calls:

      AssertionError: expected '0x2b4f651f00ed82400' to equal '0x2a6f0f4064b89c800'
      + expected - actual

      -0x2b4f651f00ed82400
      +0x2a6f0f4064b89c800
      
      at Context.<anonymous> (packages/server/tests/acceptance/rpc_batch2.spec.ts:552:22)
      at Generator.next (<anonymous>)
      at fulfilled (packages/server/tests/acceptance/rpc_batch2.spec.ts:6:58)
      at processTicksAndRejections (node:internal/process/task_queues:105:5)
[...]

Note

This happens against both previewnet and testnet

For reference, here's the failing test

it('@release should execute "eth_getBalance" with block number in the last 15 minutes for account that has performed contract deploys/calls', async function () {
const res = await relay.call(
RelayCalls.ETH_ENDPOINTS.ETH_GET_BALANCE,
[accounts[0].address, numberTo0x(blockNumberAtStartOfTests)],
requestId,
);
const balanceAtBlock = BigInt(accounts0StartBalance);
expect(res).to.eq(`0x${balanceAtBlock.toString(16)}`);
});

The issue seems to be a race condition when accounts0StartBalance is set at blockNumberAtStartOfTests. PR #3495 refactors these tests. However, it seems it also changed its semantics. See

https://github.com/hiero-ledger/hiero-json-rpc-relay/pull/3495/files#diff-e91ffd80132cb7a1d8cfed9a53ebc797b745e3113c4cd7004b02a0679566d2d4R138-R148

in particular note how before said PR the line pollForValidTransactionReceipt(createChildTx.hash) was before setting the value for accounts0StartBalance. Moreover, the line [childTx, blockNumber, balance] = await Promise.all[...] can be causing additional issues because if childTx was included in blockNumber then the reported balance would be incorrect.

Another thing to take into account could be the cache on eth_blockNumber. If there is another call to eth_blockNumber (on a public network this can easily happen) while the test is being setup, then blockNumberAtStartOfTests could refer to a cached block number. This could also be the source of the issue described above.

const cacheKey = `${constants.CACHE_KEY.ETH_BLOCK_NUMBER}`;
const blockNumberCached = await this.cacheService.getAsync(
cacheKey,
CommonService.latestBlockNumber,
requestDetails,
);
if (blockNumberCached) {
if (this.logger.isLevelEnabled('trace')) {
this.logger.trace(
`${requestDetails.formattedRequestId} returning cached value ${cacheKey}:${JSON.stringify(
blockNumberCached,
)}`,
);
}
return blockNumberCached;
}

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

No branches or pull requests

1 participant