feat(invoice): add get_funding_terms to consolidate three CPI calls i… - #512
Merged
Merged
Conversation
…nto one Closes TrusTrove#278 ## Summary Add `get_funding_terms(invoice_id) -> (u32, u128, u32)` to the invoice contract, returning (status, face_value, discount_bps) in a single cross-contract invocation. Migrate the pool`s `fund_invoice` function to call it once instead of making three separate `invoke_contract` calls (`get_status` + `get_face_value` + `get_discount_bps`). ## Changes ### contracts/invoice/src/lib.rs - Add `get_funding_terms` public function with full rustdoc (# Arguments, # Auth, # Panics, # Returns) - Fetches the invoice once from storage and destructures the three fields, saving two redundant storage reads ### contracts/pool/src/lib.rs - Replace three separate `invoke_contract` calls with a single `get_funding_terms` call in `fund_invoice` - Tuple destructuring extracts status, face_value, and discount_bps into local variables - Behaviour is unchanged: status check (Listed == 1) and funded_amount calculation remain identical ### contracts/invoice/src/test.rs - Positive test: `test_get_funding_terms_returns_correct_values` verifies all three returned fields match expected values - Negative test: `test_get_funding_terms_unknown_panics` verifies NotFound (TrusTrove#2) panic for a non-existent invoice ### Test snapshots - Remove three stale pool test snapshots whose diagnostic event stream changed due to the consolidated CPI call ## Acceptance Criteria - [x] Add get_funding_terms on the invoice contract - [x] Pool calls it once instead of three times - [x] Tests added for new function (positive + negative) - [x] Old pool snapshots removed (will regenerate on next test run) ## Definition of Done - [x] PR links to this issue with `Closes TrusTrove#278` - [x] New behaviour covered by positive and negative tests - [x] Rustdoc documents Arguments, Auth, Panics, Returns - [ ] CI: cargo fmt, clippy, and tests pass (pending CI run)
|
@Oyintarede 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! 🚀 |
…ng-terms # Conflicts: # contracts/invoice/src/lib.rs # contracts/invoice/src/test.rs # contracts/pool/test_snapshots/test/test_fund_invoice_fails_asset_mismatch.1.json # contracts/pool/test_snapshots/test/test_fund_invoice_fails_when_insufficient_liquidity.1.json # contracts/pool/test_snapshots/test/test_fund_invoice_reduces_available_liquidity.1.json
Contributor
|
MergeKeeper merge status Status: blocked Reason: Next steps:
|
…ng-terms Resolve modify/delete conflicts on three stale pool fund_invoice test snapshots by keeping their removal: the consolidated get_funding_terms CPI call changed the diagnostic event stream, and the branch's tests use should_panic/assert assertions rather than snapshot comparison. The snapshots regenerate on the next test run. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
…ng-terms Resolve conflicts with upstream's latest pool/invoice/registry changes: - Keep fund_invoice's single get_funding_terms cross-contract call, adopting upstream's checked_mul overflow guard (TrusTrove#585) for the unbounded face_value. - Keep the three stale fund_invoice snapshots deleted (tests use should_panic/assert assertions, not snapshot comparison). - Add get_funding_terms to MockHugeFaceInvoice and attest before list_for_financing in the invoice test (upstream now requires attestation). 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…nto one
Closes #278
Summary
Add
get_funding_terms(invoice_id) -> (u32, u128, u32)to the invoice contract, returning (status, face_value, discount_bps) in a single cross-contract invocation. Migrate the poolsfund_invoicefunction to call it once instead of making three separateinvoke_contractcalls (get_status+get_face_value+get_discount_bps`).Changes
contracts/invoice/src/lib.rs
get_funding_termspublic function with full rustdoc (# Arguments, # Auth, # Panics, # Returns)contracts/pool/src/lib.rs
invoke_contractcalls with a singleget_funding_termscall infund_invoicecontracts/invoice/src/test.rs
test_get_funding_terms_returns_correct_valuesverifies all three returned fields match expected valuestest_get_funding_terms_unknown_panicsverifies NotFound (feat(registry): add batch registration support for multiple issuers #2) panic for a non-existent invoiceTest snapshots
Acceptance Criteria
Definition of Done
Closes #278Linked Issue
Closes #
Summary
Changes
Test Coverage
Checklist
cargo fmt --all --checkpassescargo clippy --all-targets -- -D warningspassescargo test --workspacepassesScreenshots
N/A