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: testing ibc transactions on e2e tests #2284

Merged
merged 15 commits into from
Oct 19, 2023
14 changes: 7 additions & 7 deletions tests/e2e/docker/gaia.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM golang:1.21-alpine
ARG GAIA_VERSION=v5.0.7
FROM golang:1.20
ARG GAIA_VERSION=v13.0.0
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved

ENV PACKAGES curl make git libc-dev bash gcc linux-headers
RUN apk add --no-cache $PACKAGES
# ENV PACKAGES curl make git libc-dev bash gcc linux-headers
# RUN apk add --no-cache $PACKAGES
RUN apt update && apt install curl make git gcc -y

WORKDIR /downloads/
RUN git clone https://github.com/cosmos/gaia.git
RUN cd gaia && git checkout ${GAIA_VERSION} && make build && cp ./build/gaiad /usr/local/bin/

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"]
4 changes: 1 addition & 3 deletions tests/e2e/docker/hermes.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FROM informalsystems/hermes:0.12.0 AS hermes-builder
FROM informalsystems/hermes:1.6.0 AS hermes-builder

FROM debian:buster-slim
USER root

COPY --chown=0:0 --from=hermes-builder /usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1
COPY --chown=0:0 --from=hermes-builder /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
COPY --from=hermes-builder /usr/bin/hermes /usr/local/bin/
RUN chmod +x /usr/local/bin/hermes

Expand Down
44 changes: 22 additions & 22 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,24 @@ func (s *E2ETest) checkOutflows(umeeAPIEndpoint, denom string, checkWithExcRate
}

func (s *E2ETest) checkSupply(endpoint, ibcDenom string, amount math.Int) {
attempt := 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am removing attempt from here bcause the relayer taking so much time making ibc txn submitting on both sides

s.Require().Eventually(
func() bool {
attempt++
supply, err := s.QueryTotalSupply(endpoint)
if err != nil {
return false
}
if supply.AmountOf(ibcDenom).Equal(amount) {
return true
}
if attempt == 59 {
// if we're nearing the end of our attempts, print expected and actual values
s.T().Logf("expected: %s, got: %s", amount, supply.AmountOf(ibcDenom))
}
return false
},
2*time.Minute,
10*time.Minute,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we increase it to 10min? that sounds too much...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know ibc txn is succeed or not, we only know txn is succceed when that denom exists in supply query

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 minutes I know it is too much but that is the maximum time to check the ibc txn because sometimes hermes relayer taking too much time submit the ibc txn on both sides

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for e2e tests, 10min is too much. Can we keep it to 2 or 3 min?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know how much time taking to succeed ibc txn with this new hermes , so I keep maximum 10m , 2minutes or 3 minutes not enough at least it required 6minutes to check the supply (like ibc txn to succeed)

I will update this time in next PR (once cross checking done with go relayer and hermes )

2*time.Second,
fmt.Sprintf("check supply: %s (expected %s)", ibcDenom, amount),
)
}

