Skip to content

Commit

Permalink
e2e with IBC tx and test (#1216)
Browse files Browse the repository at this point in the history
* second chain with tests

* add hermes, comment out balance query for now

* eventually

* Update Makefile

Co-authored-by: Roman <[email protected]>

* remove gas fees and unused functions

* readded check

* Nicco changes to own hermes image

* Remove unused hermes.Dockerfile

* Use a single Dockerfile for both debug and official image

* readd build hermes in makefile

* remove hermes

* Set correct golang image and use correct debug image tag

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Niccolo Raspa <[email protected]>
  • Loading branch information
4 people authored Apr 8, 2022
1 parent 9adf6d8 commit 20cfa05
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 57 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# syntax=docker/dockerfile:1

ARG BASE_IMG_TAG=nonroot

## Build Image
FROM golang:1.18-bullseye as build

Expand All @@ -13,7 +15,7 @@ RUN sha256sum /lib/libwasmvm_muslc.a | grep d0152067a5609bfdfb3f0d5d6c0f2760f79d
RUN BUILD_TAGS=muslc make build

## Deploy image
FROM gcr.io/distroless/base-debian11:nonroot
FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG}

COPY --from=build /osmosis/build/osmosisd /bin/osmosisd

Expand All @@ -22,6 +24,7 @@ WORKDIR $HOME

EXPOSE 26656
EXPOSE 26657
EXPOSE 1317
EXPOSE 1317

ENTRYPOINT ["osmosisd"]
CMD [ "start" ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_UNIT)

docker-build-debug:
@docker build -t osmolabs/osmosisd-e2e --build-arg IMG_TAG=debug -f e2e.Dockerfile .
@docker build -t osmosis:debug --build-arg BASE_IMG_TAG=debug -f Dockerfile .

###############################################################################
### Linting ###
Expand Down
26 changes: 0 additions & 26 deletions e2e.Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions tests/e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ type chain struct {
validators []*validator
}

