From 6db18b135bf177745e0ad58ef8c1250f6d7c231e Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Fri, 24 Nov 2023 15:40:00 +0400 Subject: [PATCH] tests for io on add order --- .gas-snapshot | 13 +++- test/concrete/OrderBook.addOrder.t.sol | 103 ++++++++++++++++++++----- 2 files changed, 92 insertions(+), 24 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index e3a83024c..f76548d27 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -14,10 +14,17 @@ OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaReverts(address,((address, OrderBookAddOrderMockTest:testAddOrderWithoutCalculationsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 225041, ~: 222495) OrderBookAddOrderMockTest:testAddOrderWithoutInputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 180462, ~: 180326) OrderBookAddOrderMockTest:testAddOrderWithoutOutputsReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 181258, ~: 180681) -OrderBookAddOrderTest:testAddOrderRealNoHandleIOReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 173061, ~: 170719) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts1(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 243931, ~: 241589) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts2(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 245629, ~: 243287) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsRevertsPreference(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 245191, ~: 242849) +OrderBookAddOrderTest:testAddOrderRealHandleIOInputsReverts1(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 261570, ~: 259228) +OrderBookAddOrderTest:testAddOrderRealHandleIOInputsReverts2(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 263259, ~: 260917) +OrderBookAddOrderTest:testAddOrderRealNoHandleIOReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 173094, ~: 170752) OrderBookAddOrderTest:testAddOrderRealNoSourcesReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 176464, ~: 174474) -OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 725463, ~: 718929) -OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 718735, ~: 712201) +OrderBookAddOrderTest:testAddOrderRealOneStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 248580, ~: 246238) +OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 725429, ~: 718895) +OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 718723, ~: 712189) +OrderBookAddOrderTest:testAddOrderRealZeroStackCalculateReverts(address,((address,uint8,uint256)[],(address,uint8,uint256)[],(address,bytes,uint256[]),bytes)) (runs: 5096, μ: 242660, ~: 240318) OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 637093) OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 619410) OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 619395) diff --git a/test/concrete/OrderBook.addOrder.t.sol b/test/concrete/OrderBook.addOrder.t.sol index 2185d265b..af1f22032 100644 --- a/test/concrete/OrderBook.addOrder.t.sol +++ b/test/concrete/OrderBook.addOrder.t.sol @@ -5,6 +5,11 @@ import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRea import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol"; import {IParserV1} from "rain.interpreter/src/interface/IParserV1.sol"; +import { + UnsupportedCalculateOutputs, + UnsupportedCalculateInputs, + UnsupportedHandleInputs +} from "src/concrete/OrderBook.sol"; /// @title OrderBookAddOrderTest /// @notice A test harness for testing the OrderBook addOrder function. @@ -29,28 +34,28 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { iOrderbook.addOrder(config); } - // /// A stack of 0 for calculate order reverts. - // function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { - // LibTestAddOrder.conformConfig(config, iDeployer); - // (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;:;"); - // config.evaluableConfig.constants = constants; - // config.evaluableConfig.bytecode = bytecode; - // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 0, 2)); - // vm.prank(owner); - // iOrderbook.addOrder(config); - // } + /// A stack of 0 for calculate order reverts. + function testAddOrderRealZeroStackCalculateReverts(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse(":;:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateOutputs.selector, 0)); + vm.prank(owner); + iOrderbook.addOrder(config); + } - // /// A stack of 1 for calculate order reverts. - // function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { - // LibTestAddOrder.conformConfig(config, iDeployer); - // (bytes memory bytecode, uint256[] memory constants) = - // IParserV1(address(iParser)).parse("_:block-timestamp();:;"); - // config.evaluableConfig.constants = constants; - // config.evaluableConfig.bytecode = bytecode; - // vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 1, 2)); - // vm.prank(owner); - // iOrderbook.addOrder(config); - // } + /// A stack of 1 for calculate order reverts. + function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = + IParserV1(address(iParser)).parse("_:block-timestamp();:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateOutputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } /// A stack of 2 for calculate order deploys. function testAddOrderRealTwoStackCalculateReverts(address owner, OrderConfigV2 memory config) public { @@ -73,4 +78,60 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest { vm.prank(owner); iOrderbook.addOrder(config); } + + /// Inputs for calculate order errors. Tests one input. + function testAddOrderRealCalculateInputsReverts1(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("i:;:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateInputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for calculate order errors. Tests two inputs. + function testAddOrderRealCalculateInputsReverts2(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("i0 i1:;:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateInputs.selector, 2)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for calculate order errors. This takes precedent over the same + /// error in handle io. + function testAddOrderRealCalculateInputsRevertsPreference(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("i:;i:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedCalculateInputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for handle io errors. Tests one input. + function testAddOrderRealHandleIOInputsReverts1(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("_ _:1e18 1e18;i:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedHandleInputs.selector, 1)); + vm.prank(owner); + iOrderbook.addOrder(config); + } + + /// Inputs for handle io errors. Tests two inputs. + function testAddOrderRealHandleIOInputsReverts2(address owner, OrderConfigV2 memory config) public { + LibTestAddOrder.conformConfig(config, iDeployer); + (bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iParser)).parse("_ _:1e18 1e18;i0 i1:;"); + config.evaluableConfig.constants = constants; + config.evaluableConfig.bytecode = bytecode; + vm.expectRevert(abi.encodeWithSelector(UnsupportedHandleInputs.selector, 2)); + vm.prank(owner); + iOrderbook.addOrder(config); + } }