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 btt tests for finalize methods #159

Merged
merged 26 commits into from
Jul 22, 2024
Merged

feat: add btt tests for finalize methods #159

merged 26 commits into from
Jul 22, 2024

Conversation

0xteddybear
Copy link

proposal: what do you thing of refactoring BPool btt unit tests so the pool deployer is the test runner, so the normal case is for the caller to be the pool's controller, and we don't need a branch+modifier for it.

that's the main difference I found between tests for bpool and bcowpool, do you have any opinion on any of them being safer/cleaner?

@wei3erHase
Copy link
Member

since we're using a "valid scenario" approach doesn't seem bad to me

Comment on lines 1 to 4
// as we previously did in fuzzed tests, here we only test the new behaviour
// introduced by the extension, however we don't go as far as just testing the
// _afterFinalize hook to avoid an internal change to BPool.finalize from
// inadvertedly breaking the derived method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted, i'd remove this comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ok, but i don't think the comment belongs here, whatever decision we take, is taken, shouldn't be on the tree

@0xteddybear 0xteddybear requested a review from wei3erHase July 16, 2024 22:32
│ └── it should revert
└── when preconditions are met
├── it finalizes the pool
├── it mints initial pool supply to controller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it mints initial pool supply + it pushes initial pool supply to controller

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

watch out this contract doesn't have the .t.sol termination

vm.mockCall(tokens[1], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true));
}

function test_WhenCalled() external {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_What?

Copy link
Author

@0xteddybear 0xteddybear Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the result of implementing feedback from this: #159 (comment) 😭 what did you have in mind?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this because Finalize is the only method in the tree for now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, precisely. That's why PRs depending on this all have renames of these methods 😭

Copy link
Member

@wei3erHase wei3erHase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be testing _finalize here if i'm not mistaken

@0xteddybear
Copy link
Author

we should be testing _finalize here if i'm not mistaken

we previously decided to test the behaviour of _afterFinalize as an implementation detail of finalize and not re-assert in BCoWPool tests the behaviour already asserted by BPool tests: https://github.com/defi-wonderland/balancer-v1-amm/pull/159/files/31e634a8e81b1c94e090d3a362ceabe20998ea51#diff-7e75a9fe3f8126c1cca0ddcf61f0b115b82b1ac011da5f1a0c3b140a7067a021

or are you referring to something else?

@0xteddybear 0xteddybear requested a review from wei3erHase July 18, 2024 15:58
@wei3erHase
Copy link
Member

what's the difference in rationale between BCoWFactory::_newBPool?

@0xteddybear
Copy link
Author

what's the difference in rationale between BCoWFactory::_newBPool?

in _newBPool we had the internal method return the address of the newly created pool. Therefore, mocking its return value allowed us to assert (with the help of fuzzing) that all other operations were performed against whatever _newBPool returned, which is a step up from precomputing the CREATE'd address and testing against that value only, which kind of justifies doing it differently. In general, I prefer this approach for the reasons described in previous comments + it's easier to keep consistent, since we will be able to do the same kind of testing in cases where it's not practical to mock the internal function's behaviour.

If you want to sacrifice the extra testing in _newBPool to maximize consistency, I happen to have this: #168 🤗

@@ -0,0 +1,8 @@
BCoWPool::Finalize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BCoWPool::Finalize
BCoWPool::finalize

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do it this way then the contract has to be named BCoWPoolfinalize which isn't as clean

Copy link
Member

@wei3erHase wei3erHase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, i don't really like the "implicit tree" in which you need to read BPool::finalize to know what happens inside BCoWPool::finalize, in the case that BCoWPool definitely overrides BPool one, i'd be ok with having both in different tests, in this case, i think i very much prefer the _afterFinalize hook as we had in other examples

i don't have strong opinions on it either, if you think is good like this i'm ok with it

Base automatically changed from test/btt-bcowpool-verify to dev July 22, 2024 16:46
@@ -1,4 +1,4 @@
BCoWPool::Finalize
BCoWPool::_afterFinalize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much betta!

@0xteddybear 0xteddybear requested a review from wei3erHase July 22, 2024 16:58
Copy link
Member

@wei3erHase wei3erHase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨‍🎤

@wei3erHase wei3erHase changed the title Test/btt tests for finalize methods feat: add btt tests for finalize methods Jul 22, 2024
@wei3erHase wei3erHase merged commit 2a0b429 into dev Jul 22, 2024
4 checks passed
@wei3erHase wei3erHase deleted the test/btt-finalize branch July 22, 2024 17:00
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

Successfully merging this pull request may close these issues.

2 participants