Last active
November 21, 2018 07:06
-
-
Save 3esmit/8954425d2ed0322505245803d6c045e4 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.0-nightly.2018.11.13+commit.ac980fb8.js&optimize=true&gist=8954425d2ed0322505245803d6c045e4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Bar { | |
event FooChanged(uint8 num); | |
uint256 public foo; | |
constructor() public { | |
reset(); | |
} | |
function testAssert(bool _fail) external { | |
setFoo(1); | |
assert(_fail); | |
setFoo(2); | |
} | |
function testRequire(bool _fail) external{ | |
setFoo(3); | |
require(_fail, "Require false"); | |
setFoo(4); | |
} | |
function testReturn(bool _fail) external { | |
setFoo(5); | |
if (_fail){ | |
return; | |
} | |
setFoo(6); | |
} | |
function reset() public { | |
setFoo(0); | |
} | |
function setFoo(uint8 num) private { | |
foo = num; | |
emit FooChanged(num); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./Bar.sol"; | |
contract Caller { | |
event RawExecution(bool success, bytes returned); | |
event Testing(uint num); | |
event Tested(uint num); | |
address public owner; | |
constructor() public { | |
} | |
function testAssert(Bar _to, bool _fail) external { | |
emit Testing(1); | |
_to.testAssert(_fail); | |
emit Tested(1); | |
} | |
function testRequire(Bar _to, bool _fail) external { | |
emit Testing(2); | |
_to.testRequire(_fail); | |
emit Tested(2); | |
} | |
function testReturn(Bar _to, bool _fail) external { | |
emit Testing(3); | |
_to.testReturn(_fail); | |
emit Tested(3); | |
} | |
function rawTestAssert(Bar _to, bool _fail, uint256 _gasLimit) external { | |
emit Testing(4); | |
_execute( | |
address(_to), | |
0, | |
abi.encodeWithSignature("testAssert(bool)", _fail), | |
_gasLimit | |
); | |
emit Tested(4); | |
} | |
function rawTestRequire(Bar _to, bool _fail, uint256 _gasLimit) external { | |
emit Testing(5); | |
_execute( | |
address(_to), | |
0, | |
abi.encodeWithSignature("testRequire(bool)", _fail), | |
_gasLimit | |
); | |
emit Tested(5); | |
} | |
function rawTestReturn(Bar _to, bool _fail, uint256 _gasLimit) external { | |
emit Testing(6); | |
_execute( | |
address(_to), | |
0, | |
abi.encodeWithSignature("testReturn(bool)", _fail), | |
_gasLimit | |
); | |
emit Tested(6); | |
} | |
function _execute( | |
address _to, | |
uint256 _value, | |
bytes memory _data, | |
uint256 _gasLimit | |
) | |
private | |
returns(bool success) | |
{ | |
bytes memory returned; | |
if(_gasLimit == 0) { | |
(success,returned) = _to.call.value(_value)(_data); | |
} else { | |
(success,returned) = _to.call.gas(_gasLimit).value(_value)(_data); | |
} | |
emit RawExecution(true, returned); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment