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

refactor: refactor the e2e setup suite #2048

Merged
merged 7 commits into from
Jun 22, 2023
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
10 changes: 4 additions & 6 deletions tests/e2e/cw_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package e2e

import "github.com/umee-network/umee/v5/tests/util"

type TestCosmwasm struct {
IntegrationTestSuite
util.Cosmwasm
}
// type TestCosmwasm struct {
// IntegrationTestSuite
// util.Cosmwasm
// }

/*
// TODO : needs to setup live network with dockernet
Expand Down
67 changes: 34 additions & 33 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

appparams "github.com/umee-network/umee/v5/app/params"
setup "github.com/umee-network/umee/v5/tests/e2e/setup"
"github.com/umee-network/umee/v5/tests/grpc"
"github.com/umee-network/umee/v5/x/uibc"
)

var powerReduction = sdk.MustNewDecFromStr("10").Power(6)

func (s *IntegrationTestSuite) checkOutflowByPercentage(endpoint, excDenom string, outflow, amount, perDiff sdk.Dec) {
func (s *E2ETest) checkOutflowByPercentage(endpoint, excDenom string, outflow, amount, perDiff sdk.Dec) {
// get historic average price for denom (SYMBOL_DENOM)
histoAvgPrice, err := queryHistAvgPrice(endpoint, excDenom)
histoAvgPrice, err := s.QueryHistAvgPrice(endpoint, excDenom)
s.Require().NoError(err)
totalPrice := amount.Quo(powerReduction).Mul(histoAvgPrice)
s.T().Log("exchangeRate total price ", totalPrice.String(), "outflow value", outflow.String())
Expand All @@ -25,10 +26,10 @@ func (s *IntegrationTestSuite) checkOutflowByPercentage(endpoint, excDenom strin
s.Require().True(outflow.GTE(totalPrice.Sub(percentageDiff)) || totalPrice.GTE(outflow.Sub(percentageDiff)))
}

func (s *IntegrationTestSuite) checkOutflows(umeeAPIEndpoint, denom string, checkWithExcRate bool, amount sdk.Dec, excDenom string) {
func (s *E2ETest) checkOutflows(umeeAPIEndpoint, denom string, checkWithExcRate bool, amount sdk.Dec, excDenom string) {
s.Require().Eventually(
func() bool {
a, err := queryOutflows(umeeAPIEndpoint, denom)
a, err := s.QueryOutflows(umeeAPIEndpoint, denom)
s.Require().NoError(err)
if checkWithExcRate {
s.checkOutflowByPercentage(umeeAPIEndpoint, excDenom, a, amount, sdk.MustNewDecFromStr("0.01"))
Expand All @@ -40,10 +41,10 @@ func (s *IntegrationTestSuite) checkOutflows(umeeAPIEndpoint, denom string, chec
)
}

func (s *IntegrationTestSuite) checkSupply(endpoint, ibcDenom string, amount math.Int) {
func (s *E2ETest) checkSupply(endpoint, ibcDenom string, amount math.Int) {
s.Require().Eventually(
func() bool {
supply, err := queryTotalSupply(endpoint)
supply, err := s.QueryTotalSupply(endpoint)
s.Require().NoError(err)
s.Require().Equal(supply.AmountOf(ibcDenom).Int64(), amount.Int64())
return supply.AmountOf(ibcDenom).Equal(amount)
Expand All @@ -53,14 +54,14 @@ func (s *IntegrationTestSuite) checkSupply(endpoint, ibcDenom string, amount mat
)
}

func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
func (s *E2ETest) TestIBCTokenTransfer() {
// s.T().Parallel()
var ibcStakeDenom string

s.Run("ibc_transfer_quota", func() {
// require the recipient account receives the IBC tokens (IBC packets ACKd)
gaiaAPIEndpoint := s.gaiaREST()
umeeAPIEndpoint := s.umeeREST()
gaiaAPIEndpoint := s.GaiaREST()
umeeAPIEndpoint := s.UmeeREST()
atomSymbol := "ATOM"
umeeSymbol := "UMEE"
totalQuota := math.NewInt(120)
Expand All @@ -72,23 +73,23 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {

// send uatom from gaia to umee
// Note : gaia -> umee (ibc_quota will not check token limit)
atomPrice, err := queryHistAvgPrice(umeeAPIEndpoint, atomSymbol)
atomPrice, err := s.QueryHistAvgPrice(umeeAPIEndpoint, atomSymbol)
s.Require().NoError(err)
emOfAtom := sdk.NewDecFromInt(totalQuota).Quo(atomPrice)
c := sdk.NewInt64Coin("uatom", emOfAtom.Mul(powerReduction).RoundInt64())
s.Require().True(atomPrice.GT(sdk.OneDec()), "price should be non zero, and expecting higher than 1, got: %s", atomPrice)
s.Require().True(c.Amount.GT(sdk.NewInt(2_000_000)), "amount should be non zero, and expecting much higher than 2 atom = 2e6 uatom, got: %s", c.Amount)

s.sendIBC(gaiaChainID, s.chain.id, "", c)
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", c)
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, c.Amount)

// sending more tokens than token_quota limit of umee (token_quota is 100$)
histoAvgPriceOfUmee, err := queryHistAvgPrice(umeeAPIEndpoint, umeeSymbol)
histoAvgPriceOfUmee, err := s.QueryHistAvgPrice(umeeAPIEndpoint, umeeSymbol)
s.Require().NoError(err)
exceedAmountOfUmee := sdk.NewDecFromInt(totalQuota).Quo(histoAvgPriceOfUmee)
s.T().Logf("sending %s amount %s more than %s", umeeSymbol, exceedAmountOfUmee.String(), totalQuota.String())
exceedAmountCoin := sdk.NewInt64Coin(appparams.BondDenom, exceedAmountOfUmee.Mul(powerReduction).RoundInt64())
s.sendIBC(s.chain.id, gaiaChainID, "", exceedAmountCoin)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedAmountCoin)
// check the ibc (umee) quota after ibc txs
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())

Expand All @@ -99,14 +100,14 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
belowTokenQuota := sdk.NewDecFromInt(umeeInitialQuota).Quo(histoAvgPriceOfUmee)
s.T().Logf("sending %s amount %s less than token quota %s", "UMEE", belowTokenQuota.String(), tokenQuota.String())
token := sdk.NewInt64Coin(appparams.BondDenom, belowTokenQuota.Mul(powerReduction).RoundInt64())
s.sendIBC(s.chain.id, gaiaChainID, "", token)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", token)
s.checkOutflows(umeeAPIEndpoint, appparams.BondDenom, true, sdk.NewDecFromInt(token.Amount), appparams.Name)
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, token.Amount)

// send uatom (ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2) from umee to gaia
uatomIBCToken := sdk.NewInt64Coin(uatomIBCHash, c.Amount.Int64())
// supply will be not be decreased because sending uatomIBCToken amount is more than token quota so it will fail
s.sendIBC(s.chain.id, gaiaChainID, "", uatomIBCToken)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", uatomIBCToken)
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, uatomIBCToken.Amount)

// send uatom below the token quota
Expand All @@ -117,37 +118,37 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
*/
belowTokenQuotabutNotBelowTotalQuota := sdk.NewDecFromInt(math.NewInt(90)).Quo(atomPrice)
uatomIBCToken.Amount = math.NewInt(belowTokenQuotabutNotBelowTotalQuota.Mul(powerReduction).RoundInt64())
s.sendIBC(s.chain.id, gaiaChainID, "", uatomIBCToken)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", uatomIBCToken)
// supply will be not be decreased because sending more than total quota from umee to gaia
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, c.Amount)
// making sure below the total quota
belowTokenQuotaInUSD := totalQuota.Sub(umeeInitialQuota).Sub(math.NewInt(2))
belowTokenQuotaforAtom := sdk.NewDecFromInt(belowTokenQuotaInUSD).Quo(atomPrice)
uatomIBCToken.Amount = math.NewInt(belowTokenQuotaforAtom.Mul(powerReduction).RoundInt64())
s.sendIBC(s.chain.id, gaiaChainID, "", uatomIBCToken)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", uatomIBCToken)
// remaing supply still exists for uatom in umee
s.checkSupply(umeeAPIEndpoint, uatomIBCHash, c.Amount.Sub(uatomIBCToken.Amount))
s.checkOutflows(umeeAPIEndpoint, uatomIBCHash, true, sdk.NewDecFromInt(uatomIBCToken.Amount), atomSymbol)

// sending more tokens then token_quota limit of umee
s.sendIBC(s.chain.id, gaiaChainID, "", exceedAmountCoin)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", exceedAmountCoin)
// check the ibc (umee) supply after ibc txs, it will same as previous because it will fail because to quota limit exceed
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, token.Amount)

/* sending back some amount from receiver to sender (ibc/XXX)
gaia -> umee
*/
s.sendIBC(gaiaChainID, s.chain.id, "", sdk.NewInt64Coin(umeeIBCHash, 1000))
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", sdk.NewInt64Coin(umeeIBCHash, 1000))
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, token.Amount.Sub(math.NewInt(1000)))
// sending back remaining ibc amount from receiver to sender (ibc/XXX)
s.sendIBC(gaiaChainID, s.chain.id, "", sdk.NewInt64Coin(umeeIBCHash, token.Amount.Sub(math.NewInt(1000)).Int64()))
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", sdk.NewInt64Coin(umeeIBCHash, token.Amount.Sub(math.NewInt(1000)).Int64()))
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(
func() bool {
amount, err := queryOutflows(umeeAPIEndpoint, appparams.BondDenom)
amount, err := s.QueryOutflows(umeeAPIEndpoint, appparams.BondDenom)
s.Require().NoError(err)
if amount.IsZero() {
s.T().Logf("quota is reset : %s is 0", appparams.BondDenom)
Expand All @@ -165,30 +166,30 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
***/
// Make gov proposal to disable the quota check on ibc-transfer
err = grpc.UIBCIBCTransferSatusUpdate(
s.umee,
s.Umee,
uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_DISABLED,
)
s.Require().NoError(err)
// Get the uibc params for quota checking
uibcParams, err := s.umee.QueryUIBCParams()
uibcParams, err := s.Umee.QueryUIBCParams()
s.Require().NoError(err)
s.Require().Equal(uibcParams.IbcStatus, uibc.IBCTransferStatus_IBC_TRANSFER_STATUS_QUOTA_DISABLED)
token = sdk.NewInt64Coin("uumee", 100000000) // 100 Umee
// sending the umee tokens
s.sendIBC(s.chain.id, gaiaChainID, "", token)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, "", token)
// Check the outflows
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, token.Amount)
s.Require().Eventually(
func() bool {
a, err := queryOutflows(umeeAPIEndpoint, appparams.BondDenom)
a, err := s.QueryOutflows(umeeAPIEndpoint, appparams.BondDenom)
s.Require().NoError(err)
return a.Equal(sdk.ZeroDec())
},
time.Minute,
5*time.Second,
)
// resend the umee token from gaia to umee
s.sendIBC(gaiaChainID, s.chain.id, "", sdk.NewInt64Coin(umeeIBCHash, token.Amount.Int64()))
s.SendIBC(setup.GaiaChainID, s.Chain.ID, "", sdk.NewInt64Coin(umeeIBCHash, token.Amount.Int64()))
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, sdk.ZeroInt())

})
Expand All @@ -203,17 +204,17 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
)

stakeIBCHash := "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878"
umeeAPIEndpoint := s.umeeREST()
umeeAPIEndpoint := s.UmeeREST()

valAddr, err := s.chain.validators[0].keyInfo.GetAddress()
valAddr, err := s.Chain.Validators[0].KeyInfo.GetAddress()
s.Require().NoError(err)
recipient := valAddr.String()
token := sdk.NewInt64Coin("stake", 3300000000) // 3300stake
s.sendIBC(gaiaChainID, s.chain.id, recipient, token)
s.SendIBC(setup.GaiaChainID, s.Chain.ID, recipient, token)

s.Require().Eventually(
func() bool {
balances, err = queryUmeeAllBalances(umeeAPIEndpoint, recipient)
balances, err = s.QueryUmeeAllBalances(umeeAPIEndpoint, recipient)
s.Require().NoError(err)
// uncomment whene we re-enable inflow limit
// return math.ZeroInt().Equal(balances.AmountOf(stakeIBCHash))
Expand All @@ -230,7 +231,7 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
s.Run("deploy_stake_erc20 ibcStakeERC20Addr", func() {
s.T().Skip("paused due to Ethereum PoS migration and PoW fork")
s.Require().NotEmpty(ibcStakeDenom)
ibcStakeERC20Addr = s.deployERC20Token(ibcStakeDenom)
ibcStakeERC20Addr = s.DeployERC20Token(ibcStakeDenom)
})

// send 300 stake tokens from Umee to Ethereum
Expand All @@ -242,7 +243,7 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
umeeFee := sdk.NewCoin(appparams.BondDenom, math.NewInt(10000))
gravityFee := sdk.NewCoin(ibcStakeDenom, math.NewInt(7))

s.sendFromUmeeToEthCheck(umeeValIdxSender, orchestratorIdxReceiver, ibcStakeERC20Addr, amount, umeeFee, gravityFee)
s.SendFromUmeeToEthCheck(umeeValIdxSender, orchestratorIdxReceiver, ibcStakeERC20Addr, amount, umeeFee, gravityFee)
})

