Files
core/lib/forge-std/src/StdJson.sol
2022-09-16 12:51:34 -04:00

119 lines
3.0 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "./Vm.sol";
// Helpers for parsing keys into types.
library stdJson {
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
function parseRaw(string memory json, string memory key)
internal
returns (bytes memory)
{
return vm.parseJson(json, key);
}
function readUint(string memory json, string memory key)
internal
returns (uint256)
{
return abi.decode(vm.parseJson(json, key), (uint256));
}
function readUintArray(string memory json, string memory key)
internal
returns (uint256[] memory)
{
return abi.decode(vm.parseJson(json, key), (uint256[]));
}
function readInt(string memory json, string memory key)
internal
returns (int256)
{
return abi.decode(vm.parseJson(json, key), (int256));
}
function readIntArray(string memory json, string memory key)
internal
returns (int256[] memory)
{
return abi.decode(vm.parseJson(json, key), (int256[]));
}
function readBytes32(string memory json, string memory key)
internal
returns (bytes32)
{
return abi.decode(vm.parseJson(json, key), (bytes32));
}
function readBytes32Array(string memory json, string memory key)
internal
returns (bytes32[] memory)
{
return abi.decode(vm.parseJson(json, key), (bytes32[]));
}
function readString(string memory json, string memory key)
internal
returns (string memory)
{
return abi.decode(vm.parseJson(json, key), (string));
}
function readStringArray(string memory json, string memory key)
internal
returns (string[] memory)
{
return abi.decode(vm.parseJson(json, key), (string[]));
}
function readAddress(string memory json, string memory key)
internal
returns (address)
{
return abi.decode(vm.parseJson(json, key), (address));
}
function readAddressArray(string memory json, string memory key)
internal
returns (address[] memory)
{
return abi.decode(vm.parseJson(json, key), (address[]));
}
function readBool(string memory json, string memory key)
internal
returns (bool)
{
return abi.decode(vm.parseJson(json, key), (bool));
}
function readBoolArray(string memory json, string memory key)
internal
returns (bool[] memory)
{
return abi.decode(vm.parseJson(json, key), (bool[]));
}
function readBytes(string memory json, string memory key)
internal
returns (bytes memory)
{
return abi.decode(vm.parseJson(json, key), (bytes));
}
function readBytesArray(string memory json, string memory key)
internal
returns (bytes[] memory)
{
return abi.decode(vm.parseJson(json, key), (bytes[]));
}
}