Skip to content

Conversation

@Pantani
Copy link
Collaborator

@Pantani Pantani commented Oct 28, 2021

close #1702

Description

This PR adds the simulation manager into the app.go for new scaffolded chains. Creates the module_simultation.go for new modules and also for old chains without simap after scaffolding new messages. Keeping the compatibility for old scaffolded chains.

How to test

Scaffold a new chain:

starport s chain github.com/cosmonaut/foo

Scaffold messages and types:

starport s single singleEg desc egId:uint && \  
starport s map mapIndexEg desc --index egId:uint,anotherID && \
starport s map mapEg desc egId:uint && \
starport s list listEg desc egId:uint && \
starport s message msgEg desc egId:uint

Run the simulation:

go test -v -benchmem -run=^$ -bench ^BenchmarkSimulation ./app

@Pantani Pantani self-assigned this Oct 28, 2021
Copy link
Contributor

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

👍

Haven't tested yet. I may see that there are some issues with the integration tests

I refactoring suggestion I have is to try to separate the different types of file modification in the different files now that we have many different types of things that are scaffolded.
So putting moduleSimulationModify in templates/map/simulation.go for example.

@Pantani Pantani requested a review from lumtis October 30, 2021 05:29
@lumtis
Copy link
Contributor

lumtis commented Nov 1, 2021

Pretty neat💯

For the operations scaffolding, I would personally prefer avoiding scaffolding everything in WeightedOperations and trying to perform file creation as much as possible. Keeping file modification only to append element in list, so in this case, appending the operation method in the returned list []simtypes.WeightedOperation like spn:

return []simtypes.WeightedOperation{
		simulation.NewWeightedOperation(
			weightMsgCreateChain,
			launchsimulation.SimulateMsgCreateChain(am.accountKeeper, am.bankKeeper, am.keeper),
		),
		simulation.NewWeightedOperation(
			weightMsgEditChain,
			launchsimulation.SimulateMsgEditChain(am.accountKeeper, am.bankKeeper, am.keeper),
		),
		simulation.NewWeightedOperation(
			weightMsgRequestAddGenesisAccount,
			launchsimulation.SimulateMsgRequestAddGenesisAccount(am.accountKeeper, am.bankKeeper, am.keeper),
		),
                // ...
	}

I would suggest having the template:

func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
	operations := make([]simtypes.WeightedOperation, 0)

	// ...

	// placeholder for simState.AppParams.GetOrGenerate

        return []simtypes.WeightedOperation{
		// placeholder for operation
	}
}

And scaffolding the operation in x/{module_name}/simulation/{message_name} or x/{module_name}/simulation/{type_name}

@Pantani Pantani requested a review from lumtis November 2, 2021 03:22
@lumtis
Copy link
Contributor

lumtis commented Nov 2, 2021

I got this error when runnnig the simulation: invalid memory address or nil pointer dereference

I think it would be fine to return an empty operation with simtypes.NoOpMsg for scaffolded types and messages

@fadeev
Copy link
Contributor

fadeev commented Nov 2, 2021

If I run commands from the PR's description, it returns the following (see the gist). Is this the expected result?

https://gist.github.com/fadeev/68c1abff3b7912bf8ce9f7c785d4910e

@Pantani
Copy link
Collaborator Author

Pantani commented Nov 2, 2021

@fadeev and @lubtd, the reason is an issue with the bank and the account module for simulations. It's fixed. You can try now.

@Pantani Pantani requested a review from lumtis November 2, 2021 16:23
fadeev
fadeev previously approved these changes Nov 2, 2021
Copy link
Contributor

@fadeev fadeev left a comment

Choose a reason for hiding this comment

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

Great work! Excited about simapp being included with Starport! 🙌

Copy link
Contributor

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

👍

ilgooz
ilgooz previously approved these changes Nov 8, 2021
@Pantani Pantani dismissed stale reviews from ilgooz and fadeev via d06735a November 8, 2021 22:03
@Pantani Pantani requested review from fadeev, ilgooz and lumtis November 8, 2021 23:39
Copy link
Contributor

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

Very great👍

Just one last thing: it seems the delete operation (for list, map or single) is never called. I don't know if it may be related to the wight we define.

We can track the issue if we don't solve it for this PR

@Pantani Pantani merged commit 1ae4394 into develop Nov 11, 2021
@Pantani Pantani deleted the feat/scaffold-simap branch November 11, 2021 05:33
Jchicode pushed a commit to Jchicode/cli that referenced this pull request Aug 9, 2023
…gnite#1731)

* scaffold simapp template

* add one line space

* add support to old chains

* improve the noOpMsg description

* improve todo comment for simap weight value

* reuse msg simap scaffold code

* split the simulation methods into a new file

* fix merge from develop

* fix some typos

* scaffold simulaiton package for module

* fix msg signer for plush templates

* fix auth and bank keeper panic

* add expetec keepers for auth and bank modules

* add creator to all msgs

* fix already exist simulation entry

* fix expected keeper conflicts for bank and account

* use existing objs from store to create the update and delete simulation messages

* fix missing imports for simulation

* create a method to find account easilly

* fix simap failures

* remove automatcly added fields for template

Co-authored-by: İlker G. Öztürk <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>
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.

Scaffold simulation testing with simapp

5 participants