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

feat: add support for actions without parent conditions #26

Merged
merged 2 commits into from
Aug 31, 2023

Conversation

alexfertel
Copy link
Owner

@alexfertel alexfertel commented Aug 31, 2023

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

  • Remove the semantic check that every action needs a parent condition.
  • Emit a test for each top-level action.

Closes #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
  }
}

@alexfertel alexfertel added the Feat New feature or request label Aug 31, 2023
@alexfertel alexfertel self-assigned this Aug 31, 2023
@alexfertel alexfertel merged commit d22320e into main Aug 31, 2023
5 checks passed
@alexfertel alexfertel deleted the issue-22-add-support-for-actions-no-conditions branch August 31, 2023 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: Add support for actions without conditions.
1 participant