Skip to main content
Building an application is complicated and requires a lot of testing. The Cosmos SDK provides a way to test your application in a real-world environment: a testnet. We allow developers to take the state from their mainnet and run tests against the state. This is useful for testing upgrade migrations, or for testing the application in a real-world environment.

Testnet Setup

We will be breaking down the steps to create a testnet from mainnet state.

Required Changes

Staking

When creating a testnet the important part is migrate the validator set from many validators to one or a few. This allows developers to spin up the chain without needing to replace validator keys.

Distribution

Since the validator set has changed, we need to update the distribution records for the new validator.

Slashing

We also need to set the validator signing info for the new validator.

Bank

It is useful to create new accounts for your testing purposes. This avoids the need to have the same key as you may have on mainnet.

Upgrade

If you would like to schedule an upgrade the below can be used.

Optional Changes

If you have custom modules that rely on specific state from the above modules and/or you would like to test your custom module, you will need to update the state of your custom module to reflect your needs

Running the Testnet

Before we can run the testnet we must plug everything together. in root.go, in the initRootCmd function we add:
Next we will add a newTestnetApp helper function: