2

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        
    }
}
2

This 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 and revert 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 specific require or revert 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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