|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity >=0.6.0 <0.9.0; |
| 3 | + |
| 4 | +import "./Vm.sol"; |
| 5 | + |
| 6 | +// Helpers for parsing keys into types. |
| 7 | +abstract contract StdCheatsJson { |
| 8 | + |
| 9 | + Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); |
| 10 | + |
| 11 | + function parseRaw(string memory json, string memory key) |
| 12 | + internal |
| 13 | + returns (bytes memory) |
| 14 | + { |
| 15 | + return vm.parseJson(json, key); |
| 16 | + } |
| 17 | + |
| 18 | + function readUint(string memory json, string memory key) |
| 19 | + internal |
| 20 | + returns (uint256) |
| 21 | + { |
| 22 | + return abi.decode(vm.parseJson(json, key), (uint256)); |
| 23 | + } |
| 24 | + |
| 25 | + function readUintArray(string memory json, string memory key) |
| 26 | + internal |
| 27 | + returns (uint256[] memory) |
| 28 | + { |
| 29 | + return abi.decode(vm.parseJson(json, key), (uint256[])); |
| 30 | + } |
| 31 | + |
| 32 | + function readInt(string memory json, string memory key) |
| 33 | + internal |
| 34 | + returns (int256) |
| 35 | + { |
| 36 | + return abi.decode(vm.parseJson(json, key), (int256)); |
| 37 | + } |
| 38 | + |
| 39 | + function readIntArray(string memory json, string memory key) |
| 40 | + internal |
| 41 | + returns (int256[] memory) |
| 42 | + { |
| 43 | + return abi.decode(vm.parseJson(json, key), (int256[])); |
| 44 | + } |
| 45 | + |
| 46 | + function readBytes32(string memory json, string memory key) |
| 47 | + internal |
| 48 | + returns (bytes32) |
| 49 | + { |
| 50 | + return abi.decode(vm.parseJson(json, key), (bytes32)); |
| 51 | + } |
| 52 | + |
| 53 | + function readBytes32Array(string memory json, string memory key) |
| 54 | + internal |
| 55 | + returns (bytes32[] memory) |
| 56 | + { |
| 57 | + return abi.decode(vm.parseJson(json, key), (bytes32[])); |
| 58 | + } |
| 59 | + |
| 60 | + function readString(string memory json, string memory key) |
| 61 | + internal |
| 62 | + returns (string memory) |
| 63 | + { |
| 64 | + return abi.decode(vm.parseJson(json, key), (string)); |
| 65 | + } |
| 66 | + |
| 67 | + function readStringArray(string memory json, string memory key) |
| 68 | + internal |
| 69 | + returns (string[] memory) |
| 70 | + { |
| 71 | + return abi.decode(vm.parseJson(json, key), (string[])); |
| 72 | + } |
| 73 | + |
| 74 | + function readAddress(string memory json, string memory key) |
| 75 | + internal |
| 76 | + returns (address) |
| 77 | + { |
| 78 | + return abi.decode(vm.parseJson(json, key), (address)); |
| 79 | + } |
| 80 | + |
| 81 | + function readAddressArray(string memory json, string memory key) |
| 82 | + internal |
| 83 | + returns (address[] memory) |
| 84 | + { |
| 85 | + return abi.decode(vm.parseJson(json, key), (address[])); |
| 86 | + } |
| 87 | + |
| 88 | + function readBool(string memory json, string memory key) |
| 89 | + internal |
| 90 | + returns (bool) |
| 91 | + { |
| 92 | + return abi.decode(vm.parseJson(json, key), (bool)); |
| 93 | + } |
| 94 | + |
| 95 | + function readBoolArray(string memory json, string memory key) |
| 96 | + internal |
| 97 | + returns (bool[] memory) |
| 98 | + { |
| 99 | + return abi.decode(vm.parseJson(json, key), (bool[])); |
| 100 | + } |
| 101 | + |
| 102 | + function readBytes(string memory json, string memory key) |
| 103 | + internal |
| 104 | + returns (bytes memory) |
| 105 | + { |
| 106 | + return abi.decode(vm.parseJson(json, key), (bytes)); |
| 107 | + } |
| 108 | + |
| 109 | + function readBytesArray(string memory json, string memory key) |
| 110 | + internal |
| 111 | + returns (bytes[] memory) |
| 112 | + { |
| 113 | + return abi.decode(vm.parseJson(json, key), (bytes[])); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | +} |
0 commit comments