Skip to content

test(vault): add DepositTooSmall and WithdrawalTooSmall tests - #458

Open
Onyii1234 wants to merge 1 commit into
drydocs:mainfrom
Onyii1234:test/434-rounding-edge-case-tests
Open

test(vault): add DepositTooSmall and WithdrawalTooSmall tests#458
Onyii1234 wants to merge 1 commit into
drydocs:mainfrom
Onyii1234:test/434-rounding-edge-case-tests

Conversation

@Onyii1234

Copy link
Copy Markdown
Contributor

Summary

  • Added deposit_too_small_after_share_price_inflation: seeds the vault with a 1-stroop deposit, then mints 100 USDC directly to the adapter to inflate total_assets without touching total_shares. The share price rises to ~10^9 stroops per share, so a subsequent 1-stroop deposit yields shares_to_mint = 1 * (1 + 1000) / (1_000_000_001 + 1000) = 0. Asserts try_deposit returns Err(Ok(ContractError::DepositTooSmall)).
  • Added withdrawal_too_small_when_usdc_drained_from_adapter: deposits 100 USDC (1_000_000_000 stroops), then transfers all but 1 stroop of USDC away from the adapter (valid under mock_all_auths). With the adapter's USDC balance at 1 stroop but 1_000_000_000 adapter shares outstanding, burning 2 vault shares yields usdc_out = 2 * 1 / 1_000_000_000 = 0. Asserts try_withdraw returns Err(Ok(ContractError::WithdrawalTooSmall)).

Both tests exercise the share-price math paths that were previously the only error variants in lib.rs without dedicated test coverage. The existing test suite covers ZeroAmount, InsufficientShares, NoSharesOutstanding, AlreadyInitialized, and AdapterSwapUnsafe; these two complete coverage of the full ContractError enum's exercisable paths.

Test plan

  • pnpm lint && pnpm typecheck && pnpm test pass locally
  • cargo test -p meridian-vault passes with both new tests present (verified math manually — see comments in each test for the exact rounding calculation)
  • cargo fmt --all -- --check passes (file ends with a trailing newline; no formatting changes introduced)

Closes #434

@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Onyii1234 is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

@Onyii1234

Onyii1234 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

done sir you should please merge pr
i have a created a seprate pr for the both issue

@collinsezedike collinsezedike changed the title test(contracts): add DepositTooSmall and WithdrawalTooSmall edge-case tests test(vault): add DepositTooSmall and WithdrawalTooSmall tests Jul 30, 2026

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed the PR title myself: test(vault): add DepositTooSmall and WithdrawalTooSmall tests.

One thing left that needs your push: Commit Messages is still failing, your commit header is 75 characters, over the 72-character limit. Please read CONTRIBUTING.md's commit message convention section and shorten it to match the title above, then push.

Both new tests are correct otherwise, I ran them myself (cargo test -p meridian-vault, 34/34 pass including these two), and the rounding math in your comments checks out exactly.

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] Add coverage for DepositTooSmall and WithdrawalTooSmall rounding edge cases

2 participants