Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(WIP): improving the e2e tests with gorelayer #2291

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,10 @@ docker-build-e2e:
docker-build:
@DOCKER_BUILDKIT=1 docker build -t umee-network/umeed -f contrib/images/umeed.dockerfile .

docker-push-hermes:
@cd tests/e2e/docker; docker build -t ghcr.io/umee-network/hermes-e2e:latest -f hermes.Dockerfile .; docker push ghcr.io/umee-network/hermes-e2e:latest

docker-push-gaia:
@cd tests/e2e/docker; docker build -t ghcr.io/umee-network/gaia-e2e:latest -f gaia.Dockerfile .; docker push ghcr.io/umee-network/gaia-e2e:latest

.PHONY: docker-build docker-push-hermes docker-push-gaia
.PHONY: docker-build docker-push-gaia

###############################################################################
## Tests ##
Expand Down Expand Up @@ -233,8 +230,8 @@ test-e2e-cov: $(TEST_E2E_DEPS)
go test ./tests/e2e/... -mod=readonly -timeout 30m -race -v -tags='$(TEST_E2E_TAGS)' -coverpkg=./... -coverprofile=e2e-profile.out -covermode=atomic

test-e2e-clean:
docker stop umee0 umee1 umee2 umee-gaia-relayer gaiaval0 umee-price-feeder || true
docker rm umee0 umee1 umee2 umee-gaia-relayer gaiaval0 umee-price-feeder || true
docker stop umee0 umee1 umee2 umee-gaia-gorelayer umee-gaia-relayer gaiaval0 umee-price-feeder || true
docker rm umee0 umee1 umee2 umee-gaia-gorelayer umee-gaia-relayer gaiaval0 umee-price-feeder || true
docker network prune -f

test-qa:
Expand Down
13 changes: 9 additions & 4 deletions tests/e2e/docker/gaia.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20
FROM golang:1.20 AS gaiad-builder
ARG GAIA_VERSION=v13.0.0

# ENV PACKAGES curl make git libc-dev bash gcc linux-headers
Expand All @@ -7,6 +7,11 @@ RUN apt update && apt install curl make git gcc -y

WORKDIR /downloads/
RUN git clone --single-branch --depth 1 --branch ${GAIA_VERSION} https://github.com/cosmos/gaia.git
RUN cd gaia && make build && cp ./build/gaiad /usr/local/bin/
EXPOSE 26656 26657 1317 9090
ENTRYPOINT ["gaiad", "start"]
RUN cd gaia && CGO_ENABLED=0 make build && cp ./build/gaiad /usr/local/bin/

# Final image
FROM alpine:edge
# Install ca-certificates
RUN apk add --update ca-certificates bash
COPY --from=gaiad-builder /usr/local/bin/gaiad /usr/local/bin/
EXPOSE 26656 26657 1317 9090
9 changes: 9 additions & 0 deletions tests/e2e/docker/gorelayer.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Use Golang Docker Image
FROM golang:1.21
# Set working dir
WORKDIR /home/rly
# Install git
RUN apt-get install git
# Clone relayer repository and install relayer
RUN git clone --single-branch --branch v2.4.2 --depth 1 https://github.com/cosmos/relayer.git && cd relayer && git checkout v2.4.2 && make build && cp ./build/rly /usr/local/bin/
RUN chmod +x /usr/local/bin/rly
56 changes: 24 additions & 32 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,46 +75,48 @@ func (s *E2ETest) checkSupply(endpoint, ibcDenom string, amount math.Int) {
}
return false
},
10*time.Minute,
2*time.Minute,
2*time.Second,
fmt.Sprintf("check supply: %s (expected %s)", ibcDenom, amount),
)
}

func (s *E2ETest) TestIBCTokenTransfer() {
// IBC inbound transfer of non x/leverage registered tokens must fail, because
// because we won't have price for it.
s.Run("send_stake_to_umee", func() {
// require the recipient account receives the IBC tokens (IBC packets ACKd)
umeeAPIEndpoint := s.UmeeREST()
recipient := s.AccountAddr(0).String()

token := sdk.NewInt64Coin("stake", 3300000000) // 3300stake
s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token, false, "")
// Zero, since not a registered token
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, sdk.ZeroInt())
})
s.T().Log("Waiting for hermes to sync")
time.Sleep(10 * time.Second)

