function_call.sol 700 B

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