Skip to content

Cover new credential code paths and drop duplicate address compute#94

Merged
n13 merged 4 commits intoilluzen/wormhole-secretfrom
illuzen/wormhole-secret-review-tests
Apr 18, 2026
Merged

Cover new credential code paths and drop duplicate address compute#94
n13 merged 4 commits intoilluzen/wormhole-secretfrom
illuzen/wormhole-secret-review-tests

Conversation

@n13
Copy link
Copy Markdown
Contributor

@n13 n13 commented Apr 18, 2026

Follow-up on #92 addressing review feedback around test coverage of the new WormholeCredential code paths.

Summary

  • Extract resolve_credential helper in collect_rewards_lib.rs so the WormholeCredential::Mnemonic / WormholeCredential::Secret branches are directly unit-testable instead of being buried inside collect_rewards.
  • Drop the redundant compute_wormhole_address call inside the per-transfer proof loop — the top-level match already produces wormhole_address_bytes with the identical value, so we were hashing the secret once per transfer for no reason.
  • Replace the 6 indirect tests with 7 direct tests that actually exercise resolve_credential (the previous tests re-implemented the logic in a "simulate what WormholeCredential::Secret does" style, so a real bug in the match arm would still pass).
  • Add clap parsing tests for the new three-way mutual exclusion — this is the headline behavior of Allow using secret to collect rewards #92 per its description, so it should have a guardrail.

New tests

collect_rewards_lib::tests:

  • `test_resolve_credential_secret` — Secret branch produces correct (address, address_bytes, secret_bytes)
  • `test_resolve_credential_secret_accepts_0x_prefix`
  • `test_resolve_credential_secret_invalid` — "Invalid secret" error path (too short, bad hex)
  • `test_resolve_credential_mnemonic` — HD derivation branch, self-consistent
  • `test_resolve_credential_mnemonic_index_changes_output`
  • `test_resolve_credential_mnemonic_invalid_phrase` — "HD derivation failed" error path
  • `test_resolve_credential_mnemonic_and_secret_equivalence` — key invariant: derive secret from mnemonic via HD, feed it back as `Secret { hex }`, and verify identical (address, address_bytes, secret_bytes). This is what makes the two variants safely interchangeable.

`cli::wormhole::tests`:

  • `collect_rewards_requires_one_credential` — `required_unless_present_any`
  • `collect_rewards_accepts_each_credential_alone`
  • `collect_rewards_credentials_mutually_exclusive` — all three `conflicts_with_all` pairs (wallet+mnemonic, wallet+secret, mnemonic+secret)

Test plan

  • `cargo test --lib -p quantus-cli` → 88 passed, 0 failed
  • `cargo clippy --lib -p quantus-cli --tests` → clean

Follow-up review feedback for #92. The original PR tested helpers
indirectly (parse_secret_hex_str, compute_wormhole_address) but never
exercised the new match arms in collect_rewards, and left the clap
mutual-exclusion constraints without a guardrail.

- Extract credential resolution into `resolve_credential` so the
  Mnemonic / Secret branches are directly testable, and call it from
  `collect_rewards`.
- Remove the redundant `compute_wormhole_address` call inside the
  per-transfer proof loop now that `wormhole_address_bytes` is already
  produced at the top of the flow.
- Replace the 6 indirect tests with 7 direct tests that actually run
  `resolve_credential`, including a mnemonic -> HD-derived-secret ->
  `Secret { hex }` equivalence test and the `HD derivation failed`
  error path.
- Add 3 clap parsing tests covering `required_unless_present_any` and
  the three `conflicts_with_all` pairs (wallet+mnemonic, wallet+secret,
  mnemonic+secret).
n13 added 3 commits April 18, 2026 12:58
Port the derivation-path fix from main (#93): the wormhole HD path
for `collect_rewards` must be `m/44'/CHAIN/0'/0'/index'` — the
intermediate segment is 0', not 1'. Also move the `derive` progress
call to after resolution so it reports the actual derived SS58
address, matching main's behavior.

Add `test_resolve_credential_mnemonic_pinned_derivation_path` which
pins the expected (address_bytes, secret_bytes) for the canonical
abandon-art test mnemonic at index 0. Any future silent regression of
the path segments will fail this test.
@n13 n13 merged commit a09c969 into illuzen/wormhole-secret Apr 18, 2026
6 checks passed
illuzen added a commit that referenced this pull request Apr 18, 2026
* allow using secret to collect rewards

* add tests

* Cover new credential code paths and drop duplicate address compute (#94)

* Cover new credential code paths and drop duplicate address compute

Follow-up review feedback for #92. The original PR tested helpers
indirectly (parse_secret_hex_str, compute_wormhole_address) but never
exercised the new match arms in collect_rewards, and left the clap
mutual-exclusion constraints without a guardrail.

- Extract credential resolution into `resolve_credential` so the
  Mnemonic / Secret branches are directly testable, and call it from
  `collect_rewards`.
- Remove the redundant `compute_wormhole_address` call inside the
  per-transfer proof loop now that `wormhole_address_bytes` is already
  produced at the top of the flow.
- Replace the 6 indirect tests with 7 direct tests that actually run
  `resolve_credential`, including a mnemonic -> HD-derived-secret ->
  `Secret { hex }` equivalence test and the `HD derivation failed`
  error path.
- Add 3 clap parsing tests covering `required_unless_present_any` and
  the three `conflicts_with_all` pairs (wallet+mnemonic, wallet+secret,
  mnemonic+secret).

* Fix wormhole HD path and pin it with a regression test

Port the derivation-path fix from main (#93): the wormhole HD path
for `collect_rewards` must be `m/44'/CHAIN/0'/0'/index'` — the
intermediate segment is 0', not 1'. Also move the `derive` progress
call to after resolution so it reports the actual derived SS58
address, matching main's behavior.

Add `test_resolve_credential_mnemonic_pinned_derivation_path` which
pins the expected (address_bytes, secret_bytes) for the canonical
abandon-art test mnemonic at index 0. Any future silent regression of
the path segments will fail this test.

* format

---------

Co-authored-by: Nikolaus Heger <nheger@gmail.com>
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.

1 participant