s.Run("ibc_transfer_quota", func() {
// require the recipient account receives the IBC tokens (IBC packets ACKd)
gaiaAPIEndpoint := s.GaiaREST()
umeeAPIEndpoint := s.UmeeREST()
// totalQuota := math.NewInt(120)
tokenQuota := math.NewInt(100)

// compute the amount of ATOM sent from umee to gaia which would meet atom's token quota
atomPrice, err := s.QueryHistAvgPrice(umeeAPIEndpoint, atomSymbol)
s.Require().NoError(err)
s.Require().True(atomPrice.GT(sdk.OneDec()),
"atom price should be non zero, and expecting higher than 1, got: %s", atomPrice)
atomQuota := sdk.NewCoin(uatomIBCHash,
sdk.NewDecFromInt(tokenQuota).Quo(atomPrice).Mul(powerReduction).RoundInt(),
var atomQuota sdk.Coin
s.Require().Eventually(
func() bool {
// compute the amount of ATOM sent from umee to gaia which would meet atom's token quota
atomPrice, err := s.QueryHistAvgPrice(umeeAPIEndpoint, atomSymbol)
s.Require().NoError(err)
if atomPrice.GT(sdk.ZeroDec()) {
atomQuota = sdk.NewCoin(uatomIBCHash,
sdk.NewDecFromInt(tokenQuota).Quo(atomPrice).Mul(powerReduction).RoundInt(),
)
}
return atomPrice.GT(sdk.ZeroDec())
},
4*time.Minute,
3*time.Second,
)

//<<<< INFLOW : gaia -> umee >>
token := sdk.NewInt64Coin("stake", 3300000000) // 3300stake
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", token, false, "")
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, token.Amount)

// send $500 ATOM from gaia to umee. (ibc_quota will not check token limit)
atomFromGaia := mulCoin(atomQuota, "5.0")
atomFromGaia.Denom = "uatom"
// atomFromGaia.Amount = math.ZeroInt()
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", atomFromGaia, false, "")
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount)

Expand Down Expand Up @@ -166,16 +168,6 @@ func (s *E2ETest) TestIBCTokenTransfer() {
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount.Sub(sendAtom.Amount))
s.checkOutflows(umeeAPIEndpoint, uatomIBCHash, true, sdk.NewDecFromInt(sendAtom.Amount), atomSymbol)

// send $45 UMEE from gaia to umee
returnUmee := mulCoin(sendUmee, "0.5")
returnUmee.Denom = umeeIBCHash
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", returnUmee, false, "send back some umee")
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, returnUmee.Amount) // half was returned, so half remains

// sending back remaining amount
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", returnUmee, false, "send back remaining umee")
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())

// reset the outflows
s.T().Logf("waiting until quota reset, basically it will take around 300 seconds to do quota reset")
s.Require().Eventually(
Expand Down Expand Up @@ -212,7 +204,7 @@ func (s *E2ETest) TestIBCTokenTransfer() {

// sending the umee tokens - they would have exceeded quota before
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedUmee, false, "sending umee")
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, exceedUmee.Amount)
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, exceedUmee.Amount.Add(sendUmee.Amount))
// Check the outflows
s.Require().Eventually(
func() bool {
Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/scripts/gaia_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gaiad gentx val01 500000000000stake --chain-id=$UMEE_E2E_GAIA_CHAIN_ID --keyring
gaiad collect-gentxs
sed -i 's/127.0.0.1:26657/0.0.0.0:26657/g' /root/.gaia/config/config.toml
sed -i -e 's/enable = false/enable = true/g' /root/.gaia/config/app.toml
sed -i -e 's/pruning = "default"/pruning = "nothing"/g' /root/.gaia/config/app.toml
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' /root/.gaia/config/config.toml
gaiad start --x-crisis-skip-assert-invariants
# sed -i -e 's/pruning = "default"/pruning = "nothing"/g' /root/.gaia/config/app.toml
sed -i 's/timeout_commit = "5s"/timeout_commit = "2s"/g' /root/.gaia/config/config.toml
# 362880 (3*7*24*60*60 / 2 = 907200) represents a 3 week unbonding period (assuming 2 seconds per block).
gaiad start --x-crisis-skip-assert-invariants --pruning=custom --pruning-keep-recent=907200 --pruning-keep-every=0 --pruning-interval=100
8 changes: 8 additions & 0 deletions tests/e2e/scripts/gorelayer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rly config init
rly chains add-dir $HOME/relayer/configs
rly paths add-dir $HOME/relayer/paths
rly keys restore $UMEE_E2E_UMEE_CHAIN_ID ibc "$UMEE_E2E_UMEE_VAL_MNEMONIC"
rly keys restore $UMEE_E2E_GAIA_CHAIN_ID ibc "$UMEE_E2E_GAIA_VAL_MNEMONIC"
rly q balance $UMEE_E2E_UMEE_CHAIN_ID
rly q balance $UMEE_E2E_GAIA_CHAIN_ID
rly tx link rly-path
17 changes: 9 additions & 8 deletions tests/e2e/scripts/hermes_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ hermes keys add --chain ${UMEE_E2E_GAIA_CHAIN_ID} --key-name "val01-gaia" --mnem
hermes keys add --chain ${UMEE_E2E_UMEE_CHAIN_ID} --key-name "val01-umee" --mnemonic-file /root/.hermes/val01-umee


### Configure the clients and connection
echo "Initiating connection handshake..."
hermes create connection --a-chain $UMEE_E2E_UMEE_CHAIN_ID --b-chain $UMEE_E2E_GAIA_CHAIN_ID
sleep 2
echo "Creating the channels..."
hermes create channel --order unordered --a-chain $UMEE_E2E_UMEE_CHAIN_ID --a-connection connection-0 --a-port transfer --b-port transfer

# ### Configure the clients and connection
# echo "Initiating connection handshake..."
# hermes create connection --a-chain $UMEE_E2E_UMEE_CHAIN_ID --b-chain $UMEE_E2E_GAIA_CHAIN_ID
# sleep 2
# echo "Creating the channels..."
# hermes create channel --order unordered --a-chain $UMEE_E2E_UMEE_CHAIN_ID --a-connection connection-0 --a-port transfer --b-port transfer

# Note: we are using gorelayer for creating ibc channels
# start Hermes relayer
hermes start
hermes start --full-scan
19 changes: 19 additions & 0 deletions tests/e2e/scripts/relayer/configs/gaia-test-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "cosmos",
"value": {
"key": "ibc",
"chain-id": "gaia-test-1",
"rpc-addr": "http://gaiaval0:26657",
"grpc-addr": "http://gaiaval0:9090",
"account-prefix": "cosmos",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.01stake",
"min-gas-amount": 1000000,
"max-gas-amount": 3000000,
"debug": true,
"timeout": "10s",
"output-format": "json",
"sign-mode": "direct"
}
}
19 changes: 19 additions & 0 deletions tests/e2e/scripts/relayer/configs/umee-test-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "cosmos",
"value": {
"key": "ibc",
"chain-id": "umee-test-1",
"rpc-addr": "http://umee0:26657",
"grpc-addr": "http://umee0:9090",
"account-prefix": "umee",
"keyring-backend": "test",
"gas-adjustment": 1.5,
"gas-prices": "0.01uumee",
"min-gas-amount": 1000000,
"max-gas-amount": 3000000,
"debug": true,
"timeout": "10s",
"output-format": "json",
"sign-mode": "direct"
}
}
17 changes: 17 additions & 0 deletions tests/e2e/scripts/relayer/paths/rly-path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"src": {
"chain-id": "umee-test-1",
"port-id": "transfer",
"order": "unordered",
"version": "ics20-1"
},
"dst": {
"chain-id": "gaia-test-1",
"port-id": "transfer",
"order": "unordered",
"version": "ics20-1"
},
"strategy": {
"type": "naive"
}
}
3 changes: 1 addition & 2 deletions tests/e2e/setup/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
sdkparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
tmrand "github.com/tendermint/tendermint/libs/rand"

