From 942739ffdfde5991a2c0ca011d5dac0f8a483c8c Mon Sep 17 00:00:00 2001 From: Vincent ibochi <290086463+ibochivincent-lang@users.noreply.github.com> Date: Mon, 31 Aug 2026 08:40:54 +0100 Subject: [PATCH] test(defindex-adapter): cover deposit()'s NotInitialized panic when DFX_VAULT is unset withdraw() already had this coverage (withdraw_panics_with_typed_error_when_dfx_vault_is_unset); deposit() went through the identical get_or_not_initialized panic path with no test exercising it. --- .../contracts/defindex-adapter/src/lib.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/contracts/defindex-adapter/src/lib.rs b/packages/contracts/defindex-adapter/src/lib.rs index 03d551e..76e3354 100644 --- a/packages/contracts/defindex-adapter/src/lib.rs +++ b/packages/contracts/defindex-adapter/src/lib.rs @@ -395,6 +395,27 @@ mod tests { adapter.withdraw(&amount, &recipient); } + #[test] + #[should_panic] + fn deposit_panics_with_typed_error_when_dfx_vault_is_unset() { + // The deposit()-side counterpart to + // withdraw_panics_with_typed_error_when_dfx_vault_is_unset above: + // __constructor always sets DFX_VAULT on any real deployment, so + // this state is unreachable in practice; this test clears it + // directly after construction to prove deposit() still fails with + // the typed NotInitialized panic rather than an opaque unwrap trap + // if that invariant is ever violated by a future change. + let (env, _vault, _usdc, adapter, _dfx) = setup(); + + env.as_contract(&adapter.address, || { + env.storage().instance().remove(&DFX_VAULT); + }); + + // The NotInitialized check runs before any token movement, so no + // USDC funding is needed to reach it. + adapter.deposit(&100_0000000_i128); + } + #[test] fn get_protocol_returns_defindex() { let (env, _vault, _usdc, adapter, _dfx) = setup();