rollmint
rollmint copied to clipboard
Testing Methods in production code
Finding 012 - Testing Methods in production code
ID
012
Finding
Testing Methods in production code
Severity
0 - Informational
Description
There are testing methods in production code, these testing methods also affect performance because a mutex lock is dependent on a component only used in testing.
Recommendation
Move the methods in a testing package, methods in testing packages can be accessed within testing context.
Code References
https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/manager.go#L208 https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/manager.go#L213 https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/manager.go#L220 https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/manager.go#L225 https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/manager.go#L230 https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/manager.go#L235 https://github.com/rollkit/rollkit/blob/eccdd0f1793a5ac532011ef4d896de9e0d8bcb9d/block/block_cache.go#L13
Test methods can only be accessed within the same package.
https://github.com/golang/go/issues/31135
I believe the advice around defining exports in a test package only really applies to Functions which can live outside a package where an interface or struct is defined.
This methods, are working on unexported fields so they required being defined in the block manager package.
The only way to move them out of production code, would be to move the functionality entirely to mocks within the node package.
The alternative would be to define an interface that can then be accessed within the tests. However the interface itself would still be defined within the production code.
Due to the minimal scope of this code, I recommend just closing this issue.
cc @Manav-Aggarwal
Closing this due to above comment.