Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifiers for each testing branch #77

Closed
PaulRBerg opened this issue Jun 21, 2022 · 1 comment
Closed

Modifiers for each testing branch #77

PaulRBerg opened this issue Jun 21, 2022 · 1 comment
Assignees

Comments

@PaulRBerg
Copy link
Member

PaulRBerg commented Jun 21, 2022

For this testing tree:

getSender.t.sol
├── when the stream does not exist
│  └── it should return zero
└── when the stream exists
   └── it should return the correct sender

Generate a test contract that uses modifiers to structure the tests:

contract SablierV2Linear__GetSender is SablierV2LinearUnitTest {
    /// @dev it should return zero.
    function testGetSender__StreamNonExistent() external {
        // ...
    }

    modifier StreamExistent() {
        _;
    }

    /// @dev it should return the correct sender.
    function testGetSender() external StreamExistent {
        // ...
    }
}
@PaulRBerg PaulRBerg self-assigned this Jun 21, 2022
PaulRBerg added a commit that referenced this issue Jun 26, 2022
chore: disable "no-empty-blocks" solhint rule
test: refactor all test function names

Closes #77
PaulRBerg added a commit that referenced this issue Jun 26, 2022
chore: disable "no-empty-blocks" solhint rule
test: refactor all test function names

Closes #77
PaulRBerg added a commit that referenced this issue Jun 26, 2022
chore: disable "no-empty-blocks" solhint rule
test: refactor all test function names

Closes #77
@PaulRBerg
Copy link
Member Author

PaulRBerg commented Jun 26, 2022

The long-term benefits of implementing this:

  1. Makes it harder to fool yourself while writing tests. Because the test file mirrors the testing branch exactly, you can see very quickly what is the context and state for a given test function.
  2. Reduces the amount of time spent thinking (and debating) how to name contracts and function names.
  3. Reduces the information needed to provide in the test descriptors (the @dev NatSpec comments), since the contract name and inheritance structures provides the testing branch.
  4. This is on objective way of generating tests based on a testing tree, so, in principle, it should be possible to write a script that takes a .tree file as an input and generates a skeleton file with the contract names and test functions.

@PaulRBerg PaulRBerg changed the title Create a test contract for each testing branch Modifiers for each testing branch Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant