Skip to content

fix(rs-platform-wallet/e2e): bank.fund_address pays fee from input [QA-001b]#3579

Merged
lklimek merged 3 commits intofeat/rs-platform-wallet-e2efrom
fix/bank-fund-deduct-from-input
May 5, 2026
Merged

fix(rs-platform-wallet/e2e): bank.fund_address pays fee from input [QA-001b]#3579
lklimek merged 3 commits intofeat/rs-platform-wallet-e2efrom
fix/bank-fund-deduct-from-input

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented May 4, 2026

Issue being fixed or feature implemented

Stacks on top of #3549.

QA-001b discovered while running the identity e2e suite (id_003_identity_to_identity_credit_transfer): `bank.fund_address(addr, N)` previously used `[ReduceOutput(0)]` fee strategy, so the recipient received `N - fee` (~`N - 9.5M` on testnet) instead of `N`. Tests calling `register_identity_from_addresses({addr: N}, ...)` then failed with `AddressesNotEnoughFundsError` because the address balance was lower than the requested input amount.

This is a framework bug — `bank.fund_address` couples its funding contract with the protocol's fee model in a way that surprises every caller. Tests have to either compensate by passing post-fee amounts everywhere, or by pre-funding extra. Both leak the fee model into test logic that shouldn't care.

What was done?

Switched `bank.fund_address` to `[DeductFromInput(0)]` (already supported by the wallet's `auto_select_inputs` selector at `packages/rs-platform-wallet/src/wallet/platform_addresses/transfer.rs:246`). The bank's own input absorbs the fee; the recipient receives the exact requested amount.

  • New `bank_fee_strategy()` helper in `framework/wallet_factory.rs` returning `[DeductFromInput(0)]`.
  • `bank.fund_address` switched to `bank_fee_strategy()`.
  • `default_fee_strategy()` (= `[ReduceOutput(0)]`) preserved unchanged for self-transfer tests like PA-002b that explicitly assert `Σ outputs + fee == input balance`.

How Has This Been Tested?

  • `cargo check --tests --all-features` — green
  • `cargo clippy --tests --all-features -- -D warnings` — green (zero lints)
  • `cargo fmt --check` — green
  • Live testnet run of `PA-001 transfer_between_two_platform_addresses` — NOT YET RUN (requires testnet env). Worth a smoke check before merge.

Breaking Changes

None. Test-framework only; no change to wallet API.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests (this IS the test framework)
  • I have added "!" to the title and described breaking changes
  • I have made corresponding changes to the documentation if needed (docstring on `fund_address` updated)

🤖 Co-authored by Claudius the Magnificent AI Agent

…ot recipient [QA-001b]

bank.fund_address previously used `[ReduceOutput(0)]`, so recipients
received `funding_per - fee` instead of the requested `funding_per`.
Tests calling `register_identity_from_addresses({addr: funding_per}, ...)`
then failed with `AddressesNotEnoughFundsError` because the address
balance was lower than the requested input amount.

Switch the bank to `[DeductFromInput(0)]` so the bank's own input
absorbs the fee and the recipient receives the exact requested
amount. Other call sites of `default_fee_strategy()` are
unaffected — they keep the `ReduceOutput(0)` semantics that PA tests
rely on.

Reported by Marvin (id_003 retest after QA-001 wait-threshold fix).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba519522-c2cb-43ec-9e62-a4cc46cb4349

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bank-fund-deduct-from-input

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

lklimek and others added 2 commits May 4, 2026 16:28
…nput(0) bank semantics

Under Option C, bank.fund_address uses [DeductFromInput(0)] so the
recipient receives the exact requested amount; the bank's fee is
deducted from its own input and is invisible to the test wallet.

The previous arithmetic derived bank_fee from
(FUNDING_CREDITS - observed_total - transfer_fee), which under the new
strategy always computes 0 — making the bank_fee > 0 assertion at
transfer.rs:169 fail unconditionally.

Replace with a direct bank.total_credits() pre/post comparison:
capture bank_pre before fund_address, resync the bank afterward,
capture bank_post, then bank_fee = bank_pre - bank_post - FUNDING_CREDITS.

Also adds an assert_eq! that addr_1 retains FUNDING_CREDITS minus only
the self-transfer fee (not the bank fee), and updates const comments to
reflect DeductFromInput(0) semantics for the bank step.

Reported by Marvin (PA-001 smoke test on PR #3579).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ReduceOutput(0)] semantics [QA-104]

Previous fix updated bank_fee derivation (bc3fe60) but left the
addr_1 retention assertion wrong: it asserted
addr_1 == FUNDING_CREDITS - transfer_fee, but the protocol's
[ReduceOutput(0)] strategy deducts the fee from output[0]
(addr_2's amount), not from addr_1's residual.

Correct math:
- addr_1 retains FUNDING_CREDITS - TRANSFER_CREDITS (what was sent leaves).
- addr_2 receives TRANSFER_CREDITS - transfer_fee (post-fee delivery).

Reported by Marvin (suite-2 PA-001 rerun on PR #3579).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lklimek lklimek marked this pull request as ready for review May 5, 2026 07:07
@lklimek lklimek requested a review from QuantumExplorer as a code owner May 5, 2026 07:07
@lklimek lklimek merged commit 8c7ec00 into feat/rs-platform-wallet-e2e May 5, 2026
1 of 3 checks passed
@lklimek lklimek deleted the fix/bank-fund-deduct-from-input branch May 5, 2026 07:07
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