function_call.sol 713 B

1234567891011121314151617181920212223242526272829
  1. contract a {
  2. function test() public {
  3. b v = new b();
  4. // the following four lines are equivalent to "uint32 res = v.foo(3,5);"
  5. // Note that the signature is only hashed and not parsed. So, ensure that the
  6. // arguments are of the correct type.
  7. bytes data = abi.encodeWithSignature(
  8. "foo(uint32,uint32)",
  9. uint32(3),
  10. uint32(5)
  11. );
  12. (bool success, bytes rawresult) = address(v).call(data);
  13. assert(success == true);
  14. uint32 res = abi.decode(rawresult, (uint32));
  15. assert(res == 8);
  16. }
  17. }
  18. contract b {
  19. function foo(uint32 a, uint32 b) public returns (uint32) {
  20. return a + b;
  21. }
  22. }