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(sim): add sim genesis state for custom modules #1759

Merged
merged 8 commits into from
Jan 1, 2024

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Jan 1, 2024

Purpose / Abstract

Scaffolds the simulation genesis state for Nibiru's custom modules. I decided to go with a breadth approach (multiple modules) instead of a depth approach (a single module) for the sim genesis state because the code was repetitive so it would be easier to review.

Helps towards closing #1736.

Summary by CodeRabbit

  • New Features

    • Introduced simulation functionality for generating random GenesisState across various modules.
  • Improvements

    • Enhanced randomness in the generation of GenesisState for better testing scenarios.
  • Documentation

    • Updated CHANGELOG with details of new simulation features and dependency version bump.
  • Dependency Updates

    • Updated google.golang.org/protobuf from version 1.31.0 to 1.32.0.

Copy link
Contributor

coderabbitai bot commented Jan 1, 2024

Walkthrough

The recent updates involve refining the Cosmos SDK modules by enhancing exported entities, reorganizing imports, and implementing the AppModuleSimulation interface. New simulation-related functions were added, and GenesisState generation now includes randomness features for various modules, ensuring dynamic and unpredictable initial states.

Changes

Files Summary
x/.../module.go, x/.../simulation/genesis.go Updated exported entities, reorganized imports, and implemented AppModuleSimulation interface. Added functions to generate random GenesisState, marshal to JSON, and simulate gas for denom creation.
x/inflation/module.go, x/inflation/simulation/genesis.go Introduced new simulation package import and updated GenerateGenesisState to include randomness.
x/sudo/simulation/genesis.go Removed unused constants and functions, added rootAddress for enhanced randomness in GenesisState.

🐇✨
To the code we hop and bound,
With randomness now profound,
Genesis blooms, a state so free,
In the blockchain's burrowed tree. 🌳🚀

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 with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. 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.
    • @coderabbitai read the files in the src/scheduler package and generate 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.

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.

@k-yang k-yang marked this pull request as ready for review January 1, 2024 16:07
@k-yang k-yang requested a review from a team as a code owner January 1, 2024 16:07
@k-yang k-yang self-assigned this Jan 1, 2024
@k-yang k-yang linked an issue Jan 1, 2024 that may be closed by this pull request
6 tasks
@k-yang k-yang changed the title test(sim): wire sim genesis state for modules test(sim): add sim genesis state for custom modules Jan 1, 2024
@k-yang k-yang enabled auto-merge (squash) January 1, 2024 16:09
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 f235fe2 and 310e53c.
Files selected for processing (11)
  • x/devgas/v1/module.go (7 hunks)
  • x/devgas/v1/simulation/genesis.go (1 hunks)
  • x/inflation/module.go (2 hunks)
  • x/inflation/simulation/genesis.go (1 hunks)
  • x/perp/v2/module/module.go (2 hunks)
  • x/perp/v2/simulation/genesis.go (1 hunks)
  • x/spot/module.go (2 hunks)
  • x/spot/simulation/genesis.go (1 hunks)
  • x/sudo/simulation/genesis.go (1 hunks)
  • x/tokenfactory/module.go (7 hunks)
  • x/tokenfactory/simulation/genesis.go (1 hunks)
Additional comments: 23
x/perp/v2/simulation/genesis.go (1)
  • 14-24: The RandomizedGenState function correctly initializes a default genesis state, marshals it into JSON, and assigns it to the simulation state. The use of panic and MustMarshalJSON is appropriate here as this code is for simulation setup where failures are critical and should stop execution.
x/sudo/simulation/genesis.go (1)
  • 14-22: The RandomizedGenState function in the sudo module correctly introduces a rootAddress to randomize the genesis state. The use of panic and MustMarshalJSON is appropriate for simulation setup code.
x/spot/simulation/genesis.go (1)
  • 23-34: The RandomizedGenState function correctly initializes a default genesis state for the spot module, marshals it into JSON, and assigns it to the simulation state. The use of MustMarshalJSON ensures proper error handling for simulation setup.
x/devgas/v1/simulation/genesis.go (1)
  • 24-46: The RandomizedGenState function for the devgas module correctly generates a random developerFeeShare and uses it to initialize the genesis state. The use of GetOrGenerate for parameter generation and MustMarshalJSON for marshaling is appropriate for simulation setup.
x/tokenfactory/simulation/genesis.go (1)
  • 23-44: The RandomizedGenState function for the tokenfactory module correctly generates a random denomCreationGasConsume and uses it to initialize the genesis state. The use of GetOrGenerate for parameter generation and MustMarshalJSON for marshaling is appropriate for simulation setup.
x/inflation/simulation/genesis.go (1)
  • 15-47: The RandomizedGenState function for the inflation module initializes the genesis state with hardcoded values for simulation purposes. The use of panic and MustMarshalJSON for error handling is appropriate for simulation setup.
x/inflation/module.go (1)
  • 157-158: The GenerateGenesisState function in the inflation module has been correctly updated to accept a simState parameter and call the RandomizedGenState function from the simulation package, aligning with the PR objectives to set up simulation genesis states.
