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(simulation): re-enable simulation tests #1735

Merged
merged 14 commits into from
Dec 28, 2023

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Dec 28, 2023

Purpose / Abstract

Re-enables and fixes the following simulation tests:

  • TestAppImportExport
  • TestAppSimulationAfterImport
  • TestAppStateDeterminism
  • TestFullAppSimulation

The tests were copied over from https://github.com/cosmos/cosmos-sdk/blob/d09f40d0a1160dc576c68b6be9c54e4ac07aa92f/simapp/sim_test.go and adapted to run with the Nibiru app.

The PR also adds a GHA workflow to run the simulation tests once a day on the main branch.

There are follow-up PRs to add simulation operations for Nibiru custom modules (see #1737)

Summary by CodeRabbit

This update does not change the existing bullet-point list. Therefore, the previous list remains valid and can be repeated verbatim:

Summary by CodeRabbit

  • New Features

    • Introduced a workflow for automated simulation tests.
    • Enhanced simulation test commands and parameters for better testing scenarios.
    • Expanded application initialization and configuration options in testing utilities.
  • Improvements

    • Renamed a key field for clarity and consistency across the application codebase.
    • Updated module management calls to align with the renamed field.
  • Documentation

    • Updated CHANGELOG with recent pull request modifications and dependency updates.
  • Refactor

    • Restructured simulation-related code to improve maintainability and performance.
  • Bug Fixes

    • Addressed issues in simulation tests to ensure reliability.

Copy link
Contributor

coderabbitai bot commented Dec 28, 2023

Walkthrough

The project has introduced a workflow for simulation testing, enhanced the naming clarity in the application code, and improved the simulation testing framework. It has also updated the module management within the application files and extended the functionality of the x/sudo module to support simulation operations. These updates streamline development processes and enrich the application's capabilities.

Changes

File Path Change Summary
.github/workflows/simulation-tests.yml Introduced workflow for simulation tests with daily runs and various scenarios.
CHANGELOG.md Documented PRs modifying scripts, fixing tests, and dependency updates.
app/app.go
app/export.go
app/keepers.go
app/upgrades.go
Refactored to rename mm to ModuleManager and updated method calls and references.
contrib/make/simulation.mk Overhauled test commands for simulation scenarios.
simapp/sim_test.go
simapp/state_test.go
Updated test functions, imports, and control flow for simulation setup.
x/common/testutil/testapp/testapp.go Modified function signature to accept baseAppOptions and added import.
simapp/README.md Added documentation for simulation tests for the simapp module.
x/sudo/module.go
x/sudo/simulation/genesis.go
Expanded simulation functionality and implemented simulation interface.

🐇✨
Code hops through fields anew,
Tests simulate a dawn's soft hue,
Modules align in tidy queue,
As x/sudo learns to brew.
🌿🎉

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.

Copy link

codecov bot commented Dec 28, 2023

Codecov Report

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

Comparison is base (d33dfe9) 73.89% compared to head (811a00f) 73.86%.
Report is 5 commits behind head on main.

❗ Current head 811a00f differs from pull request most recent head 6eae1e3. Consider uploading reports for the commit 6eae1e3 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1735      +/-   ##
==========================================
- Coverage   73.89%   73.86%   -0.03%     
==========================================
  Files         192      193       +1     
  Lines       15142    15206      +64     
==========================================
+ Hits        11189    11232      +43     
- Misses       3297     3312      +15     
- Partials      656      662       +6     
Files Coverage Δ
app/app.go 58.06% <100.00%> (ø)
app/keepers.go 99.18% <100.00%> (-0.03%) ⬇️
app/upgrades.go 55.55% <100.00%> (ø)
cmd/nibid/cmd/root.go 80.51% <100.00%> (+0.10%) ⬆️
app/export.go 0.00% <0.00%> (ø)
cmd/nibid/cmd/decode_base64.go 72.28% <72.28%> (ø)

... and 2 files with indirect coverage changes

@k-yang k-yang marked this pull request as ready for review December 28, 2023 14:30
@k-yang k-yang requested a review from a team as a code owner December 28, 2023 14:30
@k-yang k-yang self-assigned this Dec 28, 2023
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 68bddeb and faa6c8d.
Files ignored due to filter (1)
  • simapp/params.json
Files selected for processing (12)
  • .github/workflows/simulation-tests.yml (1 hunks)
  • CHANGELOG.md (2 hunks)
  • app/app.go (4 hunks)
  • app/export.go (1 hunks)
  • app/keepers.go (2 hunks)
  • app/upgrades.go (1 hunks)
  • contrib/make/simulation.mk (1 hunks)
  • simapp/sim_test.go (3 hunks)
  • simapp/state_test.go (1 hunks)
  • x/common/testutil/testapp/testapp.go (3 hunks)
  • x/sudo/module.go (2 hunks)
  • x/sudo/simulation/genesis.go (1 hunks)
Additional comments: 35
app/upgrades.go (1)
  • 23-23: The change from app.mm to app.ModuleManager in the CreateUpgradeHandler method call is consistent with the renaming of the field. Ensure that all references to the old mm field have been updated across the codebase to maintain consistency.
x/sudo/simulation/genesis.go (3)
  • 23-25: The GenCommunityTax function generates a random community tax rate. The calculation seems correct, but it's important to ensure that the resulting tax rate is within acceptable bounds for the application.

  • 28-30: The GenWithdrawEnabled function has a 95% chance to enable withdrawals. This hardcoded probability should be documented or configurable if the business logic requires flexibility.

  • 33-47: The RandomizedGenState function correctly generates a random GenesisState for the x/sudo module. It's important to ensure that the simState.Accounts[0].Address.String() call is safe and that the account at index 0 is guaranteed to exist.

contrib/make/simulation.mk (4)
  • 6-14: The test-sim-nondeterminism target has been updated with new parameters. Verify that these parameters (-Enabled, -Params, -NumBlocks, -BlockSize, -Commit, -Period, -Verbose) are correctly used in the test and that the test is functioning as expected with these new settings.

  • 19-27: The test-sim-default-genesis-fast target has been updated similarly to test-sim-nondeterminism. Ensure that the parameters are appropriate for the intended test scenarios and that the test behaves correctly.

  • 32-39: The new test-sim-import-export target is introduced for running application import/export simulation tests. Confirm that the parameters provided are suitable for the tests and that the tests cover the necessary scenarios.

  • 44-51: The test-sim-after-import target is added for running application simulation-after-import tests. As with the other targets, ensure that the parameters are correctly set and that the tests are comprehensive.

.github/workflows/simulation-tests.yml (4)
  • 17-27: The test-sim-nondeterminism job is set up to run on the ubuntu-latest runner with Go version 1.21. Ensure that this Go version is compatible with the project's requirements and that the job will execute the make test-sim-nondeterminism command as intended.

  • 29-39: The test-sim-default-genesis-fast job is configured similarly to test-sim-nondeterminism. Confirm that the Go version and the runner are appropriate for the project and that the command is correctly set up to run the test.

  • 41-51: The test-sim-import-export job is introduced to run the import/export simulation tests. Verify that the setup is correct and that the test command will run as expected.

  • 53-63: The test-sim-after-import job is added for running simulation-after-import tests. Ensure that the setup is correct and that the test command will run as expected.

simapp/state_test.go (1)
  • 67-67: An empty line has been added at line 67. This does not affect the functionality but improves readability by separating logical blocks of code.
x/common/testutil/testapp/testapp.go (1)
  • 107-107: The addition of baseAppOptions as variadic arguments to the NewNibiruTestApp function signature allows for more flexible configuration of the BaseApp. Ensure that all calls to this function have been updated to pass the appropriate options where necessary.
app/export.go (1)
  • 32-32: The change from app.mm.ExportGenesisForModules to app.ModuleManager.ExportGenesisForModules is consistent with the renaming of the field. Ensure that all references to the old mm field have been updated across the codebase to maintain consistency.
x/sudo/module.go (3)
  • 14-14: The addition of the simtypes import is necessary for the simulation functionality.

  • 26-28: The AppModule struct now implements the module.AppModuleSimulation interface, which is required for simulation functionality.

  • 162-164: The GenerateGenesisState function correctly implements the required interface method for simulation state generation.

app/app.go (5)
  • 93-93: Renaming the mm field to ModuleManager in the NibiruApp struct improves code readability and clarity.

  • 182-182: The method initSimulationManager is correctly renamed to follow Go's convention of unexported methods starting with a lowercase letter.

  • 254-254: The BeginBlocker method correctly references the renamed ModuleManager field.

  • 259-259: The EndBlocker method also correctly references the renamed ModuleManager field.

  • 268-269: The InitChainer method correctly uses the renamed ModuleManager field and its method InitGenesis. This is a key part of the application initialization process.

simapp/sim_test.go (8)
  • 8-9: The addition of "runtime/debug" and "strings" imports suggests new error handling and string manipulation functionality. Ensure these are used appropriately in the test functions.

  • 58-61: The new type StoreKeysPrefixes is added. Verify that this type is used effectively in the tests and that the naming convention is consistent with the project's standards.

  • 64-109: The TestFullAppSimulation function has been refactored to use the simtestutil package for setup and simulation. Ensure that the simulation setup and teardown are correctly handled and that the simulation parameters are properly configured.

  • 5-143: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [111-175]

The TestAppStateDeterminism function has been modified to use the simcli package for configuration and setup. Verify that the determinism test is correctly implemented and that the simulation parameters are properly configured.

  • 148-158: The simulation function SimulateFromSeed is called with the new setup. Ensure that the simulation is executed correctly and that the error handling is appropriate.

  • 160-161: The PrintStats function is called conditionally based on the config.Commit flag. Verify that the statistics are printed correctly and that the condition is appropriate.

  • 177-301: The TestAppImportExport function is added to test the import/export functionality of the application. Verify that the import/export simulation is set up correctly, that the application state is exported and imported as expected, and that the store comparison is correctly implemented.

  • 303-389: The TestAppSimulationAfterImport function is added to test the application simulation after import. Verify that the simulation after import is set up correctly, that the application state is exported and imported as expected, and that the simulation is executed correctly.

app/keepers.go (2)
  • 708-724: The refactoring from app.mm to app.ModuleManager is consistent with the summary provided. Ensure that all references to the old app.mm have been updated across the entire codebase to prevent any runtime errors.
Verification successful

The search for references to app.mm in Go files has found a commented-out line in app/keepers.go. Since it is a comment, it does not affect the execution of the code. Therefore, there are no runtime errors to be concerned about due to references to app.mm.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to 'app.mm' which should have been replaced.
rg --type go 'app\.mm'

Length of output: 83

* 850-858: The update to the simulation manager initialization using `module.NewSimulationManagerFromAppModules` and the override map is a significant change. Verify that the override modules are correctly configured and that the simulation manager is properly initialized with these changes.
Verification successful

The verification of the initSimulationManager function and the overrideModules map in app/keepers.go indicates that the simulation manager is being initialized correctly with the provided override modules. The outputs from the shell scripts confirm that the changes align with the PR objectives and the AI-generated summaries.

  • The app.sm is properly assigned using module.NewSimulationManagerFromAppModules.
  • The overrideModules map is declared and used correctly, with at least one override for authtypes.ModuleName.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the usage of the simulation manager to ensure it's being initialized correctly.
rg --type go 'app\.sm'
# Verify that the overrideModules map is correctly used in the simulation manager.
ast-grep --lang go --pattern $'map[string]module.AppModuleSimulation{$$$}'

Length of output: 556

CHANGELOG.md (2)
  • 75-91: The changelog entries are well-structured and adhere to the guidelines provided in the comments at the beginning of the file.

  • 97-99: The format for versioning and dates is consistent and follows the project's standards.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
x/sudo/module.go Show resolved Hide resolved
x/sudo/module.go Outdated Show resolved Hide resolved
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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between faa6c8d and 811a00f.
Files selected for processing (3)
  • CHANGELOG.md (3 hunks)
  • simapp/README.md (1 hunks)
  • x/sudo/module.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • x/sudo/module.go
Additional comments: 3
simapp/README.md (3)
  • 1-16: The description for the non-determinism test case is clear and concise, explaining the purpose and the expected outcome of the test.

  • 18-25: The description for the full app simulation test is clear, indicating what the test does and what it checks for.

  • 51-59: The explanation of the params.json file provides important context for why certain operations are weighted as zero. This is a good documentation of a known issue and the current workaround.

Comment on lines +27 to +36
### Import/Export

```sh
make test-sim-import-export
```

This test case runs the simulation with the default genesis file. It checks that
the simulation does not panic and that the resulting state is valid. It then
exports the state to a file and imports it back. It checks that the imported
state is the same as the exported state.
Copy link
Contributor

Choose a reason for hiding this comment

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

The description for the import/export test case is clear, but consider if the repeated explanation in the simulation after import section is necessary, as it may be seen as redundant.

Comment on lines +38 to +49
### Simulation After Import

```sh
make test-sim-after-import
```

This test case runs the simulation with the default genesis file. It checks that
the simulation does not panic and that the resulting state is valid. It then
exports the state to a file and imports it back. It checks that the imported
state is the same as the exported state. It then runs the simulation again with
the imported state. It checks that the simulation does not panic and that the
resulting state is valid.
Copy link
Contributor

Choose a reason for hiding this comment

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

The simulation after import test case description repeats information from the import/export test case. It might be more concise to reference the previous test and focus on the additional steps that are unique to this test.

@@ -90,7 +90,7 @@ type NibiruApp struct {
AppKeepers // embed all module keepers

// the module manager
mm *module.Manager
ModuleManager *module.Manager
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have some benefit of adding it public?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's required for TestAppImportExport.

@Unique-Divine Unique-Divine enabled auto-merge (squash) December 28, 2023 15:34
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 811a00f and 6eae1e3.
Files selected for processing (1)
  • CHANGELOG.md (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@Unique-Divine Unique-Divine merged commit a8ff7ef into main Dec 28, 2023
16 checks passed
@Unique-Divine Unique-Divine deleted the test/simulation/fix-sim-tests branch December 28, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Completed
3 participants