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

Move variables from Defaults to Constants #63

Open
smol-ninja opened this issue Feb 10, 2025 · 3 comments
Open

Move variables from Defaults to Constants #63

smol-ninja opened this issue Feb 10, 2025 · 3 comments
Labels
effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: chore Maintenance work. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.

Comments

@smol-ninja
Copy link
Member

What if we move constant and immutable variables from Defaults to Constants contract? This can remove several redundant lines from the code where we have to set the default value onto a local variable to make expectRevert work.

For example,

uint256 index1 = defaults.INDEX1();
uint128 amount = defaults.CLAIM_AMOUNT();
bytes32[] memory merkleProof = defaults.index1Proof();
uint256 fee = defaults.FEE();

vm.expectRevert(abi.encodeWithSelector(Errors.SablierMerkleBase_InsufficientFeePayment.selector, 0, fee));
merkleBase.claim{ value: 0 }(index1, users.recipient1, amount, merkleProof);

would become

bytes32[] memory merkleProof = defaults.index1Proof();

vm.expectRevert(abi.encodeWithSelector(Errors.SablierMerkleBase_InsufficientFeePayment.selector, 0, FEE));
merkleBase.claim{ value: 0 }(INDEX1, users.recipient1, CLAIM_AMOUNT, merkleProof);

cc @sablier-labs/evm.

@smol-ninja smol-ninja added effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: chore Maintenance work. work: clear Sense-categorize-respond. The relationship between cause and effect is clear. labels Feb 10, 2025
@andreivladbrg
Copy link
Member

i don't remember exactly the initial reason for not inheriting the Defaults contract and instead deploying it in BaseTest. but now, i believe it would be better to simply inherit it. (cc @PaulRBerg do you remember?)

so, i’d say not to move just some variables to Constants while keeping others in Defaults, but rather to move all variables to a single contract (either we call it Constants or Defaults) that will be inherited in BaseTest (similarly how we do it in Flow tests). wdyt?

@smol-ninja
Copy link
Member Author

Yes I agree. I just realized we did the same in Flow.

@PaulRBerg
Copy link
Member

Your plan sounds good.

The original rationale, AFAIK, was to provide context when reading the texts — seeing defaults.VAR_NAME instead of VAR_NAME points to the fact that that value is a global default used in multiple tests. However, you make a good point @smol-ninja that because of the expect revert behavior of Foundry, we need to pre-define the vars, which makes the original rationale not so strong anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: low Easy or tiny task that takes less than a day. priority: 2 We will do our best to deal with this. type: chore Maintenance work. work: clear Sense-categorize-respond. The relationship between cause and effect is clear.
Projects
None yet
Development

No branches or pull requests

3 participants