x/spot/module.go (1)
  • 161-162: The GenerateGenesisState function has been correctly added to the spot module's AppModule, and the module now implements the AppModuleSimulation interface, which is in line with the PR objectives for simulation enhancements.
x/perp/v2/module/module.go (1)
  • 175-176: The GenerateGenesisState function has been correctly added to the perp module's AppModule, and the module now implements the AppModuleSimulation interface, which aligns with the PR objectives for simulation enhancements.
x/tokenfactory/module.go (7)
  • 23-31: The import of simtypes and renaming of module references to types are consistent with the PR objectives to set up simulation genesis state for modules.

  • 51-51: The reference to ModuleName has been correctly updated to use the types package.

  • 70-85: The RegisterInterfaces and DefaultGenesis functions have been updated to use the types package. Ensure that the types package contains the correct implementations for these functions.

Verification successful

The shell script output confirms that the types package in the x/tokenfactory directory contains the RegisterInterfaces and DefaultGenesis functions. The RegisterInterfaces function is located in codec.go, and the DefaultGenesis function is in genesis.go.

  • The RegisterInterfaces function is correctly implemented in the types package.
  • The DefaultGenesis function is also present and correctly implemented in the types package.

Based on the provided output, the changes to the RegisterInterfaces and DefaultGenesis functions to use the types package are verified to be correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func RegisterInterfaces' 'x/tokenfactory/types'
rg --type go 'func DefaultGenesis' 'x/tokenfactory/types'

Length of output: 284

* 96-108: The `RegisterGRPCGatewayRoutes`, `GetTxCmd`, and `GetQueryCmd` functions have been updated to use the `types` package. Ensure that the `types` package contains the correct implementations for these functions.
Verification successful

The review comment is concerned with the updates to the RegisterGRPCGatewayRoutes, GetTxCmd, and GetQueryCmd functions to use the types package. The shell script output confirms the presence of the necessary functions in the respective packages:

  • RegisterQueryHandlerClient is found in x/tokenfactory/types/query.pb.gw.go.
  • NewTxCmd is found in x/tokenfactory/cli/tx.go.
  • NewQueryCmd is found in x/tokenfactory/cli/query.go.

Based on the script output, the functions are correctly located in their respective packages, which aligns with the changes mentioned in the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func RegisterQueryHandlerClient' 'x/tokenfactory/types'
rg --type go 'func NewTxCmd' 'x/tokenfactory/cli'
rg --type go 'func NewQueryCmd' 'x/tokenfactory/cli'

Length of output: 434

* 148-151: The `RegisterServices` function has been updated to use the `types` package. Ensure that the `types` package contains the correct implementations for these functions.
Verification successful

The shell script output confirms that the types package contains the necessary functions RegisterMsgServer and RegisterQueryServer. These functions are defined in tx.pb.go and query.pb.go respectively within the x/tokenfactory/types directory.

  • RegisterMsgServer is present in x/tokenfactory/types/tx.pb.go.
  • RegisterQueryServer is present in x/tokenfactory/types/query.pb.go.

Based on this information, the review comment has been addressed correctly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func RegisterMsgServer' 'x/tokenfactory/types'
rg --type go 'func RegisterQueryServer' 'x/tokenfactory/types'

Length of output: 302

* 167-167: The `InitGenesis` function has been updated to use the `types` package. Ensure that the `types` package contains the correct implementations for this function.
Verification successful

The InitGenesis function is indeed present within the keeper package of the tokenfactory module, as indicated by the output of the script. This confirms that the types package is being used correctly in the context of the InitGenesis function within the tokenfactory module.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func InitGenesis' 'x/tokenfactory/keeper'

Length of output: 55



Script:

#!/bin/bash
# Search for the InitGenesis function within the types package of the tokenfactory module.
rg --type go 'func InitGenesis' 'x/tokenfactory/types'

Length of output: 54



Script:

#!/bin/bash
# Search for the InitGenesis function definition in the keeper package of the tokenfactory module.
rg --type go 'func \(.*Keeper\) InitGenesis'

Length of output: 155

* 180-192: New simulation-related functions `GenerateGenesisState`, `RegisterStoreDecoder`, and `WeightedOperations` have been added. Ensure that these functions are correctly implemented and align with the simulation setup objectives.
Verification successful

The RandomizedGenState function exists in the x/tokenfactory/simulation package, confirming that the GenerateGenesisState method in AppModule is correctly implemented by calling this function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the simulation package.
rg --type go 'func RandomizedGenState' 'x/tokenfactory/simulation'

Length of output: 163

x/devgas/v1/module.go (7)
  • 14-23: The import of simtypes and renaming of module references to types are consistent with the PR objectives to set up simulation genesis state for modules.

  • 41-41: The reference to ModuleName has been correctly updated to use the types package.

  • 60-78: The RegisterInterfaces and DefaultGenesis functions have been updated to use the types package. Ensure that the types package contains the correct implementations for these functions.

Verification successful

