Skip to content

Commit

Permalink
tests for io on add order
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Nov 24, 2023
1 parent a40dbcf commit 6db18b1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 24 deletions.
13 changes: 10 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
103 changes: 82 additions & 21 deletions test/concrete/OrderBook.addOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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);
}
}

0 comments on commit 6db18b1

Please sign in to comment.