Skip to content

Conversation

@Chralt98
Copy link
Member

@Chralt98 Chralt98 commented Dec 3, 2025

What does it do?

It adds the zombienet battery station IT test and fixes #1456 (comment)

What important points should reviewers know?

Is there something left for follow-up PRs?

What alternative implementations were considered?

Are there relevant PRs or issues?

References

Summary by CodeRabbit

  • Tests

    • Added post-upgrade runtime tests for Battery Station and ensured websocket setup runs before related tests
    • Enhanced transaction status tracking with a configurable timeout and broader failure detection
  • Chores

    • Added a Node WebSocket compatibility shim for test environments
  • CI

    • Added a new workflow job to run the Battery Station post-upgrade tests and ensured the shim is loaded in relevant test jobs

✏️ Tip: You can customize this high-level summary in your review settings.

@Chralt98 Chralt98 self-assigned this Dec 3, 2025
@Chralt98 Chralt98 added the s:in-progress The pull requests is currently being worked on label Dec 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

Walkthrough

Adds a Node.js WebSocket shim and loads it in multiple integration tests, extends txStatus with a timeout and unified cleanup, and introduces a new GitHub Actions job for Battery Station zombienet post-upgrade tests with NODE_OPTIONS requiring the shim.

Changes

Cohort / File(s) Change Summary
GitHub Actions workflow
/.github/workflows/integration-tests.yml
Added zombienet_battery_station_upgrade job; set NODE_OPTIONS to --require ./integration-tests/scripts/ws-shim.cjs in several post-upgrade test paths (Zeitgeist, Battery Station, Chopsticks).
Transaction status helper
integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts
txStatus(tx, label)txStatus(tx, label, timeoutMs = 120_000): added timeout handling, a finish() helper for cleanup and logging, expanded failure checks (isDropped, isInvalid, isUsurped, isRetracted, isFinalityTimeout), and improved error propagation.
WebSocket shim & test setup
integration-tests/scripts/ws-shim.cjs, integration-tests/tests/setup-websocket.ts, integration-tests/tests/common-tests.ts, integration-tests/tests/*/*-chopsticks/*test-*.ts
New ws-shim.cjs polyfills global.WebSocket using the ws package; added setup-websocket module that assigns globalThis.WebSocket when missing; imported ./setup-websocket / ../setup-websocket at top of several test files (e.g., integration-tests/tests/common-tests.ts, integration-tests/tests/rt-upgrade-battery-station-chopsticks/test-battery-station-chopsticks-runtime-upgrade.ts, integration-tests/tests/rt-upgrade-zeitgeist-chopsticks/test-zeitgeist-chopsticks-runtime-upgrade.ts) to ensure shim is loaded in Node test runs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect txStatus promise/timeout interactions and finish() cleanup correctness.
  • Verify expanded failure-condition handling and that logging/error messages remain clear.
  • Confirm ws-shim.cjs and setup-websocket.ts correctly polyfill global.WebSocket without side effects across environments.
  • Validate workflow NODE_OPTIONS paths, job steps, and artifact handling in .github/workflows/integration-tests.yml.

Possibly related PRs

Suggested labels

s:accepted

Suggested reviewers

  • robhyrk

Poem

🐰 With whiskers primed and paws that tap,
I plug the webs and mind the gap.
Timers set and tests made snug,
Upgrades pass with one soft hug—
Hoppity hops, the checks unwrap!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding a Zombienet battery station upgrade test and updating integration tests with WebSocket shims and timeout improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chralt98-it-tests-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Chralt98 Chralt98 added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Dec 3, 2025
@Chralt98 Chralt98 requested a review from robhyrk December 3, 2025 09:52
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/integration-tests.yml (1)

167-168: Consider updating GitHub Actions to latest versions.

Static analysis flags actions/checkout@v2 and actions/setup-node@v3 as outdated. While this is consistent with existing jobs in this file, consider updating all jobs to use actions/checkout@v4 and actions/setup-node@v4 in a follow-up to ensure continued compatibility with GitHub Actions runners.

Also applies to: 176-176

integration-tests/pnpmfile.cjs (1)

22-27: Consider combining the two conditions.

These two conditions apply the same transformation and could be consolidated for clarity.

-      if (pkg.name === "polkadot-api_ws-provider_web") {
-        redirectToNode(pkg);
-      }
-      if (pkg.name === "polkadot-api_ws-provider") {
+      if (
+        pkg.name === "polkadot-api_ws-provider_web" ||
+        pkg.name === "polkadot-api_ws-provider"
+      ) {
         redirectToNode(pkg);
       }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39ad8d6 and 5954e43.

📒 Files selected for processing (3)
  • .github/workflows/integration-tests.yml (1 hunks)
  • integration-tests/pnpmfile.cjs (1 hunks)
  • integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts (1)
node/src/cli.rs (1)
  • status (451-453)
🪛 actionlint (1.7.9)
.github/workflows/integration-tests.yml

168-168: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


176-176: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build Parachain
  • GitHub Check: Summary
🔇 Additional comments (4)
.github/workflows/integration-tests.yml (1)

162-216: LGTM!

The new zombienet_battery_station_upgrade job correctly mirrors the structure of the existing zombienet_zeitgeist_upgrade job, with appropriate path adjustments for battery-station-runtime artifacts.

integration-tests/pnpmfile.cjs (1)

1-35: Well-documented workaround for Node.js compatibility.

The hook clearly explains the problem (Moonwall expects global WebSocket) and solution (redirect web imports to node build). The implementation safely handles string fields while passing through non-strings unchanged.

integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts (2)

120-181: Good addition of timeout and comprehensive status handling.

The txStatus function now properly handles:

  • Configurable timeout with cleanup
  • Centralized cleanup via finish helper
  • All terminal failure states (isDropped, isInvalid, isUsurped, isRetracted, isFinalityTimeout)
  • Success on isInBlock or isFinalized

This is a robust improvement over the previous implementation.


140-153: Good logging improvements.

Extracting status to a local variable and including status?.type ?? "unknown" in the log output improves debuggability, especially when investigating failed upgrade tests.

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.28%. Comparing base (39ad8d6) to head (9e88156).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1459   +/-   ##
=======================================
  Coverage   93.28%   93.28%           
=======================================
  Files         181      181           
  Lines       35049    35049           
=======================================
  Hits        32696    32696           
  Misses       2353     2353           
Flag Coverage Δ
tests 93.28% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mergify mergify bot added s:in-progress The pull requests is currently being worked on and removed s:review-needed The pull request requires reviews labels Dec 3, 2025
@Chralt98 Chralt98 added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Dec 3, 2025
@mergify mergify bot added s:in-progress The pull requests is currently being worked on and removed s:review-needed The pull request requires reviews labels Dec 3, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/integration-tests.yml (1)

169-169: Consider updating GitHub Actions versions across the workflow.

actions/checkout@v2 and actions/setup-node@v3 are outdated; the current stable versions are v6 for both. While the new job follows the existing pattern in this file, updating all action versions in a follow-up PR would improve security, compatibility, and support.

Also applies to: 177-177

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 494a12f and 4925037.

📒 Files selected for processing (2)
  • .github/workflows/integration-tests.yml (3 hunks)
  • integration-tests/scripts/ws-shim.cjs (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.9)
.github/workflows/integration-tests.yml

169-169: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


177-177: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: Fuzz
  • GitHub Check: Test parachain build
  • GitHub Check: Checks (clippy)
  • GitHub Check: Checks (parachain)
  • GitHub Check: Test standalone build
  • GitHub Check: Quick check benchmarks
  • GitHub Check: Checks (standalone)
  • GitHub Check: Format
  • GitHub Check: Coverage
  • GitHub Check: Coverage
  • GitHub Check: Quick check benchmarks
  • GitHub Check: Test parachain build
  • GitHub Check: Fuzz
  • GitHub Check: Test standalone build
  • GitHub Check: Format
  • GitHub Check: Checks (standalone)
  • GitHub Check: Checks (clippy)
  • GitHub Check: Checks (parachain)
  • GitHub Check: Build Parachain
  • GitHub Check: Summary
🔇 Additional comments (6)
.github/workflows/integration-tests.yml (5)

160-160: LGTM! WebSocket polyfill correctly configured.

The NODE_OPTIONS export properly preloads the ws-shim.cjs to ensure WebSocket support is available before test execution.


217-217: LGTM! WebSocket polyfill correctly configured.

The NODE_OPTIONS export properly preloads the ws-shim.cjs to ensure WebSocket support is available before test execution.


266-266: LGTM! WebSocket polyfill correctly configured.

The NODE_OPTIONS export properly preloads the ws-shim.cjs to ensure WebSocket support is available before test execution.


322-322: LGTM! WebSocket polyfill correctly configured.

The NODE_OPTIONS export properly preloads the ws-shim.cjs to ensure WebSocket support is available before test execution.


163-219: LGTM! Battery Station test job properly structured.

The new zombienet_battery_station_upgrade job correctly mirrors the existing Zeitgeist upgrade test pattern with appropriate path adjustments for the battery-station runtime. All necessary setup steps are included, and the WebSocket polyfill is properly configured.

integration-tests/scripts/ws-shim.cjs (1)

1-4: LGTM! The ws dependency is properly configured.

The WebSocket polyfill is correctly implemented. The ws package (v8.17.1) is installed as a devDependency in integration-tests, and the conditional check properly ensures existing WebSocket implementations aren't overridden.

@Chralt98 Chralt98 added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Dec 3, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
integration-tests/tests/common-tests.ts (1)

65-95: canSendBalanceTransfer never breaks on success because txHash is an unawaited promise.

At line 70, const txHash = tx.signAndSend(alice); is missing await. Without it, txHash is a Promise object rather than the actual extrinsic hash. When line 91 compares includedTxHashes.includes(txHash.toString()), it's comparing real hashes against "[object Promise]", which always fails. The loop then retries up to MAX_BALANCE_TRANSFER_TRIES times even when the first transfer succeeds.

Also at line 66, the await on paraApi.tx.balances.transferAllowDeath(...) is unnecessary since it's a synchronous call that returns an extrinsic object immediately.

Fix:

  while (tries < MAX_BALANCE_TRANSFER_TRIES) {
-   const tx = await paraApi.tx.balances.transferAllowDeath(
+   const tx = paraApi.tx.balances.transferAllowDeath(
      randomAccount.address,
      amount
    );
-   const txHash = tx.signAndSend(alice);
+   const txHash = await tx.signAndSend(alice);
🧹 Nitpick comments (1)
integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts (1)

102-181: txStatus timeout/cleanup is robust; consider fixing hash log labels and a small edge case.

The refactored txStatus looks solid:

  • Central finish helper reliably clears the timeout, logs an optional message, unsubscribes, and settles the promise.
  • Timeouts now reject with a clear error, preventing tests from hanging indefinitely.
  • You explicitly treat dropped/invalid/usurped/retracted/finality-timeout statuses as failures, which makes debugging much easier.
  • Success is cleanly gated on isInBlock or isFinalized.

Two small refinements you might want to make:

  1. Swap the “current” vs “new” runtime hash logging (diagnostic clarity only).

    Around the “Runtime not upgraded, proceeding with test” branch, codeString is the on-chain code and rtHex is read from the upgrade file, but the labels are reversed:

    log(
      "Current runtime hash: " +
        rtHex.slice(0, 10) + "..." + rtHex.slice(-10)
    );
    log(
      "New runtime hash: " +
        codeString.slice(0, 10) + "..." + codeString.slice(-10)
    );

    Swapping them keeps logs intuitive:

  •      log(
    
  •        "Current runtime hash: " +
    
  •          rtHex.slice(0, 10) +
    
  •          "..." +
    
  •          rtHex.slice(-10)
    
  •      );
    
  •      log(
    
  •        "New runtime hash: " +
    
  •          codeString.slice(0, 10) +
    
  •          "..." +
    
  •          codeString.slice(-10)
    
  •      );
    
  •      log(
    
  •        "Current runtime hash: " +
    
  •          codeString.slice(0, 10) +
    
  •          "..." +
    
  •          codeString.slice(-10)
    
  •      );
    
  •      log(
    
  •        "New runtime hash: " +
    
  •          rtHex.slice(0, 10) +
    
  •          "..." +
    
  •          rtHex.slice(-10)
    
  •      );
    
    
    
  1. Optional: guard against a synchronous throw from tx.signAndSend.

    In the unlikely event that tx.signAndSend throws synchronously (before returning its promise), the executor will reject the outer promise but the timeout will still fire later and log a misleading “timed out” error. Wrapping the call in a try/catch would avoid that:

  •        tx.signAndSend(alice, (result: any) => {
    
  •        try {
    
  •          tx.signAndSend(alice, (result: any) => {
    

@@

  •        })
    
  •          .then((unsub: () => void) => {
    
  •            unsubscribe = unsub;
    
  •          })
    
  •          .catch((err: any) => {
    
  •            clearTimeout(timeout);
    
  •            reject(err);
    
  •          });
    
  •          })
    
  •            .then((unsub: () => void) => {
    
  •              unsubscribe = unsub;
    
  •            })
    
  •            .catch((err: any) => {
    
  •              clearTimeout(timeout);
    
  •              reject(err);
    
  •            });
    
  •        } catch (err: any) {
    
  •          clearTimeout(timeout);
    
  •          reject(err);
    
  •        }
    
    
    

Both points are small, but they improve debuggability and make the helper fully defensive.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4925037 and 9e88156.

📒 Files selected for processing (5)
  • integration-tests/tests/common-tests.ts (1 hunks)
  • integration-tests/tests/rt-upgrade-battery-station-chopsticks/test-battery-station-chopsticks-runtime-upgrade.ts (1 hunks)
  • integration-tests/tests/rt-upgrade-zeitgeist-chopsticks/test-zeitgeist-chopsticks-runtime-upgrade.ts (1 hunks)
  • integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts (2 hunks)
  • integration-tests/tests/setup-websocket.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Cargo Deny
  • GitHub Check: Fuzz
  • GitHub Check: Quick check benchmarks
  • GitHub Check: Format
  • GitHub Check: Build Parachain
  • GitHub Check: Summary
🔇 Additional comments (5)
integration-tests/tests/setup-websocket.ts (1)

1-7: Global WebSocket shim is minimal and idempotent (LGTM).

The guard around g.WebSocket keeps this side-effect safe across repeated imports and avoids clobbering any existing implementation.

integration-tests/tests/common-tests.ts (1)

19-19: WebSocket setup import placement looks good.

Placing import "./setup-websocket"; first ensures the global WebSocket is initialized before the rest of the test utilities run.

integration-tests/tests/rt-upgrade-zeitgeist-chopsticks/test-zeitgeist-chopsticks-runtime-upgrade.ts (1)

19-19: WebSocket setup import correctly ordered.

Importing "../setup-websocket" first ensures the WebSocket shim is in place before the chopsticks tests interact with the chain APIs.

integration-tests/tests/rt-upgrade-battery-station-chopsticks/test-battery-station-chopsticks-runtime-upgrade.ts (1)

19-19: Consistent WebSocket setup for battery station tests.

Bringing in "../setup-websocket" at the top mirrors the other upgrade suites and ensures a global WebSocket is available before these tests run.

integration-tests/tests/rt-upgrade-zombienet/test-zombienet-runtime-upgrade.ts (1)

19-19: WebSocket setup import aligns zombienet test with other suites.

The side-effect import of "../setup-websocket" ensures the runtime upgrade test has a global WebSocket available before creating API connections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s:review-needed The pull request requires reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants