Skip to content

Commit

Permalink
Merge pull request #52 from Kwenta/arbitrum-release-zap-etch
Browse files Browse the repository at this point in the history
vm.etch for tests
  • Loading branch information
Flocqst authored Oct 14, 2024
2 parents e6db3ac + a18ae47 commit 9eca450
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 400 deletions.
160 changes: 79 additions & 81 deletions test/AsyncOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,86 +25,84 @@ contract AsyncOrderTest is Bootstrap, SynthetixMock {
}
}

/// @custom:todo rewrite commented tests with hardhat
/// cause : InvalidFEOpcode when calling getPricesInWei on Arbitrum
contract CommitOrder is AsyncOrderTest {
// function test_commitOrder() public {
// vm.prank(ACTOR);

// (IPerpsMarketProxy.Data memory retOrder, uint256 fees) = engine
// .commitOrder({
// _perpsMarketId: SETH_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// });

// assertTrue(retOrder.settlementTime != 0);
// assertTrue(retOrder.request.marketId == SETH_PERPS_MARKET_ID);
// assertTrue(retOrder.request.accountId == accountId);
// assertTrue(retOrder.request.sizeDelta == SIZE_DELTA);
// assertTrue(
// retOrder.request.settlementStrategyId == SETTLEMENT_STRATEGY_ID
// );
// assertTrue(retOrder.request.acceptablePrice == ACCEPTABLE_PRICE_LONG);
// assertTrue(retOrder.request.trackingCode == TRACKING_CODE);
// assertTrue(retOrder.request.referrer == REFERRER);

// assertTrue(fees != 0);
// }

// function test_commitOrder_invalid_market() public {
// vm.prank(ACTOR);

// vm.expectRevert(
// abi.encodeWithSelector(
// InvalidMarket.selector, INVALID_PERPS_MARKET_ID
// )
// );

// engine.commitOrder({
// _perpsMarketId: INVALID_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// });
// }

// function test_commitOrder_insufficient_collateral() public {
// vm.prank(ACTOR);

// try engine.commitOrder({
// _perpsMarketId: SETH_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA * SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// }) {} catch (bytes memory reason) {
// assertEq(bytes4(reason), InsufficientMargin.selector);
// }
// }

// function test_commitOrder_Unauthorized() public {
// vm.prank(BAD_ACTOR);

// vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));

// engine.commitOrder({
// _perpsMarketId: SETH_PERPS_MARKET_ID,
// _accountId: accountId,
// _sizeDelta: SIZE_DELTA,
// _settlementStrategyId: SETTLEMENT_STRATEGY_ID,
// _acceptablePrice: ACCEPTABLE_PRICE_LONG,
// _trackingCode: TRACKING_CODE,
// _referrer: REFERRER
// });
// }
function test_commitOrder() public {
vm.prank(ACTOR);

(IPerpsMarketProxy.Data memory retOrder, uint256 fees) = engine
.commitOrder({
_perpsMarketId: SETH_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
});

assertTrue(retOrder.settlementTime != 0);
assertTrue(retOrder.request.marketId == SETH_PERPS_MARKET_ID);
assertTrue(retOrder.request.accountId == accountId);
assertTrue(retOrder.request.sizeDelta == SIZE_DELTA);
assertTrue(
retOrder.request.settlementStrategyId == SETTLEMENT_STRATEGY_ID
);
assertTrue(retOrder.request.acceptablePrice == ACCEPTABLE_PRICE_LONG);
assertTrue(retOrder.request.trackingCode == TRACKING_CODE);
assertTrue(retOrder.request.referrer == REFERRER);

assertTrue(fees != 0);
}

function test_commitOrder_invalid_market() public {
vm.prank(ACTOR);

vm.expectRevert(
abi.encodeWithSelector(
InvalidMarket.selector, INVALID_PERPS_MARKET_ID
)
);

engine.commitOrder({
_perpsMarketId: INVALID_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
});
}

function test_commitOrder_insufficient_collateral() public {
vm.prank(ACTOR);

try engine.commitOrder({
_perpsMarketId: SETH_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA * SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
}) {} catch (bytes memory reason) {
assertEq(bytes4(reason), InsufficientMargin.selector);
}
}

function test_commitOrder_Unauthorized() public {
vm.prank(BAD_ACTOR);

vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));

engine.commitOrder({
_perpsMarketId: SETH_PERPS_MARKET_ID,
_accountId: accountId,
_sizeDelta: SIZE_DELTA,
_settlementStrategyId: SETTLEMENT_STRATEGY_ID,
_acceptablePrice: ACCEPTABLE_PRICE_LONG,
_trackingCode: TRACKING_CODE,
_referrer: REFERRER
});
}
}
Loading

0 comments on commit 9eca450

Please sign in to comment.