0

I have a function test in contract Test which calls a function in contract A that is expected to fail. How can I extract the information from returnData so that I can include this information in the require statement?

contract A {
    event E(string msg);

    function e() public {
        require(false, "BUM!");
        emit E("hello");
    }
}

contract Test {
    A a = new A();

    event E(bytes data);

    function test() public {
        (bool res, bytes memory returnData) = address(a).call(abi.encode(A.e.selector));
        emit E(returnData);
        //require(res, "forward failed: "+..error message from the returnData...);
    }
}

1 Answer 1

0

Solidity require() statement does not return an error message per se, since it aborts the operation you will need to implement a try/catch block"

contract A {
event E(string msg);

function e() public {
    require(false, "BUM!");
    emit E("hello");
}
}

contract Test {
  A a = new A();

  event E(bytes data);

  function test() public {
    (bool res, bytes memory returnData) = address(a).call(abi.encode(A.e.selector));
    try A.e.selector
    {
        //What it does if no error happens...
    }
    catch (bytes memory reason) {
        emit E(reason);
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.