-
Notifications
You must be signed in to change notification settings - Fork 108
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
refactor: improve ZETA deposit check with max supply check #3074
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces several enhancements primarily focused on the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3074 +/- ##
========================================
Coverage 63.43% 63.43%
========================================
Files 425 425
Lines 30003 30019 +16
========================================
+ Hits 19031 19044 +13
- Misses 10137 10139 +2
- Partials 835 836 +1
|
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.
Actionable comments posted: 9
🧹 Outside diff range and nitpick comments (4)
testutil/keeper/mocks/fungible/bank.go (1)
Line range hint
11-14
: Consider adding helper methods for common testing scenarios.Since this mock is being used for testing ZETA deposit checks with max supply validation, consider adding helper methods to simplify test setup:
type FungibleBankKeeper struct { mock.Mock + + // Helper methods for common testing scenarios + defaultSupply types.Coin } +// WithDefaultSupply sets up the mock to return a specific supply for any denom +func (_m *FungibleBankKeeper) WithDefaultSupply(supply types.Coin) *FungibleBankKeeper { + _m.defaultSupply = supply + _m.On("GetSupply", mock.Anything, mock.Anything).Return(supply) + return _m +}This would allow test cases to be written more concisely:
keeper := NewFungibleBankKeeper(t).WithDefaultSupply(types.NewCoin("zeta", sdkmath.NewInt(1000)))x/fungible/keeper/zeta_test.go (1)
34-72
: Enhance test readability and maintainability.While the test logic is correct, consider these improvements:
- Use a named constant for the overflow amount instead of magic number "1"
- Make test names more descriptive of the scenarios being tested
- t.Run("mint the token to reach max supply", func(t *testing.T) { + t.Run("should successfully mint tokens up to exactly max supply", func(t *testing.T) { - t.Run("can't mint more than max supply", func(t *testing.T) { + t.Run("should fail when attempting to mint beyond max supply", func(t *testing.T) { + const overflowAmount = 1 // Amount to exceed max supply by - newAmount := zetaMaxSupply.Sub(supply).Add(sdk.NewInt(1)) + newAmount := zetaMaxSupply.Sub(supply).Add(sdk.NewInt(overflowAmount))x/fungible/keeper/zevm_message_passing_test.go (1)
Line range hint
1-378
: Enhance overall test coverage with comprehensive scenarios.While the current test suite covers basic functionality, consider adding the following test scenarios to improve coverage:
Edge Cases:
- Test with supply exactly at max limit
- Test with amounts that would cause overflow
- Test with zero amounts
Error Conditions:
- Test concurrent minting scenarios
- Test recovery from failed transactions
Integration Scenarios:
- Test interaction between supply validation and contract reverts
- Test supply validation with various contract states
These additional test cases would help ensure the robustness of the supply validation mechanism and its interaction with other system components.
x/fungible/keeper/deposits_test.go (1)
440-443
: Enhance mock setup clarity and error handlingThe mock setup could be more explicit and maintainable. Consider these improvements:
-errorMint := errors.New("", 1, "error minting coins") +errMintFailure := errors.New("fungible", 1, "mock: mint coins operation failed") bankMock.On("GetSupply", ctx, mock.Anything, mock.Anything). - Return(sdk.NewCoin(config.BaseDenom, sdk.NewInt(0))). + Return(sdk.NewCoin(config.BaseDenom, sdk.NewInt(0))). + Run(func(args mock.Arguments) { + // Verify that we're checking supply for the correct denomination + denom := args.Get(1).(string) + require.Equal(t, config.BaseDenom, denom) + }). Once() -bankMock.On("MintCoins", ctx, types.ModuleName, mock.Anything).Return(errorMint).Once() +bankMock.On("MintCoins", ctx, types.ModuleName, mock.Anything). + Run(func(args mock.Arguments) { + // Verify the coins being minted + coins := args.Get(2).(sdk.Coins) + require.Equal(t, amount.Int64(), coins.AmountOf(config.BaseDenom).Int64()) + }). + Return(errMintFailure). + Once()This improves the test by:
- Using a more descriptive error variable name
- Adding domain and context to the error message
- Adding assertions in mock callbacks to verify input parameters
- Making the mock setup more explicit about what's being tested
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (7)
testutil/keeper/mocks/fungible/bank.go
(1 hunks)x/fungible/keeper/deposits_test.go
(1 hunks)x/fungible/keeper/zeta.go
(3 hunks)x/fungible/keeper/zeta_test.go
(5 hunks)x/fungible/keeper/zevm_message_passing_test.go
(2 hunks)x/fungible/types/errors.go
(1 hunks)x/fungible/types/expected_keepers.go
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
testutil/keeper/mocks/fungible/bank.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/keeper/deposits_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/keeper/zeta.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/keeper/zeta_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/keeper/zevm_message_passing_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/types/errors.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/fungible/types/expected_keepers.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
🪛 GitHub Check: codecov/patch
x/fungible/keeper/zeta.go
[warning] 22-23: x/fungible/keeper/zeta.go#L22-L23
Added lines #L22 - L23 were not covered by tests
[warning] 44-45: x/fungible/keeper/zeta.go#L44-L45
Added lines #L44 - L45 were not covered by tests
🔇 Additional comments (2)
x/fungible/types/expected_keepers.go (1)
36-36
: Well-designed interface extension for supply management.
The addition of GetSupply
method to the BankKeeper
interface is well-structured and follows good design principles:
- Clear and purposeful method signature
- Appropriate return type using
sdk.Coin
- Maintains interface cohesion with existing supply management methods
- Enables proper implementation of max supply validation for ZETA tokens
x/fungible/types/errors.go (1)
37-37
: Well-structured error definition.
The new error ErrMaxSupplyReached
is well-defined and follows the module's established patterns:
- Maintains sequential error codes (1135)
- Uses clear, concise error message
- Properly aligned with existing declarations
- Directly supports the PR's objective of implementing max supply validation
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.
Left a comment, other than that all good
Description
Add a check for ZETA deposit to not surpass a supply cap as an extra security check
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests