3

I am using JavaScript to run some tests on my solidity contract. Since solidity ^0.4.22 you can have a message in require such as:

function Hello {
    require(msg.sender == 0x001234, "msg.sender MUST BE 0x001234"); 
}

When writing tests in javascript I can use the contractName.methods.function to access functions from within the solidity contract. Any idea how I could access the message from require or to implement to test that this message is shown correctly?

1 Answer 1

1

You can modify this helper a little bit to check error.message should contain your message on the require

https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/test/helpers/assertRevert.js

1
  • Thanks a lot! I also found another possibility, basically using a try/catch and identify the error. Now I am going to integrate the message as well :D
    – Iulian
    Commented Sep 7, 2018 at 14:51

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.