What does it mean when a Solidity contract includes a comment starting with // dev:
after a revert or require statement?
For example:
contract Example {
function greet(){
revert(); // dev: Hello World
}
}
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityThis is called a developer revert comment. From the Brownie documentation:
Each revert string adds a minimum 20000 gas to your contract deployment cost, and increases the cost for a function to execute. Including a revert string for every
require
andrevert
statement is often impractical and sometimes simply not possible due to the block gas limit.For this reason, Brownie allows you to include revert strings as source code comments that are not included in the bytecode but still accessible via
TransactionReceipt.revert_msg
. You write tests that target a specificrequire
orrevert
statement without increasing gas costs.
To write a test that handles the example in the question, use the entire revert comment starting with dev
:
import brownie
def test_greet(example):
with brownie.reverts("dev: Hello World"):
example.greet()
For more information:
Disclosure: I am the lead developer for Brownie.