diff --git a/contract/test/Day4PriceUpdate.t.sol b/contract/test/Day4PriceUpdate.t.sol index 8242645..142dd3c 100644 --- a/contract/test/Day4PriceUpdate.t.sol +++ b/contract/test/Day4PriceUpdate.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.20; import "./utils/ExchangeFixture.sol"; -import "../../src/core/ExchangeStorage.sol"; +import "../src/core/ExchangeStorage.sol"; // import "./mocks/MockPyth.sol"; // Day 4: Pyth 价格更新(模板级别,使用本地 mock) diff --git a/contract/test/PositionMargin.t.sol b/contract/test/PositionMargin.t.sol index cb97623..71d8a23 100644 --- a/contract/test/PositionMargin.t.sol +++ b/contract/test/PositionMargin.t.sol @@ -109,14 +109,14 @@ contract PositionMarginTest is Test { // 诊断信息 aliceMargin = exchange.margin(alice); - MonadPerpExchange.Position memory alicePos = exchange.getPosition(alice); + MonadPerpExchange.Position memory alicePosAfterTrade = exchange.getPosition(alice); console.log("\nDiagnostics:"); console.log(" Alice margin:", aliceMargin / 1e18, "ETH"); - console.log(" Alice position size:", uint256(alicePos.size)); - console.log(" Alice position entry:", alicePos.entryPrice / 1e18, "ETH"); + console.log(" Alice position size:", uint256(alicePosAfterTrade.size)); + console.log(" Alice position entry:", alicePosAfterTrade.entryPrice / 1e18, "ETH"); // 计算理论保证金需求 - uint256 positionNotional = uint256(alicePos.size) * exchange.markPrice() / 1e18; + uint256 positionNotional = uint256(alicePosAfterTrade.size) * exchange.markPrice() / 1e18; uint256 positionMargin = positionNotional * exchange.initialMarginBps() / 10_000; console.log(" Current position margin needed:", positionMargin / 1e18, "ETH"); @@ -124,7 +124,7 @@ contract PositionMarginTest is Test { uint256 newOrderMargin = newOrderNotional * exchange.initialMarginBps() / 10_000; console.log(" New order margin needed:", newOrderMargin / 1e18, "ETH"); - fail("Trade #2 failed"); + assertTrue(false, "Trade #2 failed"); } // Step 5: Trade #3 - 1490 @ 0.015 ETH @@ -144,7 +144,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Alice buy order failed!"); console.log("Reason:", reason); - fail("Trade #3 failed"); + assertTrue(false, "Trade #3 failed"); } // Step 6: Trade #4 - 1550 @ 0.03 ETH @@ -164,7 +164,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Alice buy order failed!"); console.log("Reason:", reason); - fail("Trade #4 failed"); + assertTrue(false, "Trade #4 failed"); } console.log("\n==========================================="); @@ -181,7 +181,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Alice buy @ 1400 failed!"); console.log("Reason:", reason); - fail("Alice buy order @ 1400 failed"); + assertTrue(false, "Alice buy order @ 1400 failed"); } vm.prank(alice); @@ -190,7 +190,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Alice buy @ 1450 failed!"); console.log("Reason:", reason); - fail("Alice buy order @ 1450 failed"); + assertTrue(false, "Alice buy order @ 1450 failed"); } vm.prank(bob); @@ -199,7 +199,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Bob sell @ 1600 failed!"); console.log("Reason:", reason); - fail("Bob sell order @ 1600 failed"); + assertTrue(false, "Bob sell order @ 1600 failed"); } vm.prank(bob); @@ -208,7 +208,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Bob sell @ 1650 failed!"); console.log("Reason:", reason); - fail("Bob sell order @ 1650 failed"); + assertTrue(false, "Bob sell order @ 1650 failed"); } // Step 8: Creating Partial Fills @@ -222,7 +222,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Alice buy @ 1580 failed!"); console.log("Reason:", reason); - fail("Alice buy order @ 1580 failed"); + assertTrue(false, "Alice buy order @ 1580 failed"); } vm.prank(bob); @@ -231,7 +231,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Bob sell @ 1580 failed!"); console.log("Reason:", reason); - fail("Bob sell @ 1580 failed"); + assertTrue(false, "Bob sell @ 1580 failed"); } // Scenario 2: Bob Sell 0.02 @ 1620, Alice Buy 0.005 @ 1620 @@ -241,7 +241,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Bob sell @ 1620 failed!"); console.log("Reason:", reason); - fail("Bob sell @ 1620 failed"); + assertTrue(false, "Bob sell @ 1620 failed"); } vm.prank(alice); @@ -250,7 +250,7 @@ contract PositionMarginTest is Test { } catch Error(string memory reason) { console.log("FAILED: Alice buy @ 1620 failed!"); console.log("Reason:", reason); - fail("Alice buy @ 1620 failed"); + assertTrue(false, "Alice buy @ 1620 failed"); } console.log("\n==========================================="); diff --git a/contract/test/utils/MonadPerpExchangeHarness.sol b/contract/test/utils/MonadPerpExchangeHarness.sol index 7bd7471..dd841a9 100644 --- a/contract/test/utils/MonadPerpExchangeHarness.sol +++ b/contract/test/utils/MonadPerpExchangeHarness.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.20; import "../../src/Exchange.sol"; contract MonadPerpExchangeHarness is MonadPerpExchange { - constructor() MonadPerpExchange() {} + constructor() {} bool public manualPriceMode;