Skip to content

test: panics when growing WASM memory - #10783

Merged
mraszyk merged 6 commits into
masterfrom
mraszyk/memory-grow-panic-system-test
Jul 16, 2026
Merged

mraszyk merged 6 commits into
masterfrom
mraszyk/memory-grow-panic-system-test

Conversation

@mraszyk

@mraszyk mraszyk commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This PR implements regression tests for this PR.

Unit tests (rs/execution_environment/tests/canister_snapshots.rs):

  1. upload_and_load_snapshot_with_wasm_memory — Uploads a snapshot declaring 2 MiB (32 pages) of wasm memory for a (memory 1 1) module, loads it, and asserts inc fails gracefully (the
    1-page max can't grow to 32).
  2. upgrade_with_keep_heap_exceeds_module_max_fails_gracefully — Installs a 20-page module with orthogonal persistence, upgrades to (memory 1 1) with wasm_memory_persistence: Keep,
    and asserts the retained 20-page heap exceeding the new 1-page max fails gracefully.

System test (rs/tests/execution/general_execution_tests/canister_snapshots.rs):
3. upload_and_load_snapshot_with_wasm_memory — The end-to-end mirror of unit test #1: same setup driven over the public API against an application subnet (heap uploaded in 1 MiB
chunks), asserting inc fails gracefully rather than panicking the replica.

All three exercise the same code path — the embedder returning IC0521 ("Failed to grow wasm memory … exceeds module's declared maximum") instead of the old .expect("memory grow failed") panic.

mraszyk and others added 4 commits June 29, 2026 07:49
The system test loaded a 2 MiB snapshot heap into a `(memory 1 1)` module,
which cannot grow to the snapshot's 32 pages, so `inc` fails gracefully with
IC0521. Assert the graceful failure (mirroring the unit test) instead of
expecting the call to succeed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions github-actions Bot added the test label Jul 15, 2026
Assert the exact IC0521 (CanisterWasmEngineError) error message in the two
graceful-failure unit tests instead of a bare is_err(). Also fix pre-existing
clippy lints in both test files (unseparated_literal_suffix on integer literals
and needless_borrows_for_generic_args on the wat::parse_str arguments).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Copilot AI 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.

Pull request overview

Adds regression tests to ensure canister snapshot loading/upgrade paths fail with a proper wasm-engine error (rather than panicking) when the snapshot/retained heap requires growing Wasm memory beyond a module’s declared maximum.

Changes:

  • Add a new end-to-end system test that uploads a snapshot with a larger declared wasm_memory_size than the module’s (memory 1 1) max and verifies the ensuing call fails.
  • Add two state-machine unit tests covering (1) snapshot load with oversized wasm memory and (2) upgrade with wasm_memory_persistence: Keep where the retained heap exceeds the new module max.
  • Wire the new system test module into the general execution test suite.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
rs/tests/execution/general_execution_tests/mod.rs Exposes the new canister_snapshots system-test module.
rs/tests/execution/general_execution_tests/canister_snapshots.rs Adds an end-to-end snapshot upload/load test intended to catch prior embedder panics when memory growth exceeds module max.
rs/tests/execution/general_execution_test.rs Registers the new system test in the execution test runner.
rs/execution_environment/tests/canister_snapshots.rs Adds state-machine regression tests asserting specific wasm-engine error behavior for snapshot load and upgrade-with-keep scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mraszyk
mraszyk marked this pull request as ready for review July 15, 2026 15:09
@mraszyk
mraszyk requested a review from a team as a code owner July 15, 2026 15:09
@zeropath-ai

zeropath-ai Bot commented Jul 15, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to 7ff5d05.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/execution_environment/tests/canister_snapshots.rs
    upload_and_load_snapshot_with_wasm_memory
► rs/tests/execution/general_execution_test.rs
    upload_and_load_snapshot_with_wasm_memory
► rs/tests/execution/general_execution_tests/canister_snapshots.rs
    upload_and_load_snapshot_with_wasm_memory
Enhancement ► rs/tests/execution/general_execution_test.rs
    Upgrade test addition: upgrade_with_keep_heap_exceeds_module_max_fails_gracefully
Enhancement ► rs/tests/execution/general_execution_tests/canister_snapshots.rs
    upload_and_load_snapshot_with_wasm_memory
Enhancement ► rs/tests/execution/general_execution_tests/mod.rs
    pub mod canister_snapshots

@mraszyk
mraszyk added this pull request to the merge queue Jul 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 2026
@mraszyk
mraszyk added this pull request to the merge queue Jul 16, 2026
Merged via the queue into master with commit 88f609f Jul 16, 2026
40 checks passed
@mraszyk
mraszyk deleted the mraszyk/memory-grow-panic-system-test branch July 16, 2026 19:23
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.

3 participants