Skip to content

Commit f353b5d

Browse files
committed
fix: another anchor test fix
1 parent 62ad6e6 commit f353b5d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/orderMarginChecks.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ describe('order margin checks with isolated positions', () => {
187187

188188
// Reset user state between tests
189189
async function resetUserState() {
190+
// Restore oracle feeds to default prices so tests start with deterministic state
191+
await setFeedPriceNoProgram(bankrunContextWrapper, 100, solUsd);
192+
await setFeedPriceNoProgram(bankrunContextWrapper, 1000, ethUsd);
193+
190194
await driftClient.fetchAccounts();
191195

192196
// Close any open positions
@@ -197,6 +201,8 @@ describe('order margin checks with isolated positions', () => {
197201
await driftClient.closePosition(perpPosition.marketIndex);
198202
} catch (e) {
199203
// Ignore errors when closing
204+
} finally {
205+
await driftClient.fetchAccounts();
200206
}
201207
}
202208
}
@@ -430,7 +436,7 @@ describe('order margin checks with isolated positions', () => {
430436
// Cross: $800 collateral, 10 SOL cross position ($500 IM required) -> passes with $300 buffer
431437
// Isolated: 1 ETH with $550 collateral, want to increase by 0.5 ETH
432438
// After increase: 1.5 ETH = $750 IM required, but only $550 isolated collateral
433-
// Shortfall: $200. Cross provides $200, cross has $600 vs $500 IM -> passes
439+
// Shortfall: $202. Cross provides $202, cross has $598 vs $500 IM -> passes
434440

435441
// Deposit initial cross collateral
436442
await driftClient.deposit(
@@ -472,8 +478,14 @@ describe('order margin checks with isolated positions', () => {
472478
// Cross already at effective $800 from oracle move above
473479
await driftClient.fetchAccounts();
474480

475-
// Now increase isolated position by 0.5 ETH - should pass
476-
// Shortfall of $200 from cross leaves cross with $600 > $500 IM -> passes
481+
// $202 from cross leaves cross with $598 > $500 IM -> passes (202 because of rounding)
482+
await driftClient.depositIntoIsolatedPerpPosition(
483+
new BN(202 * 10 ** 6),
484+
1,
485+
userUSDCAccount.publicKey
486+
);
487+
488+
// Now increase isolated position by 0.5 ETH - should pass with $750 collateral on IM
477489
const txSig = await driftClient.placePerpOrder(
478490
getOrderParams({
479491
orderType: OrderType.MARKET,

0 commit comments

Comments
 (0)