Skip to content

Commit

Permalink
Merge pull request #713 from rainlanguage/2024-07-07-165
Browse files Browse the repository at this point in the history
165 support
  • Loading branch information
thedavidmeister authored Jul 7, 2024
2 parents 49413eb + 790042a commit 06fd51b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/concrete/parser/OrderBookSubParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,27 @@ import {
SUB_PARSER_WORD_PARSERS,
OPERAND_HANDLER_FUNCTION_POINTERS as SUB_PARSER_OPERAND_HANDLERS
} from "../../generated/OrderBookSubParser.pointers.sol";
import {IDescribedByMetaV1} from "rain.metadata/interface/unstable/IDescribedByMetaV1.sol";

contract OrderBookSubParser is BaseRainterpreterSubParserNPE2 {
using LibUint256Matrix for uint256[][];

/// @inheritdoc IDescribedByMetaV1
function describedByMetaV1() external pure returns (bytes32) {
return DESCRIBED_BY_META_HASH;
}

/// @inheritdoc BaseRainterpreterSubParserNPE2
function subParserParseMeta() internal pure virtual override returns (bytes memory) {
return SUB_PARSER_PARSE_META;
}

/// @inheritdoc BaseRainterpreterSubParserNPE2
function subParserWordParsers() internal pure virtual override returns (bytes memory) {
return SUB_PARSER_WORD_PARSERS;
}

/// @inheritdoc BaseRainterpreterSubParserNPE2
function subParserOperandHandlers() internal pure virtual override returns (bytes memory) {
return SUB_PARSER_OPERAND_HANDLERS;
}
Expand Down
6 changes: 3 additions & 3 deletions src/generated/OrderBookSubParser.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0xa6e8aeaad0bc26812d8e1af94bc45ea29b4d1cdbe4f33cf5317c0d3b9d04de44);
bytes32 constant BYTECODE_HASH = bytes32(0xa24098eea11f3a83e475674e649959ac6d6b382fea5e47b47376e8c15a4a6863);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xa90cf581ab38cb58f1502cd049627a3a1f49857ec6a26c8bcc6da98b05bd4696);
Expand Down Expand Up @@ -42,13 +42,13 @@ uint8 constant PARSE_META_BUILD_DEPTH = 1;
/// to things that happen entirely on the interpreter such as well known
/// constants and references to the context grid.
bytes constant SUB_PARSER_WORD_PARSERS =
hex"102710461057106810781089109a10ab10bc10cd10de10ee10ff111011211132114311531163";
hex"1073109210a310b410c410d510e610f711081119112a113a114b115c116d117e118f119f11af";

/// @dev Every two bytes is a function pointer for an operand handler.
/// These positional indexes all map to the same indexes looked up in the parse
/// meta.
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS =
hex"12a812a812a812a812a812a812a812a812a812a812a812a812a812a812a812a812a812ed137c";
hex"12f412f412f412f412f412f412f412f412f412f412f412f412f412f412f412f412f4133913c8";

/// @dev Every two bytes is a function pointer for a literal parser.
/// Literal dispatches are determined by the first byte(s) of the literal
Expand Down
23 changes: 23 additions & 0 deletions test/concrete/parser/OrderBookSubParser.ierc165.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.25;

import {Test} from "forge-std/Test.sol";

import {IERC165} from "openzeppelin-contracts/contracts/utils/introspection/IERC165.sol";
import {OrderBookSubParser} from "src/concrete/parser/OrderBookSubParser.sol";
import {ISubParserV2} from "rain.interpreter.interface/interface/ISubParserV2.sol";
import {IDescribedByMetaV1} from "rain.metadata/interface/unstable/IDescribedByMetaV1.sol";

contract OrderBookSubParserIERC165Test is Test {
function testOrderBookSubParserIERC165(bytes4 badInterfaceId) external {
vm.assume(badInterfaceId != type(IERC165).interfaceId);
vm.assume(badInterfaceId != type(ISubParserV2).interfaceId);
vm.assume(badInterfaceId != type(IDescribedByMetaV1).interfaceId);

OrderBookSubParser subParser = new OrderBookSubParser();
assertTrue(subParser.supportsInterface(type(IERC165).interfaceId));
assertTrue(subParser.supportsInterface(type(ISubParserV2).interfaceId));
assertTrue(subParser.supportsInterface(type(IDescribedByMetaV1).interfaceId));
assertFalse(subParser.supportsInterface(badInterfaceId));
}
}

0 comments on commit 06fd51b

Please sign in to comment.