// send 300 stake tokens from Ethereum back to Umee
Expand All @@ -252,6 +253,6 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
orchestratorIdxSender := 1
amount := uint64(300)

s.sendFromEthToUmeeCheck(orchestratorIdxSender, umeeValIdxReceiver, ibcStakeERC20Addr, ibcStakeDenom, amount)
s.SendFromEthToUmeeCheck(orchestratorIdxSender, umeeValIdxReceiver, ibcStakeERC20Addr, ibcStakeDenom, amount)
})
}
44 changes: 28 additions & 16 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
package e2e

import (
"testing"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

appparams "github.com/umee-network/umee/v5/app/params"
setup "github.com/umee-network/umee/v5/tests/e2e/setup"
"github.com/umee-network/umee/v5/tests/grpc"
)

func (s *IntegrationTestSuite) TestPhotonTokenTransfers() {
type E2ETest struct {
setup.E2ETestSuite
}

func TestE2ETestSuite(t *testing.T) {
suite.Run(t, new(E2ETest))
}

func (s *E2ETest) TestPhotonTokenTransfers() {
s.T().Skip("paused due to Ethereum PoS migration and PoW fork")
// deploy photon ERC20 token contact
var photonERC20Addr string
s.Run("deploy_photon_erc20", func() {
photonERC20Addr = s.deployERC20Token(photonDenom)
photonERC20Addr = s.DeployERC20Token(setup.PhotonDenom)
})

// send 100 photon tokens from Umee to Ethereum
s.Run("send_photon_tokens_to_eth", func() {
umeeValIdxSender := 0
orchestratorIdxReceiver := 1
amount := sdk.NewCoin(photonDenom, math.NewInt(100))
amount := sdk.NewCoin(setup.PhotonDenom, math.NewInt(100))
umeeFee := sdk.NewCoin(appparams.BondDenom, math.NewInt(10000))
gravityFee := sdk.NewCoin(photonDenom, math.NewInt(3))
gravityFee := sdk.NewCoin(setup.PhotonDenom, math.NewInt(3))

s.sendFromUmeeToEthCheck(umeeValIdxSender, orchestratorIdxReceiver, photonERC20Addr, amount, umeeFee, gravityFee)
s.SendFromUmeeToEthCheck(umeeValIdxSender, orchestratorIdxReceiver, photonERC20Addr, amount, umeeFee, gravityFee)
})

// send 100 photon tokens from Ethereum back to Umee
Expand All @@ -34,16 +46,16 @@ func (s *IntegrationTestSuite) TestPhotonTokenTransfers() {
orchestratorIdxSender := 1
amount := uint64(100)

s.sendFromEthToUmeeCheck(orchestratorIdxSender, umeeValIdxReceiver, photonERC20Addr, photonDenom, amount)
s.SendFromEthToUmeeCheck(orchestratorIdxSender, umeeValIdxReceiver, photonERC20Addr, setup.PhotonDenom, amount)
})
}