func newChain(name string) (*chain, error) {
func newChain(id string) (*chain, error) {
tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-")
if err != nil {
return nil, err
}

return &chain{
id: name,
id: id,
dataDir: tmpDir,
}, nil
}
Expand Down
141 changes: 124 additions & 17 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand All @@ -27,16 +31,18 @@ import (

const (
// common
osmoDenom = "uosmo"
stakeDenom = "stake"
minGasPrice = "0.00001"
osmoDenom = "uosmo"
stakeDenom = "stake"
ibcDenom = "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518"
minGasPrice = "0.000"
ibcSendAmount = 3300000000
// chainA
chainAName = "osmo-test-a"
chainAID = "osmo-test-a"
osmoBalanceA = 200000000000
stakeBalanceA = 110000000000
stakeAmountA = 100000000000
// chainB
chainBName = "osmo-test-b"
chainBID = "osmo-test-b"
osmoBalanceB = 500000000000
stakeBalanceB = 440000000000
stakeAmountB = 400000000000
Expand All @@ -54,12 +60,13 @@ var (
type IntegrationTestSuite struct {
suite.Suite

tmpDirs []string
chainA *chain
chainB *chain
dkrPool *dockertest.Pool
dkrNet *dockertest.Network
valResources map[string][]*dockertest.Resource
tmpDirs []string
chainA *chain
chainB *chain
dkrPool *dockertest.Pool
dkrNet *dockertest.Network
hermesResource *dockertest.Resource
valResources map[string][]*dockertest.Resource
}

func TestIntegrationTestSuite(t *testing.T) {
Expand All @@ -70,10 +77,10 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up e2e integration test suite...")

var err error
s.chainA, err = newChain(chainAName)
s.chainA, err = newChain(chainAID)
s.Require().NoError(err)

s.chainB, err = newChain(chainBName)
s.chainB, err = newChain(chainBID)
s.Require().NoError(err)

s.dkrPool, err = dockertest.NewPool("")
Expand Down Expand Up @@ -101,6 +108,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.initGenesis(s.chainB)
s.initValidatorConfigs(s.chainB)
s.runValidators(s.chainB, 10)

s.runIBCRelayer()
}

func (s *IntegrationTestSuite) TearDownSuite() {
Expand All @@ -115,6 +124,8 @@ func (s *IntegrationTestSuite) TearDownSuite() {

s.T().Log("tearing down e2e integration test suite...")

s.Require().NoError(s.dkrPool.Purge(s.hermesResource))

for _, vr := range s.valResources {
for _, r := range vr {
s.Require().NoError(s.dkrPool.Purge(r))
Expand All @@ -137,11 +148,11 @@ func (s *IntegrationTestSuite) initNodes(c *chain) {
// initialize a genesis file for the first validator
val0ConfigDir := c.validators[0].configDir()
for _, val := range c.validators {
if c.id == chainAName {
if c.id == chainAID {
s.Require().NoError(
addGenesisAccount(val0ConfigDir, "", initBalanceStrA, val.keyInfo.GetAddress()),
)
} else if c.id == chainBName {
} else if c.id == chainBID {
s.Require().NoError(
addGenesisAccount(val0ConfigDir, "", initBalanceStrB, val.keyInfo.GetAddress()),
)
Expand Down Expand Up @@ -197,7 +208,7 @@ func (s *IntegrationTestSuite) initGenesis(c *chain) {
genTxs := make([]json.RawMessage, len(c.validators))
for i, val := range c.validators {
stakeAmountCoin := stakeAmountCoinA
if c.id != chainAName {
if c.id != chainAID {
stakeAmountCoin = stakeAmountCoinB
}
createValmsg, err := val.buildCreateValidatorMsg(stakeAmountCoin)
Expand Down Expand Up @@ -288,7 +299,8 @@ func (s *IntegrationTestSuite) runValidators(c *chain, portOffset int) {
Mounts: []string{
fmt.Sprintf("%s/:/osmosis/.osmosisd", val.configDir()),
},
Repository: "osmolabs/osmosisd-e2e",
Repository: "osmosis",
Tag: "debug",
}

// expose the first validator for debugging and communication
Expand Down Expand Up @@ -340,6 +352,101 @@ func (s *IntegrationTestSuite) runValidators(c *chain, portOffset int) {
)
}

func (s *IntegrationTestSuite) runIBCRelayer() {
s.T().Log("starting Hermes relayer container...")

tmpDir, err := ioutil.TempDir("", "gaia-e2e-testnet-hermes-")
s.Require().NoError(err)
s.tmpDirs = append(s.tmpDirs, tmpDir)

gaiaAVal := s.chainA.validators[0]
gaiaBVal := s.chainB.validators[0]
hermesCfgPath := path.Join(tmpDir, "hermes")

s.Require().NoError(os.MkdirAll(hermesCfgPath, 0755))
_, 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: fmt.Sprintf("%s-%s-relayer", s.chainA.id, s.chainB.id),
Repository: "osmolabs/hermes",
Tag: "0.13.0",
NetworkID: s.dkrNet.Network.ID,
Cmd: []string{
"start",
},
User: "root:root",
Mounts: []string{
fmt.Sprintf("%s/:/root/hermes", hermesCfgPath),
},
ExposedPorts: []string{
"3031",
},
PortBindings: map[docker.Port][]docker.PortBinding{
"3031/tcp": {{HostIP: "", HostPort: "3031"}},
},
Env: []string{
fmt.Sprintf("OSMO_A_E2E_CHAIN_ID=%s", s.chainA.id),
fmt.Sprintf("OSMO_B_E2E_CHAIN_ID=%s", s.chainB.id),
fmt.Sprintf("OSMO_A_E2E_VAL_MNEMONIC=%s", gaiaAVal.mnemonic),
fmt.Sprintf("OSMO_B_E2E_VAL_MNEMONIC=%s", gaiaBVal.mnemonic),
fmt.Sprintf("OSMO_A_E2E_VAL_HOST=%s", s.valResources[s.chainA.id][0].Container.Name[1:]),
fmt.Sprintf("OSMO_B_E2E_VAL_HOST=%s", s.valResources[s.chainB.id][0].Container.Name[1:]),
},
Entrypoint: []string{
"sh",
"-c",
"chmod +x /root/hermes/hermes_bootstrap.sh && /root/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)

// XXX: Give time to both networks to start, otherwise we might see gRPC
// transport errors.
time.Sleep(10 * time.Second)

// create the client, connection and channel between the two Gaia chains
s.connectIBCChains()
}

func noRestart(config *docker.HostConfig) {
// in this case we don't want the nodes to restart on failure
config.RestartPolicy = docker.RestartPolicy{
Expand Down
Loading

0 comments on commit 20cfa05

Please sign in to comment.