@agoric/cosmos 0.35.0-u19.2 → 0.35.0-u20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/e2e_test/util.go DELETED
@@ -1,271 +0,0 @@
1
- package e2etest
2
-
3
- import (
4
- "context"
5
- "fmt"
6
- "os"
7
- "strconv"
8
- "strings"
9
- "testing"
10
-
11
- "github.com/agoric-labs/interchaintest/v6"
12
- "github.com/agoric-labs/interchaintest/v6/chain/cosmos"
13
- "github.com/agoric-labs/interchaintest/v6/ibc"
14
- "github.com/agoric-labs/interchaintest/v6/relayer"
15
- "github.com/agoric-labs/interchaintest/v6/testutil"
16
-
17
- "go.uber.org/zap/zaptest"
18
- )
19
-
20
- const CHAIN_AGORIC = "agoric"
21
- const CHAIN_GAIA = "gaia"
22
-
23
- const RELAYER_COSMOS = "cosmos"
24
- const RELAYER_HERMES = "hermes"
25
-
26
- const DEFAULT_CHAINIMAGE_AGORIC = "agoric:heighliner-agoric"
27
- const DEFAULT_BLOCKS_TO_WAIT = 25
28
-
29
- const FMT_ENV_CHAINNAME = "E2ETEST_CHAINNAME%d"
30
- const ENV_CHAINIMAGE_AGORIC = "E2ETEST_CHAINIMAGE_AGORIC"
31
- const ENV_RELAYERNAME = "E2ETEST_RELAYERNAME"
32
- const ENV_BLOCKS_TO_WAIT = "E2ETEST_BLOCKS_TO_WAIT"
33
-
34
- // newHermesFactory creates a hermes relayer
35
- func newHermesFactory(t *testing.T) interchaintest.RelayerFactory {
36
- return interchaintest.NewBuiltinRelayerFactory(
37
- ibc.Hermes,
38
- zaptest.NewLogger(t),
39
- )
40
- }
41
-
42
- // newCosmosRlyFactory creates a cosmos relayer
43
- func newCosmosRlyFactory(t *testing.T) interchaintest.RelayerFactory {
44
-
45
- // TODO: At one point was using latest docker image for relyaer but disabling
46
- // to remove variables while debugging heighliner builds of agoric chain are failing
47
- //
48
- IBCRelayerImage := "ghcr.io/cosmos/relayer"
49
- IBCRelayerVersion := "latest"
50
- image := relayer.CustomDockerImage(IBCRelayerImage, IBCRelayerVersion, "100:1000")
51
-
52
- return interchaintest.NewBuiltinRelayerFactory(
53
- ibc.CosmosRly,
54
- zaptest.NewLogger(t),
55
- image,
56
- )
57
- }
58
-
59
- // newCosmosHubChainSpec creates a chainspec for a gaia instance compatible with these tests
60
- // TODO: replacing the v13.0.01 version with latest has not been tested.
61
- func newCosmosHubChainSpec(chainUniqueName string, chainID string, numOfValidators int, numOfFullNodes int) *interchaintest.ChainSpec {
62
- ret := &interchaintest.ChainSpec{
63
- Name: "gaia",
64
- ChainName: chainUniqueName,
65
- Version: "v13.0.1", // This version of gaiad has the interface interchaintestv6 needs
66
- NumValidators: &numOfValidators,
67
- NumFullNodes: &numOfFullNodes,
68
- }
69
-
70
- ret.ChainConfig.ChainID = chainID
71
- return ret
72
- }
73
-
74
- // newUnknownCosmosChainSpec creates any cosmos chain where interchaintest has a built in definition
75
- // NB: In many cases these images will not work due to issues outside the scope of Agoric's project
76
- func newUnknownCosmosChainSpec(chain string, chainUniqueName string, chainID string, numOfValidators int, numOfFullNodes int) *interchaintest.ChainSpec {
77
- ret := &interchaintest.ChainSpec{
78
- Name: chain,
79
- ChainName: chainUniqueName,
80
- Version: "latest",
81
- NumValidators: &numOfValidators,
82
- NumFullNodes: &numOfFullNodes,
83
- }
84
-
85
- ret.ChainConfig.ChainID = chainID
86
- return ret
87
- }
88
-
89
- // newAgoricChainSpec fully specifies the details necessary to launch an Agoric chain image built from
90
- // - https://github.com/strangelove-ventures/heighliner/pull/211
91
- // - NoCrisisModule is a flag added in the agoric-labs fork of interchaintest
92
- func newAgoricChainSpec(chainUniqueName string, chainID string, chainImage ibc.DockerImage, numOfValidators int, numOfFullNodes int) *interchaintest.ChainSpec {
93
- coinDecimals := int64(6)
94
- gasAdjustment := 1.3
95
- noHostMount := false
96
-
97
- return &interchaintest.ChainSpec{
98
- Name: "agoric",
99
- ChainName: chainUniqueName,
100
- Version: chainImage.Version,
101
- GasAdjustment: &gasAdjustment,
102
- NoHostMount: &noHostMount,
103
- ChainConfig: ibc.ChainConfig{
104
- Type: "cosmos",
105
- Name: "agoric",
106
- ChainID: chainID,
107
- Images: []ibc.DockerImage{
108
- chainImage,
109
- },
110
- Bin: "agd",
111
- Bech32Prefix: "agoric",
112
- Denom: "ubld",
113
- CoinType: "564",
114
- // interchaintest is super flaky when gas is enabled
115
- GasPrices: "0.0ubld",
116
- GasAdjustment: 1.3,
117
- TrustingPeriod: "672h",
118
- NoHostMount: false,
119
- NoCrisisModule: true,
120
- SkipGenTx: false,
121
- CoinDecimals: &coinDecimals,
122
- },
123
- NumValidators: &numOfValidators,
124
- NumFullNodes: &numOfFullNodes,
125
- }
126
- }
127
-
128
- // getChainImage will build a docker image from the environment variable value
129
- // E2ETEST_CHAINIMAGE_AGORIC. The value of this env var
130
- // must be in the form "repo/image:version"
131
- func getChainImageAgoric(t *testing.T) ibc.DockerImage {
132
- ret := ibc.DockerImage{
133
- UidGid: "1025:1025",
134
- }
135
-
136
- chainImage, present := os.LookupEnv(ENV_CHAINIMAGE_AGORIC)
137
- if !present {
138
- chainImage = DEFAULT_CHAINIMAGE_AGORIC
139
- }
140
-
141
- parts := strings.Split(chainImage, ":")
142
- if len(parts) == 2 {
143
- ret.Repository = parts[0]
144
- ret.Version = parts[1]
145
- } else {
146
- t.Fatalf("Invalid value for %s[%s]. Must be of the format 'repository:version'", ENV_CHAINIMAGE_AGORIC, chainImage)
147
- }
148
-
149
- t.Logf("ChainImages: %s[%s:%s]", ENV_CHAINIMAGE_AGORIC, ret.Repository, ret.Version)
150
-
151
- return ret
152
- }
153
-
154
- // getChainNames reads the environment variables FMT_ENV_CHAINNAME0, FMT_ENV_CHAINNAME1, FMT_ENV_CHAINNAME2, FMT_ENV_CHAINNAME3
155
- func getChainNames(t *testing.T) [4]string {
156
-
157
- ret := [4]string{
158
- CHAIN_AGORIC, CHAIN_AGORIC, CHAIN_AGORIC, CHAIN_AGORIC,
159
- }
160
-
161
- for i := 0; i < 4; i++ {
162
- envVar := fmt.Sprintf(FMT_ENV_CHAINNAME, i)
163
- chainName, present := os.LookupEnv(envVar)
164
- if present {
165
- ret[i] = chainName
166
- }
167
- }
168
-
169
- t.Logf("ChainNames: %s[%s] %s[%s] %s[%s] %s[%s]",
170
- fmt.Sprintf(FMT_ENV_CHAINNAME, 0), ret[0],
171
- fmt.Sprintf(FMT_ENV_CHAINNAME, 1), ret[1],
172
- fmt.Sprintf(FMT_ENV_CHAINNAME, 2), ret[2],
173
- fmt.Sprintf(FMT_ENV_CHAINNAME, 3), ret[3])
174
-
175
- return ret
176
- }
177
-
178
- // getChainSpec reads environment variables and builds a full ChainSpec
179
- func getChainSpec(t *testing.T) []*interchaintest.ChainSpec {
180
- nv := 1
181
- nf := 0
182
-
183
- chainNames := getChainNames(t)
184
- chainImage := getChainImageAgoric(t)
185
-
186
- ret := make([]*interchaintest.ChainSpec, 4)
187
-
188
- for index, chainName := range chainNames {
189
- chainId := fmt.Sprintf("%s%d", chainName, index)
190
- chainUniqueName := chainId
191
-
192
- switch chainName {
193
- case CHAIN_AGORIC:
194
- ret[index] = newAgoricChainSpec(chainUniqueName, chainId, chainImage, nv, nf)
195
- case CHAIN_GAIA:
196
- ret[index] = newCosmosHubChainSpec(chainUniqueName, chainId, nv, nf)
197
- default:
198
- ret[index] = newUnknownCosmosChainSpec(chainName, chainUniqueName, chainId, nv, nf)
199
- }
200
- }
201
-
202
- return ret
203
- }
204
-
205
- // getRelayerFactory reads environment variables and builds the correct RelayerFactory
206
- func getRelayerFactory(t *testing.T) interchaintest.RelayerFactory {
207
- relayerName, present := os.LookupEnv(ENV_RELAYERNAME)
208
- if !present {
209
- relayerName = RELAYER_COSMOS
210
- }
211
-
212
- var ret interchaintest.RelayerFactory
213
-
214
- switch relayerName {
215
- case RELAYER_COSMOS:
216
- ret = newCosmosRlyFactory(t)
217
- case RELAYER_HERMES:
218
- ret = newHermesFactory(t)
219
- default:
220
- t.Fatalf("Invalid value for %s[%s]. Valid values are [%s] or [%s]", ENV_RELAYERNAME, relayerName, RELAYER_COSMOS, RELAYER_HERMES)
221
- }
222
-
223
- t.Logf("RelayerNmae: %s[%s]", ENV_RELAYERNAME, relayerName)
224
-
225
- return ret
226
- }
227
-
228
- // sendIBCTransferWithWait performs cosmos.CosmosChain.SendIBCTransfer
229
- // - Automatically waits to confirm TX is ACK'd
230
- // - Automatically waits for results to settle
231
- // - The environment variable E2ETEST_BLOCKS_TO_WAIT controls how many blocks to wait for ACK and settlement
232
- func sendIBCTransferWithWait(
233
- c *cosmos.CosmosChain,
234
- ctx context.Context,
235
- channelID string,
236
- keyName string,
237
- amount ibc.WalletAmount,
238
- options ibc.TransferOptions,
239
- ) (tx ibc.Tx, err error) {
240
- blocksToWait := DEFAULT_BLOCKS_TO_WAIT
241
-
242
- blocksAsStr, present := os.LookupEnv(ENV_BLOCKS_TO_WAIT)
243
- if present {
244
- blocksToWait, err = strconv.Atoi(blocksAsStr)
245
- if err != nil {
246
- return tx, err
247
- }
248
- }
249
-
250
- chainAHeight, err := c.Height(ctx)
251
- if err != nil {
252
- return tx, err
253
- }
254
-
255
- tx, err = c.SendIBCTransfer(ctx, channelID, keyName, amount, options)
256
- if err != nil {
257
- return tx, err
258
- }
259
-
260
- _, err = testutil.PollForAck(ctx, c, chainAHeight, chainAHeight+30, tx.Packet)
261
- if err != nil {
262
- return tx, err
263
- }
264
-
265
- err = testutil.WaitForBlocks(ctx, blocksToWait, c)
266
- if err != nil {
267
- return tx, err
268
- }
269
-
270
- return tx, err
271
- }