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

(test): improve IBC check in e2e tests #2558

Merged
merged 3 commits into from
Jun 21, 2024
Merged
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
6 changes: 3 additions & 3 deletions tests/e2e/e2e_ibc_memo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *E2ETest) testIBCTokenTransferWithMemo(umeeAPIEndpoint string, atomQuota

invalidMemoBZ, err := cdc.MarshalJSON(&invalidMemo)
assert.Nil(err)
s.SendIBC(setup.GaiaChainID, s.Chain.ID, accs.Alice.String(), atomFromGaia, false, "", string(invalidMemoBZ))
s.SendIBC(setup.GaiaChainID, s.Chain.ID, accs.Alice.String(), atomFromGaia, "", string(invalidMemoBZ), "")
updatedIBCAtomBalance := atomFromGaia.Amount.Add(prevIBCAtomBalance)
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, updatedIBCAtomBalance)
s.checkLeverageAccountBalance(umeeAPIEndpoint, fallbackAddr, uatomIBCHash, math.ZeroInt())
Expand All @@ -60,7 +60,7 @@ func (s *E2ETest) testIBCTokenTransferWithMemo(umeeAPIEndpoint string, atomQuota
invalidMemo = uibc.ICS20Memo{Messages: anyMsgOfCollateralize, FallbackAddr: ""}
invalidMemoBZ, err = cdc.MarshalJSON(&invalidMemo)
assert.Nil(err)
s.SendIBC(setup.GaiaChainID, s.Chain.ID, accs.Alice.String(), atomFromGaia, false, "", string(invalidMemoBZ))
s.SendIBC(setup.GaiaChainID, s.Chain.ID, accs.Alice.String(), atomFromGaia, "", string(invalidMemoBZ), "")
updatedIBCAtomBalance = updatedIBCAtomBalance.Add(atomFromGaia.Amount)
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, updatedIBCAtomBalance)
s.checkLeverageAccountBalance(umeeAPIEndpoint, fallbackAddr, uatomIBCHash, math.ZeroInt())
Expand All @@ -82,7 +82,7 @@ func (s *E2ETest) testIBCTokenTransferWithMemo(umeeAPIEndpoint string, atomQuota

bz, err := cdc.MarshalJSON(&memo)
assert.Nil(err)
s.SendIBC(setup.GaiaChainID, s.Chain.ID, accs.Alice.String(), atomFromGaia, false, "", string(bz))
s.SendIBC(setup.GaiaChainID, s.Chain.ID, accs.Alice.String(), atomFromGaia, "", string(bz), "")
updatedIBCAtomBalance = updatedIBCAtomBalance.Add(atomFromGaia.Amount)
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, updatedIBCAtomBalance)
s.checkLeverageAccountBalance(umeeAPIEndpoint, accs.Alice.String(), uatomIBCHash, atomFromGaia.Amount)
Expand Down
30 changes: 16 additions & 14 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (

atomSymbol = "ATOM"
umeeSymbol = "UMEE"

errQuotaExceed = "quota transfer exceeded"
)

var powerReduction = sdk.MustNewDecFromStr("10").Power(6)
Expand Down Expand Up @@ -136,7 +138,7 @@ func (s *E2ETest) TestIBCTokenTransfer() {
recipient := s.AccountAddr(0).String()

token := sdk.NewInt64Coin("stake", 3300000000) // 3300stake
s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token, false, "", "")
s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token, "", "", "")
s.checkSupply(umeeAPIEndpoint, stakeIBCHash, token.Amount)
})

Expand All @@ -145,7 +147,7 @@ func (s *E2ETest) TestIBCTokenTransfer() {
// 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.SendIBC(setup.GaiaChainID, s.Chain.ID, "", atomFromGaia, "", "", "")
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount)

// <<< OUTLOW : umee -> gaia >>
Expand All @@ -161,45 +163,45 @@ func (s *E2ETest) TestIBCTokenTransfer() {
// << TOKEN QUOTA EXCCEED >>
// 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, "", "")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedUmee, "", "", errQuotaExceed)
// check the ibc (umee) quota after ibc txs - this one should have failed
// supply don't change
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())

// << Receiver Addr = maximum length + 1
// send $110 UMEE from umee to gaia (token_quota is 100$)
recvAddr := tsdk.GenerateString(ibcutil.MaximumMemoLength + 1)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, recvAddr, exceedUmee, true, "", "")
// check the ibc (umee) quota after ibc txs - this one should have failed
// supply don't change
s.SendIBC(s.Chain.ID, setup.GaiaChainID, recvAddr, exceedUmee, "", "",
"recipient address must not exceed 2048 bytes")
// supply should not 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.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedAtom, "uatom from umee to gaia", "", errQuotaExceed)
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount)

// << 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.SendIBC(s.Chain.ID, setup.GaiaChainID, "", sendUmee,
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 QUOTA 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", "")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", atom40, "below token quota but not total quota", "", errQuotaExceed)
// 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 $5 ATOM from umee to gaia
sendAtom := mulCoin(atomQuota, "0.05")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", sendAtom, false, "below both quotas", "")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", sendAtom, "below both quotas", "", "")
// remaing supply decreased uatom on umee
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, atomFromGaia.Amount.Sub(sendAtom.Amount))
s.checkOutflows(umeeAPIEndpoint, uatomIBCHash, true, sdk.NewDecFromInt(sendAtom.Amount), atomSymbol)
Expand All @@ -210,11 +212,11 @@ func (s *E2ETest) TestIBCTokenTransfer() {
coins, err := s.QueryTotalSupply(gaiaAPIEndpoint) // before sending back
remainingTokens := coins.AmountOf(umeeIBCHash).Sub(returnUmee.Amount)
s.Require().NoError(err)
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", returnUmee, false, "send back some umee", "")
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", returnUmee, "send back some umee", "", "")
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, remainingTokens)

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

/*
Expand Down Expand Up @@ -267,7 +269,7 @@ func (s *E2ETest) TestIBCTokenTransfer() {
s.Require().Equal(uibcParams.IbcStatus, uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_DISABLED)

// sending the umee tokens - they would have exceeded quota before
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedUmee, false, "sending umee", "")
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedUmee, "sending umee", "", "")
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, exceedUmee.Amount)
// Check the outflows
s.Require().Eventually(
Expand Down
17 changes: 8 additions & 9 deletions tests/e2e/setup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (s *E2ETestSuite) Delegate(testAccount, valIndex int, amount uint64) error
return s.BroadcastTxWithRetry(msg, s.AccountClient(testAccount))
}

func (s *E2ETestSuite) SendIBC(srcChainID, dstChainID, recipient string, token sdk.Coin, failDueToQuota bool,
desc, memo string) {
if failDueToQuota {
s.T().Logf("sending %s from %s to %s (exceed quota: %v) %s",
token, srcChainID, dstChainID, failDueToQuota, desc)
func (s *E2ETestSuite) SendIBC(srcChainID, dstChainID, recipient string, token sdk.Coin,
desc, memo, expectedErr string) {
if expectedErr != "" {
s.T().Logf("sending %s from %s to %s, %s (expectedErr: %s)",
token, srcChainID, dstChainID, desc, expectedErr)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
Expand Down Expand Up @@ -131,9 +131,8 @@ func (s *E2ETestSuite) SendIBC(srcChainID, dstChainID, recipient string, token s
// Note: we are cchecking only one side of ibc , we don't know whethever ibc transfer is succeed on one side
// some times relayer can't send the packets to another chain

// // don't check for the tx hash if we expect this to fail due to quota
if strings.Contains(errBuf.String(), "quota transfer exceeded") {
s.Require().True(failDueToQuota)
if expectedErr != "" {
s.Require().Contains(outBuf.String(), expectedErr)
return
}

Expand All @@ -142,7 +141,7 @@ func (s *E2ETestSuite) SendIBC(srcChainID, dstChainID, recipient string, token s
if i < 4 {
continue
}
if !strings.Contains(outBuf.String(), "must not exceed") {
if !strings.Contains(outBuf.String(), expectedErr) {
s.Require().Failf("failed to find transaction hash in output outBuf: %s errBuf: %s",
outBuf.String(), errBuf.String())
}
Expand Down
Loading