Skip to content

Bridge.ReservationAcceptanceAuthorization.test.ts: root-level before() hook runs for the whole mocha suite #1138

Open

Description

@piotr-roslaniec

Observation

solidity/test/bridge/Bridge.ReservationAcceptanceAuthorization.test.ts declares a top-level before(async () => {...}) (line 131) outside any describe(...) block. Mocha treats this as a root hook: it runs once before the entire combined test suite, not scoped to this file, whenever the full hardhat test (no file filter) is invoked.

This is a deliberate, documented design decision, not an oversight (see the comment at lines 228-240 in the same file) - the root hook establishes the shared bridgeFixture() deployment exactly once, and the file's own establishReservationPreconditions() helper re-asserts this file's specific preconditions before each describe block, compensating for state drift from other test files that run between the root hook and this file's own tests in Mocha's combined execution order.

Risk

Because it is a root hook, a failure in it (e.g. an environment/network gap in resolving an external dependency during bridgeFixture()) aborts test collection for the entire suite, not just this file - every other test file's tests report as unrun rather than as their own independent pass/fail. This was observed locally (not in CI) when an external NuCypherToken deployment artifact could not be resolved for the in-memory hardhat network; CI itself resolves this fine, since contracts-build-and-test is green.

Suggested follow-up (not urgent, no functional bug present)

Consider whether the shared-fixture-once-per-suite goal can be achieved with a narrower mechanism (e.g. Mocha's proper mochaHooks.beforeAll root-hook-plugin convention, explicitly opted into, rather than an implicit bare before() at module scope) so a hook failure is visibly scoped to "global setup," and/or add defensive handling so a hook failure surfaces clearly as environment-only rather than looking like every file's fixture broke.

Filed as a documentation/robustness follow-up per PR #1116's review; no code change proposed here since the current behavior is intentional and CI is unaffected.

Activity

  1. linear commented on Sep 9, 2026

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions