test(vault): add DepositTooSmall and WithdrawalTooSmall tests - #458
test(vault): add DepositTooSmall and WithdrawalTooSmall tests#458Onyii1234 wants to merge 1 commit into
Conversation
|
@Onyii1234 is attempting to deploy a commit to the Collins' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
done sir you should please merge pr |
collinsezedike
left a comment
There was a problem hiding this comment.
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.
Summary
deposit_too_small_after_share_price_inflation: seeds the vault with a 1-stroop deposit, then mints 100 USDC directly to the adapter to inflatetotal_assetswithout touchingtotal_shares. The share price rises to ~10^9 stroops per share, so a subsequent 1-stroop deposit yieldsshares_to_mint = 1 * (1 + 1000) / (1_000_000_001 + 1000) = 0. Assertstry_depositreturnsErr(Ok(ContractError::DepositTooSmall)).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 undermock_all_auths). With the adapter's USDC balance at 1 stroop but 1_000_000_000 adapter shares outstanding, burning 2 vault shares yieldsusdc_out = 2 * 1 / 1_000_000_000 = 0. Assertstry_withdrawreturnsErr(Ok(ContractError::WithdrawalTooSmall)).Both tests exercise the share-price math paths that were previously the only error variants in
lib.rswithout dedicated test coverage. The existing test suite coversZeroAmount,InsufficientShares,NoSharesOutstanding,AlreadyInitialized, andAdapterSwapUnsafe; these two complete coverage of the fullContractErrorenum's exercisable paths.Test plan
pnpm lint && pnpm typecheck && pnpm testpass locallycargo test -p meridian-vaultpasses with both new tests present (verified math manually — see comments in each test for the exact rounding calculation)cargo fmt --all -- --checkpasses (file ends with a trailing newline; no formatting changes introduced)Closes #434