-
Notifications
You must be signed in to change notification settings - Fork 14
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: reorder migrate modules #944
Conversation
WalkthroughThe pull request introduces modifications to the upgrade testing and migration processes across multiple files. In Changes
Sequence DiagramsequenceDiagram
participant Upgrade as Upgrade Process
participant Contract as Contract Updater
participant Migration as Migration Handler
Upgrade->>Contract: updateWPUNDIAILogicCode()
Contract-->>Upgrade: Update WPUNDIAI Contract
Upgrade->>Contract: updateERC20LogicCode()
Contract-->>Upgrade: Update ERC20 Contract
Upgrade->>Migration: migrateModulesData()
Migration-->>Upgrade: Perform Module Migrations
Possibly related PRs
Poem
✨ Finishing Touches
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
CodeRabbit Configuration File (
|
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: 3
🧹 Nitpick comments (2)
app/upgrades/v8/upgrade.go (1)
Line range hint
377-381
: Correct Comment Indentation and FormattingThere are mismatched indentation levels and commented code in this section, which reduces readability.
Align the comments and code properly:
} - if moduleName == ethtypes.ModuleName { - balance := myApp.BankKeeper.GetBalance(ctx, myApp.AccountKeeper.GetModuleAddress(moduleName), fxtypes.DefaultDenom) - oldCoins := bdd.ModuleBalances[ethtypes.ModuleName] - require.Equal(t, balance.Amount.String(), fxtypes.SwapAmount(oldCoins.AmountOf(fxtypes.LegacyFXDenom)).String()) - } + if moduleName == ethtypes.ModuleName { + balance := myApp.BankKeeper.GetBalance(ctx, myApp.AccountKeeper.GetModuleAddress(moduleName), fxtypes.DefaultDenom) + oldCoins := bdd.ModuleBalances[ethtypes.ModuleName] + require.Equal(t, balance.Amount.String(), fxtypes.SwapAmount(oldCoins.AmountOf(fxtypes.LegacyFXDenom)).String()) + } }app/upgrade_test.go (1)
378-381
: Improve Clarity in Test AssertionsThe test assertion combines several function calls within the
require.Equal
statement. For improved readability and easier debugging, consider breaking down the expression.Refactor the code as follows:
balance := myApp.BankKeeper.GetBalance(ctx, myApp.AccountKeeper.GetModuleAddress(moduleName), fxtypes.DefaultDenom) oldCoinAmount := oldCoins.AmountOf(fxtypes.LegacyFXDenom) swappedAmount := fxtypes.SwapAmount(oldCoinAmount) require.Equal(t, balance.Amount.String(), swappedAmount.String())This makes each step explicit and aids in understanding the test logic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
app/upgrade_test.go
(3 hunks)app/upgrades/v8/upgrade.go
(5 hunks)scripts/linter.sh
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Mergify Merge Protections
- GitHub Check: Summary
🔇 Additional comments (10)
app/upgrades/v8/upgrade.go (6)
184-197
: Reordering Migration Functions for Logical FlowThe migration functions within
migrateModulesData
seem to be reordered. Ensure that the order of these migrations does not introduce dependencies that could cause issues.Please confirm that reordering these functions does not affect the integrity of the migration process. If certain migrations depend on previous steps, they should be ordered accordingly.
Line range hint
378-381
: Verify Balance Swap LogicIn the balance check for the
ethtypes.ModuleName
, ensure that the swapping of amounts fromLegacyFXDenom
toDefaultDenom
is correct and that balances match expectations after the upgrade.Double-check that
fxtypes.SwapAmount
correctly transforms the old coin amounts and that the balances align with the new denominations.
Line range hint
396-396
: Potential Issue with Coin Swapping LogicWhen swapping coins in
checkAccountBalance
, verify thatfxtypes.SwapCoins
correctly handles all coin denominations, especially for any new or deprecated denominations.Ensure that the swapping function accurately reflects the intended transformations and that no coins are missed or incorrectly converted.
177-178
:⚠️ Potential issueHandle Errors from
migrateModulesData
FunctionErrors returned by
migrateModulesData
should be properly handled to prevent issues during the upgrade.Apply this diff:
if err = migrateModulesData(ctx, codec, app); err != nil { return fromVM, err }Likely invalid or redundant comment.
77-78
: Ensure Error Handling for Contract Code UpdatesThe functions
updateWPUNDIAILogicCode
andupdateERC20LogicCode
are called here, but their potential errors are not being handled. If an error occurs during the contract code update, it might be silently ignored.Consider checking the returned errors from these functions and handle them appropriately to ensure that any issues during the upgrade process are caught and managed.
updateWPUNDIAILogicCode(ctx, app.EvmKeeper) updateERC20LogicCode(ctx, app.EvmKeeper) +if err := updateWPUNDIAILogicCode(ctx, app.EvmKeeper); err != nil { + return err +} +if err := updateERC20LogicCode(ctx, app.EvmKeeper); err != nil { + return err +}
Line range hint
645-645
: Update Assertions for Non-Empty QuoteThe assertion
require.Empty(t, quote)
checks if the quote is empty. Given the context, verify whether the quote should indeed be empty or if this test needs adjustment.Confirm the expected behavior of
GetDefaultOracleQuote
after the upgrade. If quotes are expected to exist, the test should reflect that.If quotes should be present, update the assertion:
-require.Empty(t, quote) +require.NotEmpty(t, quote)app/upgrade_test.go (3)
396-396
: Check for Possible Missing DenominationsIn the coin swapping logic within
checkAccountBalance
, ensure that all denominations, including any new ones introduced in the upgrade, are accounted for.Review if any denominations are being missed due to assumptions in
fxtypes.SwapCoins
and update the swapping logic accordingly.
645-645
: Verify Expected Bridge Fee QuoteThe test currently requires the
quote
to be empty. Confirm whether, after the upgrade, the bridge fee quote should indeed be empty or if there should be valid data.If the quote is expected to have data, update the assertion to reflect that. If it should be empty, consider adding comments explaining why.
377-381
: Update Test to Reflect Correct Balance Swap LogicThe test checks the balance for the
ethtypes
module after swapping denominations. Ensure that the test accurately reflects the expected state post-upgrade.Confirm that the old coins are correctly transformed using
fxtypes.SwapAmount
and that the assertion is valid.balance := myApp.BankKeeper.GetBalance(ctx, myApp.AccountKeeper.GetModuleAddress(moduleName), fxtypes.DefaultDenom) oldCoins := bdd.ModuleBalances[ethtypes.ModuleName] require.Equal(t, balance.Amount.String(), fxtypes.SwapAmount(oldCoins.AmountOf(fxtypes.LegacyFXDenom)).String())Ensure that
fxtypes.SwapAmount
handles the amount conversion correctly.✅ Verification successful
Balance Swap Logic Verification Successful
The test correctly verifies the balance conversion from FX to apundiai tokens. The
SwapAmount
function implements a 100:1 conversion ratio by dividing the amount by 100, which is the expected behavior for the upgrade process.🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
#!/bin/bash # Find SwapAmount function implementation ast-grep --pattern 'func SwapAmount($$$) $$$' # Search for denomination constants rg "DefaultDenom|LegacyFXDenom" -A 2 # Look for related test cases rg "SwapAmount.*test" -A 3Length of output: 53729
scripts/linter.sh (1)
6-6
: Update Allowed Suppression Count for 'nolint'The allowed count for the 'nolint' pattern has been reduced from 23 to 22. Ensure that this decrease corresponds to a reduction in 'nolint' comments in the codebase.
No action needed if this reflects the current state of the code.
Summary by CodeRabbit
New Features
Refactor
Chores