Closed PaulRBerg closed 8 months ago
Given how our test structure is designed (shared
dir) is the code identity test really needed?
We are running the same tests for these functions:cancel
, renounce
and withdraw
in both contracts, so if there were to be difference between the implementations, the tests would fail for that contract (ofc assuming we have a 100% coverage for each function and we are testing what each line does).
I believe this test would be helpful only if we want to check if the comments are identical, thus we should lower the priority.
Regarding the test method, using forge seems to be an overkill. Adding a Bash script in the shell
directory, which should be run during CI, would be more appropriate.
Yes, performing these code identity checks would still be helpful even if we run the same tests for these contracts.
1 + 3 = 2 +2
. So it's not just about the comments.Regarding the test method, using forge seems to be an overkill. Adding a Bash script in the shell directory, which should be run during CI, would be more appropriate
Fair enough
@PaulRBerg since we implemented https://github.com/sablier-labs/v2-core/pull/813 should we close this issue?
Not sure. Isn't there duplicated code still?
If there is, we should keep this issue open (though revise the description in light of the new spec).
Just these lines, but I don't think they count
Linear:
Dynamic:
Everything else is completely different
Yeah, they don't count, especially since we might end up removing protocol fees.
Problem
Because Solidity does not have anything equivalent to Rust traits, we are forced to duplicate any logic that touches upon different structs despite the logic being completely identical.
_cancel
_renounce
_withdraw
Technically speaking, there is a way out, but it's ugly and not worth it. We could implement a setter for every struct field (e.g.,
setIsCancelable
,setWasCanceled
, etc.), but:Solution
Introduce a new class of tests, i.e. differential tests, that perform the following checks:
LockupLinear
and theLockupDynamic
contracts (and potentiallyLockupTranched
in the future)_cancel
and the_withdraw
functions. They should be 100% identical, down to the English comments.awk
utility might be helpful hereThe tests would use Bash scripting and the
ffi
cheat code to read the file contents.Alternatively, if implementing this in Forge is too complicated, we can write a CI check. There should be GitHub Actions for performing diffs between files.
References