func (s *IntegrationTestSuite) TestUmeeTokenTransfers() {
func (s *E2ETest) TestUmeeTokenTransfers() {
s.T().Skip("paused due to Ethereum PoS migration and PoW fork")
// deploy umee ERC20 token contract
var umeeERC20Addr string
s.Run("deploy_umee_erc20", func() {
umeeERC20Addr = s.deployERC20Token(appparams.BondDenom)
umeeERC20Addr = s.DeployERC20Token(appparams.BondDenom)
})

// send 300 umee tokens from Umee to Ethereum
Expand All @@ -54,7 +66,7 @@ func (s *IntegrationTestSuite) TestUmeeTokenTransfers() {
umeeFee := sdk.NewCoin(appparams.BondDenom, math.NewInt(10000))
gravityFee := sdk.NewCoin(appparams.BondDenom, math.NewInt(7))

s.sendFromUmeeToEthCheck(umeeValIdxSender, orchestratorIdxReceiver, umeeERC20Addr, amount, umeeFee, gravityFee)
s.SendFromUmeeToEthCheck(umeeValIdxSender, orchestratorIdxReceiver, umeeERC20Addr, amount, umeeFee, gravityFee)
})

// send 300 umee tokens from Ethereum back to Umee
Expand All @@ -63,34 +75,34 @@ func (s *IntegrationTestSuite) TestUmeeTokenTransfers() {
orchestratorIdxSender := 1
amount := uint64(300)

s.sendFromEthToUmeeCheck(orchestratorIdxSender, umeeValIdxReceiver, umeeERC20Addr, appparams.BondDenom, amount)
s.SendFromEthToUmeeCheck(orchestratorIdxSender, umeeValIdxReceiver, umeeERC20Addr, appparams.BondDenom, amount)
})
}

// TestMedians queries for the oracle params, collects historical
// prices based on those params, checks that the stored medians and
// medians deviations are correct, updates the oracle params with
// a gov prop, then checks the medians and median deviations again.
func (s *IntegrationTestSuite) TestMedians() {
err := grpc.MedianCheck(s.umee)
func (s *E2ETest) TestMedians() {
err := grpc.MedianCheck(s.Umee)
s.Require().NoError(err)
}

func (s *IntegrationTestSuite) TestUpdateOracleParams() {
params, err := s.umee.QueryOracleParams()
func (s *E2ETest) TestUpdateOracleParams() {
params, err := s.Umee.QueryOracleParams()
s.Require().NoError(err)

s.Require().Equal(uint64(5), params.HistoricStampPeriod)
s.Require().Equal(uint64(4), params.MaximumPriceStamps)
s.Require().Equal(uint64(20), params.MedianStampPeriod)

err = grpc.SubmitAndPassProposal(
s.umee,
s.Umee,
grpc.OracleParamChanges(10, 2, 20),
)
s.Require().NoError(err)

params, err = s.umee.QueryOracleParams()
params, err = s.Umee.QueryOracleParams()
s.Require().NoError(err)

s.Require().Equal(uint64(10), params.HistoricStampPeriod)
Expand Down
Loading
Loading