-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(sims): TestAppSimulationAfterImport and legacy proposal handling #21800
Conversation
WalkthroughWalkthroughThe pull request encompasses a series of changes across multiple files, primarily focusing on the removal of a specific test target related to v2 simulation tests, modifications to function signatures to include account parameters, enhancements to error handling, and restructuring of message factory management. The changes aim to improve clarity, robustness, and functionality within the simulation framework and related testing processes. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Recent review detailsConfiguration used: .coderabbit.yml Files selected for processing (1)
Additional context usedPath-based instructions (1)
Additional comments not posted (2)
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
|
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: 1
Outside diff range and nitpick comments (1)
simapp/sim_test.go (1)
198-198
: Remove the unused parameter from the function signature.The
_ []simtypes.Account
parameter has been added to the function signature but is not being used within the function. Consider removing it to keep the function signature clean.Apply this diff to remove the unused parameter:
-func captureAndCheckHash(t testing.TB, ti simsx.TestInstance[*SimApp], _ []simtypes.Account) { +func captureAndCheckHash(t testing.TB, ti simsx.TestInstance[*SimApp]) {
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (10)
- scripts/build/simulations.mk (0 hunks)
- simapp/sim_test.go (3 hunks)
- simsx/environment.go (1 hunks)
- simsx/registry.go (5 hunks)
- simsx/registry_test.go (2 hunks)
- simsx/reporter.go (1 hunks)
- simsx/runner.go (8 hunks)
- x/gov/simulation/msg_factory.go (1 hunks)
- x/simulation/mock_cometbft.go (2 hunks)
- x/simulation/simulate.go (10 hunks)
Files not reviewed due to no reviewable changes (1)
- scripts/build/simulations.mk
Additional context used
Path-based instructions (9)
x/simulation/mock_cometbft.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simsx/reporter.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simsx/registry_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"simsx/registry.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/sim_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"x/gov/simulation/msg_factory.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simsx/environment.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simsx/runner.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/simulation/simulate.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (30)
x/simulation/mock_cometbft.go (2)
95-96
: LGTM!The change from a fatal error to a log message when attempting to delete a non-existent validator enhances the robustness of the function by preventing abrupt test failures due to non-critical issues. This improves the error handling and contributes to a more stable behavior in the simulation.
190-200
: LGTM!The change in the logic for selecting a misbehavior time and corresponding validator improves the reliability of the function by ensuring that it operates within the bounds of available data. By calculating the starting height based on the total number of blocks processed, the selection of past times and vote information is always valid. This change contributes to a more predictable behavior in the simulation.
simsx/reporter.go (1)
243-245
: LGTM!The conditional check and the appending of the "Skip reasons:" header improve the clarity of the output by providing additional context when there are skip reasons present. The code segment is logically correct and follows the Uber Golang style guide.
simsx/registry_test.go (6)
119-122
: LGTM!The change from
f1
toexampleFactory
usingSimMsgFactoryFn
is consistent with the rest of the test cases and reflects a more structured approach.
125-130
: Test cases look good!The updated expected output in the test cases reflects the changes in the factory function and covers both unique and duplicate factory scenarios.
158-173
: New test function looks good!The
TestWeightedFactories
function tests the addition of weighted factory methods and verifies the correct number of entries and their weights.
175-196
: New test function looks good!The
TestAppendIterators
function checks the functionality of appending iterators from two different registries and verifies that the combined output meets the expected criteria.
198-204
: New helper function looks good!The
readAll
function streamlines the process of reading from iterators by collecting the weight and factory method pairs into a slice ofWeightedFactoryMethod
instances.
Line range hint
1-204
: Conforms to the Uber Golang style guide!The file follows the Uber Golang style guide conventions for naming, formatting, and code organization. The package name, imports, function and variable names, structs, interfaces, and comments adhere to the recommended guidelines.
simsx/registry.go (7)
Line range hint
4-12
: Imports look good!The imported packages seem to be valid and necessary for the code in this file.
40-40
: The type alias is defined correctly.The
WeightedProposalMsgIter
type alias is defined clearly usingiter.Seq2[uint32, FactoryMethod]
. The name is descriptive and follows the Go naming convention.
Line range hint
112-131
: ThelegacyOperationAdapter
function looks good!The function correctly adapts a
SimMsgFactoryX
to asimtypes.Operation
. It sets up the necessary dependencies, runs the factory method safely, and handles the delivery result appropriately. The error handling and reporting look good. The function is well-structured and readable.
Line range hint
172-186
: TheIterator
method is implemented correctly.The method returns a
WeightedProposalMsgIter
that yieldsFactoryMethod
instances. It correctly sorts theWeightedFactory
instances by weight in descending order. The returned iterator function behaves as expected. The method is well-structured and readable.
209-247
: TheWeightedFactoryMethod
andWeightedFactoryMethods
types and methods are implemented correctly.The struct and type definitions are clear and follow Go conventions. The constructor and methods have correct signatures and return types. The
Add
method correctly appends a newWeightedFactoryMethod
and handles nil and zero weight cases. TheIterator
method correctly sorts the instances by weight and returns an iterator that yieldsFactoryMethod
instances. The code is well-structured and readable.
249-259
: ThelegacyToMsgFactoryAdapter
function looks good!The function correctly adapts a
simtypes.MsgSimulatorFnX
to aFactoryMethod
. The returned closure calls thesimtypes.MsgSimulatorFnX
with the provided arguments and returns the generated message. The error handling and reporting look appropriate. The function is well-structured and readable.
261-268
: TheAppendIterators
function is implemented correctly.The function takes multiple
WeightedProposalMsgIter
and returns a single iterator that sequentially yields items from each provided iterator. The function is well-structured and readable.simapp/sim_test.go (4)
119-144
: LGTM!The changes introduce a new way of initializing the application state using the exported genesis state. The
accs
parameter is being used to ensure consistency in the application state during simulation. The changes improve the clarity of the simulation process by explicitly managing the accounts used during the initialization of the application state.
151-151
: LGTM!Setting the
InitialBlockHeight
to the exported genesis height ensures that the simulation starts from the correct block height.
Line range hint
198-222
: LGTM!The changes ensure determinism by comparing the app hashes from multiple iterations of the same seed. Printing the execution logs and failing the test when the app hashes are not equal helps in identifying non-determinism.
128-144
: LGTM!Initializing the chain using the exported genesis state ensures that the simulation starts from the correct state. Skipping the test if the validator set is empty after initializing the genesis state prevents the simulation from running with an invalid state. Using the
accs
parameter to initialize the application state ensures consistency during simulation.x/gov/simulation/msg_factory.go (1)
118-120
: LGTM!The change simplifies the invocation of the
payloadFactory
by removing the need for an additionalCreate()
method call. This streamlines the function's logic, enhancing clarity and potentially improving performance by reducing the method call overhead. The overall functionality remains focused on creating a simulation message factory for submitting proposals, but the internal handling of thepayloadFactory
has been made more straightforward.simsx/environment.go (1)
272-274
: LGTM!The added validation check enhances the robustness of the code by ensuring that all accounts processed have valid addresses. This proactive error handling prevents potential runtime errors or undefined behavior later in the execution flow.
simsx/runner.go (5)
84-84
: LGTM!The change to include
accs []simtypes.Account
in thepostRunActions
variadic function parameter is a good addition. It allows passing the accounts data to the post-run actions for further analysis and assertions.
112-112
: Looks good!The change to include
accs []simtypes.Account
in thepostRunActions
variadic function parameter is consistent with the change made in theRun
function. It allows passing the accounts data to the post-run actions for further analysis and assertions.
139-139
: Looks good to me!The change to include
accs []simtypes.Account
in thepostRunActions
variadic function parameter is consistent with the changes made in theRun
andRunWithSeeds
functions. It allows passing the accounts data to the post-run actions for further analysis and assertions.
Line range hint
156-166
: Looks good!The change to pass the
accs
slice returned fromSimulateFromSeedX
to thepostRunActions
functions is consistent with the changes made in the function signatures. It allows the post-run actions to access the accounts data for further analysis and assertions.
Line range hint
176-281
: The changes look good!The introduction of the
WeightedProposalMsgIter
parameter in theHasWeightedOperationsXWithProposals
interface and the corresponding updates in theprepareWeightedOps
function provide a more flexible way of handling proposals. The changes maintain backward compatibility by handling both the newWeightedProposalMsgIter
parameter and the legacy proposal handling code using thelegacyPReg
variable and theAppendIterators
function.The changes do not introduce any apparent issues and improve the overall proposal handling mechanism.
x/simulation/simulate.go (3)
51-51
: LGTM!The addition of the
InitialHeight
field to theabci.InitChainRequest
based on theconfig.InitialBlockHeight
is a good change. It allows the chain to be initialized at a specific block height, providing more flexibility in the simulation setup.
Line range hint
64-76
: LGTM!The modification to the return signature of
SimulateFromSeed
to includeaccs []simtypes.Account
is a good change. It allows the accounts generated during the simulation to be propagated to the caller for further analysis or testing.
Line range hint
96-282
: LGTM!The modifications to
SimulateFromSeedX
are good changes that improve the robustness of the simulation:
The return signature has been updated to include
accs []simtypes.Account
, which allows the accounts generated during the simulation to be propagated to the caller for further analysis or testing.The error handling has been refined to return the accounts alongside the parameters in various error scenarios (lines 123, 191, 203, 250). This ensures that the state of the accounts is preserved even when an error occurs, aiding in debugging and understanding the simulation's state at the time of failure.
The changes are straightforward and enhance the functionality and error reporting of the simulation.
@@ -74,7 +74,7 @@ var ( | |||
) | |||
|
|||
func TestAppImportExport(t *testing.T) { | |||
simsx.Run(t, NewSimApp, setupStateFactory, func(t testing.TB, ti simsx.TestInstance[*SimApp]) { | |||
simsx.Run(t, NewSimApp, setupStateFactory, func(t testing.TB, ti simsx.TestInstance[*SimApp], _ []simtypes.Account) { |
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.
Use the accs
parameter to initialize the application state.
The accs
parameter has been added to the function signature but is not being used within the function. Consider using it to initialize the application state to ensure consistency during simulation.
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.
heavy to digest, but lgtm!
x := maps.Values(s) | ||
sortedWeightedFactory := slices.SortedFunc(x, func(a, b WeightedFactory) int { | ||
return a.Compare(b) | ||
}) | ||
|
||
return func(yield func(uint32, SimMsgFactoryX) bool) { |
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.
Unrelated, but can we add godocs to SimMsgFactoryX
Description
The
make test-sim-after-import
run was failing after sims2 were merged. This PR includes a fix that takes the startup height into account and ensures that the bech32 addresses for the test accounts are set. For this the accounts from the initial run are forwarded instead of parsing genesis with new (non matching) private keys.includes #21784
Please note the changes to the x/simulation package that are api breaking. This does not affect module code and should be covered by the original changelog
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Bug Fixes
New Features
Refactor
Tests