Skip to content

Commit

Permalink
Merge pull request #222 from rainlanguage/2023-02-12-bump-i9r-dep
Browse files Browse the repository at this point in the history
bump i9r dep
  • Loading branch information
thedavidmeister authored Feb 12, 2024
2 parents 3e6ae8c + 7e84c95 commit fd16087
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 67 deletions.
2 changes: 1 addition & 1 deletion lib/rain.interpreter
37 changes: 12 additions & 25 deletions test/concrete/ob/OrderBook.clear.handleIO.revert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {OrderBookExternalRealTest} from "test/util/abstract/OrderBookExternalRea
import {ClearConfig, OrderV2, TakeOrderConfigV2, IO, OrderConfigV2} from "src/interface/unstable/IOrderBookV3.sol";
import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/interface/IInterpreterCallerV2.sol";
import {IParserV1} from "rain.interpreter/interface/IParserV1.sol";
import {EnsureFailed} from "rain.interpreter/lib/op/logic/LibOpEnsureNP.sol";

/// @title OrderBookClearHandleIORevertTest
/// @notice A test harness for testing the OrderBook clear function will run
Expand Down Expand Up @@ -79,51 +78,39 @@ contract OrderBookClearHandleIORevertTest is OrderBookExternalRealTest {
}

function testClearOrderHandleIO0() external {
bytes memory aliceErr = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes memory bobErr = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);
bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure(0 \"alice err\");";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure(0 \"bob err\");";

bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure<1>(0);";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure<2>(0);";

checkClearOrderHandleIO(aliceString, bobString, aliceErr, bobErr);
checkClearOrderHandleIO(aliceString, bobString, "alice err", "bob err");
}

function testClearOrderHandleIO1() external {
bytes memory aliceErr = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);
bytes memory bobErr = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);

bytes memory aliceString = "_ _:max-int-value() 1e18;:;";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure<2>(0);";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure(0 \"bob err\");";

checkClearOrderHandleIO(aliceString, bobString, aliceErr, bobErr);
checkClearOrderHandleIO(aliceString, bobString, "bob err", "bob err");
}

function testClearOrderHandleIO2() external {
bytes memory aliceErr = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes memory bobErr = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);

bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure<1>(0);";
bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure(0 \"alice err\");";
bytes memory bobString = "_ _:max-int-value() 1e18;:;";

checkClearOrderHandleIO(aliceString, bobString, aliceErr, bobErr);
checkClearOrderHandleIO(aliceString, bobString, "alice err", "alice err");
}

function testClearOrderHandleIO3() external {
bytes memory aliceErr = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes memory bobErr = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure(0 \"alice err\");";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure(0 \"bob err\");";

bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure<1>(0);";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure<1>(0);";

checkClearOrderHandleIO(aliceString, bobString, aliceErr, bobErr);
checkClearOrderHandleIO(aliceString, bobString, "alice err", "bob err");
}

function testClearOrderHandleIO4() external {
bytes memory aliceErr = "";
bytes memory bobErr = "";

bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure<1>(1);";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure<1>(1);";
bytes memory aliceString = "_ _:max-int-value() 1e18;:ensure(1 \"alice err\");";
bytes memory bobString = "_ _:max-int-value() 1e18;:ensure(1 \"bob err\");";

checkClearOrderHandleIO(aliceString, bobString, aliceErr, bobErr);
}
Expand Down
70 changes: 29 additions & 41 deletions test/concrete/ob/OrderBook.takeOrder.handleIO.revert.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
OrderConfigV2,
TakeOrdersConfigV2
} from "src/interface/unstable/IOrderBookV3.sol";
import {EnsureFailed} from "rain.interpreter/lib/op/logic/LibOpEnsureNP.sol";
import {IParserV1} from "rain.interpreter/interface/IParserV1.sol";
import {SignedContextV1, EvaluableConfigV3} from "rain.interpreter/interface/IInterpreterCallerV2.sol";

Expand Down Expand Up @@ -71,111 +70,100 @@ contract OrderBookTakeOrderHandleIORevertTest is OrderBookExternalRealTest {
}

function testTakeOrderHandleIO0() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes[] memory configs = new bytes[](1);
configs[0] = "_ _:max-int-value() 1e18;:ensure<1>(0);";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
configs[0] = "_ _:max-int-value() 1e18;:ensure(0 \"err\");";
checkTakeOrderHandleIO(configs, "err", type(uint256).max);
}

function testTakeOrderHandleIO1() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes[] memory configs = new bytes[](2);
configs[0] = "_ _:1e18 1e18;:ensure<1>(0);";
configs[0] = "_ _:1e18 1e18;:ensure(0 \"err\");";
configs[1] = "_ _:1e18 1e18;:;";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
checkTakeOrderHandleIO(configs, "err", type(uint256).max);
}

function testTakeOrderHandleIO2() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes[] memory configs = new bytes[](2);
configs[0] = "_ _:1e18 1e18;:;";
configs[1] = "_ _:1e18 1e18;:ensure<1>(0);";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
configs[1] = "_ _:1e18 1e18;:ensure(0 \"err\");";
checkTakeOrderHandleIO(configs, "err", type(uint256).max);
}

function testTakeOrderHandleIO3() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes[] memory configs = new bytes[](3);
configs[0] = "_ _:1e18 1e18;:;";
configs[1] = "_ _:1e18 1e18;:ensure<1>(0);";
configs[1] = "_ _:1e18 1e18;:ensure(0 \"err\");";
configs[2] = "_ _:1e18 1e18;:;";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
checkTakeOrderHandleIO(configs, "err", type(uint256).max);
}

