|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +// solhint-disable-next-line gas-struct-packing |
| 5 | +struct TestStruct { |
| 6 | + int32 Field; |
| 7 | + string DifferentField; |
| 8 | + uint8 OracleId; |
| 9 | + uint8[32] OracleIds; |
| 10 | + address Account; |
| 11 | + address[] Accounts; |
| 12 | + int192 BigField; |
| 13 | + MidLevelDynamicTestStruct NestedDynamicStruct; |
| 14 | + MidLevelStaticTestStruct NestedStaticStruct; |
| 15 | +} |
| 16 | + |
| 17 | +struct MidLevelDynamicTestStruct { |
| 18 | + bytes2 FixedBytes; |
| 19 | + InnerDynamicTestStruct Inner; |
| 20 | +} |
| 21 | + |
| 22 | +struct InnerDynamicTestStruct { |
| 23 | + int64 IntVal; |
| 24 | + string S; |
| 25 | +} |
| 26 | + |
| 27 | +struct MidLevelStaticTestStruct { |
| 28 | + bytes2 FixedBytes; |
| 29 | + InnerStaticTestStruct Inner; |
| 30 | +} |
| 31 | + |
| 32 | +struct InnerStaticTestStruct { |
| 33 | + int64 IntVal; |
| 34 | + address A; |
| 35 | +} |
| 36 | + |
| 37 | +contract ChainReaderTester { |
| 38 | + event Triggered( |
| 39 | + int32 indexed field, |
| 40 | + uint8 oracleId, |
| 41 | + MidLevelDynamicTestStruct nestedDynamicStruct, |
| 42 | + MidLevelStaticTestStruct nestedStaticStruct, |
| 43 | + uint8[32] oracleIds, |
| 44 | + address Account, |
| 45 | + address[] Accounts, |
| 46 | + string differentField, |
| 47 | + int192 bigField |
| 48 | + ); |
| 49 | + |
| 50 | + event TriggeredEventWithDynamicTopic(string indexed fieldHash, string field); |
| 51 | + |
| 52 | + // First topic is event hash |
| 53 | + event TriggeredWithFourTopics(int32 indexed field1, int32 indexed field2, int32 indexed field3); |
| 54 | + |
| 55 | + // first topic is event hash, second and third topics get hashed before getting stored |
| 56 | + event TriggeredWithFourTopicsWithHashed(string indexed field1, uint8[32] indexed field2, bytes32 indexed field3); |
| 57 | + |
| 58 | + TestStruct[] private s_seen; |
| 59 | + uint64[] private s_arr; |
| 60 | + uint64 private s_value; |
| 61 | + |
| 62 | + constructor() { |
| 63 | + // See chain_reader_interface_tests.go in chainlink-relay |
| 64 | + s_arr.push(3); |
| 65 | + s_arr.push(4); |
| 66 | + } |
| 67 | + |
| 68 | + function addTestStruct( |
| 69 | + int32 field, |
| 70 | + string calldata differentField, |
| 71 | + uint8 oracleId, |
| 72 | + uint8[32] calldata oracleIds, |
| 73 | + address account, |
| 74 | + address[] calldata accounts, |
| 75 | + int192 bigField, |
| 76 | + MidLevelDynamicTestStruct calldata nestedDynamicStruct, |
| 77 | + MidLevelStaticTestStruct calldata nestedStaticStruct |
| 78 | + ) public { |
| 79 | + s_seen.push( |
| 80 | + TestStruct( |
| 81 | + field, |
| 82 | + differentField, |
| 83 | + oracleId, |
| 84 | + oracleIds, |
| 85 | + account, |
| 86 | + accounts, |
| 87 | + bigField, |
| 88 | + nestedDynamicStruct, |
| 89 | + nestedStaticStruct |
| 90 | + ) |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + function setAlterablePrimitiveValue(uint64 value) public { |
| 95 | + s_value = value; |
| 96 | + } |
| 97 | + |
| 98 | + function returnSeen( |
| 99 | + int32 field, |
| 100 | + string calldata differentField, |
| 101 | + uint8 oracleId, |
| 102 | + uint8[32] calldata oracleIds, |
| 103 | + address account, |
| 104 | + address[] calldata accounts, |
| 105 | + int192 bigField, |
| 106 | + MidLevelDynamicTestStruct calldata nestedDynamicStruct, |
| 107 | + MidLevelStaticTestStruct calldata nestedStaticStruct |
| 108 | + ) public pure returns (TestStruct memory) { |
| 109 | + return |
| 110 | + TestStruct( |
| 111 | + field, |
| 112 | + differentField, |
| 113 | + oracleId, |
| 114 | + oracleIds, |
| 115 | + account, |
| 116 | + accounts, |
| 117 | + bigField, |
| 118 | + nestedDynamicStruct, |
| 119 | + nestedStaticStruct |
| 120 | + ); |
| 121 | + } |
| 122 | + |
| 123 | + function getElementAtIndex(uint256 i) public view returns (TestStruct memory) { |
| 124 | + // See chain_reader_interface_tests.go in chainlink-relay |
| 125 | + return s_seen[i - 1]; |
| 126 | + } |
| 127 | + |
| 128 | + function getPrimitiveValue() public pure returns (uint64) { |
| 129 | + // See chain_reader_interface_tests.go in chainlink-relay |
| 130 | + return 3; |
| 131 | + } |
| 132 | + |
| 133 | + function getAlterablePrimitiveValue() public view returns (uint64) { |
| 134 | + // See chain_reader_interface_tests.go in chainlink-relay |
| 135 | + return s_value; |
| 136 | + } |
| 137 | + |
| 138 | + function getDifferentPrimitiveValue() public pure returns (uint64) { |
| 139 | + // See chain_reader_interface_tests.go in chainlink-relay |
| 140 | + return 1990; |
| 141 | + } |
| 142 | + |
| 143 | + function getSliceValue() public view returns (uint64[] memory) { |
| 144 | + return s_arr; |
| 145 | + } |
| 146 | + |
| 147 | + function triggerEvent( |
| 148 | + int32 field, |
| 149 | + uint8 oracleId, |
| 150 | + MidLevelDynamicTestStruct calldata nestedDynamicStruct, |
| 151 | + MidLevelStaticTestStruct calldata nestedStaticStruct, |
| 152 | + uint8[32] calldata oracleIds, |
| 153 | + address account, |
| 154 | + address[] calldata accounts, |
| 155 | + string calldata differentField, |
| 156 | + int192 bigField |
| 157 | + ) public { |
| 158 | + emit Triggered( |
| 159 | + field, |
| 160 | + oracleId, |
| 161 | + nestedDynamicStruct, |
| 162 | + nestedStaticStruct, |
| 163 | + oracleIds, |
| 164 | + account, |
| 165 | + accounts, |
| 166 | + differentField, |
| 167 | + bigField |
| 168 | + ); |
| 169 | + } |
| 170 | + |
| 171 | + function triggerEventWithDynamicTopic(string calldata field) public { |
| 172 | + emit TriggeredEventWithDynamicTopic(field, field); |
| 173 | + } |
| 174 | + |
| 175 | + // first topic is the event signature |
| 176 | + function triggerWithFourTopics(int32 field1, int32 field2, int32 field3) public { |
| 177 | + emit TriggeredWithFourTopics(field1, field2, field3); |
| 178 | + } |
| 179 | + |
| 180 | + // first topic is event hash, second and third topics get hashed before getting stored |
| 181 | + function triggerWithFourTopicsWithHashed(string memory field1, uint8[32] memory field2, bytes32 field3) public { |
| 182 | + emit TriggeredWithFourTopicsWithHashed(field1, field2, field3); |
| 183 | + } |
| 184 | +} |
0 commit comments