Created
May 11, 2018 20:48
-
-
Save kosecki123/61d14815eaac23a89cf7f5ce21259b4a to your computer and use it in GitHub Desktop.
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 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