Skip to content
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

test(sims): Add sims function for token factory module #1802

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

GNaD13
Copy link

@GNaD13 GNaD13 commented Feb 19, 2024

Purpose / Abstract

Summary by CodeRabbit

  • New Features

    • Enhanced the token factory module to support new simulation operations for token creation, minting, burning, changing administrators, and setting metadata.
    • Introduced functionality for proposing and simulating updates to module parameters related to token creation.
  • Refactor

    • Updated the AppModule structure to include a new BankKeeper field and adjusted initialization to accommodate this change.
    • Modified message type retrieval functions and added new constants for message types to improve clarity and maintainability.
  • Tests

    • Extended module test suite to cover the integration of BankKeeper and new simulation operations.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2024

Walkthrough

This update integrates the BankKeeper into the tokenfactory module, enhancing its functionality with new simulation and governance features. It adds support for token operations like creation, minting, and burning, and introduces simulation for these actions and governance proposals. This ensures a more robust and tested module, ready for diverse use cases in token management and operations.

Changes

Files Change Summary
app/keepers.go, x/tokenfactory/module_test.go Modified initAppModules to include app.BankKeeper in tokenfactory.NewAppModule call and adjusted tests accordingly
x/tokenfactory/module.go Updated AppModule to include bk field, added new simulation and governance functions
x/tokenfactory/simulation/operations.go, proposals.go Introduced simulation operations and proposals for token actions
x/tokenfactory/types/tx_msgs.go Added constants for message types, updated message type functions
x/tokenfactory/keeper/grpc_query.go, keeper/keeper.go, keeper/msg_server.go Updated references to BankKeeper for consistency and clarity in various keeper files

Related issues

  • Issue register x/tokenfactory simulation functions #1758: This PR seems to address the objective of implementing and integrating simulation functions for x/tokenfactory, which aligns with the issue's goal of ensuring accurate simulation and seamless integration.

Poem

In the land of code, where the bits do roam,
A rabbit hopped in, making blockchain its home.
With a hop and a skip, it wove a magical feat,
Tokens to mint, burn, and tweak.
🌟 Through the keeper's gate, it danced with glee,
For a factory of tokens, as vast as the sea.
"To the future," it whispered, with a twinkle in its eye,
Where tokens and dreams, in harmony, lie. 🚀🐇

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@GNaD13 GNaD13 changed the title Add sims function for token factory module test: Add sims function for token factory module Feb 19, 2024
@GNaD13 GNaD13 marked this pull request as ready for review February 19, 2024 04:55
@GNaD13 GNaD13 requested a review from a team as a code owner February 19, 2024 04:55
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 688ac5d and 760df98.
Files selected for processing (6)
  • app/keepers.go (1 hunks)
  • x/tokenfactory/module.go (2 hunks)
  • x/tokenfactory/module_test.go (1 hunks)
  • x/tokenfactory/simulation/operations.go (1 hunks)
  • x/tokenfactory/simulation/proposals.go (1 hunks)
  • x/tokenfactory/types/tx_msgs.go (7 hunks)
Additional comments: 10
x/tokenfactory/simulation/proposals.go (1)
  • 31-43: The function SimulateMsgUpdateParams generates a random MsgUpdateModuleParams message for simulation purposes. It uses the default governance module account address as the authority and sets a random value for DenomCreationGasConsume. This approach is effective for simulating various scenarios with different gas consumption values. However, it's important to ensure that the range of random values generated for DenomCreationGasConsume aligns with realistic and meaningful test scenarios.
x/tokenfactory/module_test.go (1)
  • 26-26: The addition of bapp.BankKeeper as a parameter to NewAppModule in the test setup aligns with the changes made to the AppModule constructor to accommodate the new BankKeeper dependency. This ensures that the module is properly initialized with all necessary dependencies for the tests to run correctly. It's a good practice to update test setups in accordance with changes to the codebase to maintain test accuracy and relevance.
x/tokenfactory/module.go (2)
  • 118-131: The addition of the bk field of type types.BankKeeper to the AppModule struct and its inclusion in the NewAppModule function signature are necessary changes to integrate the bank keeper into the token factory module. This allows the module to interact with the bank keeper, facilitating operations involving token and financial transactions. It's important to ensure that all references and usages of the AppModule throughout the codebase are updated to include the new BankKeeper dependency.
  • 183-201: The addition of simulation functions (GenerateGenesisState, ProposalMsgs, RegisterStoreDecoder, and WeightedOperations) to the AppModule struct enhances the module's capabilities by introducing simulation functionalities. These changes are aligned with the PR's objectives to integrate simulation operations and functionalities into the token factory module. It's crucial to ensure that these simulation functions are properly tested to validate their behavior and effectiveness in simulating real-world scenarios.
x/tokenfactory/types/tx_msgs.go (3)
  • 9-15: The introduction of constants for message types (MsgCreateDenomType, MsgChangeAdminType, MsgMintType, MsgBurnType, MsgSetDenomMetadataType) is a good practice for maintaining consistency and readability in the code. Using these constants in message type retrieval functions helps avoid hard-coded strings, reducing the potential for typos and making the code easier to maintain.
  • 143-161: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [110-157]

