Skip to content

Flaky test: basic_migration_with_native_tokens fails non-deterministically due to HashMap iteration order #11867

Description

@Thoralf-M

Summary

The test iota_genesis_builder::stardust::migration::tests::basic::basic_migration_with_native_tokens failed intermittently in CI on PR #11697 (attempt 1 of the "Run rust tests" job, job ID 80802386929). The run was rerun and passed on attempt 2. The failure was a Rust unwrap() panic at crates/iota-genesis-builder/src/stardust/migration/tests/basic.rs:352.

Failure evidence

Root cause analysis

Two sources of non-determinism interact in this test:

  1. random_output_header() is called for each of the 10 foundry outputs created in the test loop (lines 320–337). This gives each native token a random Object ID, making the order of objects in the execution result's written map unpredictable across runs.

  2. written.values().find(...) inside extract_native_tokens_from_bag() (in tests/mod.rs) iterates over a HashMap's values in an arbitrary order to locate the expected coin object. When combined with the randomised Object IDs above, the lookup can fail to match the correct coin object and returns Err("missing coin object") — which then propagates to the .unwrap() at basic.rs:352.

Expected behaviour

The test should pass deterministically regardless of Object ID assignment or HashMap iteration order. The lookup logic should not rely on HashMap iteration order to correlate native-token coins with their expected types.

Suggested fix

Replace the HashMap::values().find(...) approach with a lookup keyed on a stable identifier (e.g. the struct tag or token ID) so that the result does not depend on iteration order. Alternatively, use a deterministic data structure (BTreeMap) for the written map if iteration order matters to the test assertions.

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions