-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
153 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package setup | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/ory/dockertest/v3" | ||
"github.com/ory/dockertest/v3/docker" | ||
) | ||
|
||
func (s *E2ETestSuite) runIBCRelayer() { | ||
s.T().Log("starting Hermes relayer container...") | ||
|
||
tmpDir, err := os.MkdirTemp("", "umee-e2e-testnet-hermes-") | ||
s.Require().NoError(err) | ||
s.tmpDirs = append(s.tmpDirs, tmpDir) | ||
|
||
gaiaVal := s.Chain.GaiaValidators[0] | ||
// umeeVal for the relayer needs to be a different account | ||
// than what we use for runPriceFeeder. | ||
umeeVal := s.Chain.Validators[1] | ||
hermesCfgPath := path.Join(tmpDir, "hermes") | ||
|
||
s.Require().NoError(os.MkdirAll(hermesCfgPath, 0o755)) | ||
_, err = copyFile( | ||
filepath.Join("./scripts/", "hermes_bootstrap.sh"), | ||
filepath.Join(hermesCfgPath, "hermes_bootstrap.sh"), | ||
) | ||
s.Require().NoError(err) | ||
|
||
s.HermesResource, err = s.DkrPool.RunWithOptions( | ||
&dockertest.RunOptions{ | ||
Name: "umee-gaia-relayer", | ||
Repository: "ghcr.io/umee-network/hermes-e2e", | ||
Tag: "latest", | ||
NetworkID: s.DkrNet.Network.ID, | ||
Mounts: []string{ | ||
fmt.Sprintf("%s/:/home/hermes", hermesCfgPath), | ||
}, | ||
ExposedPorts: []string{"3031"}, | ||
PortBindings: map[docker.Port][]docker.PortBinding{ | ||
"3031/tcp": {{HostIP: "", HostPort: "3031"}}, | ||
}, | ||
Env: []string{ | ||
fmt.Sprintf("UMEE_E2E_GAIA_CHAIN_ID=%s", GaiaChainID), | ||
fmt.Sprintf("UMEE_E2E_UMEE_CHAIN_ID=%s", s.Chain.ID), | ||
fmt.Sprintf("UMEE_E2E_GAIA_VAL_MNEMONIC=%s", gaiaVal.mnemonic), | ||
fmt.Sprintf("UMEE_E2E_UMEE_VAL_MNEMONIC=%s", umeeVal.mnemonic), | ||
fmt.Sprintf("UMEE_E2E_GAIA_VAL_HOST=%s", s.GaiaResource.Container.Name[1:]), | ||
fmt.Sprintf("UMEE_E2E_UMEE_VAL_HOST=%s", s.ValResources[1].Container.Name[1:]), | ||
}, | ||
Entrypoint: []string{ | ||
"sh", | ||
"-c", | ||
"chmod +x /home/hermes/hermes_bootstrap.sh && /home/hermes/hermes_bootstrap.sh", | ||
}, | ||
}, | ||
noRestart, | ||
) | ||
s.Require().NoError(err) | ||
|
||
endpoint := fmt.Sprintf("http://%s/state", s.HermesResource.GetHostPort("3031/tcp")) | ||
s.Require().Eventually( | ||
func() bool { | ||
resp, err := http.Get(endpoint) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
bz, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
var respBody map[string]interface{} | ||
if err := json.Unmarshal(bz, &respBody); err != nil { | ||
return false | ||
} | ||
|
||
status := respBody["status"].(string) | ||
result := respBody["result"].(map[string]interface{}) | ||
|
||
return status == "success" && len(result["chains"].([]interface{})) == 2 | ||
}, | ||
5*time.Minute, | ||
time.Second, | ||
"hermes relayer not healthy", | ||
) | ||
|
||
s.T().Logf("started Hermes relayer container: %s", s.HermesResource.Container.ID) | ||
|
||
// create the client, connection and channel between the Umee and Gaia chains | ||
s.connectIBCChains() | ||
} | ||
|
||
func (s *E2ETestSuite) connectIBCChains() { | ||
s.T().Logf("connecting %s and %s chains via IBC", s.Chain.ID, GaiaChainID) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
exec, err := s.DkrPool.Client.CreateExec(docker.CreateExecOptions{ | ||
Context: ctx, | ||
AttachStdout: true, | ||
AttachStderr: true, | ||
Container: s.HermesResource.Container.ID, | ||
User: "root", | ||
Cmd: []string{ | ||
"hermes", | ||
"create", | ||
"channel", | ||
s.Chain.ID, | ||
GaiaChainID, | ||
"--port-a=transfer", | ||
"--port-b=transfer", | ||
}, | ||
}) | ||
s.Require().NoError(err) | ||
|
||
var ( | ||
outBuf bytes.Buffer | ||
errBuf bytes.Buffer | ||
) | ||
|
||
err = s.DkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ | ||
Context: ctx, | ||
Detach: false, | ||
OutputStream: &outBuf, | ||
ErrorStream: &errBuf, | ||
}) | ||
s.Require().NoErrorf( | ||
err, | ||
"failed connect chains; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), | ||
) | ||
|
||
s.Require().Containsf( | ||
errBuf.String(), | ||
"successfully opened init channel", | ||
"failed to connect chains via IBC: %s", errBuf.String(), | ||
) | ||
|
||
s.T().Logf("connected %s and %s chains via IBC", s.Chain.ID, GaiaChainID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters