-
Notifications
You must be signed in to change notification settings - Fork 166
/
gaia.go
130 lines (106 loc) · 3.05 KB
/
gaia.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package setup
import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"time"
rpchttp "github.com/cometbft/cometbft/rpc/client/http"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)
const GaiaChainID = "test-gaia-chain"
type gaiaValidator struct {
index int
mnemonic string
keyInfo keyring.Record
}
func (g *gaiaValidator) instanceName() string {
return fmt.Sprintf("gaiaval%d", g.index)
}
func (c *chain) createAndInitGaiaValidator(cdc codec.Codec) error {
// create gaia validator
gaiaVal := c.createGaiaValidator(0)
// create keys
mnemonic, info, err := createMemoryKey(cdc)
if err != nil {
return err
}
gaiaVal.keyInfo = *info
gaiaVal.mnemonic = mnemonic
c.GaiaValidators = append(c.GaiaValidators, gaiaVal)
return nil
}
func (c *chain) createGaiaValidator(index int) *gaiaValidator {
return &gaiaValidator{
index: index,
}
}
func (s *E2ETestSuite) runGaiaNetwork() {
s.T().Log("starting Gaia network container...")
tmpDir, err := os.MkdirTemp("", "umee-e2e-testnet-gaia-")
s.Require().NoError(err)
s.tmpDirs = append(s.tmpDirs, tmpDir)
gaiaVal := s.Chain.GaiaValidators[0]
gaiaCfgPath := path.Join(tmpDir, "cfg")
s.Require().NoError(os.MkdirAll(gaiaCfgPath, 0o755))
_, err = copyFile(
filepath.Join("./scripts/", "gaia_bootstrap.sh"),
filepath.Join(gaiaCfgPath, "gaia_bootstrap.sh"),
)
s.Require().NoError(err)
s.GaiaResource, err = s.DkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: gaiaVal.instanceName(),
// Note: we are using this image for testing purpose
Repository: "ghcr.io/umee-network/gaia-e2e",
Tag: "latest",
NetworkID: s.DkrNet.Network.ID,
Mounts: []string{
fmt.Sprintf("%s/:/root/.gaia", tmpDir),
},
PortBindings: map[docker.Port][]docker.PortBinding{
"1317/tcp": {{HostIP: "", HostPort: "1417"}},
"9090/tcp": {{HostIP: "", HostPort: "9190"}},
"26656/tcp": {{HostIP: "", HostPort: "27656"}},
"26657/tcp": {{HostIP: "", HostPort: "27657"}},
},
Env: []string{
fmt.Sprintf("UMEE_E2E_GAIA_CHAIN_ID=%s", GaiaChainID),
fmt.Sprintf("UMEE_E2E_GAIA_VAL_MNEMONIC=%s", gaiaVal.mnemonic),
},
Entrypoint: []string{
"sh",
"-c",
"chmod +x /root/.gaia/cfg/gaia_bootstrap.sh && /root/.gaia/cfg/gaia_bootstrap.sh",
},
},
noRestart,
)
s.Require().NoError(err)
endpoint := fmt.Sprintf("tcp://%s", s.GaiaResource.GetHostPort("26657/tcp"))
s.gaiaRPC, err = rpchttp.New(endpoint, "/websocket")
s.Require().NoError(err)
s.Require().Eventually(
func() bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
status, err := s.gaiaRPC.Status(ctx)
if err != nil {
return false
}
// let the node produce a few blocks
if status.SyncInfo.CatchingUp || status.SyncInfo.LatestBlockHeight < 1 {
return false
}
return true
},
5*time.Minute,
time.Second,
"gaia node failed to produce blocks",
)
s.T().Logf("✅ Started Gaia network container: %s", s.GaiaResource.Container.ID)
}