Skip to content

DeFi Connector Integration Tests#302

Open
UlyanaAndrukhiv wants to merge 7 commits intomainfrom
UlianaAndrukhiv/282-defi-connector-tests
Open

DeFi Connector Integration Tests#302
UlyanaAndrukhiv wants to merge 7 commits intomainfrom
UlianaAndrukhiv/282-defi-connector-tests

Conversation

@UlyanaAndrukhiv
Copy link
Copy Markdown
Contributor

@UlyanaAndrukhiv UlyanaAndrukhiv commented Mar 31, 2026

Closes: #282

Context

This PR adds the remaining missing tests from the issue, with a primary focus on reentrancy scenarios in DeFi actions.

  • Malicious Sink calls back into protocol during deposit
  • Malicious Source calls back during withdrawal
  • Reentrancy guards effectiveness
  • State consistency validation

Notes:

@UlyanaAndrukhiv UlyanaAndrukhiv self-assigned this Mar 31, 2026
@UlyanaAndrukhiv UlyanaAndrukhiv requested a review from mts1715 March 31, 2026 10:51
@UlyanaAndrukhiv UlyanaAndrukhiv marked this pull request as ready for review March 31, 2026 15:28
@UlyanaAndrukhiv UlyanaAndrukhiv requested a review from a team as a code owner March 31, 2026 15:28
access(contract) var uniqueID: DeFiActions.UniqueIdentifier?
/// An unentitled Capability on the Vault to which deposits are distributed
access(self) let depositVault: Capability<&{FungibleToken.Vault}>
access(all) let liveDataCap: Capability<&LiveData>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe access(self) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My changes were based on the existing VaultSourceHacked struct to keep things consistent. I’m not sure it matters much, though, since this contract is used for testing only.

@UlyanaAndrukhiv UlyanaAndrukhiv requested a review from a team April 2, 2026 08:37
Copy link
Copy Markdown
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Looks good -- just one test that we already cover elsewhere.

Comment on lines +214 to +219
// -----------------------------------------------------------------------------
/// Swapper returns 10 % less collateral than quoted.
///
/// The protocol validates `seizeAmount < quote.inAmount`, which is checked
/// before the swap executes, liquidation tx must revert.
// -----------------------------------------------------------------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is using the manual liquidation path, we aren't actually performing a swap. Instead we are using the swapper as a price reference point to decide whether or not to accept the liquidation request from the liquidator.

When we have automated liquidation where we trade against a DEX, I think a test like this will be useful (although we would need to modify the behaviour of the Swapper so that its quote price differs from its swap price). For now, this test is equivalent to the existing liquidation tests (eg. testManualLiquidation_dexOraclePriceDivergence_dexAboveOracle).

I'd suggest marking this test as TODO when automated liquidation is implemented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point — that makes sense.
I’ve added a TODO and clarified the intent so we can update it once automated liquidation is implemented.

UlyanaAndrukhiv and others added 2 commits April 3, 2026 12:01
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.

DeFi Connector Integration Tests

3 participants