func (s *E2ETest) TestIBCTokenTransfer() {
s.T().Skip("TODO: Re-enable ibc e2e")
// 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() {
Expand Down Expand Up @@ -118,49 +111,56 @@ func (s *E2ETest) TestIBCTokenTransfer() {
sdk.NewDecFromInt(tokenQuota).Quo(atomPrice).Mul(powerReduction).RoundInt(),
)

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

// <<< OUTLOW : umee -> gaia >>
// compute the amout of UMEE sent to gaia which would meet umee's token quota
umeePrice, err := s.QueryHistAvgPrice(umeeAPIEndpoint, umeeSymbol)
s.Require().NoError(err)
s.Require().True(umeePrice.GT(sdk.MustNewDecFromStr("0.001")),
"umee price should be non zero, and expecting higher than 0.001, got: %s", umeePrice)
umeeQuota := sdk.NewCoin(appparams.BondDenom,
sdk.NewDecFromInt(tokenQuota).Quo(atomPrice).Mul(powerReduction).RoundInt(),
sdk.NewDecFromInt(tokenQuota).Quo(umeePrice).Mul(powerReduction).RoundInt(),
)

// send $90 UMEE from umee to gaia (ibc_quota will check)
// Note: receiver is null so hermes will default send to key_name (from config) of target chain (gaia)
sendUmee := mulCoin(umeeQuota, "0.9")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", sendUmee, false, fmt.Sprintf(
"sending %s (less than token quota) ", sendUmee.String()))
s.checkOutflows(umeeAPIEndpoint, appparams.BondDenom, true, sdk.NewDecFromInt(sendUmee.Amount), appparams.Name)
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, sendUmee.Amount)
// << TOKEN QUOTA EXCCEED >>
// send $110 UMEE from umee to gaia (token_quota is 100$)
exceedUmee := mulCoin(umeeQuota, "1.1")
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedUmee, true, "")
// check the ibc (umee) quota after ibc txs - this one should have failed
// supply don't change
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())

// send $110 ATOM from umee to gaia
exceedAtom := mulCoin(atomQuota, "1.1")
// supply will be not be decreased because sending amount is more than token quota so it will fail
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedAtom, true, "uatom from umee to gaia")
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount)

// send $110 UMEE from umee to gaia (token_quota is 100$)
exceedUmee := mulCoin(umeeQuota, "1.1")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedUmee, true, "")
// check the ibc (umee) quota after ibc txs - this one should have failed
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())
// << BELOW TOKEN QUOTA >>
// send $90 UMEE from umee to gaia (ibc_quota will check)
// Note: receiver is null so hermes will default send to key_name (from config) of target chain (gaia)
sendUmee := mulCoin(umeeQuota, "0.9")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", sendUmee, false, fmt.Sprintf(
"sending %s (less than token quota) ", sendUmee.String()))
s.checkOutflows(umeeAPIEndpoint, appparams.BondDenom, true, sdk.NewDecFromInt(sendUmee.Amount), appparams.Name)
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, sendUmee.Amount)

// << BELOW TOKEN QUTOA 40$ but ATOM_QUOTA (40$)+ UMEE_QUOTA(90$) >= TOTAL QUOTA (120$) >>
// send $40 ATOM from umee to gaia
atom40 := mulCoin(atomQuota, "0.4")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", atom40, true, "below token quota but not total quota")
// supply will be not be decreased because sending more than total quota from umee to gaia
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount)

// ✅ << BELOW TOKEN QUTOA 5$ but ATOM_QUOTA (5$)+ UMEE_QUOTA(90$) <= TOTAL QUOTA (120$) >>
// send $15 ATOM from umee to gaia
sendAtom := mulCoin(atomQuota, "0.15")
sendAtom := mulCoin(atomQuota, "0.05")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we change the amount here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just making sure the total sending quota is always less than TotalQuota (120$)

s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", sendAtom, false, "below both quotas")
// remaing supply decreased uatom on umee
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount.Sub(sendAtom.Amount))
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/scripts/gaia_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -ex

chmod +x /usr/local/bin/gaiad
gaiad version
gaiad init val01 --chain-id=$UMEE_E2E_GAIA_CHAIN_ID
echo $UMEE_E2E_GAIA_VAL_MNEMONIC | gaiad keys add val01 --recover --keyring-backend=test
gaiad add-genesis-account $(gaiad keys show val01 -a --keyring-backend=test) 1000000000000stake,1000000000000uatom
Expand All @@ -10,5 +12,5 @@ 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 = "300ms"/g' /root/.gaia/config/config.toml
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is too fast 300ms , so relayer needs to catup the blocks height , so I making 1s

gaiad start --x-crisis-skip-assert-invariants
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' /root/.gaia/config/config.toml
gaiad start --x-crisis-skip-assert-invariants
62 changes: 44 additions & 18 deletions tests/e2e/scripts/hermes_bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,89 @@ refresh = true
misbehaviour = true

[mode.connections]
enabled = false
enabled = true

[mode.channels]
enabled = false
enabled = true

[mode.packets]
enabled = true
clear_interval = 10
clear_on_start = true
clear_interval = 100
clear_on_start = false
tx_confirmation = true

[rest]
enabled = true
host = '0.0.0.0'
port = 3031
port = 3000

[telemetry]
enabled = true
host = '127.0.0.1'
enabled = false
host = '0.0.0.0'
port = 3001

[[chains]]
id = '$UMEE_E2E_UMEE_CHAIN_ID'
rpc_addr = 'http://$UMEE_E2E_UMEE_VAL_HOST:26657'
grpc_addr = 'http://$UMEE_E2E_UMEE_VAL_HOST:9090'
websocket_addr = 'ws://$UMEE_E2E_UMEE_VAL_HOST:26657/websocket'
event_source = { mode = 'push', url = 'ws://$UMEE_E2E_UMEE_VAL_HOST:26657/websocket', batch_delay = '500ms' }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batch_delay 500ms they are recommended with their tests

rpc_timeout = '10s'
account_prefix = 'umee'
key_name = 'val01-umee'
address_type = { derivation = 'cosmos' }
store_prefix = 'ibc'
max_gas = 6000000
default_gas = 100000
max_gas = 3000000
gas_price = { price = 0.05, denom = 'uumee' }
gas_adjustment = 1.0
clock_drift = '1m' # to accommodate docker containers
gas_multiplier = 1.1
max_msg_num = 30
trusted_node = false
max_tx_size = 2097152
max_block_time = '5s'
trusting_period = '14days'
clock_drift = '5s' # to accommodate docker containers
trust_threshold = { numerator = '1', denominator = '3' }

[[chains]]
id = '$UMEE_E2E_GAIA_CHAIN_ID'
rpc_addr = 'http://$UMEE_E2E_GAIA_VAL_HOST:26657'
grpc_addr = 'http://$UMEE_E2E_GAIA_VAL_HOST:9090'
websocket_addr = 'ws://$UMEE_E2E_GAIA_VAL_HOST:26657/websocket'
event_source = { mode = 'push', url = 'ws://$UMEE_E2E_GAIA_VAL_HOST:26657/websocket', batch_delay = '500ms' }
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'val01-gaia'
address_type = { derivation = 'cosmos' }
store_prefix = 'ibc'
max_gas = 6000000
default_gas = 100000
trusted_node = false
max_gas = 3000000
gas_price = { price = 0.001, denom = 'stake' }
gas_adjustment = 1.0
clock_drift = '1m' # to accommodate docker containers
gas_multiplier = 1.1
max_msg_num = 30
max_tx_size = 2097152
clock_drift = '5s'
max_block_time = '5s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
EOF

# import gaia and umee keys
hermes keys restore ${UMEE_E2E_GAIA_CHAIN_ID} -n "val01-gaia" -m "${UMEE_E2E_GAIA_VAL_MNEMONIC}"
hermes keys restore ${UMEE_E2E_UMEE_CHAIN_ID} -n "val01-umee" -m "${UMEE_E2E_UMEE_VAL_MNEMONIC}"
echo ${UMEE_E2E_GAIA_VAL_MNEMONIC} > /root/.hermes/val01-gaia
echo ${UMEE_E2E_UMEE_VAL_MNEMONIC} > /root/.hermes/val01-umee

cat /root/.hermes/val01-umee
cat /root/.hermes/val01-gaia

hermes keys add --chain ${UMEE_E2E_GAIA_CHAIN_ID} --key-name "val01-gaia" --mnemonic-file /root/.hermes/val01-gaia
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