umeeapp "github.com/umee-network/umee/v6/app"
)
Expand Down Expand Up @@ -53,7 +52,7 @@ func newChain() (*chain, error) {
}

return &chain{
ID: "chain-" + tmrand.NewRand().Str(6),
ID: "umee-test-1",
dataDir: tmpDir,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/setup/gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

const GaiaChainID = "test-gaia-chain"
const GaiaChainID = "gaia-test-1"

type gaiaValidator struct {
index int
Expand Down
85 changes: 85 additions & 0 deletions tests/e2e/setup/gorelayer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package setup

import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"time"

"github.com/ory/dockertest/v3"
)

func (s *E2ETestSuite) runIBCGoRelayer() {
s.T().Log("starting gorelayer container...")

tmpDir, err := os.MkdirTemp("", "umee-e2e-testnet-go-relayer-")
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[0]
rlyCfgPath := path.Join(tmpDir, "relayer")

s.Require().NoError(os.MkdirAll(rlyCfgPath, 0o755))
_, err = copyFile(
filepath.Join("./scripts/", "gorelayer.sh"),
filepath.Join(rlyCfgPath, "gorelayer.sh"),
)
s.Require().NoError(err)

c := exec.Command("cp", "-r", filepath.Join("./scripts/", "relayer"), rlyCfgPath)
if err = c.Run(); err == nil {
s.T().Log("rly config files copied from ", filepath.Join("./scripts/", "relayer"), " to ", rlyCfgPath)
}

s.GoRelayerResource, err = s.DkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: "umee-gaia-gorelayer",
Repository: "ghcr.io/cosmos/relayer",
Tag: "v2.4.2",
NetworkID: s.DkrNet.Network.ID,
Mounts: []string{
fmt.Sprintf("%s/:/home/relayer", rlyCfgPath),
},
User: "relayer",
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[0].Container.Name[1:]),
},
Entrypoint: []string{
"sh",
"/home/relayer/gorelayer.sh",
},
},
noRestart,
)

s.Require().NoError(err)
s.T().Logf("✅ Started gorelayer container: %s", s.GoRelayerResource.Container.ID)

s.T().Logf("ℹ️ Waiting for ibc channel creation...")
s.Require().Eventually(
func() bool {
s.T().Log("We are waiting for channel creation...")
channels, err := s.QueryIBCChannels(s.UmeeREST())
if channels {
s.T().Log("✅ IBC Channel is created among the the chains")
}
if err != nil {
return false
}
return channels
},
5*time.Minute,
3*time.Second,
)
return
}
4 changes: 2 additions & 2 deletions tests/e2e/setup/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ory/dockertest/v3/docker"
)

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

tmpDir, err := os.MkdirTemp("", "umee-e2e-testnet-hermes-")
Expand Down Expand Up @@ -81,7 +81,7 @@ func (s *E2ETestSuite) runIBCRelayer() {
}
return channels
},
10*time.Minute,
1*time.Minute,
3*time.Second,
)

Expand Down
Loading
Loading