Skip to content

Instantly share code, notes, and snippets.

@kosecki123
Created May 11, 2018 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosecki123/61d14815eaac23a89cf7f5ce21259b4a to your computer and use it in GitHub Desktop.
Save kosecki123/61d14815eaac23a89cf7f5ce21259b4a to your computer and use it in GitHub Desktop.
contract Test1 {
function add(int a, int b) returns(bytes){ //Simply add the two arguments and return
return abi.encode(a+b);
}
}
contract Test2 {
Test1 test1;
function Test2(){
test1 = new Test1();
}
function testAdd() constant returns(bytes) {
//encoded add(int256,int256) call add(2,2) expected return 4
bytes memory a = hex"a5f3c23b00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002";
return callWithData(address(test1), a);
}
function callWithData(address dest, bytes data) private returns (bytes c) {
assembly {
let freemem := mload(0x40)
pop(
call(
5000,
dest,
0,
add(data, 0x20),
mload(data),
0,
0
)
)
let size := returndatasize
returndatacopy(freemem, 0, size)
return (freemem, size)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment