I'm using Solidity 0.8.13 and Truffle 5.5.6.
I'm just trying to debug a transaction call that fails then reverts when I do truffle migration.
I temporarily changed my onlyOwner
modifier to make the reason message display the values of my owner
and msg.sender
into something like below:
modifier onlyOwner() {
//require( msg.sender == owner, "Only Owner can call." ); // this reason message works
require( msg.sender == owner, string( abi.encodePacked( "Owner mismatch: ", owner, " != ", msg.sender ) ) );
_;
}
However, in the output of truffle migrate --reset
(where my original issue was happening), it doesn't display the reason message at all and just display:
"Foo" hit a require or revert statement somewhere in its constructor. Try:
* Verifying that your constructor params satisfy all require conditions.
* Adding reason strings to your require statements.
Can anyone tell me what's wrong with passing in concatenated string reason message in require()?
Best Answer
You can use
Strings.sol
library about OpenZeppelin andstrings.sol
about Arachnid to concatenate strings and build your message.You can see this example:
UPDATED ANSWER: