Skip to content

test(cross-chain): pin the LayerZero delivery-guard keys - #815

Merged
mergekeeper[bot] merged 1 commit into
accensa:mainfrom
olatecki:test/issue-619-layerzero-peer-keys
Oct 17, 2026
Merged

mergekeeper[bot] merged 1 commit into
accensa:mainfrom
olatecki:test/issue-619-layerzero-peer-keys

Conversation

@olatecki

@olatecki olatecki commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #619

What changed

file why
contracts/cross-chain/src/layerzero_test.rs a delivery_guard_keys module appended — 4 tests
contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/*.json the snapshots those tests generate, following the 23 already committed under contracts/cross-chain/test_snapshots/
CHANGELOG.md an [Unreleased] entry

layerzero.rs is unmodified (read-only per the issue), no entry point was added,
no Error variant changed, the existing setup helpers and the mock endpoint are
untouched, and ROADMAP.md is not edited.

On CHANGELOG.md: the changelog & version check job fails any PR touching
contracts/*/src/ without a CHANGELOG.md change unless it carries the
skip-changelog label, which I can't apply. PR #808 — also test-only — added an
entry the same way. Happy to drop that file if a maintainer prefers to label it.

The four behaviours #619 lists were already pinned

Worth saying up front, because it changes what this PR contains.
layerzero_test.rs does not name TrustedPeer, PeerNonce or DisputeSettled
— but only because the existing tests read state back through the getters,
exactly as the issue asks them to. The behaviours themselves landed with
ddd24bb on 2026-09-28, twelve days before the issue was filed:

#619 asks for already covered by
unregistered (chain_id, sender) rejected untrusted_peer_is_rejected, wrong_chain_is_rejected_even_for_a_trusted_peer
first accepted nonce stores PeerNonce authorized_endpoint_delivers_dispute_resolution (get_peer_nonce == 1)
lower or equal nonce rejected replayed_and_stale_nonces_are_rejected (nonce 5 again, then 4)
higher nonce advances the stored value later_nonces_are_accepted_and_advance_the_channel (1 → 7)
second settle refused by DisputeSettled settled_dispute_cannot_be_settled_again (Error::AlreadyRefunded)

So this does not restate them in a second harness. It closes what the issue's own
"What done looks like" left open:

  1. layerzero.rs:116 — TrustedPeer. is_trusted_peer had no coverage
    anywhere in the suite. only_the_registered_pair_is_trusted asserts the peer
    set is keyed by the whole (chain_id, sender) pair: the registered pair is
    trusted, and neither the same sender on another chain nor another sender on
    the same chain is.
  2. layerzero.rs:118 — PeerNonce. the_mark_holds_the_highest_accepted_nonce
    asserts the mark reads 0 before any delivery, takes the accepted packet's
    nonce, accepts a strictly higher nonce that skips packets never delivered
    (2 → 9), and then refuses every nonce at or below it, 3..=9. That loop is
    what pins nonce <= last rather than nonce < last, including the gap the
    jump skipped.
  3. layerzero.rs:120 — DisputeSettled. a_settled_dispute_publishes_one_event_and_stays_settled
    asserts the accepted delivery publishes exactly one event, that a second packet
    naming that dispute is refused with AlreadyRefunded, and that the channel
    still advances for a dispute that has not been settled.
  4. a_packet_from_an_unregistered_channel_is_refused covers the wrong-chain
    refusal end to end: a packet naming a chain the peer was never registered on is
    Unauthorized, and the trusted channel still takes its own first packet after.

No getter is missing — is_trusted_peer, get_peer_nonce and is_dispute_settled
cover all three keys, so none was added. TrustedPeer is readable only as a
boolean, which is all the assertions above need.

What these tests cannot prove

One criterion in the issue — a second settle "emits no duplicate event" — is not
observable, and the module says so instead of carrying an assertion that cannot
fail. Soroban rolls back a refused invocation, storage and events, so a refusal
can never leave either behind. Verified by fault injection rather than assumed:

  • write PeerNonce before the settled-dispute check → the refusal assertions still pass (the write rolls back);
  • publish a duplicate event on the refusal path → the refusal assertions still pass (the event is discarded);
  • publish a duplicate event on the accepted path → the test fails, so the one-event assertion is real.

"Settles exactly once" is therefore pinned by the accepted-path event count plus
the settled-dispute ledger, not by the refusal.

Verification

  • cargo fmt --all -- --check — clean
  • cargo clippy --locked --all-targets -- -D warnings — clean
  • cargo test --locked --workspace — PASS: 1124 tests across all binaries, 0 failures
  • cargo test --locked -p accensa-cross-chain — 40 passed (36 before, 4 new)
  • Specific test proving layerzero.rs:118 is handled:
    layerzero_test::delivery_guard_keys::the_mark_holds_the_highest_accepted_nonce
  • The new snapshots are deterministic — a second run leaves their hashes identical.

Summary by CodeRabbit

  • Tests
    • Expanded coverage of cross-chain LayerZero delivery checks, including trusted-peer matching, nonce acceptance and replay rejection, dispute settlement, and refusal of unregistered channels.
    • Verified that rejected deliveries do not advance the trusted channel’s nonce and that accepted deliveries publish a single event.
  • Documentation
    • Added an unreleased changelog entry describing the test coverage. No contract behavior changed.

Issue accensa#619 asks for the trusted-peer, nonce and settled-dispute keys to be
covered in layerzero_test.rs. The four behaviours it lists were already
pinned by ddd24bb, so this adds the parts of the issue's own "What done looks
like" that were genuinely missing, all read back through the getters the
crate already exposes.

- `is_trusted_peer` had no coverage at all; the peer set is now asserted to
  be keyed by the whole `(chain_id, sender)` pair, not by either half.
- `get_peer_nonce` is asserted absent before any delivery, then taken from
  the accepted packet, and every nonce at or below the mark stays refused
  after a forward jump — pinning `nonce <= last` rather than `nonce < last`.
- A settled dispute now has its accepted delivery asserted to publish exactly
  one event, with the channel still advancing for a dispute that has not been
  settled.

A refused invocation is rolled back by the host, so the module only claims
what can actually fail: the accepted-path assertions. That was checked by
fault injection — writing PeerNonce before the settled-dispute check, and
publishing a duplicate event on the refusal path, both leave refused-path
assertions passing, while a duplicate publish on the accepted path is caught.

Verified: cargo fmt --all -- --check, cargo clippy --locked --all-targets --
-D warnings and cargo test --locked --workspace are all clean, and the
cross-chain suite goes from 36 to 40 tests.

Closes accensa#619

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@olatecki Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@mergekeeper

mergekeeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

MergeKeeper review

Scope: in scope for linked issue #619.
Verdict: clean

The PR successfully adds comprehensive test coverage for LayerZero trusted peer, nonce, and settled dispute keys in contracts/cross-chain/src/layerzero_test.rs along with required snapshots and a changelog entry, fulfilling issue #619 correctly without modifying read-only contract source files.

Reviewed commit: 1772b3ebc8a87dfa3620413407d81dd5732ce12e.
CI and merge eligibility are checked separately.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 92033056-72a4-48a7-b6e2-c5ab8762af40
📥 Commits

Reviewing files that changed from the base of the PR and between 4c51848 and 1772b3e.

📒 Files selected for processing: 6
  • CHANGELOG.md
  • contracts/cross-chain/src/layerzero_test.rs
  • contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/a_packet_from_an_unregistered_channel_is_refused.1.json
  • contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/a_settled_dispute_publishes_one_event_and_stays_settled.1.json
  • contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/only_the_registered_pair_is_trusted.1.json
  • contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/the_mark_holds_the_highest_accepted_nonce.1.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The pull request adds LayerZero integration tests and snapshots for trusted-peer matching, nonce advancement and replay rejection, and dispute-settlement persistence. The changelog describes the additions as test-only and states that contract behavior is unchanged.

Changes: LayerZero delivery-guard tests

Layer / File(s) Summary
Trusted-peer authorization
contracts/cross-chain/src/layerzero_test.rs, contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/*, CHANGELOG.md
Tests check that only the registered (chain_id, sender) pair is trusted and that an unregistered channel is refused. The snapshots record setup and ledger state. The changelog records the tests as test-only.
Accepted nonce tracking
contracts/cross-chain/src/layerzero_test.rs, contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/*
The test checks that the nonce mark starts at zero, advances to higher accepted nonces, and rejects nonces at or below the mark. The snapshot records peer nonce 9.
Dispute settlement and replay rejection
contracts/cross-chain/src/layerzero_test.rs, contracts/cross-chain/test_snapshots/layerzero_test/delivery_guard_keys/*
The test checks that the first delivery publishes one event, a duplicate settlement is rejected, and a fresh dispute can be settled. The snapshot records settled-dispute flags and peer nonce 2.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 1772b

This change only adds tests and documentation for LayerZero delivery guards. It does not change contract behavior, so the risk of merging is minimal.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Out of Scope Changes check Warning The PR adds an [Unreleased] entry to CHANGELOG.md. Issue #619 limits the implementation to contracts/cross-chain/src/layerzero_test.rs and test or fixture files needed by that change. It also st… Remove the CHANGELOG.md change, or obtain an explicit scope exception that permits this changelog entry.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise, specific, and accurately describes the added LayerZero delivery-guard tests.
Description check Passed The description provides a detailed summary, related issue, contract-safety information, changelog rationale, file scope, and verification results. It does not use every template heading or checkbox, …
Linked Issues check Passed Issue #619 is addressed in layerzero_test.rs. The existing tests cover unregistered peers, first nonce storage, stale or replayed nonces, higher nonce advancement, and duplicate settlement refusal. …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (5 skipped: 5 …
Full details: Description check

Explanation

The description provides a detailed summary, related issue, contract-safety information, changelog rationale, file scope, and verification results. It does not use every template heading or checkbox, but it covers the required information.

Full details: Linked Issues check

Explanation

Issue #619 is addressed in layerzero_test.rs. The existing tests cover unregistered peers, first nonce storage, stale or replayed nonces, higher nonce advancement, and duplicate settlement refusal. The appended delivery_guard_keys module adds exact (chain_id, sender) trust coverage, verifies the nonce high-water mark after a forward jump and rejects every nonce at or below it, and verifies one event for an accepted settlement plus refusal of a repeated settlement. The PR reports the required format, clippy, and workspace test checks as passing. The scope restrictions on entry points, errors, setup helpers, layerzero.rs, and ROADMAP.md are respected.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (5 skipped: 5 unsupported.)

Full details: Out of Scope Changes check

Explanation

The PR adds an [Unreleased] entry to CHANGELOG.md. Issue #619 limits the implementation to contracts/cross-chain/src/layerzero_test.rs and test or fixture files needed by that change. It also states that files outside those regions are not in scope. The changelog entry is related documentation, but it is still outside the explicit file boundary. The repository diff was unavailable, so this finding relies on the supplied change summary and the reviewed CHANGELOG.md blob.

Resolution

Remove the CHANGELOG.md change, or obtain an explicit scope exception that permits this changelog entry.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@mergekeeper mergekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved

The PR successfully adds comprehensive test coverage for LayerZero trusted peer, nonce, and settled dispute keys in contracts/cross-chain/src/layerzero_test.rs along with required snapshots and a changelog entry, fulfilling issue #619 correctly without modifying read-only contract source files.

@mergekeeper
mergekeeper Bot merged commit f3cff01 into accensa:main Oct 17, 2026
3 checks passed
@mergekeeper

mergekeeper Bot commented Oct 17, 2026

Copy link
Copy Markdown

Merged

Merged with squash.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: test LayerZero trusted peer, nonce and settled keys

1 participant