Skip to content

test(stablecoin): add the full position lifecycle integration test - #355

Open
gravityblast wants to merge 1 commit into
feat/stablecoin-close-positionfrom
feat/stablecoin-lifecycle-integration-test
Open

test(stablecoin): add the full position lifecycle integration test#355
gravityblast wants to merge 1 commit into
feat/stablecoin-close-positionfrom
feat/stablecoin-lifecycle-integration-test

Conversation

@gravityblast

Copy link
Copy Markdown
Collaborator

Adds stablecoin_full_position_lifecycle, the end-to-end test that closes out
Plan 3: open → deposit → borrow → accrue → repay → withdraw → close, all through
the zkVM against a really-bootstrapped protocol (initialize_program, not
force-inserted globals).

This is "Mode A" from the issue — Plan 2 has shipped, so accrue_stability_fee
runs between borrowing and repaying. The test asserts the accumulator moves above
FIXED_POINT_ONE and that the accrued nominal debt exceeds the amount minted,
which is the only place §6.3's directional rounding gets exercised at a
non-trivial accumulator.

That fee gap is why the owner is seeded with a stablecoin balance before
borrowing: repaying in full costs more than was minted, so the shortfall has to
come from somewhere — the market, per §2. total_supply is credited to match, or
the chained Burn underflows.

Two things the run surfaced, both already handled in the stack:

  • The bootstrap fixture's oracle is anchored at timestamp 0, which generate_debt's
    staleness gate correctly rejects against a real wall clock. The test seeds a
    fresh observation.
  • close_position cannot clear the account to Account::default(); see feat(stablecoin): add close_position instruction #354.

assert_fungible_balance was hardcoded to the collateral definition, so it grew
an assert_fungible_balance_of variant for the stablecoin holding.

Last of eight issues in Plan 3 (#173). Stacked on #354.

closes #181

Copilot AI 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.

🟡 Changes recommended

The new lifecycle test mutates stablecoin total_supply for the seeded buffer but doesn’t assert post-borrow/repay supply and balances stay consistent, leaving a key end-to-end invariant unverified.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new stablecoin end-to-end integration test that exercises the full “Plan 3” position lifecycle through the zkVM on top of a properly bootstrapped protocol state (via initialize_program), including Plan 2 stability-fee accrual between borrow and repay.

Changes:

  • Add stablecoin_full_position_lifecycle integration test covering open → deposit → borrow → accrue → repay → withdraw → close.
  • Generalize assert_fungible_balance by introducing assert_fungible_balance_of to assert holdings for non-collateral token definitions (stablecoin holdings).
File summaries
File Description
programs/integration_tests/tests/stablecoin.rs Adds the full-lifecycle stablecoin zkVM integration test and a generalized fungible-balance assertion helper.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +984 to +985
assert_eq!(read_position(&state).normalized_debt_amount, 0);

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.

2 participants