alexfertel / bulloak

A Solidity test generator based on the Branching Tree Technique.
Apache License 2.0
225 stars 13 forks source link

feat: add support for actions without parent conditions #26

Closed alexfertel closed 10 months ago

alexfertel commented 10 months ago

This PR introduces one major change: adding support for actions without conditions. This is reflected in two areas:

Closes https://github.com/alexfertel/bulloak/issues/22

Considerations

We emit one test per top-level action. Even though this is inconsistent with how actions behave when they have parent conditions, I think it is less surprising, since actions without conditions suggest unrelated function invariants. This means that for the following .tree:

test.sol
├── it should match the output of a high-level hash
└── it should never revert

bulloak emits:

pragma solidity 0.8.0;

contract TestTest {
  function test_MatchTheOutputOfAHigh_levelHash() external {
    // it should match the output of a high-level hash
  }

  function test_NeverRevert() external {
    // it should never revert
  }
}

Also, it's possible to interleave any number of actions and conditions. This enables testing function invariants & more specific scenarios using the same .tree file, instead of having to use two separate trees. This means that for the following .tree:

file.sol
└── it should do stuff
└── when something happens
    └── it should revert
└── it does everything

bulloak emits:

pragma solidity 0.8.0;

contract FileTest {
  function test_DoStuff() external {
    // it should do stuff
  }

  modifier whenSomethingHappens() {
    _;
  }

  function test_RevertWhen_SomethingHappens()
    external
    whenSomethingHappens
  {
    // it should revert
  }

  function test_DoesEverything() external {
    // it does everything
  }
}