Skip to content

fix: deflake //rs/tests/cross_chain:ic_xc_cketh_test_head_nns - #9209

Merged
basvandijk merged 1 commit into
masterfrom
ai/deflake-ic_xc_cketh_test_head_nns-2026-03-05
Mar 6, 2026
Merged

basvandijk merged 1 commit into
masterfrom
ai/deflake-ic_xc_cketh_test_head_nns-2026-03-05

Conversation

@basvandijk

Copy link
Copy Markdown
Collaborator

Root Cause Analysis

This PR fixes two sources of flakiness in //rs/tests/cross_chain:ic_xc_cketh_test_head_nns observed since 2026-03-03 (3 flaky runs: 2 on master, 1 on a PR branch).

Issue 1: Option::unwrap() on None (2 of 3 failures)

After the ckETH minter is reinstalled in support_eth_deposit, the ECDSA public key in the minter state is reset to None. When test_cketh_deposit (and similar functions) immediately call get_minter_info(), the minter_address field is None because get_minter_info() reads state synchronously without triggering the lazy ECDSA key derivation.

Fix: Call minter.minter_address().await before get_minter_info(). The minter_address() endpoint lazily fetches the ECDSA key from the management canister and stores it in state. By the time get_minter_info() is called, the key is available. Applied to test_cketh_deposit, test_ckerc20_deposit, and test_deposit_with_subaccount.

Issue 2: JSON parse failure with trailing characters (1 of 3 failures)

In send_smart_contract, the cast send --json command run via docker run occasionally produces extra output after the JSON object (e.g., container cleanup messages), causing serde_json::from_str to fail with Error("trailing characters", line: 2, column: 1).

Fix: Parse only the first line of the trimmed output, which contains the JSON object from cast send.


Verified with bazel test --test_output=errors --runs_per_test=3 --jobs=3 — all 3 runs passed.

This PR was created following the steps in .claude/skills/fix-flaky-tests/SKILL.md.

Fix two sources of flakiness:

1. After minter reinstall, get_minter_info() returns minter_address: None
   because the ECDSA public key hasn't been lazily fetched yet. Fix by
   calling minter_address() first (which triggers the lazy ECDSA key fetch)
   before calling get_minter_info() in test_cketh_deposit,
   test_ckerc20_deposit, and test_deposit_with_subaccount.

2. In send_smart_contract, cast send --json via docker may include extra
   output after the JSON object, causing serde_json::from_str to fail with
   trailing characters. Fix by parsing only the first line of the output.
@github-actions github-actions Bot added the fix label Mar 5, 2026
@basvandijk
basvandijk marked this pull request as ready for review March 5, 2026 15:11
@basvandijk
basvandijk requested a review from a team as a code owner March 5, 2026 15:11
@github-actions github-actions Bot added the @defi label Mar 5, 2026
@basvandijk
basvandijk enabled auto-merge March 5, 2026 15:23

@gregorydemay gregorydemay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All very good insights, thanks!

@basvandijk
basvandijk added this pull request to the merge queue Mar 6, 2026
Merged via the queue into master with commit 120d2f8 Mar 6, 2026
40 checks passed
@basvandijk
basvandijk deleted the ai/deflake-ic_xc_cketh_test_head_nns-2026-03-05 branch March 6, 2026 08:39
pull Bot pushed a commit to mikeyhodl/ic that referenced this pull request Jun 15, 2026
…tracts offline (dfinity#10459)

## Problem

`//rs/tests/cross_chain:ic_xc_cketh_test` and
`…:ic_xc_cketh_test_head_nns` are
flaky in data centers with unreliable IPv4 connectivity (e.g. `dm1`),
panicking
in `deploy_smart_contract`:

```
thread 'main' panicked at rs/tests/cross_chain/ic_xc_cketh_test.rs:
called `Result::unwrap()` on an `Err` value: block_on_bash_script: exit_status = 1. Output:
  Err: Error: error sending request for url (https://binaries.soliditylang.org/linux-amd64/list.json)
  - Error #1: tcp connect error: Network unreachable (os error 101)
```

## Root cause

The `foundry` container ships `forge`/`cast`/`anvil` but **no `solc`**.
When `forge create` compiles a helper contract, it downloads the
Solidity compiler from `binaries.soliditylang.org` at test runtime
(first the release index `list.json`, then the `solc` binary). That is
why the foundry UVM was created with `.enable_ipv4()`. Whenever the
UVM's IPv4 connectivity is unavailable, the download fails and the test
flakes.

This is a third, distinct source of flakiness from the two fixed in
dfinity#9209.

This is also
[preventing](https://github.com/dfinity/ic/pull/10253/changes#r3387217110.)
these tests to run on the local system-test backend which doesn't have
external network access.

## Fix

Vendor the required `solc` compilers as pinned, hash-verified Bazel
`http_file` dependencies, ship them in the ckETH UVM config image,
bind-mount them into the foundry container, and pass them to `forge
create --use <path>`. Compilation now happens fully offline and the
`.enable_ipv4()` dependency is removed.

- **MODULE.bazel**: add the `solc` and `solc_eth_deposit_helper`
`http_file` deps (sha256 taken from `list.json`). The compilers are
named by role rather than version, so a future compiler bump only
touches the `http_file` URL and sha256.
- **rs/tests/cross_chain/BUILD.bazel**: add both binaries to the
`cketh_uvm_config_image` srcmap (→ `/config/solc` and
`/config/solc_eth_deposit_helper`).
- **rs/tests/cross_chain/ic_xc_cketh_test.rs**: drop `.enable_ipv4()`;
copy the compilers to a writable path + `chmod +x` (vfat drops the exec
bit); pass the compiler matching each contract's `pragma` to `forge
create --use`.

This also removes a source of non-determinism: contracts declaring
`pragma solidity ^0.8.20` previously let `svm` pick the latest 0.8.x
available at runtime; they are now pinned to exactly 0.8.20.
`EthDepositHelper.sol` stays on 0.8.18 to remain faithful to the
[deployed mainnet helper
contract](https://etherscan.io/address/0x7574eB42cA208A4f6960ECCAfDF186D627dCC175),
so it gets its own `solc_eth_deposit_helper` compiler.

## Verification

Ran on `dm1` (the flaky environment) with caching disabled:

```
bazel test //rs/tests/cross_chain:ic_xc_cketh_test --cache_test_results=no
```

```
============== Summary for //rs/tests/cross_chain:ic_xc_cketh_test ==============
Task setup                            PASSED  in 118.22s
Task ic_xc_cketh_test                 PASSED  in 225.80s
Task assert_no_metrics_errors         PASSED  in   3.96s
Task assert_no_unallowed_log_patterns PASSED  in   0.85s
//rs/tests/cross_chain:ic_xc_cketh_test    PASSED in 353.9s
```

The foundry UVM came up without IPv4, `forge create --use` compiled and
deployed all four contracts from the vendored compilers, and every
ETH/ERC-20/subaccount deposit flow passed — no network fetch to
`binaries.soliditylang.org`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants