{"contractName":"MockInterface","abi":[{"constant":false,"inputs":[{"internalType":"bytes","name":"response","type":"bytes"}],"name":"givenAnyReturn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"response","type":"bool"}],"name":"givenAnyReturnBool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"response","type":"uint256"}],"name":"givenAnyReturnUint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"response","type":"address"}],"name":"givenAnyReturnAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"givenAnyRevert","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"message","type":"string"}],"name":"givenAnyRevertWithMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"givenAnyRunOutOfGas","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"},{"internalType":"bytes","name":"response","type":"bytes"}],"name":"givenMethodReturn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"},{"internalType":"bool","name":"response","type":"bool"}],"name":"givenMethodReturnBool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"},{"internalType":"uint256","name":"response","type":"uint256"}],"name":"givenMethodReturnUint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"},{"internalType":"address","name":"response","type":"address"}],"name":"givenMethodReturnAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"}],"name":"givenMethodRevert","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"},{"internalType":"string","name":"message","type":"string"}],"name":"givenMethodRevertWithMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"}],"name":"givenMethodRunOutOfGas","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"call","type":"bytes"},{"internalType":"bytes","name":"response","type":"bytes"}],"name":"givenCalldataReturn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"call","type":"bytes"},{"internalType":"bool","name":"response","type":"bool"}],"name":"givenCalldataReturnBool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"call","type":"bytes"},{"internalType":"uint256","name":"response","type":"uint256"}],"name":"givenCalldataReturnUint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"call","type":"bytes"},{"internalType":"address","name":"response","type":"address"}],"name":"givenCalldataReturnAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"givenCalldataRevert","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"string","name":"message","type":"string"}],"name":"givenCalldataRevertWithMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"givenCalldataRunOutOfGas","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"invocationCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"method","type":"bytes"}],"name":"invocationCountForMethod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"call","type":"bytes"}],"name":"invocationCountForCalldata","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"reset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x","deployedBytecode":"0x","sourceMap":"","deployedSourceMap":"","source":"pragma solidity ^0.5.0;\n\ninterface MockInterface {\n\t/**\n\t * @dev After calling this method, the mock will return `response` when it is called\n\t * with any calldata that is not mocked more specifically below\n\t * (e.g. using givenMethodReturn).\n\t * @param response ABI encoded response that will be returned if method is invoked\n\t */\n\tfunction givenAnyReturn(bytes calldata response) external;\n\tfunction givenAnyReturnBool(bool response) external;\n\tfunction givenAnyReturnUint(uint response) external;\n\tfunction givenAnyReturnAddress(address response) external;\n\n\tfunction givenAnyRevert() external;\n\tfunction givenAnyRevertWithMessage(string calldata message) external;\n\tfunction givenAnyRunOutOfGas() external;\n\n\t/**\n\t * @dev After calling this method, the mock will return `response` when the given\n\t * methodId is called regardless of arguments. If the methodId and arguments\n\t * are mocked more specifically (using `givenMethodAndArguments`) the latter\n\t * will take precedence.\n\t * @param method ABI encoded methodId. It is valid to pass full calldata (including arguments). The mock will extract the methodId from it\n\t * @param response ABI encoded response that will be returned if method is invoked\n\t */\n\tfunction givenMethodReturn(bytes calldata method, bytes calldata response) external;\n\tfunction givenMethodReturnBool(bytes calldata method, bool response) external;\n\tfunction givenMethodReturnUint(bytes calldata method, uint response) external;\n\tfunction givenMethodReturnAddress(bytes calldata method, address response) external;\n\n\tfunction givenMethodRevert(bytes calldata method) external;\n\tfunction givenMethodRevertWithMessage(bytes calldata method, string calldata message) external;\n\tfunction givenMethodRunOutOfGas(bytes calldata method) external;\n\n\t/**\n\t * @dev After calling this method, the mock will return `response` when the given\n\t * methodId is called with matching arguments. These exact calldataMocks will take\n\t * precedence over all other calldataMocks.\n\t * @param call ABI encoded calldata (methodId and arguments)\n\t * @param response ABI encoded response that will be returned if contract is invoked with calldata\n\t */\n\tfunction givenCalldataReturn(bytes calldata call, bytes calldata response) external;\n\tfunction givenCalldataReturnBool(bytes calldata call, bool response) external;\n\tfunction givenCalldataReturnUint(bytes calldata call, uint response) external;\n\tfunction givenCalldataReturnAddress(bytes calldata call, address response) external;\n\n\tfunction givenCalldataRevert(bytes calldata data) external;\n\tfunction givenCalldataRevertWithMessage(bytes calldata data, string calldata message) external;\n\tfunction givenCalldataRunOutOfGas(bytes calldata data) external;\n\n\t/**\n\t * @dev Returns the number of times anything has been called on this mock since last reset\n\t */\n\tfunction invocationCount() external returns (uint);\n\n\t/**\n\t * @dev Returns the number of times the given method has been called on this mock since last reset\n\t * @param method ABI encoded methodId. It is valid to pass full calldata (including arguments). The mock will extract the methodId from it\n\t */\n\tfunction invocationCountForMethod(bytes calldata method) external returns (uint);\n\n\t/**\n\t * @dev Returns the number of times this mock has been called with the exact calldata since last reset.\n\t * @param call ABI encoded calldata (methodId and arguments)\n\t */\n\tfunction invocationCountForCalldata(bytes calldata call) external returns (uint);\n\n\t/**\n\t * @dev Resets all mocked methods and invocation counts.\n\t */\n\t function reset() external;\n}\n\n/**\n * Implementation of the MockInterface.\n */\ncontract MockContract is MockInterface {\n\tenum MockType { Return, Revert, OutOfGas }\n\t\n\tbytes32 public constant MOCKS_LIST_START = hex\"01\";\n\tbytes public constant MOCKS_LIST_END = \"0xff\";\n\tbytes32 public constant MOCKS_LIST_END_HASH = keccak256(MOCKS_LIST_END);\n\tbytes4 public constant SENTINEL_ANY_MOCKS = hex\"01\";\n\n\t// A linked list allows easy iteration and inclusion checks\n\tmapping(bytes32 => bytes) calldataMocks;\n\tmapping(bytes => MockType) calldataMockTypes;\n\tmapping(bytes => bytes) calldataExpectations;\n\tmapping(bytes => string) calldataRevertMessage;\n\tmapping(bytes32 => uint) calldataInvocations;\n\n\tmapping(bytes4 => bytes4) methodIdMocks;\n\tmapping(bytes4 => MockType) methodIdMockTypes;\n\tmapping(bytes4 => bytes) methodIdExpectations;\n\tmapping(bytes4 => string) methodIdRevertMessages;\n\tmapping(bytes32 => uint) methodIdInvocations;\n\n\tMockType fallbackMockType;\n\tbytes fallbackExpectation;\n\tstring fallbackRevertMessage;\n\tuint invocations;\n\tuint resetCount;\n\n\tconstructor() public {\n\t\tcalldataMocks[MOCKS_LIST_START] = MOCKS_LIST_END;\n\t\tmethodIdMocks[SENTINEL_ANY_MOCKS] = SENTINEL_ANY_MOCKS;\n\t}\n\n\tfunction trackCalldataMock(bytes memory call) private {\n\t\tbytes32 callHash = keccak256(call);\n\t\tif (calldataMocks[callHash].length == 0) {\n\t\t\tcalldataMocks[callHash] = calldataMocks[MOCKS_LIST_START];\n\t\t\tcalldataMocks[MOCKS_LIST_START] = call;\n\t\t}\n\t}\n\n\tfunction trackMethodIdMock(bytes4 methodId) private {\n\t\tif (methodIdMocks[methodId] == 0x0) {\n\t\t\tmethodIdMocks[methodId] = methodIdMocks[SENTINEL_ANY_MOCKS];\n\t\t\tmethodIdMocks[SENTINEL_ANY_MOCKS] = methodId;\n\t\t}\n\t}\n\n\tfunction _givenAnyReturn(bytes memory response) internal {\n\t\tfallbackMockType = MockType.Return;\n\t\tfallbackExpectation = response;\n\t}\n\n\tfunction givenAnyReturn(bytes calldata response) external {\n\t\t_givenAnyReturn(response);\n\t}\n\n\tfunction givenAnyReturnBool(bool response) external {\n\t\tuint flag = response ? 1 : 0;\n\t\t_givenAnyReturn(uintToBytes(flag));\n\t}\n\n\tfunction givenAnyReturnUint(uint response) external {\n\t\t_givenAnyReturn(uintToBytes(response));\t\n\t}\n\n\tfunction givenAnyReturnAddress(address response) external {\n\t\t_givenAnyReturn(addressToBytes(response));\n\t}\n\n\tfunction givenAnyRevert() external {\n\t\tfallbackMockType = MockType.Revert;\n\t\tfallbackRevertMessage = \"\";\n\t}\n\n\tfunction givenAnyRevertWithMessage(string calldata message) external {\n\t\tfallbackMockType = MockType.Revert;\n\t\tfallbackRevertMessage = message;\n\t}\n\n\tfunction givenAnyRunOutOfGas() external {\n\t\tfallbackMockType = MockType.OutOfGas;\n\t}\n\n\tfunction _givenCalldataReturn(bytes memory call, bytes memory response) private  {\n\t\tcalldataMockTypes[call] = MockType.Return;\n\t\tcalldataExpectations[call] = response;\n\t\ttrackCalldataMock(call);\n\t}\n\n\tfunction givenCalldataReturn(bytes calldata call, bytes calldata response) external  {\n\t\t_givenCalldataReturn(call, response);\n\t}\n\n\tfunction givenCalldataReturnBool(bytes calldata call, bool response) external {\n\t\tuint flag = response ? 1 : 0;\n\t\t_givenCalldataReturn(call, uintToBytes(flag));\n\t}\n\n\tfunction givenCalldataReturnUint(bytes calldata call, uint response) external {\n\t\t_givenCalldataReturn(call, uintToBytes(response));\n\t}\n\n\tfunction givenCalldataReturnAddress(bytes calldata call, address response) external {\n\t\t_givenCalldataReturn(call, addressToBytes(response));\n\t}\n\n\tfunction _givenMethodReturn(bytes memory call, bytes memory response) private {\n\t\tbytes4 method = bytesToBytes4(call);\n\t\tmethodIdMockTypes[method] = MockType.Return;\n\t\tmethodIdExpectations[method] = response;\n\t\ttrackMethodIdMock(method);\t\t\n\t}\n\n\tfunction givenMethodReturn(bytes calldata call, bytes calldata response) external {\n\t\t_givenMethodReturn(call, response);\n\t}\n\n\tfunction givenMethodReturnBool(bytes calldata call, bool response) external {\n\t\tuint flag = response ? 1 : 0;\n\t\t_givenMethodReturn(call, uintToBytes(flag));\n\t}\n\n\tfunction givenMethodReturnUint(bytes calldata call, uint response) external {\n\t\t_givenMethodReturn(call, uintToBytes(response));\n\t}\n\n\tfunction givenMethodReturnAddress(bytes calldata call, address response) external {\n\t\t_givenMethodReturn(call, addressToBytes(response));\n\t}\n\n\tfunction givenCalldataRevert(bytes calldata call) external {\n\t\tcalldataMockTypes[call] = MockType.Revert;\n\t\tcalldataRevertMessage[call] = \"\";\n\t\ttrackCalldataMock(call);\n\t}\n\n\tfunction givenMethodRevert(bytes calldata call) external {\n\t\tbytes4 method = bytesToBytes4(call);\n\t\tmethodIdMockTypes[method] = MockType.Revert;\n\t\ttrackMethodIdMock(method);\t\t\n\t}\n\n\tfunction givenCalldataRevertWithMessage(bytes calldata call, string calldata message) external {\n\t\tcalldataMockTypes[call] = MockType.Revert;\n\t\tcalldataRevertMessage[call] = message;\n\t\ttrackCalldataMock(call);\n\t}\n\n\tfunction givenMethodRevertWithMessage(bytes calldata call, string calldata message) external {\n\t\tbytes4 method = bytesToBytes4(call);\n\t\tmethodIdMockTypes[method] = MockType.Revert;\n\t\tmethodIdRevertMessages[method] = message;\n\t\ttrackMethodIdMock(method);\t\t\n\t}\n\n\tfunction givenCalldataRunOutOfGas(bytes calldata call) external {\n\t\tcalldataMockTypes[call] = MockType.OutOfGas;\n\t\ttrackCalldataMock(call);\n\t}\n\n\tfunction givenMethodRunOutOfGas(bytes calldata call) external {\n\t\tbytes4 method = bytesToBytes4(call);\n\t\tmethodIdMockTypes[method] = MockType.OutOfGas;\n\t\ttrackMethodIdMock(method);\t\n\t}\n\n\tfunction invocationCount() external returns (uint) {\n\t\treturn invocations;\n\t}\n\n\tfunction invocationCountForMethod(bytes calldata call) external returns (uint) {\n\t\tbytes4 method = bytesToBytes4(call);\n\t\treturn methodIdInvocations[keccak256(abi.encodePacked(resetCount, method))];\n\t}\n\n\tfunction invocationCountForCalldata(bytes calldata call) external returns (uint) {\n\t\treturn calldataInvocations[keccak256(abi.encodePacked(resetCount, call))];\n\t}\n\n\tfunction reset() external {\n\t\t// Reset all exact calldataMocks\n\t\tbytes memory nextMock = calldataMocks[MOCKS_LIST_START];\n\t\tbytes32 mockHash = keccak256(nextMock);\n\t\t// We cannot compary bytes\n\t\twhile(mockHash != MOCKS_LIST_END_HASH) {\n\t\t\t// Reset all mock maps\n\t\t\tcalldataMockTypes[nextMock] = MockType.Return;\n\t\t\tcalldataExpectations[nextMock] = hex\"\";\n\t\t\tcalldataRevertMessage[nextMock] = \"\";\n\t\t\t// Set next mock to remove\n\t\t\tnextMock = calldataMocks[mockHash];\n\t\t\t// Remove from linked list\n\t\t\tcalldataMocks[mockHash] = \"\";\n\t\t\t// Update mock hash\n\t\t\tmockHash = keccak256(nextMock);\n\t\t}\n\t\t// Clear list\n\t\tcalldataMocks[MOCKS_LIST_START] = MOCKS_LIST_END;\n\n\t\t// Reset all any calldataMocks\n\t\tbytes4 nextAnyMock = methodIdMocks[SENTINEL_ANY_MOCKS];\n\t\twhile(nextAnyMock != SENTINEL_ANY_MOCKS) {\n\t\t\tbytes4 currentAnyMock = nextAnyMock;\n\t\t\tmethodIdMockTypes[currentAnyMock] = MockType.Return;\n\t\t\tmethodIdExpectations[currentAnyMock] = hex\"\";\n\t\t\tmethodIdRevertMessages[currentAnyMock] = \"\";\n\t\t\tnextAnyMock = methodIdMocks[currentAnyMock];\n\t\t\t// Remove from linked list\n\t\t\tmethodIdMocks[currentAnyMock] = 0x0;\n\t\t}\n\t\t// Clear list\n\t\tmethodIdMocks[SENTINEL_ANY_MOCKS] = SENTINEL_ANY_MOCKS;\n\n\t\tfallbackExpectation = \"\";\n\t\tfallbackMockType = MockType.Return;\n\t\tinvocations = 0;\n\t\tresetCount += 1;\n\t}\n\n\tfunction useAllGas() private {\n\t\twhile(true) {\n\t\t\tbool s;\n\t\t\tassembly {\n\t\t\t\t//expensive call to EC multiply contract\n\t\t\t\ts := call(sub(gas, 2000), 6, 0, 0x0, 0xc0, 0x0, 0x60)\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction bytesToBytes4(bytes memory b) private pure returns (bytes4) {\n  \t\tbytes4 out;\n  \t\tfor (uint i = 0; i < 4; i++) {\n    \t\tout |= bytes4(b[i] & 0xFF) >> (i * 8);\n  \t\t}\n  \t\treturn out;\n\t}\n\n\tfunction addressToBytes(address a) private pure returns (bytes memory b){\n   \t\tassembly {\n        \tlet m := mload(0x40)\n        \tmstore(add(m, 20), xor(0x140000000000000000000000000000000000000000, a))\n        \tmstore(0x40, add(m, 52))\n        \tb := m\n   \t\t}\n\t}\n\n\tfunction uintToBytes(uint256 x) private pure returns (bytes memory b) {\n    \tb = new bytes(32);\n    \tassembly { mstore(add(b, 32), x) }\n\t}\n\n\tfunction() payable external {\n\t\tbytes4 methodId;\n\t\tassembly {\n\t\t\tmethodId := calldataload(0)\n\t\t}\n\n\t\t// First, check exact matching overrides\n\t\tif (calldataMockTypes[msg.data] == MockType.Revert) {\n\t\t\trevert(calldataRevertMessage[msg.data]);\n\t\t}\n\t\tif (calldataMockTypes[msg.data] == MockType.OutOfGas) {\n\t\t\tuseAllGas();\n\t\t}\n\t\tbytes memory result = calldataExpectations[msg.data];\n\n\t\t// Then check method Id overrides\n\t\tif (result.length == 0) {\n\t\t\tif (methodIdMockTypes[methodId] == MockType.Revert) {\n\t\t\t\trevert(methodIdRevertMessages[methodId]);\n\t\t\t}\n\t\t\tif (methodIdMockTypes[methodId] == MockType.OutOfGas) {\n\t\t\t\tuseAllGas();\n\t\t\t}\n\t\t\tresult = methodIdExpectations[methodId];\n\t\t}\n\n\t\t// Last, use the fallback override\n\t\tif (result.length == 0) {\n\t\t\tif (fallbackMockType == MockType.Revert) {\n\t\t\t\trevert(fallbackRevertMessage);\n\t\t\t}\n\t\t\tif (fallbackMockType == MockType.OutOfGas) {\n\t\t\t\tuseAllGas();\n\t\t\t}\n\t\t\tresult = fallbackExpectation;\n\t\t}\n\n\t\t// Record invocation\n\t\tinvocations += 1;\n\t\tmethodIdInvocations[keccak256(abi.encodePacked(resetCount, methodId))] += 1;\n\t\tcalldataInvocations[keccak256(abi.encodePacked(resetCount, msg.data))] += 1;\n\n\t\tassembly {\n\t\t\treturn(add(0x20, result), mload(result))\n\t\t}\n\t}\n}\n","compiler":{"name":"solc","version":"0.5.14+commit.01f1aaa4.Emscripten.clang"},"networks":{},"schemaVersion":"2.0.3","updatedAt":"2022-11-11T08:20:54.772Z"}