alexfertel / bulloak

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

Feature: Implement automatic fix for roots with different contract name #60

Open alexfertel opened 4 months ago

alexfertel commented 4 months ago
ContractName::func1
└── It should have a name mismatch in the contracts.

MismatchedContractName::func2
└── It should have a name mismatch in the contracts.

For the above tree, we get the following message when running bulloak check:

$ cargo run -- check tests/check/contract_names_mismatch_multiple_roots.tree
warn: an error occurred while parsing the tree: contract name mismatch: expected 'ContractName', found 'MismatchedContractName'
   --> tests/check/contract_names_mismatch_multiple_roots.tree

warn: 1 check failed

We should make the violation fixable and implement the auto fix.

alexfertel commented 2 months ago

Adding a bit more of color on the work needed here:

Violations can be fixable, meaning there may be a sequence of steps to fix them by bulloak itself. For example, if a tree root is MyContract and the contract in the solidity file is named MyBeautifulContract, it's very easy to fix it by just renaming the contract.

In that specific issue, two roots in the same .tree have different contract names. However, they describe functions in the same generated contract, so the roots should be the same. This is fixable by, for example, replacing every root that is not correct with whatever the contract name is in the first root.

Two changes are needed to implement this: first, making the violations fixable because they aren't by default, and then implementing the actual fix so that when we run bulloak check —-fix, it takes violations away.

drgorillamd commented 5 days ago

Violations can be fixable, meaning there may be a sequence of steps to fix them by bulloak itself. For example, if a tree root is MyContract and the contract in the solidity file is named MyBeautifulContract, it's very easy to fix it by just renaming the contract.

I'm currently in a campaign to implement systematic use of Bulloak within my org, and one thing we now do to have an "easy" CI/nice dev ex is to use the suffix _Unit in our roots (and then run all the unit test with --mc Unit).

"Enforcing" tree root == name of the tested contract would break this then (I know, we could then match the glob path instead, but it's less straightforward/dev friendly imo). Anecdotical report tho, I don't know if others are doing something similar.

alexfertel commented 5 days ago

I'm currently in a campaign to implement systematic use of Bulloak within my org

Let's goooo 🚀 Please share all the feedback you have, happy to help with this.

"Enforcing" tree root == name of the tested contract would break this then

Hehe, use case for a bulloak.toml with

[lints]
matching_contract_names = "allow"

Thanks for bringing this up.