-
Notifications
You must be signed in to change notification settings - Fork 48
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
Dry fy shared logic and add util Modifiers contract #1058
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@andreivladbrg can you please update this PR? I would like to review it now. |
ad7d7f0
to
722b98e
Compare
@smol-ninja it is updated now, you can start the review 👌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @andreivladbrg. I have reviewed the core tests. I will review periphery after you have replied to my comments below. Two things I want to mention:
-
Even after closing all the tabs, the browser was working slow because of large number of changes. This is a good argument in favour of why we should split large PRs like this into multiple PRs so that each PR has changes in not more than 50 files. An idea could be to have one PR for core test, another PR for periphery test etc.
-
Most of the comments below apply throughout the code. So if we decide to resolve one comment by making proposed changes, they will also apply to other parts of the diff where I have not commented.
test/core/unit/concrete/adminable/transfer-admin/transferAdmin.t.sol
Outdated
Show resolved
Hide resolved
test/core/unit/concrete/adminable/transfer-admin/transferAdmin.t.sol
Outdated
Show resolved
Hide resolved
test/core/integration/concrete/lockup-dynamic/get-stream/getStream.t.sol
Outdated
Show resolved
Hide resolved
test/core/integration/concrete/lockup-dynamic/streamed-amount-of/streamedAmountOf.t.sol
Outdated
Show resolved
Hide resolved
test/core/integration/concrete/lockup-linear/LockupLinear.t.sol
Outdated
Show resolved
Hide resolved
test/core/integration/concrete/lockup-tranched/LockupTranched.t.sol
Outdated
Show resolved
Hide resolved
15b0485
to
91f4d50
Compare
I’m so sorry to hear the review process was difficult for you. I agree that breaking down work into multiple PRs can make reviews smoother (remember the package tethering PRs?). In this case, however, the process was challenging for me as well. Unlike the package tethering, where I had a clear understanding of the necessary changes from the outset, this time, every adjustment seemed to cause something else to break. @smol-ninja I reintroduced the |
Also: Loom videos for explaining stuff in large PRs would be helpful. |
test: initialize notTransferableStreamId in Lockup shared contracts test: missing visibility for streamId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-reviewed the core tests again and discovered a few more areas where changes may be required. I also found redundant codes which I removed in f28239b. The commit includes some changes related to coding pattern. Let me know if you have any question about it.
I will be reviewing periphery now.
test/core/integration/concrete/lockup-linear/streamed-amount-of/streamedAmountOf.t.sol
Show resolved
Hide resolved
test/core/integration/concrete/lockup-linear/withdrawable-amount-of/withdrawableAmountOf.t.sol
Show resolved
Hide resolved
test/core/integration/concrete/lockup/withdraw-max-and-transfer/withdrawMaxAndTransfer.t.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is periphery review.
test/periphery/integration/merkle-campaign/shared/clawback/clawback.t.sol
Show resolved
Hide resolved
Signed-off-by: smol-ninja <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was journey, thank you again Shub🚀 |
Changes
Closes #1028 and #1045
Motivation
There are two things that this PR should solve:
About the refactor process
I will start with what this PR began with, which is adding the
Modifiers
utility contract. Currently, in thestating
branch, we have two possible places where we declare our modifiers:
v2-core/test/core/integration/concrete/lockup/burn/burn.t.sol
Line 38 in a322ba6
v2-core/test/core/integration/shared/lockup/createWithTimestamps.t.sol
Line 13 in a322ba6
Some of the modifiers contained logic that assumed some setup beforehand, but now, since the
Modifier
contract is theparent (in terms of inheritance), they can't have that logic anymore.
Also, after moving all the modifiers to the new contract mentioned above, I ended up with shared files that contained
only two lines of code, e.g. this one:
v2-core/test/core/integration/shared/lockup/streamedAmountOf.t.sol
Lines 7 to 11 in a322ba6
Which made me question whether we really need these shared files. The purpose of these files is to have a unique setup
or specific helper logic between
<function_name>_Concrete_Test
and<function_name>_Fuzz_Test
(which we’ll call 'Type of test'). However, this was not the case for the vast majority of them, as they only contained duplicated logic throughoutthe test files. Faced with this problem, I asked myself where the best place to put this duplicated logic would be, and
the answer is
Integration_Test
. But once I started doing this, I realized there was another component in thisrefactor:
Lockup_Integration_Shared_Test
, which complicates things further from an inheritance tree standpoint as the only purpose of it is to declare some virtual functions, which are implemented later (LL/LD/LT).There are a lot of pieces in this puzzle that don’t need to be divided into so many parts, as it makes 1) making changes
to the code and 2) understanding the code for new readers more fragile.
At this point, I really had to understand our inheritance tree of a lockup function, and I came up with this diagram:
Click to see diagram
After seeing this, we can conclude some obvious things:
Lockup_Integration_Shared_Test
andIntegration_Test
share the same depth, indicating that they can be abstracted into a single test.LockupModel_Integration_TypeTest
andFunctionName_Integration_TypeTest
depend onLockup_Integration_Shared_Test
andIntegration_Test
, making the organization difficult to follow.This structure adds unneeded complexity, it's like trying to reach your left ear with your right hand.
By abstracting the
Lockup_Integration_Shared_Test
's logic intoIntegration_Test
, we can removeLockupModel_Integration_TypeTest
completely, as its only purpose is to call the setup functions from the left side (LockupModel_Integration_Shared_Test
) and the right side (Integration_Test
) of the diagram. The resulting inheritance diagram would look like this:Click to see diagram
As you can see, it is much simpler now to follow.
Click to see test tree structure comparison
Before PR
After PR
Conclusion
This PR will bring improvements for both the Sablier team and external contributors, enhancing collaboration and code quality.