The shell script output confirms that the types package contains the RegisterInterfaces function in x/devgas/v1/types/codec.go and the DefaultGenesisState function in x/devgas/v1/types/genesis.go. These functions are correctly implemented and available for use in the module.go file as indicated by the changes.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func RegisterInterfaces' 'x/devgas/v1/types'
rg --type go 'func DefaultGenesisState' 'x/devgas/v1/types'

Length of output: 282

* 86-98: The `RegisterGRPCGatewayRoutes`, `GetTxCmd`, and `GetQueryCmd` functions have been updated to use the `types` package. Ensure that the `types` package contains the correct implementations for these functions.
Verification successful

The shell script output confirms the presence of the functions RegisterQueryHandlerClient, NewTxCmd, and GetQueryCmd in the respective packages as referenced in the code snippet from x/devgas/v1/module.go. The types package contains the RegisterQueryHandlerClient function, and the cli package contains both NewTxCmd and GetQueryCmd functions.

  • RegisterQueryHandlerClient is found in x/devgas/v1/types/query.pb.gw.go.
  • NewTxCmd is found in x/devgas/v1/client/cli/tx.go.
  • GetQueryCmd is found in x/devgas/v1/client/cli/query.go.

Based on this information, the review comment is verified as the functions are correctly implemented in their respective packages.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func RegisterQueryHandlerClient' 'x/devgas/v1/types'
rg --type go 'func NewTxCmd' 'x/devgas/v1/client/cli'
rg --type go 'func GetQueryCmd' 'x/devgas/v1/client/cli'

Length of output: 444

* 143-147: The `RegisterServices` function has been updated to use the `types` package. Ensure that the `types` package contains the correct implementations for these functions.
Verification successful

The shell script output confirms that the types package contains the RegisterMsgServer function and the keeper package contains the NewQuerier function. These functions are correctly implemented in their respective packages as indicated by the presence of their definitions in the tx.pb.go and grpc_query.go files.

  • RegisterMsgServer is found in x/devgas/v1/types/tx.pb.go.
  • NewQuerier is found in x/devgas/v1/keeper/grpc_query.go.

Based on this information, the review comment has been addressed correctly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the types package.
rg --type go 'func RegisterMsgServer' 'x/devgas/v1/types'
rg --type go 'func NewQuerier' 'x/devgas/v1/keeper'

Length of output: 261

* 162-162: The `InitGenesis` function has been updated to use the `types` package. Ensure that the `types` package contains the correct implementations for this function.
  • 180-191: New simulation-related functions GenerateGenesisState, RegisterStoreDecoder, and WeightedOperations have been added. Ensure that these functions are correctly implemented and align with the simulation setup objectives.
Verification successful

The RandomizedGenState function is present in the x/devgas/v1/simulation package, which confirms that the GenerateGenesisState method in the AppModule is correctly implemented by calling this function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the necessary functions are present in the simulation package.
rg --type go 'func RandomizedGenState' 'x/devgas/v1/simulation'

Length of output: 157

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 310e53c and 6addb82.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 2
CHANGELOG.md (2)
  • 89-89: The version bump for google.golang.org/protobuf is correctly documented. This is a routine update likely for improvements or security patches.

  • 81-92: The rest of the changelog entries within the hunk are consistent and provide the necessary information about the changes and dependency updates.

@@ -81,10 +81,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1728](https://github.com/NibiruChain/nibiru/pull/1728) - test(devgas-cli): CLI tests for devgas txs
* [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests
* [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs
* [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules
Copy link
Contributor

Choose a reason for hiding this comment

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

The entry for PR #1736 is missing a description of the changes made. It's important for the changelog to include a brief summary of each change for clarity.

* [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules
+ * [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all custom modules. This change sets up the simulation genesis state for various custom modules within the Nibiru blockchain framework, enhancing the simulation capabilities for testing.

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
* [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules
* [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all custom modules. This change sets up the simulation genesis state for various custom modules within the Nibiru blockchain framework, enhancing the simulation capabilities for testing.

Copy link

codecov bot commented Jan 1, 2024

Codecov Report

Attention: 22 lines in your changes are missing coverage. Please review.

Comparison is base (f235fe2) 73.46% compared to head (6addb82) 73.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1759      +/-   ##
==========================================
- Coverage   73.46%   73.43%   -0.03%     
==========================================
  Files         195      194       -1     
  Lines       15449    15459      +10     
==========================================
+ Hits        11350    11353       +3     
- Misses       3437     3444       +7     
  Partials      662      662              
Files Coverage Δ
x/perp/v2/module/module.go 84.12% <20.00%> (-5.53%) ⬇️
x/devgas/v1/module.go 82.45% <70.00%> (-6.01%) ⬇️
x/spot/module.go 56.89% <14.28%> (-5.85%) ⬇️
x/tokenfactory/module.go 82.14% <68.42%> (-6.10%) ⬇️

@k-yang k-yang merged commit d2aa561 into main Jan 1, 2024
17 of 18 checks passed
@k-yang k-yang deleted the test/simulation/generate-genesis-state branch January 1, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

epic: simulation tests [part 1]
2 participants