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

fix: trivial e2e improvements #2274

Merged
merged 14 commits into from
Oct 10, 2023
24 changes: 0 additions & 24 deletions tests/e2e/docker/eth.Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions tests/e2e/docker/ganache.Dockerfile

This file was deleted.

20 changes: 20 additions & 0 deletions tests/e2e/e2e_metoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,23 @@ func (s *E2ETest) executeRedeemWithFailure(umeeAddr string, meToken sdk.Coin, as
500*time.Millisecond,
)
}

func (s *E2ETest) TxMetokenSwap(umeeAddr string, asset sdk.Coin, meTokenDenom string) error {
req := &metoken.MsgSwap{
User: umeeAddr,
Asset: asset,
MetokenDenom: meTokenDenom,
}

return s.BroadcastTxWithRetry(req)
}

func (s *E2ETest) TxMetokenRedeem(umeeAddr string, meToken sdk.Coin, assetDenom string) error {
req := &metoken.MsgRedeem{
User: umeeAddr,
Metoken: meToken,
AssetDenom: assetDenom,
}

return s.BroadcastTxWithRetry(req)
}
49 changes: 49 additions & 0 deletions tests/e2e/e2e_oracle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package e2e

import (
"time"

"github.com/umee-network/umee/v6/tests/grpc"
)

// 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 *E2ETest) TestMedians() {
err := grpc.MedianCheck(s.Umee)
s.Require().NoError(err)
}

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)
Copy link
Member

Choose a reason for hiding this comment

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

When this is repeated many time, then it would be better to use:

require := s.Require()
require.Equal(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

It could be - I merely moved this function between files without modifying it


// simple retry loop to submit and pass a proposal
for i := 0; i < 3; i++ {
err = grpc.SubmitAndPassProposal(
s.Umee,
grpc.OracleParamChanges(10, 2, 20),
)
if err == nil {
break
}

time.Sleep(1 * time.Second)
}

s.Require().NoError(err, "submit and pass proposal")

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

s.Require().Equal(uint64(10), params.HistoricStampPeriod)
s.Require().Equal(uint64(2), params.MaximumPriceStamps)
s.Require().Equal(uint64(20), params.MedianStampPeriod)

s.Require().NoError(err)
}
49 changes: 6 additions & 43 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import (
"time"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

setup "github.com/umee-network/umee/v6/tests/e2e/setup"
"github.com/umee-network/umee/v6/tests/grpc"
)

type E2ETest struct {
setup.E2ETestSuite
}

// TestE2ETestSuite is the entry point for e2e testing. It runs after the docker build commands
// listed in Makefile as prerequisites to test-e2e. It first calls E2ETestSuite.SetupSuite() and
// then runs all public methods on the suite whose names match regex "^Test". These tests appear
// to run in series (and in alphabetical order), so the only other transactions being submitted
// while they run are the price feeder votes by the validators running in docker containers.
func TestE2ETestSuite(t *testing.T) {
suite.Run(t, new(E2ETest))
}
Expand Down Expand Up @@ -48,45 +53,3 @@ func (s *E2ETest) mustFailTx(msg sdk.Msg, errSubstring string) {
errSubstring,
)
}

// 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 *E2ETest) TestMedians() {
err := grpc.MedianCheck(s.Umee)
s.Require().NoError(err)
}

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)

// simple retry loop to submit and pass a proposal
for i := 0; i < 3; i++ {
err = grpc.SubmitAndPassProposal(
s.Umee,
grpc.OracleParamChanges(10, 2, 20),
)
if err == nil {
break
}

time.Sleep(1 * time.Second)
}

s.Require().NoError(err, "submit and pass proposal")

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

s.Require().Equal(uint64(10), params.HistoricStampPeriod)
s.Require().Equal(uint64(2), params.MaximumPriceStamps)
s.Require().Equal(uint64(20), params.MedianStampPeriod)

s.Require().NoError(err)
}
29 changes: 29 additions & 0 deletions tests/e2e/setup/accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package setup

import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"

appparams "github.com/umee-network/umee/v6/app/params"
"github.com/umee-network/umee/v6/util/coin"
"github.com/umee-network/umee/v6/x/metoken/mocks"
)

type testAccount struct {
mnemonic string
keyInfo keyring.Record
addr sdk.AccAddress
}

var (
// Initial coins to give to validators
valCoins = sdk.NewCoins(
coin.New(appparams.BondDenom, 1_000000_000000),
coin.New(PhotonDenom, 1_000000_000000),
coin.New(mocks.USDTBaseDenom, 1_000000_000000),
)

// TODO: stake less on the validators, and instead delegate from a test account
stakeAmountCoin = coin.New(appparams.BondDenom, 1_000000)
stakeAmountCoin2 = coin.New(appparams.BondDenom, 5_000000)
)
53 changes: 17 additions & 36 deletions tests/e2e/setup/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type chain struct {
GaiaValidators []*gaiaValidator
}

// newChain creates a chain with a random chain ID and makes a temporary directory to hold its data
func newChain() (*chain, error) {
tmpDir, err := os.MkdirTemp("", "umee-e2e-testnet-")
if err != nil {
Expand All @@ -56,64 +57,44 @@ func newChain() (*chain, error) {
}, nil
}

// configDir is located at <chain.dataDir>/<chain.ID>
func (c *chain) configDir() string {
return fmt.Sprintf("%s/%s", c.dataDir, c.ID)
}

// createAndInitValidators adds a number of validators to the chain and initializes their
// keys, config.toml and genesis.json in separate config directories created for each validator.
// Their monikers are all set to "umee" but their indexes are different.
func (c *chain) createAndInitValidators(cdc codec.Codec, count int) error {
for i := 0; i < count; i++ {
node := c.createValidator(i)
node := validator{
chain: c,
index: i,
moniker: "umee",
}

// generate genesis files
// create config directory and initializes config.toml and genesis.json
if err := node.init(cdc); err != nil {
return err
}

c.Validators = append(c.Validators, node)

// create keys
// generate a random key and save to keyring-backend-test in the validator's config directory
if err := node.createKey(cdc, "val"); err != nil {
return err
}
// loads or generates a node key in the validator's config directory
// TODO (comment): which are we doing? loading or generating?
if err := node.createNodeKey(); err != nil {
return err
}
// loads or generates a consensus key in the validator's config directory
// TODO (comment): which are we doing? loading or generating?
if err := node.createConsensusKey(); err != nil {
return err
}
}

return nil
}

func (c *chain) createAndInitGaiaValidator(cdc codec.Codec) error {
toteki marked this conversation as resolved.
Show resolved Hide resolved
// create gaia validator
gaiaVal := c.createGaiaValidator(0)

// create keys
mnemonic, info, err := createMemoryKey(cdc)
if err != nil {
return err
c.Validators = append(c.Validators, &node)
}

gaiaVal.keyInfo = *info
gaiaVal.mnemonic = mnemonic

c.GaiaValidators = append(c.GaiaValidators, gaiaVal)

return nil
}

func (c *chain) createValidator(index int) *validator {
return &validator{
chain: c,
index: index,
moniker: "umee",
}
}

func (c *chain) createGaiaValidator(index int) *gaiaValidator {
return &gaiaValidator{
index: index,
}
}
Loading