Skip to content

Instantly share code, notes, and snippets.

@3esmit 3esmit/Bar.sol
Last active Nov 21, 2018

Embed
What would you like to do?
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
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);
}
}
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
You can’t perform that action at this time.