# start Hermes relayer
hermes start
hermes start
7 changes: 4 additions & 3 deletions tests/e2e/setup/gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func (s *E2ETestSuite) runGaiaNetwork() {

s.GaiaResource, err = s.DkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: gaiaVal.instanceName(),
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,
Expand Down Expand Up @@ -114,7 +115,7 @@ func (s *E2ETestSuite) runGaiaNetwork() {
}

// let the node produce a few blocks
if status.SyncInfo.CatchingUp || status.SyncInfo.LatestBlockHeight < 3 {
if status.SyncInfo.CatchingUp || status.SyncInfo.LatestBlockHeight < 1 {
return false
}

Expand All @@ -125,5 +126,5 @@ func (s *E2ETestSuite) runGaiaNetwork() {
"gaia node failed to produce blocks",
)

s.T().Logf("started Gaia network container: %s", s.GaiaResource.Container.ID)
s.T().Logf("✅ Started Gaia network container: %s", s.GaiaResource.Container.ID)
}
52 changes: 39 additions & 13 deletions tests/e2e/setup/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s *E2ETestSuite) runIBCRelayer() {
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]
umeeVal := s.Chain.Validators[0]
hermesCfgPath := path.Join(tmpDir, "hermes")

s.Require().NoError(os.MkdirAll(hermesCfgPath, 0o755))
Expand All @@ -38,24 +38,26 @@ func (s *E2ETestSuite) runIBCRelayer() {

s.HermesResource, err = s.DkrPool.RunWithOptions(
&dockertest.RunOptions{
Name: "umee-gaia-relayer",
Repository: "ghcr.io/umee-network/hermes-e2e",
Tag: "latest",
Name: "umee-gaia-relayer",
// Note: we are using this image for testing purpose
Repository: "informalsystems/hermes",
Tag: "1.6.0",
NetworkID: s.DkrNet.Network.ID,
Mounts: []string{
fmt.Sprintf("%s/:/home/hermes", hermesCfgPath),
},
ExposedPorts: []string{"3031"},
User: "root",
ExposedPorts: []string{"3000"},
PortBindings: map[docker.Port][]docker.PortBinding{
"3031/tcp": {{HostIP: "", HostPort: "3031"}},
"3000/tcp": {{HostIP: "", HostPort: "3000"}},
},
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:]),
fmt.Sprintf("UMEE_E2E_UMEE_VAL_HOST=%s", s.ValResources[0].Container.Name[1:]),
},
Entrypoint: []string{
"sh",
Expand All @@ -66,15 +68,30 @@ func (s *E2ETestSuite) runIBCRelayer() {
noRestart,
)
s.Require().NoError(err)
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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to wait for ibc channels creation before making the ibc txn

s.T().Log("✅ IBC Channel is created among the the chains")
}
if err != nil {
return false
}
return channels
},
10*time.Minute,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10min is a lot

3*time.Second,
)

endpoint := fmt.Sprintf("http://%s/state", s.HermesResource.GetHostPort("3031/tcp"))
endpoint := fmt.Sprintf("http://%s/state", s.HermesResource.GetHostPort("3000/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)
Expand All @@ -97,10 +114,11 @@ func (s *E2ETestSuite) runIBCRelayer() {
"hermes relayer not healthy",
)

s.T().Logf("started Hermes relayer container: %s", s.HermesResource.Container.ID)
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()
// Note: we are creating ibc channels on entrypoint of relayer container
// s.connectIBCChains()
}

func (s *E2ETestSuite) connectIBCChains() {
Expand All @@ -119,10 +137,18 @@ func (s *E2ETestSuite) connectIBCChains() {
"hermes",
"create",
"channel",
"--order",
"unordered",
"--a-chain",
s.Chain.ID,
"--b-chain",
GaiaChainID,
"--port-a=transfer",
"--port-b=transfer",
"--a-port",
"transfer",
"--b-port",
"transfer",
"--new-client-connection",
"--yes",
},
})
s.Require().NoError(err)
Expand Down
Loading
Loading