|
| 1 | +# Interchain tests for gaia. |
| 2 | + |
| 3 | + |
| 4 | +These tests use [interchaintest](https://github.com/strangelove-ventures/interchaintest/) to |
| 5 | +create, upgrade, and test chains. |
| 6 | + |
| 7 | +They dockerize the validators, so they depend on a `gaia` docker image being built. |
| 8 | +You can build a docker image using the [docker-push](../../.github/workflows/docker-push.yml) workflow. |
| 9 | +`docker-push` runs nightly on the `main` branch, and for all new releases, but you can also |
| 10 | +[run it manually on any branch](https://github.com/cosmos/gaia/actions/workflows/docker-push.yml) |
| 11 | + |
| 12 | +Once the `gaia` image is built, the `docker-push` action workflow automatically invoke the |
| 13 | +[interchain-test](../../.github/workflows/interchain-test.yml) workflow. |
| 14 | + |
| 15 | +Read on to learn how these tests work. |
| 16 | + |
| 17 | +## Upgrade testing |
| 18 | + |
| 19 | +The tests will make sure it's possible to upgrade from a previous version of |
| 20 | +`gaia` to the current version being tested. It does so by starting a chain from genesis |
| 21 | +on the previous version, then upgrading it to the current version. |
| 22 | + |
| 23 | +## Version selection |
| 24 | + |
| 25 | +The `interchain-test` workflow will start by selecting versions to test upgrading from. |
| 26 | + |
| 27 | +The [`matrix_tool`](./matrix_tool/main.go) tool will take the tag of the image |
| 28 | +being tested (e.g. `v18.0.0`, or `main`, or `some-feature-branch`), and figure |
| 29 | +out a corresponding semver. If the tag is already a valid semver, that's the |
| 30 | +version. Otherwise, it will take the major version from the module line in `go.mod`, |
| 31 | +and append `.999.0`. Given that semver, it'll figure out: |
| 32 | + |
| 33 | +* The previous rc (if the current version is itself an rc) |
| 34 | +* The previous minor version (if applicable) |
| 35 | +* The previous major version |
| 36 | + |
| 37 | +For instance, for `v15.1.0-rc1`, we'll test upgrading from: |
| 38 | +* `v15.1.0-rc0` |
| 39 | +* `v15.0.0` |
| 40 | +* `v14.2.0` |
| 41 | + |
| 42 | +The workflow will then test upgrading from each of those three to the current |
| 43 | +version. When it's a major upgrade, it will do so via governance proposal, |
| 44 | +otherwise it'll simply stop the old image and start the new one. |
| 45 | + |
| 46 | +## Test Suites |
| 47 | + |
| 48 | +Each of the *_test.go files in this directory contains a test suite. These |
| 49 | +share some common scaffolding (a `SetupSuite`) to create and upgrade a chain, |
| 50 | +and then run a set of tests on that chain. |
| 51 | + |
| 52 | +So, for instance, a transactions suite: |
| 53 | + |
| 54 | +```go |
| 55 | +type TxSuite struct { |
| 56 | + *chainsuite.Suite |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +It extends `chainsuite.Suite,` so its SetupSuite will create and upgrade a |
| 61 | +chain (more on this later). The individual `Test*` methods then run the gaia |
| 62 | +version being tested: |
| 63 | + |
| 64 | +```go |
| 65 | +func (s *TxSuite) TestBankSend() { |
| 66 | + balanceBefore, err := s.Chain.GetBalance(s.GetContext(), s.Chain.ValidatorWallets[1].Address, chainsuite.Uatom) |
| 67 | + s.Require().NoError(err) |
| 68 | + |
| 69 | + _, err = s.Chain.Validators[0].ExecTx( |
| 70 | + s.GetContext(), |
| 71 | + s.Chain.ValidatorWallets[0].Moniker, |
| 72 | + "bank", "send", |
| 73 | + s.Chain.ValidatorWallets[0].Address, s.Chain.ValidatorWallets[1].Address, txAmountUatom(), |
| 74 | + ) |
| 75 | + s.Require().NoError(err) |
| 76 | + |
| 77 | + balanceAfter, err := s.Chain.GetBalance(s.GetContext(), s.Chain.ValidatorWallets[1].Address, chainsuite.Uatom) |
| 78 | + s.Require().NoError(err) |
| 79 | + s.Require().Equal(balanceBefore.Add(sdkmath.NewInt(txAmount)), balanceAfter) |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +Because of how testify works, we have to instantiate each suite to run it. |
| 84 | +This is also where we tell the suite to run an upgrade on Setup: |
| 85 | + |
| 86 | +```go |
| 87 | +func TestTransactions(t *testing.T) { |
| 88 | + txSuite := TxSuite{chainsuite.NewSuite(chainsuite.SuiteConfig{UpgradeOnSetup: true})} |
| 89 | + suite.Run(t, &txSuite) |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +Of course, we can also parameterize the test suites themselves. This enables us |
| 94 | +to write tests once and run them a bunch of times on different configurations: |
| 95 | + |
| 96 | +```go |
| 97 | +type ConsumerLaunchSuite struct { |
| 98 | + *chainsuite.Suite |
| 99 | + OtherChain string |
| 100 | + OtherChainVersion string |
| 101 | + ShouldCopyProviderKey [chainsuite.ValidatorCount]bool |
| 102 | +} |
| 103 | + |
| 104 | +func TestICS40ChainLaunch(t *testing.T) { |
| 105 | + s := &ConsumerLaunchSuite{ |
| 106 | + Suite: chainsuite.NewSuite(chainsuite.SuiteConfig{}), |
| 107 | + OtherChain: "ics-consumer", |
| 108 | + OtherChainVersion: "v4.0.0", |
| 109 | + ShouldCopyProviderKey: noProviderKeysCopied(), |
| 110 | + } |
| 111 | + suite.Run(t, s) |
| 112 | +} |
| 113 | + |
| 114 | +func TestICS33ConsumerAllKeysChainLaunch(t *testing.T) { |
| 115 | + s := &ConsumerLaunchSuite{ |
| 116 | + Suite: chainsuite.NewSuite(chainsuite.SuiteConfig{}), |
| 117 | + OtherChain: "ics-consumer", |
| 118 | + OtherChainVersion: "v3.3.0", |
| 119 | + ShouldCopyProviderKey: allProviderKeysCopied(), |
| 120 | + } |
| 121 | + suite.Run(t, s) |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +Notice also how `UpgradeOnSetup` isn't set here: the ConsumerLaunchSuite needs |
| 126 | +to be handed a pre-upgrade chain so it can make sure that a consumer chain that |
| 127 | +launched before the upgrade keeps working after the upgrade. |
| 128 | + |
| 129 | + |
| 130 | +## Writing new tests |
| 131 | + |
| 132 | +All you need to start writing new tests is a test suite as described above. |
| 133 | +The suite will have an `s.Chain` that you can test. Check out utilities in |
| 134 | +[`chainsuite/chain.go`](./chainsuite/chain.go) and |
| 135 | +[`chain_ics.go`](./chainsuite/chain_ics.go) for some convenience methods. |
| 136 | + |
| 137 | +In addition, the s.Chain object extends the `interchaintest` chain object, so |
| 138 | +check out [the docs](https://pkg.go.dev/github.com/strangelove-ventures/interchaintest/v7) to |
| 139 | +see what else is available. |
0 commit comments