The type assertions for MsgMint to ensure it implements both sdk.Msg and legacytx.LegacyMsg interfaces are crucial for ensuring compatibility and proper handling of the message within the Cosmos SDK framework. Similarly, the updates to the routing and type functions to use the newly introduced constants improve code maintainability and readability. It's important to ensure that all message types within the module follow this pattern for consistency.

  • 202-213: The updates made to the MsgBurn message, including the type assertion and updates to routing and type functions, follow the same pattern as MsgMint. These changes ensure that MsgBurn is properly integrated within the Cosmos SDK framework and that the code remains consistent and maintainable. As with MsgMint, it's important to apply these practices to all message types within the module.
x/tokenfactory/simulation/operations.go (2)
  • 48-77: The BuildOperationInput function constructs an OperationInput object. However, the Cdc field of the OperationInput struct is always set to nil. This might be intentional, but if the codec is required for serialization or deserialization within the simulation operations, this could lead to runtime errors. Please verify if the codec is needed and, if so, provide it appropriately.
  • 397-407: The SimulateMsgSetDenomMetadata function generates random metadata for a denomination, including description, name, and symbol. While using random data is typical in simulations, ensure that the generated strings meet any expected format or validation rules that might apply in a real-world scenario. This is to ensure the simulation accurately reflects possible outcomes.
app/keepers.go (1)
  • 617-617: The modification to pass app.BankKeeper as an argument to tokenfactory.NewAppModule is consistent with the PR's objective to enhance the token factory module by integrating simulation operations and functionalities. This change suggests an increased interaction between the token factory module and the bank keeper, likely to facilitate operations involving token and financial transactions. Ensure that the BankKeeper is properly initialized before this call to avoid any null pointer exceptions or initialization issues. Overall, this change appears to be logically sound and correctly implemented.

// Get sims account
simAccount, _ := simtypes.RandomAcc(r, accs)

// TODO: Check if sims account enough create fee when CreateDenom Msg charge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO comment at line 201 indicates a pending task to check if the simulation account has enough create fee when CreateDenom message charges a fee. It's important to address TODOs before merging to ensure that all intended functionality is complete and tested. If this check is crucial for the simulation's accuracy, it should be implemented.

Would you like assistance in implementing this check or should it be tracked via a GitHub issue?

x/tokenfactory/simulation/operations.go Outdated Show resolved Hide resolved
Comment on lines 343 to 347
// Check if admin account balance = 0
accountBalance := bk.GetBalance(ctx, adminAccount.Address, denom)
if accountBalance.Amount.LTE(sdk.ZeroInt()) {
return simtypes.NoOpMsg(types.ModuleName, types.MsgBurn{}.Type(), "sim account have no balance"), nil, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the SimulateMsgBurn function, there's a check to ensure the admin account has a balance before attempting to burn tokens. This is a good practice for preventing simulation errors. However, it might be beneficial to log or return more detailed information about why the operation cannot proceed if the balance is zero, especially for debugging purposes.

Consider enhancing the feedback for this scenario to aid in debugging and clarity.

Comment on lines +14 to +17
const (
DefaultWeightMsgUpdateModuleParams int = 100

OpWeightMsgUpdateModuleParams = "op_weight_msg_update_module_params" //nolint:gosec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of nolint:gosec to suppress the Go security linter for the OpWeightMsgUpdateModuleParams constant might be necessary due to the linter flagging it as a potential security issue. However, it's good practice to add a comment explaining why this suppression is needed to ensure future maintainers understand the reasoning.

-	OpWeightMsgUpdateModuleParams = "op_weight_msg_update_module_params" //nolint:gosec
+	OpWeightMsgUpdateModuleParams = "op_weight_msg_update_module_params" //nolint:gosec // Explanation for why this suppression is necessary.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const (
DefaultWeightMsgUpdateModuleParams int = 100
OpWeightMsgUpdateModuleParams = "op_weight_msg_update_module_params" //nolint:gosec
const (
DefaultWeightMsgUpdateModuleParams int = 100
OpWeightMsgUpdateModuleParams = "op_weight_msg_update_module_params" //nolint:gosec // Explanation for why this suppression is necessary.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 760df98 and 1143611.
Files selected for processing (1)
  • x/tokenfactory/simulation/operations.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/tokenfactory/simulation/operations.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Member

@Unique-Divine Unique-Divine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding the BankKeeper twice, you should use the one on the TokenFactoryKeeper.

// Keeper of this module maintains collections of feeshares for contracts
// registered to receive Nibiru Chain gas fees.
type Keeper struct {
	storeKey storetypes.StoreKey
	cdc      codec.BinaryCodec

	Store StoreAPI

	// interfaces with other modules
	bankKeeper          tftypes.BankKeeper  // 👈👈👈👈👈👈👈👈👈👈👈👈
	accountKeeper       tftypes.AccountKeeper
	communityPoolKeeper tftypes.CommunityPoolKeeper

	// the address capable of executing a MsgUpdateParams message. Typically,
	// this should be the x/gov module account.
	authority string
}

The change needed here for sims is to make this the bank keeper a public field

@Unique-Divine Unique-Divine changed the title test: Add sims function for token factory module test(sims): Add sims function for token factory module Feb 21, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1143611 and 8de8f73.
Files selected for processing (1)
  • x/tokenfactory/simulation/operations.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/tokenfactory/simulation/operations.go

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: Patch coverage is 40.74074% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 74.02%. Comparing base (c557272) to head (aad0afb).
Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1802      +/-   ##
==========================================
+ Coverage   73.07%   74.02%   +0.94%     
==========================================
  Files         196      196              
  Lines       15564    12713    -2851     
==========================================
- Hits        11374     9411    -1963     
+ Misses       3526     2637     -889     
- Partials      664      665       +1     
Files Coverage Δ
x/tokenfactory/keeper/grpc_query.go 100.00% <100.00%> (ø)
x/tokenfactory/keeper/keeper.go 86.20% <100.00%> (-0.46%) ⬇️
x/tokenfactory/keeper/msg_server.go 85.80% <100.00%> (+2.64%) ⬆️
x/tokenfactory/module.go 80.00% <0.00%> (-2.15%) ⬇️
x/tokenfactory/types/tx_msgs.go 85.57% <14.28%> (-11.60%) ⬇️

... and 170 files with indirect coverage changes

@GNaD13
Copy link
Author

GNaD13 commented Feb 22, 2024

Instead of adding the BankKeeper twice, you should use the one on the TokenFactoryKeeper.

// Keeper of this module maintains collections of feeshares for contracts
// registered to receive Nibiru Chain gas fees.
type Keeper struct {
	storeKey storetypes.StoreKey
	cdc      codec.BinaryCodec

	Store StoreAPI

	// interfaces with other modules
	bankKeeper          tftypes.BankKeeper  // 👈👈👈👈👈👈👈👈👈👈👈👈
	accountKeeper       tftypes.AccountKeeper
	communityPoolKeeper tftypes.CommunityPoolKeeper

	// the address capable of executing a MsgUpdateParams message. Typically,
	// this should be the x/gov module account.
	authority string
}

The change needed here for sims is to make this the bank keeper a public field

Hi @Unique-Divine, thanks for your reviewed. I've updated the code

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8de8f73 and 6ee57f2.
Files selected for processing (5)
  • x/tokenfactory/keeper/grpc_query.go (1 hunks)
  • x/tokenfactory/keeper/keeper.go (2 hunks)
  • x/tokenfactory/keeper/msg_server.go (4 hunks)
  • x/tokenfactory/module.go (1 hunks)
  • x/tokenfactory/simulation/operations.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/tokenfactory/module.go
  • x/tokenfactory/simulation/operations.go
Additional comments: 10
x/tokenfactory/keeper/keeper.go (2)
  • 26-26: The renaming of bankKeeper to BankKeeper improves consistency and clarity in the codebase. Ensure all references to this field within the package are updated accordingly.
  • 64-64: The assignment of the bk parameter to the BankKeeper field in the NewKeeper function is correctly implemented. Verify the usage of NewKeeper function across the codebase to ensure compatibility.
x/tokenfactory/keeper/grpc_query.go (1)
  • 67-67: Updating the reference from k.bankKeeper to k.BankKeeper in the QueryDenomInfo function aligns with the updated field name in the Keeper struct. Ensure to test the QueryDenomInfo function to verify its correct behavior post-update.
x/tokenfactory/keeper/msg_server.go (7)
  • 153-153: Updating the reference to BankKeeper in the mint function aligns with the updated field name in the Keeper struct. Ensure to thoroughly test the mint function to verify its correct behavior post-update.
  • 163-163: The reference to BankKeeper.BlockedAddr in the mint function correctly uses the updated field name. Ensure to test this functionality to confirm it behaves as expected after the update.
  • 168-168: The use of BankKeeper.SendCoinsFromModuleToAccount in the mint function is correctly updated. Testing this functionality is crucial to ensure it operates correctly post-update.
  • 228-228: The reference to BankKeeper.BlockedAddr in the burn function correctly uses the updated field name. It's important to test this functionality to confirm its correct behavior after the update.
  • 234-234: The use of BankKeeper.SendCoinsFromAccountToModule in the burn function is correctly updated. Testing this functionality is crucial to ensure it operates correctly post-update.
  • 240-240: The reference to BankKeeper.BurnCoins in the burn function correctly uses the updated field name. Ensure to test this functionality to confirm its correct behavior after the update.
  • 268-268: The use of BankKeeper.SetDenomMetaData in the SetDenomMetadata function is correctly updated. Testing this functionality is crucial to ensure it operates correctly post-update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

register x/tokenfactory simulation functions
3 participants