function testTakeOrderHandleIO4() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 1, 0);
bytes[] memory configs = new bytes[](3);
configs[0] = "_ _:1e18 1e18;:;";
configs[1] = "_ _:1e18 1e18;:ensure<1>(0);";
configs[2] = "_ _:1e18 1e18;:ensure<2>(0);";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
configs[1] = "_ _:1e18 1e18;:ensure(0 \"err 1\");";
configs[2] = "_ _:1e18 1e18;:ensure(0 \"err 2\");";
checkTakeOrderHandleIO(configs, "err 1", type(uint256).max);
}

function testTakeOrderHandleIO5() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);
bytes[] memory configs = new bytes[](3);
configs[0] = "_ _:1e18 1e18;:;";
configs[1] = "_ _:1e18 1e18;:ensure<2>(0);";
configs[2] = "_ _:1e18 1e18;:ensure<1>(0);";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
configs[1] = "_ _:1e18 1e18;:ensure(0 \"err 2\");";
configs[2] = "_ _:1e18 1e18;:ensure(0 \"err 1\");";
checkTakeOrderHandleIO(configs, "err 2", type(uint256).max);
}

function testTakeOrderHandleIO6() external {
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);
bytes[] memory configs = new bytes[](3);
configs[0] = "_ _:1e18 1e18;:ensure<2>(0);";
configs[0] = "_ _:1e18 1e18;:ensure(0 \"err 2\");";
configs[1] = "_ _:1e18 1e18;:;";
configs[2] = "_ _:1e18 1e18;:ensure<1>(0);";
checkTakeOrderHandleIO(configs, err, type(uint256).max);
configs[2] = "_ _:1e18 1e18;:ensure(0 \"err 1\");";
checkTakeOrderHandleIO(configs, "err 2", type(uint256).max);
}

function testTakeOrderHandleIO7(uint256 toClear) external {
toClear = bound(toClear, 3e18 + 1, type(uint256).max);
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);
bytes[] memory configs = new bytes[](4);
configs[0] = "_ _:1e18 1e18;:set(0 1);";
configs[1] = "_ _:1e18 1e18;:ensure<1>(get(0));";
configs[1] = "_ _:1e18 1e18;:ensure(get(0) \"err 1\");";
configs[2] = "_ _:1e18 1e18;:set(0 0);";
configs[3] = "_ _:1e18 1e18;:ensure<2>(get(0));";
checkTakeOrderHandleIO(configs, err, toClear);
configs[3] = "_ _:1e18 1e18;:ensure(get(0) \"err 2\");";
checkTakeOrderHandleIO(configs, "err 2", toClear);
}

function testTakeOrderHandleIO8(uint256 toClear) external {
toClear = bound(toClear, 4e18 + 1, type(uint256).max);
bytes memory err = abi.encodeWithSelector(EnsureFailed.selector, 2, 0);
bytes[] memory configs = new bytes[](5);
configs[0] = "_ _:1e18 1e18;:;";
configs[1] = "_ _:1e18 1e18;:set(0 1);";
configs[2] = "_ _:1e18 1e18;:ensure<1>(get(0));";
configs[2] = "_ _:1e18 1e18;:ensure(get(0) \"err 1\");";
configs[3] = "_ _:1e18 1e18;:set(0 0);";
configs[4] = "_ _:1e18 1e18;:ensure<2>(get(0));";
checkTakeOrderHandleIO(configs, err, toClear);
configs[4] = "_ _:1e18 1e18;:ensure(get(0) \"err 2\");";
checkTakeOrderHandleIO(configs, "err 2", toClear);
}

// This one WONT error because the take orders stops executing the handle IO
// before it clears 4e18 + 1, so it never hits the second ensure condition.
function testTakeOrderHandleIO9(uint256 toClear) external {
toClear = bound(toClear, 1, 4e18);
bytes memory err = "";
bytes[] memory configs = new bytes[](5);
configs[0] = "_ _:1e18 1e18;:;";
configs[1] = "_ _:1e18 1e18;:set(0 1);";
configs[2] = "_ _:1e18 1e18;:ensure<1>(get(0));";
configs[2] = "_ _:1e18 1e18;:ensure(get(0) \"err 1\");";
configs[3] = "_ _:1e18 1e18;:set(0 0);";
configs[4] = "_ _:1e18 1e18;:ensure<2>(get(0));";
checkTakeOrderHandleIO(configs, err, toClear);
configs[4] = "_ _:1e18 1e18;:ensure(get(0) \"err 2\");";
checkTakeOrderHandleIO(configs, "", toClear);
}

// This one WONT error because the take orders stops executing the handle IO
// before it clears 4e18 + 1, so it never hits the second ensure condition.
function testTakeOrderHandleIO10(uint256 toClear) external {
toClear = bound(toClear, 1, 3e18);
bytes memory err = "";
bytes[] memory configs = new bytes[](4);
configs[0] = "_ _:1e18 1e18;:set(0 1);";
configs[1] = "_ _:1e18 1e18;:ensure<1>(get(0));";
configs[1] = "_ _:1e18 1e18;:ensure(get(0) \"err 1\");";
configs[2] = "_ _:1e18 1e18;:set(0 0);";
configs[3] = "_ _:1e18 1e18;:ensure<2>(get(0));";
checkTakeOrderHandleIO(configs, err, toClear);
configs[3] = "_ _:1e18 1e18;:ensure(get(0) \"err 2\");";
checkTakeOrderHandleIO(configs, "", toClear);
}
}

0 comments on commit fd16087

Please sign in to comment.