From d114dc9d53ac5b7256e72a231c17436fa27f2e0f Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Thu, 7 Sep 2023 09:35:31 -0600 Subject: [PATCH 01/36] file --- tests/e2e/e2e_leverage_test.go | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/e2e/e2e_leverage_test.go diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go new file mode 100644 index 0000000000..df8caf702f --- /dev/null +++ b/tests/e2e/e2e_leverage_test.go @@ -0,0 +1 @@ +package e2e From 7dad3b9384552bb41e66a109c94a05d96edebe35 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Thu, 7 Sep 2023 23:34:08 -0600 Subject: [PATCH 02/36] mimic egor PR #2232 --- tests/e2e/e2e_test.go | 12 ++++++++++++ tests/e2e/setup/utils.go | 18 ++++++++++++++++++ tests/grpc/gov.go | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 027be4cf31..5ca26e4fb8 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -6,6 +6,8 @@ import ( "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" ) @@ -18,6 +20,16 @@ func TestE2ETestSuite(t *testing.T) { suite.Run(t, new(E2ETest)) } +func (s *E2ETest) executeTx(msg sdk.Msg) { + s.Require().Eventually( + func() bool { + return s.BroadcastTxWithRetry(msg) == nil + }, + 30*time.Second, + 500*time.Millisecond, + ) +} + // 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 diff --git a/tests/e2e/setup/utils.go b/tests/e2e/setup/utils.go index c421c88e07..63ec8ab964 100644 --- a/tests/e2e/setup/utils.go +++ b/tests/e2e/setup/utils.go @@ -281,3 +281,21 @@ func decodeTx(cdc codec.Codec, txBytes []byte) (*sdktx.Tx, error) { Signatures: raw.Signatures, }, nil } + +func (s *E2ETestSuite) BroadcastTxWithRetry(msg sdk.Msg) error { + var err error + for retry := 0; retry < 5; retry++ { + // retry if txs fails, because sometimes account sequence mismatch occurs due to txs pending + _, err = s.Umee.Client.Tx.BroadcastTx(msg) + if err == nil { + return nil + } + + if err != nil && !strings.Contains(err.Error(), "incorrect account sequence") { + return err + } + time.Sleep(time.Millisecond * 300) + } + + return err +} diff --git a/tests/grpc/gov.go b/tests/grpc/gov.go index 3906e70652..0c7904ee52 100644 --- a/tests/grpc/gov.go +++ b/tests/grpc/gov.go @@ -10,6 +10,7 @@ import ( "github.com/umee-network/umee/v6/client" "github.com/umee-network/umee/v6/util/checkers" + ltypes "github.com/umee-network/umee/v6/x/leverage/types" "github.com/umee-network/umee/v6/x/uibc" ) @@ -75,6 +76,26 @@ func UIBCIBCTransferSatusUpdate(umeeClient client.Client, status uibc.IBCTransfe return MakeVoteAndCheckProposal(umeeClient, *resp) } +func LeverageRegistryUpdate(umeeClient client.Client, addTokens, updateTokens []ltypes.Token) error { + msg := ltypes.MsgGovUpdateRegistry{ + Authority: checkers.GovModuleAddr, + Description: "", + AddTokens: addTokens, + UpdateTokens: updateTokens, + } + + resp, err := umeeClient.Tx.TxSubmitProposalWithMsg([]sdk.Msg{&msg}) + if err != nil { + return err + } + + if len(resp.Logs) == 0 { + return fmt.Errorf("no logs in response") + } + + return MakeVoteAndCheckProposal(umeeClient, *resp) +} + func MakeVoteAndCheckProposal(umeeClient client.Client, resp sdk.TxResponse) error { var proposalID string for _, event := range resp.Logs[0].Events { From c3e94e21452ff4b114c5a00521ebee3fb45f0ed4 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Thu, 7 Sep 2023 23:34:24 -0600 Subject: [PATCH 03/36] leverage execute fxns --- tests/e2e/e2e_leverage_test.go | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index df8caf702f..0ed70de8d5 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -1 +1,91 @@ package e2e + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" +) + +func (s *E2ETest) executeSupply(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgSupply{ + Supplier: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeWithdraw(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgWithdraw{ + Supplier: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeMaxWithdraw(addr, denom string) { + msg := &leveragetypes.MsgMaxWithdraw{ + Supplier: addr, + Denom: denom, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeCollateralize(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgCollateralize{ + Borrower: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeDecollateralize(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgDecollateralize{ + Borrower: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeSupplyCollateral(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgSupplyCollateral{ + Supplier: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeBorrow(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgBorrow{ + Borrower: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeRepay(addr string, asset sdk.Coin) { + msg := &leveragetypes.MsgRepay{ + Borrower: addr, + Asset: asset, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeLiquidate(addr, target, reward string, repay sdk.Coin) { + msg := &leveragetypes.MsgLiquidate{ + Liquidator: addr, + Borrower: target, + Repayment: repay, + RewardDenom: reward, + } + s.executeTx(msg) +} + +func (s *E2ETest) executeLeveragedLiquidate(addr, target, repay, reward string) { + msg := &leveragetypes.MsgLeveragedLiquidate{ + Liquidator: addr, + Borrower: target, + RepayDenom: repay, + RewardDenom: reward, + } + s.executeTx(msg) +} From 3963af5ba7a39165c8854be524d014d9a6ce52ee Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:50:32 -0600 Subject: [PATCH 04/36] comment --- tests/grpc/gov.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/grpc/gov.go b/tests/grpc/gov.go index 0c7904ee52..1d22da198b 100644 --- a/tests/grpc/gov.go +++ b/tests/grpc/gov.go @@ -76,6 +76,7 @@ func UIBCIBCTransferSatusUpdate(umeeClient client.Client, status uibc.IBCTransfe return MakeVoteAndCheckProposal(umeeClient, *resp) } +// LeverageRegistryUpdate submits a gov transaction to update leverage registry, votes, and waits for proposal to pass. func LeverageRegistryUpdate(umeeClient client.Client, addTokens, updateTokens []ltypes.Token) error { msg := ltypes.MsgGovUpdateRegistry{ Authority: checkers.GovModuleAddr, From c8c7f3ea3b87950084164534282b40ac5a3c184d Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 01:08:22 -0600 Subject: [PATCH 05/36] shorten functions --- tests/e2e/e2e_leverage_test.go | 88 ++++++++++------------------------ 1 file changed, 24 insertions(+), 64 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 0ed70de8d5..f80672434d 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -6,86 +6,46 @@ import ( leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) -func (s *E2ETest) executeSupply(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgSupply{ - Supplier: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeSupply(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgSupply(addr, asset)) } -func (s *E2ETest) executeWithdraw(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgWithdraw{ - Supplier: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeWithdraw(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgWithdraw(addr, asset)) } -func (s *E2ETest) executeMaxWithdraw(addr, denom string) { - msg := &leveragetypes.MsgMaxWithdraw{ - Supplier: addr, - Denom: denom, - } - s.executeTx(msg) +func (s *E2ETest) executeMaxWithdraw(addr sdk.AccAddress, denom string) { + s.executeTx(leveragetypes.NewMsgMaxWithdraw(addr, denom)) } -func (s *E2ETest) executeCollateralize(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgCollateralize{ - Borrower: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeCollateralize(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgCollateralize(addr, asset)) } -func (s *E2ETest) executeDecollateralize(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgDecollateralize{ - Borrower: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeDecollateralize(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgDecollateralize(addr, asset)) } -func (s *E2ETest) executeSupplyCollateral(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgSupplyCollateral{ - Supplier: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeSupplyCollateral(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgSupplyCollateral(addr, asset)) } -func (s *E2ETest) executeBorrow(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgBorrow{ - Borrower: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeBorrow(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgBorrow(addr, asset)) } -func (s *E2ETest) executeRepay(addr string, asset sdk.Coin) { - msg := &leveragetypes.MsgRepay{ - Borrower: addr, - Asset: asset, - } - s.executeTx(msg) +func (s *E2ETest) executeMaxBorrow(addr sdk.AccAddress, denom string) { + s.executeTx(leveragetypes.NewMsgMaxBorrow(addr, denom)) } -func (s *E2ETest) executeLiquidate(addr, target, reward string, repay sdk.Coin) { - msg := &leveragetypes.MsgLiquidate{ - Liquidator: addr, - Borrower: target, - Repayment: repay, - RewardDenom: reward, - } - s.executeTx(msg) +func (s *E2ETest) executeRepay(addr sdk.AccAddress, asset sdk.Coin) { + s.executeTx(leveragetypes.NewMsgRepay(addr, asset)) } -func (s *E2ETest) executeLeveragedLiquidate(addr, target, repay, reward string) { - msg := &leveragetypes.MsgLeveragedLiquidate{ - Liquidator: addr, - Borrower: target, - RepayDenom: repay, - RewardDenom: reward, - } - s.executeTx(msg) +func (s *E2ETest) executeLiquidate(addr, target sdk.AccAddress, reward string, repay sdk.Coin) { + s.executeTx(leveragetypes.NewMsgLiquidate(addr, target, repay, reward)) +} + +func (s *E2ETest) executeLeveragedLiquidate(addr, target sdk.AccAddress, repay, reward string) { + s.executeTx(leveragetypes.NewMsgLeveragedLiquidate(addr, target, repay, reward)) } From b5930ded2ea6dc4e5d1a90277f52cd3c84f97fbd Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 02:26:21 -0600 Subject: [PATCH 06/36] ++ --- tests/e2e/e2e_leverage_test.go | 44 +++++++++++++++++----------------- tests/e2e/e2e_test.go | 22 ++++++++++++++++- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index f80672434d..23c6c7300e 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -6,46 +6,46 @@ import ( leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) -func (s *E2ETest) executeSupply(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgSupply(addr, asset)) +func (s *E2ETest) supply(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgSupply(addr, asset)) } -func (s *E2ETest) executeWithdraw(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgWithdraw(addr, asset)) +func (s *E2ETest) withdraw(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgWithdraw(addr, asset)) } -func (s *E2ETest) executeMaxWithdraw(addr sdk.AccAddress, denom string) { - s.executeTx(leveragetypes.NewMsgMaxWithdraw(addr, denom)) +func (s *E2ETest) maxWithdraw(addr sdk.AccAddress, denom string) { + s.mustSucceedTx(leveragetypes.NewMsgMaxWithdraw(addr, denom)) } -func (s *E2ETest) executeCollateralize(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgCollateralize(addr, asset)) +func (s *E2ETest) collateralize(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgCollateralize(addr, asset)) } -func (s *E2ETest) executeDecollateralize(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgDecollateralize(addr, asset)) +func (s *E2ETest) decollateralize(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgDecollateralize(addr, asset)) } -func (s *E2ETest) executeSupplyCollateral(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgSupplyCollateral(addr, asset)) +func (s *E2ETest) supplyCollateral(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgSupplyCollateral(addr, asset)) } -func (s *E2ETest) executeBorrow(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgBorrow(addr, asset)) +func (s *E2ETest) borrow(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgBorrow(addr, asset)) } -func (s *E2ETest) executeMaxBorrow(addr sdk.AccAddress, denom string) { - s.executeTx(leveragetypes.NewMsgMaxBorrow(addr, denom)) +func (s *E2ETest) maxBorrow(addr sdk.AccAddress, denom string) { + s.mustSucceedTx(leveragetypes.NewMsgMaxBorrow(addr, denom)) } -func (s *E2ETest) executeRepay(addr sdk.AccAddress, asset sdk.Coin) { - s.executeTx(leveragetypes.NewMsgRepay(addr, asset)) +func (s *E2ETest) repay(addr sdk.AccAddress, asset sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgRepay(addr, asset)) } -func (s *E2ETest) executeLiquidate(addr, target sdk.AccAddress, reward string, repay sdk.Coin) { - s.executeTx(leveragetypes.NewMsgLiquidate(addr, target, repay, reward)) +func (s *E2ETest) liquidate(addr, target sdk.AccAddress, reward string, repay sdk.Coin) { + s.mustSucceedTx(leveragetypes.NewMsgLiquidate(addr, target, repay, reward)) } -func (s *E2ETest) executeLeveragedLiquidate(addr, target sdk.AccAddress, repay, reward string) { - s.executeTx(leveragetypes.NewMsgLeveragedLiquidate(addr, target, repay, reward)) +func (s *E2ETest) leveragedLiquidate(addr, target sdk.AccAddress, repay, reward string) { + s.mustSucceedTx(leveragetypes.NewMsgLeveragedLiquidate(addr, target, repay, reward)) } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 5ca26e4fb8..98b0e9bacd 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -20,7 +20,11 @@ func TestE2ETestSuite(t *testing.T) { suite.Run(t, new(E2ETest)) } -func (s *E2ETest) executeTx(msg sdk.Msg) { +// mustEventuallySucceedTx executes an sdk.Msg (retrying several times if receiving any error, +// and requires that the transaction eventually succeeded with nil error. Since this function +// retries for 30 seconds and ignores errors, it is suitable for scenario setup transaction or +// those which might require time elapsing before they succeed. +func (s *E2ETest) mustEventuallySucceedTx(msg sdk.Msg) { s.Require().Eventually( func() bool { return s.BroadcastTxWithRetry(msg) == nil @@ -30,6 +34,22 @@ func (s *E2ETest) executeTx(msg sdk.Msg) { ) } +// mustSucceedTx executes an sdk.Msg (retrying several times if receiving incorrect account sequence) and +// requires that the error returned is nil. +func (s *E2ETest) mustSucceedTx(msg sdk.Msg) { + s.Require().NoError(s.BroadcastTxWithRetry(msg)) +} + +// mustFailTx executes an sdk.Msg (retrying several times if receiving incorrect account sequence) and +// requires that the error returned contains a given substring. If the substring is empty, simply requires +// non-nil error. +func (s *E2ETest) mustFailTx(msg sdk.Msg, errSubstring string) { + s.Require().ErrorContains( + s.BroadcastTxWithRetry(msg), + 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 From 62ac6c5e4634ed03830a6296754754e45f7414c2 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 07:51:30 -0600 Subject: [PATCH 07/36] const --- tests/e2e/setup/keys.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index 17168ce70a..26d5d0ed1d 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -10,12 +10,15 @@ import ( ) const ( - PhotonDenom = "photon" - InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom - GaiaChainID = "test-gaia-chain" + ATOM = "ATOM" + ATOMBaseDenom = "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2" + ATOMExponent = 6 - EthChainID uint = 15 - EthMinerPK = "0xb1bab011e03a9862664706fc3bbaa1b16651528e5f0e7fbfcbfdd8be302a13e7" + PhotonDenom = "photon" + InitBalanceStr = "510000000000" + appparams.BondDenom + + ",100000000000" + PhotonDenom + + ",100000000000" + "test1" + GaiaChainID = "test-gaia-chain" PriceFeederContainerRepo = "ghcr.io/umee-network/price-feeder-umee" PriceFeederServerPort = "7171/tcp" @@ -31,12 +34,6 @@ var ( stakeAmountCoin2 = sdk.NewCoin(appparams.BondDenom, stakeAmount2) ) -var ( - ATOM = "ATOM" - ATOMBaseDenom = "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2" - ATOMExponent = 6 -) - func createMnemonic() (string, error) { entropySeed, err := bip39.NewEntropy(256) if err != nil { From 8c905c70aa7bd4ba5952bbf8b82dfb989e840839 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:23:53 -0600 Subject: [PATCH 08/36] add initial balances --- tests/e2e/setup/keys.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index 26d5d0ed1d..82cfb46009 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -17,7 +17,15 @@ const ( PhotonDenom = "photon" InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom + - ",100000000000" + "test1" + ",100000000000" + "test1" + + ",100000000000" + "test2" + + ",100000000000" + "test3" + + ",100000000000" + "test4" + + ",100000000000" + "test5" + + ",100000000000" + "test6" + + ",100000000000" + "test7" + + ",100000000000" + "test8" + + ",100000000000" + "test9" GaiaChainID = "test-gaia-chain" PriceFeederContainerRepo = "ghcr.io/umee-network/price-feeder-umee" From 2f9ec2bf52c7b2b70f312cdb9da52c9570b264da Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:41:15 -0600 Subject: [PATCH 09/36] leverage gov setup --- tests/e2e/e2e_leverage_test.go | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 23c6c7300e..7765583ebf 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -3,6 +3,8 @@ package e2e import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/umee-network/umee/v6/tests/grpc" + "github.com/umee-network/umee/v6/x/leverage/fixtures" leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) @@ -49,3 +51,94 @@ func (s *E2ETest) liquidate(addr, target sdk.AccAddress, reward string, repay sd func (s *E2ETest) leveragedLiquidate(addr, target sdk.AccAddress, repay, reward string) { s.mustSucceedTx(leveragetypes.NewMsgLeveragedLiquidate(addr, target, repay, reward)) } + +func (s *E2ETest) TestLeverageScenario() { + s.Run( + "register leverage tokens", func() { + tokens := []leveragetypes.Token{ + fixtures.Token("test1", "WBTC", 8), + fixtures.Token("test2", "WETH", 18), + fixtures.Token("test3", "USDT", 6), + } + + err := grpc.LeverageRegistryUpdate(s.Umee, tokens, nil) + s.Require().NoError(err) + }, + ) +} + +/* +func (s *E2ETest) TestMetokenSwapAndRedeem() { + var prices []metoken.IndexPrices + var index metoken.Index + valAddr, err := s.Chain.Validators[0].KeyInfo.GetAddress() + s.Require().NoError(err) + expectedBalance := mocks.EmptyUSDIndexBalances(mocks.MeUSDDenom) + + s.Run( + "create_stable_index", func() { + tokens := []ltypes.Token{ + mocks.ValidToken(mocks.USDTBaseDenom, mocks.USDTSymbolDenom, 6), + mocks.ValidToken(mocks.USDCBaseDenom, mocks.USDCSymbolDenom, 6), + mocks.ValidToken(mocks.ISTBaseDenom, mocks.ISTSymbolDenom, 6), + } + + err = grpc.LeverageRegistryUpdate(s.Umee, tokens, nil) + s.Require().NoError(err) + + meUSD := mocks.StableIndex(mocks.MeUSDDenom) + err = grpc.MetokenRegistryUpdate(s.Umee, []metoken.Index{meUSD}, nil) + s.Require().NoError(err) + + prices = s.checkMetokenBalance(meUSD.Denom, expectedBalance) + }, + ) + + s.Run( + "swap_100USDT_success", func() { + index = s.getIndex(mocks.MeUSDDenom) + + hundredUSDT := sdk.NewCoin(mocks.USDTBaseDenom, sdkmath.NewInt(100_000000)) + fee := index.Fee.MinFee.MulInt(hundredUSDT.Amount).TruncateInt() + + assetSettings, i := index.AcceptedAsset(mocks.USDTBaseDenom) + s.Require().True(i >= 0) + + amountToSwap := hundredUSDT.Amount.Sub(fee) + amountToReserves := assetSettings.ReservePortion.MulInt(amountToSwap).TruncateInt() + amountToLeverage := amountToSwap.Sub(amountToReserves) + + usdtPrice, err := prices[0].PriceByBaseDenom(mocks.USDTBaseDenom) + s.Require().NoError(err) + returned := usdtPrice.SwapRate.MulInt(amountToSwap).TruncateInt() + + s.executeSwap(valAddr, hundredUSDT, mocks.MeUSDDenom) + + expectedBalance.MetokenSupply.Amount = expectedBalance.MetokenSupply.Amount.Add(returned) + usdtBalance, i := expectedBalance.AssetBalance(mocks.USDTBaseDenom) + s.Require().True(i >= 0) + usdtBalance.Fees = usdtBalance.Fees.Add(fee) + usdtBalance.Reserved = usdtBalance.Reserved.Add(amountToReserves) + usdtBalance.Leveraged = usdtBalance.Leveraged.Add(amountToLeverage) + expectedBalance.SetAssetBalance(usdtBalance) + + prices = s.checkMetokenBalance(mocks.MeUSDDenom, expectedBalance) + }, + ) + + s.Run( + "redeem_200meUSD_failure", func() { + twoHundredsMeUSD := sdk.NewCoin(mocks.MeUSDDenom, sdkmath.NewInt(200_000000)) + + s.executeRedeemWithFailure( + valAddr, + twoHundredsMeUSD, + mocks.USDTBaseDenom, + "not enough", + ) + + prices = s.checkMetokenBalance(mocks.MeUSDDenom, expectedBalance) + }, + ) +} +*/ From a40355fbf26ea4174aa933ec88ab4eda8033882a Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:47:12 -0600 Subject: [PATCH 10/36] special assets pair gov setup --- tests/e2e/e2e_leverage_test.go | 79 +++------------------------------- tests/grpc/gov.go | 21 +++++++++ 2 files changed, 28 insertions(+), 72 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 7765583ebf..d97fcc63a4 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -63,82 +63,17 @@ func (s *E2ETest) TestLeverageScenario() { err := grpc.LeverageRegistryUpdate(s.Umee, tokens, nil) s.Require().NoError(err) - }, - ) -} - -/* -func (s *E2ETest) TestMetokenSwapAndRedeem() { - var prices []metoken.IndexPrices - var index metoken.Index - valAddr, err := s.Chain.Validators[0].KeyInfo.GetAddress() - s.Require().NoError(err) - expectedBalance := mocks.EmptyUSDIndexBalances(mocks.MeUSDDenom) - s.Run( - "create_stable_index", func() { - tokens := []ltypes.Token{ - mocks.ValidToken(mocks.USDTBaseDenom, mocks.USDTSymbolDenom, 6), - mocks.ValidToken(mocks.USDCBaseDenom, mocks.USDCSymbolDenom, 6), - mocks.ValidToken(mocks.ISTBaseDenom, mocks.ISTSymbolDenom, 6), + sets := []leveragetypes.SpecialAssetSet{ + { + Assets: []string{"test1", "test2"}, + CollateralWeight: sdk.MustNewDecFromStr("0.4"), + LiquidationThreshold: sdk.MustNewDecFromStr("0.5"), + }, } - err = grpc.LeverageRegistryUpdate(s.Umee, tokens, nil) - s.Require().NoError(err) - - meUSD := mocks.StableIndex(mocks.MeUSDDenom) - err = grpc.MetokenRegistryUpdate(s.Umee, []metoken.Index{meUSD}, nil) - s.Require().NoError(err) - - prices = s.checkMetokenBalance(meUSD.Denom, expectedBalance) - }, - ) - - s.Run( - "swap_100USDT_success", func() { - index = s.getIndex(mocks.MeUSDDenom) - - hundredUSDT := sdk.NewCoin(mocks.USDTBaseDenom, sdkmath.NewInt(100_000000)) - fee := index.Fee.MinFee.MulInt(hundredUSDT.Amount).TruncateInt() - - assetSettings, i := index.AcceptedAsset(mocks.USDTBaseDenom) - s.Require().True(i >= 0) - - amountToSwap := hundredUSDT.Amount.Sub(fee) - amountToReserves := assetSettings.ReservePortion.MulInt(amountToSwap).TruncateInt() - amountToLeverage := amountToSwap.Sub(amountToReserves) - - usdtPrice, err := prices[0].PriceByBaseDenom(mocks.USDTBaseDenom) + err = grpc.LeverageSpecialPairsUpdate(s.Umee, sets, []leveragetypes.SpecialAssetPair{}) s.Require().NoError(err) - returned := usdtPrice.SwapRate.MulInt(amountToSwap).TruncateInt() - - s.executeSwap(valAddr, hundredUSDT, mocks.MeUSDDenom) - - expectedBalance.MetokenSupply.Amount = expectedBalance.MetokenSupply.Amount.Add(returned) - usdtBalance, i := expectedBalance.AssetBalance(mocks.USDTBaseDenom) - s.Require().True(i >= 0) - usdtBalance.Fees = usdtBalance.Fees.Add(fee) - usdtBalance.Reserved = usdtBalance.Reserved.Add(amountToReserves) - usdtBalance.Leveraged = usdtBalance.Leveraged.Add(amountToLeverage) - expectedBalance.SetAssetBalance(usdtBalance) - - prices = s.checkMetokenBalance(mocks.MeUSDDenom, expectedBalance) - }, - ) - - s.Run( - "redeem_200meUSD_failure", func() { - twoHundredsMeUSD := sdk.NewCoin(mocks.MeUSDDenom, sdkmath.NewInt(200_000000)) - - s.executeRedeemWithFailure( - valAddr, - twoHundredsMeUSD, - mocks.USDTBaseDenom, - "not enough", - ) - - prices = s.checkMetokenBalance(mocks.MeUSDDenom, expectedBalance) }, ) } -*/ diff --git a/tests/grpc/gov.go b/tests/grpc/gov.go index 1d22da198b..a613b6a1e0 100644 --- a/tests/grpc/gov.go +++ b/tests/grpc/gov.go @@ -97,6 +97,27 @@ func LeverageRegistryUpdate(umeeClient client.Client, addTokens, updateTokens [] return MakeVoteAndCheckProposal(umeeClient, *resp) } +// LeverageSpecialPairsUpdate submits a gov transaction to update leverage registry, votes, and waits for proposal to pass. +func LeverageSpecialPairsUpdate(umeeClient client.Client, sets []ltypes.SpecialAssetSet, pairs []ltypes.SpecialAssetPair) error { + msg := ltypes.MsgGovUpdateSpecialAssets{ + Authority: checkers.GovModuleAddr, + Description: "", + Sets: sets, + Pairs: pairs, + } + + resp, err := umeeClient.Tx.TxSubmitProposalWithMsg([]sdk.Msg{&msg}) + if err != nil { + return err + } + + if len(resp.Logs) == 0 { + return fmt.Errorf("no logs in response") + } + + return MakeVoteAndCheckProposal(umeeClient, *resp) +} + func MakeVoteAndCheckProposal(umeeClient client.Client, resp sdk.TxResponse) error { var proposalID string for _, event := range resp.Logs[0].Events { From 39611ce6a3b875a583ebff243a484ea5709b0e12 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:56:36 -0600 Subject: [PATCH 11/36] initial leverage supply --- tests/e2e/e2e_leverage_test.go | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index d97fcc63a4..9101b3d073 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -3,16 +3,19 @@ package e2e import ( sdk "github.com/cosmos/cosmos-sdk/types" + appparams "github.com/umee-network/umee/v6/app/params" "github.com/umee-network/umee/v6/tests/grpc" "github.com/umee-network/umee/v6/x/leverage/fixtures" leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) -func (s *E2ETest) supply(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) supply(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgSupply(addr, asset)) } -func (s *E2ETest) withdraw(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) withdraw(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgWithdraw(addr, asset)) } @@ -20,19 +23,23 @@ func (s *E2ETest) maxWithdraw(addr sdk.AccAddress, denom string) { s.mustSucceedTx(leveragetypes.NewMsgMaxWithdraw(addr, denom)) } -func (s *E2ETest) collateralize(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) collateralize(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgCollateralize(addr, asset)) } -func (s *E2ETest) decollateralize(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) decollateralize(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgDecollateralize(addr, asset)) } -func (s *E2ETest) supplyCollateral(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) supplyCollateral(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgSupplyCollateral(addr, asset)) } -func (s *E2ETest) borrow(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) borrow(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgBorrow(addr, asset)) } @@ -40,11 +47,13 @@ func (s *E2ETest) maxBorrow(addr sdk.AccAddress, denom string) { s.mustSucceedTx(leveragetypes.NewMsgMaxBorrow(addr, denom)) } -func (s *E2ETest) repay(addr sdk.AccAddress, asset sdk.Coin) { +func (s *E2ETest) repay(addr sdk.AccAddress, denom string, amount uint64) { + asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgRepay(addr, asset)) } -func (s *E2ETest) liquidate(addr, target sdk.AccAddress, reward string, repay sdk.Coin) { +func (s *E2ETest) liquidate(addr, target sdk.AccAddress, repayDenom string, repayAmount uint64, reward string) { + repay := sdk.NewCoin(repayDenom, sdk.NewIntFromUint64(repayAmount)) s.mustSucceedTx(leveragetypes.NewMsgLiquidate(addr, target, repay, reward)) } @@ -76,4 +85,17 @@ func (s *E2ETest) TestLeverageScenario() { s.Require().NoError(err) }, ) + + val0, err := s.Chain.Validators[0].KeyInfo.GetAddress() + s.Require().NoError(err) + + s.Run( + "initial leverage supply", func() { + // Supply 1 WBTC, 1 ETH, 1 USDC, 1 UMEE + s.supply(val0, appparams.BondDenom, 1000000) + s.supply(val0, "test1", 100000000) + s.supply(val0, "test2", 1000000000000000000) + s.supply(val0, "test3", 1000000) + }, + ) } From b2352f49eef79a534cce2ea55861c206acdf3c30 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 08:58:12 -0600 Subject: [PATCH 12/36] lint --- tests/grpc/gov.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/grpc/gov.go b/tests/grpc/gov.go index a613b6a1e0..4fd391fcb6 100644 --- a/tests/grpc/gov.go +++ b/tests/grpc/gov.go @@ -97,8 +97,13 @@ func LeverageRegistryUpdate(umeeClient client.Client, addTokens, updateTokens [] return MakeVoteAndCheckProposal(umeeClient, *resp) } -// LeverageSpecialPairsUpdate submits a gov transaction to update leverage registry, votes, and waits for proposal to pass. -func LeverageSpecialPairsUpdate(umeeClient client.Client, sets []ltypes.SpecialAssetSet, pairs []ltypes.SpecialAssetPair) error { +// LeverageSpecialPairsUpdate submits a gov transaction to update leverage registry, +// votes, and waits for proposal to pass. +func LeverageSpecialPairsUpdate( + umeeClient client.Client, + sets []ltypes.SpecialAssetSet, + pairs []ltypes.SpecialAssetPair, +) error { msg := ltypes.MsgGovUpdateSpecialAssets{ Authority: checkers.GovModuleAddr, Description: "", From ce53a5b1d9d52780c9eb3c71b4f01e763a3b207b Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 09:40:25 -0600 Subject: [PATCH 13/36] fix --- tests/e2e/setup/keys.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index 82cfb46009..3da8a58798 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -17,15 +17,16 @@ const ( PhotonDenom = "photon" InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom + - ",100000000000" + "test1" + - ",100000000000" + "test2" + - ",100000000000" + "test3" + - ",100000000000" + "test4" + - ",100000000000" + "test5" + - ",100000000000" + "test6" + - ",100000000000" + "test7" + - ",100000000000" + "test8" + - ",100000000000" + "test9" + // 10^20 of each test token (accomodates exponent 18 tokens) + ",100000000000000000000" + "test1" + + ",100000000000000000000" + "test2" + + ",100000000000000000000" + "test3" + + ",100000000000000000000" + "test4" + + ",100000000000000000000" + "test5" + + ",100000000000000000000" + "test6" + + ",100000000000000000000" + "test7" + + ",100000000000000000000" + "test8" + + ",100000000000000000000" + "test9" GaiaChainID = "test-gaia-chain" PriceFeederContainerRepo = "ghcr.io/umee-network/price-feeder-umee" From 9ee46425f5ab45f3aa1318e8607519d320bc6f33 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:44:24 -0600 Subject: [PATCH 14/36] fix exceed max supply --- tests/e2e/e2e_leverage_test.go | 10 +++++----- tests/e2e/setup/keys.go | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 9101b3d073..9d9080107c 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -91,11 +91,11 @@ func (s *E2ETest) TestLeverageScenario() { s.Run( "initial leverage supply", func() { - // Supply 1 WBTC, 1 ETH, 1 USDC, 1 UMEE - s.supply(val0, appparams.BondDenom, 1000000) - s.supply(val0, "test1", 100000000) - s.supply(val0, "test2", 1000000000000000000) - s.supply(val0, "test3", 1000000) + // Supply 100 UMEE, 1 WBTC, 10^-10 ETH, 100 USDC using 10^8 base denom each + s.supply(val0, appparams.BondDenom, 100_000_000) + s.supply(val0, "test1", 100_000_000) + s.supply(val0, "test2", 100_000_000) + s.supply(val0, "test3", 100_000_000) }, ) } diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index 3da8a58798..267fa24407 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -17,16 +17,16 @@ const ( PhotonDenom = "photon" InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom + - // 10^20 of each test token (accomodates exponent 18 tokens) - ",100000000000000000000" + "test1" + - ",100000000000000000000" + "test2" + - ",100000000000000000000" + "test3" + - ",100000000000000000000" + "test4" + - ",100000000000000000000" + "test5" + - ",100000000000000000000" + "test6" + - ",100000000000000000000" + "test7" + - ",100000000000000000000" + "test8" + - ",100000000000000000000" + "test9" + // 10^10 of each token per account will not easily exceed the leverage fixtures maxSupply of 10^11 + ",10000000000" + "test1" + + ",10000000000" + "test2" + + ",10000000000" + "test3" + + ",10000000000" + "test4" + + ",10000000000" + "test5" + + ",10000000000" + "test6" + + ",10000000000" + "test7" + + ",10000000000" + "test8" + + ",10000000000" + "test9" GaiaChainID = "test-gaia-chain" PriceFeederContainerRepo = "ghcr.io/umee-network/price-feeder-umee" From 105d24087893910989ea06c52841301df56b5982 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:53:31 -0600 Subject: [PATCH 15/36] ++ --- tests/e2e/e2e_leverage_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 9d9080107c..9a86f5a401 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -98,4 +98,8 @@ func (s *E2ETest) TestLeverageScenario() { s.supply(val0, "test3", 100_000_000) }, ) + + // TODO: one of each transaction, optionally with some failing ones, and including + // liquidation by lowering the threshold on some existing tokens, assuming prices are up. + // Might also reduce sequence errors by using non-validator accounts. } From c0a00f94347442d619b86b167c4b8477daf02d07 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:58:18 -0600 Subject: [PATCH 16/36] fix --- tests/e2e/setup/keys.go | 1 - tests/e2e/setup/metoken.go | 4 ++-- tests/e2e/setup/utils.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index 0323bbd2ce..267fa24407 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" appparams "github.com/umee-network/umee/v6/app/params" - "github.com/umee-network/umee/v6/x/metoken/mocks" ) const ( diff --git a/tests/e2e/setup/metoken.go b/tests/e2e/setup/metoken.go index 4f5baed802..97027f0779 100644 --- a/tests/e2e/setup/metoken.go +++ b/tests/e2e/setup/metoken.go @@ -29,7 +29,7 @@ func (s *E2ETestSuite) TxMetokenSwap(umeeAddr string, asset sdk.Coin, meTokenDen MetokenDenom: meTokenDenom, } - return s.broadcastTxWithRetry(req) + return s.BroadcastTxWithRetry(req) } func (s *E2ETestSuite) TxMetokenRedeem(umeeAddr string, meToken sdk.Coin, assetDenom string) error { @@ -39,5 +39,5 @@ func (s *E2ETestSuite) TxMetokenRedeem(umeeAddr string, meToken sdk.Coin, assetD AssetDenom: assetDenom, } - return s.broadcastTxWithRetry(req) + return s.BroadcastTxWithRetry(req) } diff --git a/tests/e2e/setup/utils.go b/tests/e2e/setup/utils.go index b7a31568c7..e643ebf65e 100644 --- a/tests/e2e/setup/utils.go +++ b/tests/e2e/setup/utils.go @@ -231,7 +231,7 @@ func (s *E2ETestSuite) QueryUmeeBalance( return umeeBalance, umeeAddr } -func (s *E2ETestSuite) broadcastTxWithRetry(msg sdk.Msg) error { +func (s *E2ETestSuite) BroadcastTxWithRetry(msg sdk.Msg) error { var err error for retry := 0; retry < 3; retry++ { // retry if txs fails, because sometimes account sequence mismatch occurs due to txs pending From ff219239626eac1253be5d4ff0037bafe02fb9fd Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 20:01:58 -0600 Subject: [PATCH 17/36] account tools --- tests/e2e/e2e_leverage_test.go | 11 +++---- tests/e2e/setup/account.go | 58 ++++++++++++++++++++++++++++++++++ tests/e2e/setup/chain.go | 11 +++++++ tests/e2e/setup/setup.go | 22 +++++++++++++ 4 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 tests/e2e/setup/account.go diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 9a86f5a401..902af21a92 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -86,20 +86,19 @@ func (s *E2ETest) TestLeverageScenario() { }, ) - val0, err := s.Chain.Validators[0].KeyInfo.GetAddress() + acc1, err := s.Chain.Accounts[0].KeyInfo.GetAddress() s.Require().NoError(err) s.Run( "initial leverage supply", func() { // Supply 100 UMEE, 1 WBTC, 10^-10 ETH, 100 USDC using 10^8 base denom each - s.supply(val0, appparams.BondDenom, 100_000_000) - s.supply(val0, "test1", 100_000_000) - s.supply(val0, "test2", 100_000_000) - s.supply(val0, "test3", 100_000_000) + s.supply(acc1, appparams.BondDenom, 100_000_000) + s.supply(acc1, "test1", 100_000_000) + s.supply(acc1, "test2", 100_000_000) + s.supply(acc1, "test3", 100_000_000) }, ) // TODO: one of each transaction, optionally with some failing ones, and including // liquidation by lowering the threshold on some existing tokens, assuming prices are up. - // Might also reduce sequence errors by using non-validator accounts. } diff --git a/tests/e2e/setup/account.go b/tests/e2e/setup/account.go new file mode 100644 index 0000000000..a3f8f5d6b4 --- /dev/null +++ b/tests/e2e/setup/account.go @@ -0,0 +1,58 @@ +package setup + +import ( + "github.com/cosmos/cosmos-sdk/codec" + sdkcrypto "github.com/cosmos/cosmos-sdk/crypto" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type account struct { + chain *chain + name string + // fields below set during createKey + rootDir string + mnemonic string + KeyInfo keyring.Record + privateKey cryptotypes.PrivKey +} + +func (a *account) createKey(cdc codec.Codec, rootDir string) error { + mnemonic, err := createMnemonic() + if err != nil { + return err + } + + kb, err := keyring.New(keyringAppName, keyring.BackendTest, a.rootDir, nil, cdc) + if err != nil { + return err + } + + keyringAlgos, _ := kb.SupportedAlgorithms() + algo, err := keyring.NewSigningAlgoFromString(string(hd.Secp256k1Type), keyringAlgos) + if err != nil { + return err + } + + info, err := kb.NewAccount(a.name, mnemonic, "", sdk.FullFundraiserPath, algo) + if err != nil { + return err + } + + privKeyArmor, err := kb.ExportPrivKeyArmor(a.name, keyringPassphrase) + if err != nil { + return err + } + + privKey, _, err := sdkcrypto.UnarmorDecryptPrivKey(privKeyArmor, keyringPassphrase) + if err != nil { + return err + } + + a.KeyInfo = *info + a.mnemonic = mnemonic + a.privateKey = privKey + return nil +} diff --git a/tests/e2e/setup/chain.go b/tests/e2e/setup/chain.go index 61711f3ee8..c19675c716 100644 --- a/tests/e2e/setup/chain.go +++ b/tests/e2e/setup/chain.go @@ -41,6 +41,7 @@ type chain struct { dataDir string ID string Validators []*validator + Accounts []*account GaiaValidators []*gaiaValidator } @@ -112,6 +113,16 @@ func (c *chain) createValidator(index int) *validator { } } +// createAccount creates a non-validator account for a chain. +// Accounts require account.CreateKey before use, and a token balance +// at genesis or later if performing transactions. +func (c *chain) createAccount(index int) *account { + return &account{ + chain: c, + name: fmt.Sprint("account", index), + } +} + func (c *chain) createGaiaValidator(index int) *gaiaValidator { return &gaiaValidator{ index: index, diff --git a/tests/e2e/setup/setup.go b/tests/e2e/setup/setup.go index 0a3525dbf3..3277275de3 100644 --- a/tests/e2e/setup/setup.go +++ b/tests/e2e/setup/setup.go @@ -41,6 +41,9 @@ import ( "github.com/umee-network/umee/v6/x/uibc" ) +// the number of non-validator umee accounts to initialize during setup +const numGenesisAccounts = 10 + type E2ETestSuite struct { suite.Suite @@ -135,6 +138,22 @@ func (s *E2ETestSuite) initNodes() { ) } + // create non-validator accounts which can be used for testing. + // since they don't vote for price feeder, these accounts are + // much less vulnerable to "incorrect account sequence" problems. + // Stores their keys in the same keyring as val[0] + for i := 1; i <= numGenesisAccounts; i++ { + acc := s.Chain.createAccount(i) + s.Require().NoError( + acc.createKey(s.cdc, val0ConfigDir), + ) + accAddr, err := acc.KeyInfo.GetAddress() + s.Require().NoError(err) + s.Require().NoError( + addGenesisAccount(s.cdc, val0ConfigDir, "", InitBalanceStr, accAddr), + ) + } + // copy the genesis file to the remaining validators for _, val := range s.Chain.Validators[1:] { _, err := copyFile( @@ -669,6 +688,9 @@ func (s *E2ETestSuite) initUmeeClient() { for index, v := range s.Chain.Validators { mnemonics[fmt.Sprintf("val%d", index)] = v.mnemonic } + for _, a := range s.Chain.Accounts { + mnemonics[a.name] = a.mnemonic + } ecfg := app.MakeEncodingConfig() s.Umee, err = client.NewClient( s.Chain.dataDir, From 0593f530a159cb160fdad197d2f5505e2e501ae5 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:16:52 -0600 Subject: [PATCH 18/36] ++ --- tests/e2e/e2e_leverage_test.go | 55 +++++++++++++--------------------- tests/e2e/setup/setup.go | 4 ++- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 902af21a92..444892fa04 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -4,8 +4,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" appparams "github.com/umee-network/umee/v6/app/params" - "github.com/umee-network/umee/v6/tests/grpc" - "github.com/umee-network/umee/v6/x/leverage/fixtures" leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) @@ -61,44 +59,33 @@ func (s *E2ETest) leveragedLiquidate(addr, target sdk.AccAddress, repay, reward s.mustSucceedTx(leveragetypes.NewMsgLeveragedLiquidate(addr, target, repay, reward)) } -func (s *E2ETest) TestLeverageScenario() { - s.Run( - "register leverage tokens", func() { - tokens := []leveragetypes.Token{ - fixtures.Token("test1", "WBTC", 8), - fixtures.Token("test2", "WETH", 18), - fixtures.Token("test3", "USDT", 6), - } - - err := grpc.LeverageRegistryUpdate(s.Umee, tokens, nil) - s.Require().NoError(err) - - sets := []leveragetypes.SpecialAssetSet{ - { - Assets: []string{"test1", "test2"}, - CollateralWeight: sdk.MustNewDecFromStr("0.4"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.5"), - }, - } - - err = grpc.LeverageSpecialPairsUpdate(s.Umee, sets, []leveragetypes.SpecialAssetPair{}) - s.Require().NoError(err) - }, - ) - +func (s *E2ETest) TestLeverageBasics() { acc1, err := s.Chain.Accounts[0].KeyInfo.GetAddress() s.Require().NoError(err) s.Run( "initial leverage supply", func() { - // Supply 100 UMEE, 1 WBTC, 10^-10 ETH, 100 USDC using 10^8 base denom each s.supply(acc1, appparams.BondDenom, 100_000_000) - s.supply(acc1, "test1", 100_000_000) - s.supply(acc1, "test2", 100_000_000) - s.supply(acc1, "test3", 100_000_000) }, ) - - // TODO: one of each transaction, optionally with some failing ones, and including - // liquidation by lowering the threshold on some existing tokens, assuming prices are up. + s.Run( + "initial leverage withdraw", func() { + s.supply(acc1, "u/"+appparams.BondDenom, 10_000_000) + }, + ) + s.Run( + "initial leverage collateralize", func() { + s.collateralize(acc1, "u/"+appparams.BondDenom, 70_000_000) + }, + ) + s.Run( + "initial leverage borrow", func() { + s.borrow(acc1, appparams.BondDenom, 10_000_000) + }, + ) + s.Run( + "initial leverage repay", func() { + s.repay(acc1, appparams.BondDenom, 5_000_000) + }, + ) } diff --git a/tests/e2e/setup/setup.go b/tests/e2e/setup/setup.go index 3277275de3..12c6f3192f 100644 --- a/tests/e2e/setup/setup.go +++ b/tests/e2e/setup/setup.go @@ -130,6 +130,7 @@ func (s *E2ETestSuite) initNodes() { // initialize a genesis file for the first validator val0ConfigDir := s.Chain.Validators[0].configDir() + val0Moniker := s.Chain.Validators[0].moniker for _, val := range s.Chain.Validators { valAddr, err := val.KeyInfo.GetAddress() s.Require().NoError(err) @@ -150,8 +151,9 @@ func (s *E2ETestSuite) initNodes() { accAddr, err := acc.KeyInfo.GetAddress() s.Require().NoError(err) s.Require().NoError( - addGenesisAccount(s.cdc, val0ConfigDir, "", InitBalanceStr, accAddr), + addGenesisAccount(s.cdc, val0ConfigDir, val0Moniker, InitBalanceStr, accAddr), ) + s.Chain.Accounts = append(s.Chain.Accounts, acc) } // copy the genesis file to the remaining validators From 706ac62ef76b95272f263fc22a71467c7c1fe488 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:23:29 -0600 Subject: [PATCH 19/36] revert accunt tools --- tests/e2e/e2e_leverage_test.go | 12 +++---- tests/e2e/setup/account.go | 58 ---------------------------------- tests/e2e/setup/chain.go | 11 ------- tests/e2e/setup/setup.go | 18 +---------- 4 files changed, 7 insertions(+), 92 deletions(-) delete mode 100644 tests/e2e/setup/account.go diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 444892fa04..05c4538142 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -60,32 +60,32 @@ func (s *E2ETest) leveragedLiquidate(addr, target sdk.AccAddress, repay, reward } func (s *E2ETest) TestLeverageBasics() { - acc1, err := s.Chain.Accounts[0].KeyInfo.GetAddress() + valAddr, err := s.Chain.Validators[0].KeyInfo.GetAddress() s.Require().NoError(err) s.Run( "initial leverage supply", func() { - s.supply(acc1, appparams.BondDenom, 100_000_000) + s.supply(valAddr, appparams.BondDenom, 100_000_000) }, ) s.Run( "initial leverage withdraw", func() { - s.supply(acc1, "u/"+appparams.BondDenom, 10_000_000) + s.supply(valAddr, "u/"+appparams.BondDenom, 10_000_000) }, ) s.Run( "initial leverage collateralize", func() { - s.collateralize(acc1, "u/"+appparams.BondDenom, 70_000_000) + s.collateralize(valAddr, "u/"+appparams.BondDenom, 70_000_000) }, ) s.Run( "initial leverage borrow", func() { - s.borrow(acc1, appparams.BondDenom, 10_000_000) + s.borrow(valAddr, appparams.BondDenom, 10_000_000) }, ) s.Run( "initial leverage repay", func() { - s.repay(acc1, appparams.BondDenom, 5_000_000) + s.repay(valAddr, appparams.BondDenom, 5_000_000) }, ) } diff --git a/tests/e2e/setup/account.go b/tests/e2e/setup/account.go deleted file mode 100644 index a3f8f5d6b4..0000000000 --- a/tests/e2e/setup/account.go +++ /dev/null @@ -1,58 +0,0 @@ -package setup - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdkcrypto "github.com/cosmos/cosmos-sdk/crypto" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type account struct { - chain *chain - name string - // fields below set during createKey - rootDir string - mnemonic string - KeyInfo keyring.Record - privateKey cryptotypes.PrivKey -} - -func (a *account) createKey(cdc codec.Codec, rootDir string) error { - mnemonic, err := createMnemonic() - if err != nil { - return err - } - - kb, err := keyring.New(keyringAppName, keyring.BackendTest, a.rootDir, nil, cdc) - if err != nil { - return err - } - - keyringAlgos, _ := kb.SupportedAlgorithms() - algo, err := keyring.NewSigningAlgoFromString(string(hd.Secp256k1Type), keyringAlgos) - if err != nil { - return err - } - - info, err := kb.NewAccount(a.name, mnemonic, "", sdk.FullFundraiserPath, algo) - if err != nil { - return err - } - - privKeyArmor, err := kb.ExportPrivKeyArmor(a.name, keyringPassphrase) - if err != nil { - return err - } - - privKey, _, err := sdkcrypto.UnarmorDecryptPrivKey(privKeyArmor, keyringPassphrase) - if err != nil { - return err - } - - a.KeyInfo = *info - a.mnemonic = mnemonic - a.privateKey = privKey - return nil -} diff --git a/tests/e2e/setup/chain.go b/tests/e2e/setup/chain.go index c19675c716..61711f3ee8 100644 --- a/tests/e2e/setup/chain.go +++ b/tests/e2e/setup/chain.go @@ -41,7 +41,6 @@ type chain struct { dataDir string ID string Validators []*validator - Accounts []*account GaiaValidators []*gaiaValidator } @@ -113,16 +112,6 @@ func (c *chain) createValidator(index int) *validator { } } -// createAccount creates a non-validator account for a chain. -// Accounts require account.CreateKey before use, and a token balance -// at genesis or later if performing transactions. -func (c *chain) createAccount(index int) *account { - return &account{ - chain: c, - name: fmt.Sprint("account", index), - } -} - func (c *chain) createGaiaValidator(index int) *gaiaValidator { return &gaiaValidator{ index: index, diff --git a/tests/e2e/setup/setup.go b/tests/e2e/setup/setup.go index 12c6f3192f..c00e46db39 100644 --- a/tests/e2e/setup/setup.go +++ b/tests/e2e/setup/setup.go @@ -130,7 +130,6 @@ func (s *E2ETestSuite) initNodes() { // initialize a genesis file for the first validator val0ConfigDir := s.Chain.Validators[0].configDir() - val0Moniker := s.Chain.Validators[0].moniker for _, val := range s.Chain.Validators { valAddr, err := val.KeyInfo.GetAddress() s.Require().NoError(err) @@ -139,22 +138,10 @@ func (s *E2ETestSuite) initNodes() { ) } + // TODO: // create non-validator accounts which can be used for testing. // since they don't vote for price feeder, these accounts are // much less vulnerable to "incorrect account sequence" problems. - // Stores their keys in the same keyring as val[0] - for i := 1; i <= numGenesisAccounts; i++ { - acc := s.Chain.createAccount(i) - s.Require().NoError( - acc.createKey(s.cdc, val0ConfigDir), - ) - accAddr, err := acc.KeyInfo.GetAddress() - s.Require().NoError(err) - s.Require().NoError( - addGenesisAccount(s.cdc, val0ConfigDir, val0Moniker, InitBalanceStr, accAddr), - ) - s.Chain.Accounts = append(s.Chain.Accounts, acc) - } // copy the genesis file to the remaining validators for _, val := range s.Chain.Validators[1:] { @@ -690,9 +677,6 @@ func (s *E2ETestSuite) initUmeeClient() { for index, v := range s.Chain.Validators { mnemonics[fmt.Sprintf("val%d", index)] = v.mnemonic } - for _, a := range s.Chain.Accounts { - mnemonics[a.name] = a.mnemonic - } ecfg := app.MakeEncodingConfig() s.Umee, err = client.NewClient( s.Chain.dataDir, From 9a52706dd953ec02887e81c4e96981d843c2aa31 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:24:51 -0600 Subject: [PATCH 20/36] revert extra balances --- tests/e2e/setup/keys.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index 267fa24407..eacc3f22fb 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -15,19 +15,8 @@ const ( ATOMExponent = 6 PhotonDenom = "photon" - InitBalanceStr = "510000000000" + appparams.BondDenom + - ",100000000000" + PhotonDenom + - // 10^10 of each token per account will not easily exceed the leverage fixtures maxSupply of 10^11 - ",10000000000" + "test1" + - ",10000000000" + "test2" + - ",10000000000" + "test3" + - ",10000000000" + "test4" + - ",10000000000" + "test5" + - ",10000000000" + "test6" + - ",10000000000" + "test7" + - ",10000000000" + "test8" + - ",10000000000" + "test9" - GaiaChainID = "test-gaia-chain" + InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom + GaiaChainID = "test-gaia-chain" PriceFeederContainerRepo = "ghcr.io/umee-network/price-feeder-umee" PriceFeederServerPort = "7171/tcp" From 8b5f4516937e7649ee23b60b4215bc573b2a8763 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:26:01 -0600 Subject: [PATCH 21/36] -- --- tests/e2e/setup/keys.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/e2e/setup/keys.go b/tests/e2e/setup/keys.go index eacc3f22fb..62a080fe48 100644 --- a/tests/e2e/setup/keys.go +++ b/tests/e2e/setup/keys.go @@ -6,7 +6,9 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" + appparams "github.com/umee-network/umee/v6/app/params" + "github.com/umee-network/umee/v6/x/metoken/mocks" ) const ( @@ -15,7 +17,7 @@ const ( ATOMExponent = 6 PhotonDenom = "photon" - InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom + InitBalanceStr = "510000000000" + appparams.BondDenom + ",100000000000" + PhotonDenom + ",100000000000" + mocks.USDTBaseDenom GaiaChainID = "test-gaia-chain" PriceFeederContainerRepo = "ghcr.io/umee-network/price-feeder-umee" From a1bc63d5718de7ca5b3a9903771d617aae25bb39 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:26:35 -0600 Subject: [PATCH 22/36] -- --- tests/e2e/setup/setup.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/e2e/setup/setup.go b/tests/e2e/setup/setup.go index c00e46db39..b8246ac49a 100644 --- a/tests/e2e/setup/setup.go +++ b/tests/e2e/setup/setup.go @@ -41,9 +41,6 @@ import ( "github.com/umee-network/umee/v6/x/uibc" ) -// the number of non-validator umee accounts to initialize during setup -const numGenesisAccounts = 10 - type E2ETestSuite struct { suite.Suite From a2b403fec41a01328370ae336be8669a1c8b2319 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:27:24 -0600 Subject: [PATCH 23/36] -- --- tests/grpc/gov.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/grpc/gov.go b/tests/grpc/gov.go index 29f8cf1ea0..e8475a07d2 100644 --- a/tests/grpc/gov.go +++ b/tests/grpc/gov.go @@ -98,7 +98,7 @@ func LeverageRegistryUpdate(umeeClient client.Client, addTokens, updateTokens [] return MakeVoteAndCheckProposal(umeeClient, *resp) } -// LeverageSpecialPairsUpdate submits a gov transaction to update leverage registry, +// LeverageSpecialPairsUpdate submits a gov transaction to update leverage special assets, // votes, and waits for proposal to pass. func LeverageSpecialPairsUpdate( umeeClient client.Client, From d966fa7fb47f660da80d2b4cc1aa2d22588f868b Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 05:41:58 -0600 Subject: [PATCH 24/36] fix --- tests/e2e/e2e_leverage_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 05c4538142..1ef5578856 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -70,7 +70,7 @@ func (s *E2ETest) TestLeverageBasics() { ) s.Run( "initial leverage withdraw", func() { - s.supply(valAddr, "u/"+appparams.BondDenom, 10_000_000) + s.withdraw(valAddr, "u/"+appparams.BondDenom, 10_000_000) }, ) s.Run( From 14ab0d60db620a7abb46ee6dbe77e2908ca88a97 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 06:21:49 -0600 Subject: [PATCH 25/36] do not require historic medians for leverage e2e --- tests/e2e/e2e_leverage_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 1ef5578856..cb056f6be0 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -4,6 +4,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" appparams "github.com/umee-network/umee/v6/app/params" + "github.com/umee-network/umee/v6/tests/grpc" + "github.com/umee-network/umee/v6/x/leverage/fixtures" leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) @@ -60,6 +62,20 @@ func (s *E2ETest) leveragedLiquidate(addr, target sdk.AccAddress, repay, reward } func (s *E2ETest) TestLeverageBasics() { + umeeNoMedians := fixtures.Token(appparams.BondDenom, "UMEE", 6) + umeeNoMedians.HistoricMedians = 0 + updateTokens := []leveragetypes.Token{ + umeeNoMedians, + } + + s.Run( + "leverage gov update", func() { + s.Require().NoError( + grpc.LeverageRegistryUpdate(s.Umee, []leveragetypes.Token{}, updateTokens), + ) + }, + ) + valAddr, err := s.Chain.Validators[0].KeyInfo.GetAddress() s.Require().NoError(err) From 931343ed0ecceb7c567636f75f879e8468a9f662 Mon Sep 17 00:00:00 2001 From: Adam Moser <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 07:09:43 -0600 Subject: [PATCH 26/36] suggestion++ Co-authored-by: kosegor <30661385+kosegor@users.noreply.github.com> --- tests/e2e/e2e_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 98b0e9bacd..bb0df14718 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -20,7 +20,7 @@ func TestE2ETestSuite(t *testing.T) { suite.Run(t, new(E2ETest)) } -// mustEventuallySucceedTx executes an sdk.Msg (retrying several times if receiving any error, +// mustEventuallySucceedTx executes an sdk.Msg, retrying several times if receiving any error, // and requires that the transaction eventually succeeded with nil error. Since this function // retries for 30 seconds and ignores errors, it is suitable for scenario setup transaction or // those which might require time elapsing before they succeed. From 69a853c2b91b9276f31e28b738026783c9450a0f Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 07:54:03 -0600 Subject: [PATCH 27/36] add special pairs to e2e --- tests/e2e/e2e_leverage_test.go | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index cb056f6be0..c9d4a7b0f3 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -69,7 +69,7 @@ func (s *E2ETest) TestLeverageBasics() { } s.Run( - "leverage gov update", func() { + "leverage update registry", func() { s.Require().NoError( grpc.LeverageRegistryUpdate(s.Umee, []leveragetypes.Token{}, updateTokens), ) @@ -104,4 +104,37 @@ func (s *E2ETest) TestLeverageBasics() { s.repay(valAddr, appparams.BondDenom, 5_000_000) }, ) + s.Run( + "too high leverage borrow", func() { + asset := sdk.NewCoin( + appparams.BondDenom, + sdk.NewIntFromUint64(30_000_000), + ) + s.mustFailTx(leveragetypes.NewMsgBorrow(valAddr, asset), "undercollateralized") + }, + ) + s.Run( + "leverage add special pairs", func() { + sets := []leveragetypes.SpecialAssetSet{ + { + // a set allowing UMEE to borrow more of itself + Assets: []string{appparams.BondDenom}, + CollateralWeight: sdk.MustNewDecFromStr("0.8"), + LiquidationThreshold: sdk.MustNewDecFromStr("0.9"), + }, + } + s.Require().NoError( + grpc.LeverageSpecialPairsUpdate(s.Umee, sets, []leveragetypes.SpecialAssetPair{}), + ) + }, + ) + s.Run( + "special pair leverage borrow", func() { + asset := sdk.NewCoin( + appparams.BondDenom, + sdk.NewIntFromUint64(30_000_000), + ) + s.mustSucceedTx(leveragetypes.NewMsgBorrow(valAddr, asset)) + }, + ) } From 99a478c6ff4f0984d50be80b3eee20c034c368c7 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 08:19:45 -0600 Subject: [PATCH 28/36] fix spelling of undercollateralized --- x/leverage/keeper/borrows.go | 2 +- x/leverage/keeper/msg_server_test.go | 24 ++++++++++++------------ x/leverage/keeper/outage_test.go | 4 ++-- x/leverage/types/errors.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/x/leverage/keeper/borrows.go b/x/leverage/keeper/borrows.go index 623e5898cb..bd37e01084 100644 --- a/x/leverage/keeper/borrows.go +++ b/x/leverage/keeper/borrows.go @@ -25,7 +25,7 @@ func (k Keeper) assertBorrowerHealth(ctx sdk.Context, borrowerAddr sdk.AccAddres borrowedValue := position.BorrowedValue() borrowLimit := position.Limit() if borrowedValue.GT(borrowLimit.Mul(maxUsage)) { - return types.ErrUndercollaterized.Wrapf( + return types.ErrUndercollateralized.Wrapf( "borrowed: %s, limit: %s, max usage %s", borrowedValue, borrowLimit, maxUsage, ) } diff --git a/x/leverage/keeper/msg_server_test.go b/x/leverage/keeper/msg_server_test.go index 21aed69c4a..1f3c98ffba 100644 --- a/x/leverage/keeper/msg_server_test.go +++ b/x/leverage/keeper/msg_server_test.go @@ -432,7 +432,7 @@ func (s *IntegrationTestSuite) TestMsgWithdraw() { nil, nil, sdk.Coin{}, - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "acceptable withdrawal (dump borrower)", dumpborrower, @@ -448,7 +448,7 @@ func (s *IntegrationTestSuite) TestMsgWithdraw() { nil, nil, sdk.Coin{}, - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "acceptable withdrawal (pump borrower)", pumpborrower, @@ -464,7 +464,7 @@ func (s *IntegrationTestSuite) TestMsgWithdraw() { nil, nil, sdk.Coin{}, - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "borrow limit (undercollateralized due to borrow factor but not collateral weight)", stableUmeeBorrower, @@ -472,7 +472,7 @@ func (s *IntegrationTestSuite) TestMsgWithdraw() { nil, nil, sdk.Coin{}, - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, } @@ -1074,7 +1074,7 @@ func (s *IntegrationTestSuite) TestMsgDecollateralize() { "above borrow limit", borrower, coin.New("u/"+atomDenom, 100_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { @@ -1087,7 +1087,7 @@ func (s *IntegrationTestSuite) TestMsgDecollateralize() { "above borrow limit (undercollateralized under historic prices but ok with current prices)", dumpborrower, coin.New("u/"+pumpDenom, 20_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "acceptable decollateralize (pump borrower)", @@ -1099,7 +1099,7 @@ func (s *IntegrationTestSuite) TestMsgDecollateralize() { "above borrow limit (undercollateralized under current prices but ok with historic prices)", pumpborrower, coin.New("u/"+dumpDenom, 20_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, } @@ -1350,7 +1350,7 @@ func (s *IntegrationTestSuite) TestMsgBorrow() { "stable umee borrower (borrow factor limit)", stableUmeeBorrower, coin.New(umeeDenom, 1_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "max supply utilization", borrower, @@ -1365,12 +1365,12 @@ func (s *IntegrationTestSuite) TestMsgBorrow() { "borrow limit", borrower, coin.New(atomDenom, 100_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "zero collateral", supplier, coin.New(atomDenom, 1_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "dump borrower (acceptable)", dumpborrower, @@ -1380,7 +1380,7 @@ func (s *IntegrationTestSuite) TestMsgBorrow() { "dump borrower (borrow limit)", dumpborrower, coin.New(dumpDenom, 10_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, { "pump borrower (acceptable)", pumpborrower, @@ -1390,7 +1390,7 @@ func (s *IntegrationTestSuite) TestMsgBorrow() { "pump borrower (borrow limit)", pumpborrower, coin.New(pumpDenom, 2_000000), - types.ErrUndercollaterized, + types.ErrUndercollateralized, }, } diff --git a/x/leverage/keeper/outage_test.go b/x/leverage/keeper/outage_test.go index 0f6f394c38..9a12b73ef4 100644 --- a/x/leverage/keeper/outage_test.go +++ b/x/leverage/keeper/outage_test.go @@ -178,7 +178,7 @@ func (s *IntegrationTestSuite) TestCollateralPriceOutage() { Asset: coin.New("u/"+umeeDenom, 1), } _, err = srv.Withdraw(ctx, msg4) - require.ErrorIs(err, types.ErrUndercollaterized, "withdraw collateral umee") + require.ErrorIs(err, types.ErrUndercollateralized, "withdraw collateral umee") // UMEE can still be collateralized s.supply(umeeSupplier, coin.New(umeeDenom, 50_000000)) @@ -203,7 +203,7 @@ func (s *IntegrationTestSuite) TestCollateralPriceOutage() { Asset: coin.New("u/"+umeeDenom, 1), } _, err = srv.Decollateralize(ctx, msg7) - require.ErrorIs(err, types.ErrUndercollaterized, "decollateralize collateral umee") + require.ErrorIs(err, types.ErrUndercollateralized, "decollateralize collateral umee") // UMEE cannot be borrowed since UMEE value is unknown msg8 := &types.MsgBorrow{ diff --git a/x/leverage/types/errors.go b/x/leverage/types/errors.go index 231c317670..01d2ee0595 100644 --- a/x/leverage/types/errors.go +++ b/x/leverage/types/errors.go @@ -37,7 +37,7 @@ var ( // 4XX = Price Sensitive ErrBadValue = errors.Register(ModuleName, 400, "bad USD value") ErrInvalidOraclePrice = errors.Register(ModuleName, 401, "invalid oracle price") - ErrUndercollaterized = errors.Register(ModuleName, 402, "borrow positions are undercollaterized") + ErrUndercollateralized = errors.Register(ModuleName, 402, "borrow positions are undercollateralized") ErrLiquidationIneligible = errors.Register(ModuleName, 403, "borrower not eligible for liquidation") ErrNoHistoricMedians = errors.Register(ModuleName, 405, "insufficient historic medians available") From fe219f4a257f5677613f9c6ac78cca315ada6ea0 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 08:24:32 -0600 Subject: [PATCH 29/36] fix empty description --- tests/grpc/gov.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/grpc/gov.go b/tests/grpc/gov.go index e8475a07d2..9fb353ba7b 100644 --- a/tests/grpc/gov.go +++ b/tests/grpc/gov.go @@ -107,7 +107,7 @@ func LeverageSpecialPairsUpdate( ) error { msg := ltypes.MsgGovUpdateSpecialAssets{ Authority: checkers.GovModuleAddr, - Description: "", + Description: "Special Assets Proposal", Sets: sets, Pairs: pairs, } From 77d5a04d8f38b0dd5e49f874c97a4538f81bb8c8 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 08:47:36 -0600 Subject: [PATCH 30/36] modify amounts --- tests/e2e/e2e_leverage_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index c9d4a7b0f3..b0e71cb31a 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -91,17 +91,17 @@ func (s *E2ETest) TestLeverageBasics() { ) s.Run( "initial leverage collateralize", func() { - s.collateralize(valAddr, "u/"+appparams.BondDenom, 70_000_000) + s.collateralize(valAddr, "u/"+appparams.BondDenom, 80_000_000) }, ) s.Run( "initial leverage borrow", func() { - s.borrow(valAddr, appparams.BondDenom, 10_000_000) + s.borrow(valAddr, appparams.BondDenom, 12_000_000) }, ) s.Run( "initial leverage repay", func() { - s.repay(valAddr, appparams.BondDenom, 5_000_000) + s.repay(valAddr, appparams.BondDenom, 2_000_000) }, ) s.Run( @@ -119,8 +119,8 @@ func (s *E2ETest) TestLeverageBasics() { { // a set allowing UMEE to borrow more of itself Assets: []string{appparams.BondDenom}, - CollateralWeight: sdk.MustNewDecFromStr("0.8"), - LiquidationThreshold: sdk.MustNewDecFromStr("0.9"), + CollateralWeight: sdk.MustNewDecFromStr("0.75"), + LiquidationThreshold: sdk.MustNewDecFromStr("0.8"), }, } s.Require().NoError( @@ -134,7 +134,7 @@ func (s *E2ETest) TestLeverageBasics() { appparams.BondDenom, sdk.NewIntFromUint64(30_000_000), ) - s.mustSucceedTx(leveragetypes.NewMsgBorrow(valAddr, asset)) + s.mustEventuallySucceedTx(leveragetypes.NewMsgBorrow(valAddr, asset)) }, ) } From 6560791fa99caa4609671933a191024678f3e599 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 09:57:37 -0600 Subject: [PATCH 31/36] keeper tests with special pairs - AND A FIX --- x/leverage/keeper/grpc_query_test.go | 2 +- x/leverage/keeper/msg_server_test.go | 54 +++++++++++++++++++++++++--- x/leverage/keeper/oracle_test.go | 2 ++ x/leverage/keeper/position.go | 2 +- x/leverage/keeper/suite_test.go | 17 ++++++++- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/x/leverage/keeper/grpc_query_test.go b/x/leverage/keeper/grpc_query_test.go index 7d80dade80..93098e6421 100644 --- a/x/leverage/keeper/grpc_query_test.go +++ b/x/leverage/keeper/grpc_query_test.go @@ -25,7 +25,7 @@ func (s *IntegrationTestSuite) TestQuerier_RegisteredTokens() { "valid: get the all registered tokens", "", types.QueryRegisteredTokens{}, - 6, + 7, }, { "valid: get the registered token info by base_denom", diff --git a/x/leverage/keeper/msg_server_test.go b/x/leverage/keeper/msg_server_test.go index 1f3c98ffba..1c545dce24 100644 --- a/x/leverage/keeper/msg_server_test.go +++ b/x/leverage/keeper/msg_server_test.go @@ -17,7 +17,7 @@ func (s *IntegrationTestSuite) TestAddTokensToRegistry() { govAccAddr := checkers.GovModuleAddr registeredUmee := fixtures.Token("uumee", "UMEE", 6) ntA := fixtures.Token("unta", "ABCD", 6) - // new token with existed symbol denom + // new token with existing symbol denom ntB := fixtures.Token("untb", "ABCD", 6) testCases := []struct { name string @@ -55,7 +55,7 @@ func (s *IntegrationTestSuite) TestAddTokensToRegistry() { }, }, "", - 7, + 8, }, { "regisering new token with existed symbol denom", types.MsgGovUpdateRegistry{ @@ -66,7 +66,7 @@ func (s *IntegrationTestSuite) TestAddTokensToRegistry() { }, }, "", - 8, + 9, }, } @@ -173,7 +173,7 @@ func (s *IntegrationTestSuite) TestUpdateRegistry() { s.Require().NoError(err) // no tokens should have been deleted tokens := s.app.LeverageKeeper.GetAllRegisteredTokens(s.ctx) - s.Require().Len(tokens, 6) + s.Require().Len(tokens, 7) token, err := s.app.LeverageKeeper.GetTokenSettings(s.ctx, "uumee") s.Require().NoError(err) @@ -580,6 +580,17 @@ func (s *IntegrationTestSuite) TestMsgMaxWithdraw() { s.borrow(stableUmeeBorrower, coin.New(umeeDenom, 30_000000)) // UMEE and STABLE have the same price but different collateral weights + // supply some DAI ($1 at e18) + daiSupplier := s.newAccount(coin.New(daiDenom, 1_000000_000000_000000)) + s.supply(daiSupplier, coin.New(daiDenom, 1_000000_000000_000000)) + + // create a $0.4 DAI borrower using $1.0 PAIRED collateral + specialBorrower := s.newAccount(coin.New(pairedDenom, 1_000000)) + s.supply(specialBorrower, coin.New(pairedDenom, 1_000000)) + s.collateralize(specialBorrower, coin.New("u/"+pairedDenom, 1_000000)) + s.borrow(specialBorrower, coin.New(daiDenom, 400000_000000_000000)) + // PAIRED and DAI have the same price, 0.25 collateral weight, but 0.5 special pair weight + zeroUmee := coin.Zero(umeeDenom) zeroUUmee := coin.New("u/"+umeeDenom, 0) tcs := []struct { @@ -663,6 +674,15 @@ func (s *IntegrationTestSuite) TestMsgMaxWithdraw() { coin.New(stableDenom, 40_000000), nil, }, + { + "max withdraw with special pair", + specialBorrower, + pairedDenom, + coin.New("u/"+pairedDenom, 200000), + coin.New("u/"+pairedDenom, 200000), + coin.New(pairedDenom, 200000), + nil, + }, } for _, tc := range tcs { @@ -1320,6 +1340,17 @@ func (s *IntegrationTestSuite) TestMsgBorrow() { s.borrow(stableUmeeBorrower, coin.New(umeeDenom, 3_000000)) // UMEE and STABLE have the same price but different collateral weights + // supply some DAI ($1 at e18) + daiSupplier := s.newAccount(coin.New(daiDenom, 1_000000_000000_000000)) + s.supply(daiSupplier, coin.New(daiDenom, 1_000000_000000_000000)) + + // create a $0.4 DAI borrower using $1.0 PAIRED collateral + specialBorrower := s.newAccount(coin.New(pairedDenom, 1_000000)) + s.supply(specialBorrower, coin.New(pairedDenom, 1_000000)) + s.collateralize(specialBorrower, coin.New("u/"+pairedDenom, 1_000000)) + s.borrow(specialBorrower, coin.New(daiDenom, 200000_000000_000000)) + // PAIRED and DAI have the same price, 0.25 collateral weight, but 0.5 special pair weight + tcs := []testCase{ { "uToken", @@ -1391,6 +1422,21 @@ func (s *IntegrationTestSuite) TestMsgBorrow() { pumpborrower, coin.New(pumpDenom, 2_000000), types.ErrUndercollateralized, + }, { + "special borrower (up to regular limit)", + specialBorrower, + coin.New(daiDenom, 50000_000000_000000), + nil, + }, { + "special borrower (up to special limit)", + specialBorrower, + coin.New(daiDenom, 250000_000000_000000), + nil, + }, { + "special borrower (past special limit)", + specialBorrower, + coin.New(daiDenom, 50000_000000_000000), + types.ErrUndercollateralized, }, } diff --git a/x/leverage/keeper/oracle_test.go b/x/leverage/keeper/oracle_test.go index 914033cfd8..d2e67013df 100644 --- a/x/leverage/keeper/oracle_test.go +++ b/x/leverage/keeper/oracle_test.go @@ -68,6 +68,7 @@ func (m *mockOracleKeeper) Reset() { "DUMP": sdk.MustNewDecFromStr("0.50"), // A token which has recently halved in price "PUMP": sdk.MustNewDecFromStr("2.00"), // A token which has recently doubled in price "STABLE": sdk.MustNewDecFromStr("4.21"), // Same price as umee + "PAIRED": sdk.MustNewDecFromStr("1.00"), } m.historicExchangeRates = map[string]sdk.Dec{ "UMEE": sdk.MustNewDecFromStr("4.21"), @@ -76,6 +77,7 @@ func (m *mockOracleKeeper) Reset() { "DUMP": sdk.MustNewDecFromStr("1.00"), "PUMP": sdk.MustNewDecFromStr("1.00"), "STABLE": sdk.MustNewDecFromStr("4.21"), + "PAIRED": sdk.MustNewDecFromStr("1.00"), } } diff --git a/x/leverage/keeper/position.go b/x/leverage/keeper/position.go index 62fbdaefd7..178cfd866f 100644 --- a/x/leverage/keeper/position.go +++ b/x/leverage/keeper/position.go @@ -21,7 +21,7 @@ var minimumBorrowFactor = sdk.MustNewDecFromStr("0.5") func (k Keeper) GetAccountPosition(ctx sdk.Context, addr sdk.AccAddress, isForLiquidation bool, ) (types.AccountPosition, error) { tokenSettings := k.GetAllRegisteredTokens(ctx) - specialPairs := []types.SpecialAssetPair{} + specialPairs := k.GetAllSpecialAssetPairs(ctx) collateral := k.GetBorrowerCollateral(ctx, addr) collateralValue := sdk.NewDecCoins() borrowed := k.GetBorrowerBorrows(ctx, addr) diff --git a/x/leverage/keeper/suite_test.go b/x/leverage/keeper/suite_test.go index 6d24796f7d..41f2c19e99 100644 --- a/x/leverage/keeper/suite_test.go +++ b/x/leverage/keeper/suite_test.go @@ -28,6 +28,7 @@ const ( pumpDenom = "upump" dumpDenom = "udump" stableDenom = "stable" + pairedDenom = "upaired" ) type IntegrationTestSuite struct { @@ -78,16 +79,30 @@ func (s *IntegrationTestSuite) SetupTest() { leverage.InitGenesis(ctx, app.LeverageKeeper, *types.DefaultGenesis()) require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, newToken(appparams.BondDenom, "UMEE", 6))) require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, newToken(atomDenom, "ATOM", 6))) - require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, newToken(daiDenom, "DAI", 18))) + daiToken := newToken(daiDenom, "DAI", 18) // high exponent token will need bigger maxSupply for testing + daiToken.MaxSupply = daiToken.MaxSupply.Mul(sdk.NewInt(1_000_000_000_000)) + require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, daiToken)) // additional tokens for historacle testing require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, newToken(dumpDenom, "DUMP", 6))) require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, newToken(pumpDenom, "PUMP", 6))) + // additional token for special pairs + require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, newToken(pairedDenom, "PAIRED", 6))) // additional tokens for borrow factor testing stable := newToken(stableDenom, "STABLE", 6) stable.CollateralWeight = sdk.MustNewDecFromStr("0.8") stable.LiquidationThreshold = sdk.MustNewDecFromStr("0.9") require.NoError(app.LeverageKeeper.SetTokenSettings(ctx, stable)) + // override DefaultGenesis params with some special asset pairs + app.LeverageKeeper.SetSpecialAssetPair(ctx, + types.SpecialAssetPair{ + Collateral: pairedDenom, + Borrow: daiDenom, + CollateralWeight: sdk.MustNewDecFromStr("0.5"), + LiquidationThreshold: sdk.MustNewDecFromStr("0.75"), + }, + ) + // override DefaultGenesis params with fixtures.Params app.LeverageKeeper.SetParams(ctx, fixtures.Params()) From 4c1f858bf6d401a17a4dfe5818a46dc9b9578383 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:00:37 -0600 Subject: [PATCH 32/36] rename suite functions --- tests/e2e/e2e_leverage_test.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index b0e71cb31a..41158705c6 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -9,55 +9,55 @@ import ( leveragetypes "github.com/umee-network/umee/v6/x/leverage/types" ) -func (s *E2ETest) supply(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageSupply(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgSupply(addr, asset)) } -func (s *E2ETest) withdraw(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageWithdraw(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgWithdraw(addr, asset)) } -func (s *E2ETest) maxWithdraw(addr sdk.AccAddress, denom string) { +func (s *E2ETest) leverageMaxWithdraw(addr sdk.AccAddress, denom string) { s.mustSucceedTx(leveragetypes.NewMsgMaxWithdraw(addr, denom)) } -func (s *E2ETest) collateralize(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageCollateralize(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgCollateralize(addr, asset)) } -func (s *E2ETest) decollateralize(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageDecollateralize(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgDecollateralize(addr, asset)) } -func (s *E2ETest) supplyCollateral(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageSupplyCollateral(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgSupplyCollateral(addr, asset)) } -func (s *E2ETest) borrow(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageBorrow(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgBorrow(addr, asset)) } -func (s *E2ETest) maxBorrow(addr sdk.AccAddress, denom string) { +func (s *E2ETest) leverageMaxBorrow(addr sdk.AccAddress, denom string) { s.mustSucceedTx(leveragetypes.NewMsgMaxBorrow(addr, denom)) } -func (s *E2ETest) repay(addr sdk.AccAddress, denom string, amount uint64) { +func (s *E2ETest) leverageRepay(addr sdk.AccAddress, denom string, amount uint64) { asset := sdk.NewCoin(denom, sdk.NewIntFromUint64(amount)) s.mustSucceedTx(leveragetypes.NewMsgRepay(addr, asset)) } -func (s *E2ETest) liquidate(addr, target sdk.AccAddress, repayDenom string, repayAmount uint64, reward string) { +func (s *E2ETest) leverageLiquidate(addr, target sdk.AccAddress, repayDenom string, repayAmount uint64, reward string) { repay := sdk.NewCoin(repayDenom, sdk.NewIntFromUint64(repayAmount)) s.mustSucceedTx(leveragetypes.NewMsgLiquidate(addr, target, repay, reward)) } -func (s *E2ETest) leveragedLiquidate(addr, target sdk.AccAddress, repay, reward string) { +func (s *E2ETest) leverageLeveragedLiquidate(addr, target sdk.AccAddress, repay, reward string) { s.mustSucceedTx(leveragetypes.NewMsgLeveragedLiquidate(addr, target, repay, reward)) } @@ -81,27 +81,27 @@ func (s *E2ETest) TestLeverageBasics() { s.Run( "initial leverage supply", func() { - s.supply(valAddr, appparams.BondDenom, 100_000_000) + s.leverageSupply(valAddr, appparams.BondDenom, 100_000_000) }, ) s.Run( "initial leverage withdraw", func() { - s.withdraw(valAddr, "u/"+appparams.BondDenom, 10_000_000) + s.leverageWithdraw(valAddr, "u/"+appparams.BondDenom, 10_000_000) }, ) s.Run( "initial leverage collateralize", func() { - s.collateralize(valAddr, "u/"+appparams.BondDenom, 80_000_000) + s.leverageCollateralize(valAddr, "u/"+appparams.BondDenom, 80_000_000) }, ) s.Run( "initial leverage borrow", func() { - s.borrow(valAddr, appparams.BondDenom, 12_000_000) + s.leverageBorrow(valAddr, appparams.BondDenom, 12_000_000) }, ) s.Run( "initial leverage repay", func() { - s.repay(valAddr, appparams.BondDenom, 2_000_000) + s.leverageRepay(valAddr, appparams.BondDenom, 2_000_000) }, ) s.Run( From 06b1b95d3b123ae355d5dbd50227a5b7b0376eb7 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:01:17 -0600 Subject: [PATCH 33/36] change eventually to 5sec --- tests/e2e/e2e_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index bb0df14718..af778dc101 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -22,14 +22,14 @@ func TestE2ETestSuite(t *testing.T) { // mustEventuallySucceedTx executes an sdk.Msg, retrying several times if receiving any error, // and requires that the transaction eventually succeeded with nil error. Since this function -// retries for 30 seconds and ignores errors, it is suitable for scenario setup transaction or -// those which might require time elapsing before they succeed. +// retries for 5 seconds and ignores errors, it is suitable for scenario setup transaction or +// those which might require a few blocks elapsing before they succeed. func (s *E2ETest) mustEventuallySucceedTx(msg sdk.Msg) { s.Require().Eventually( func() bool { return s.BroadcastTxWithRetry(msg) == nil }, - 30*time.Second, + 5*time.Second, 500*time.Millisecond, ) } From 0dd49314e4ac1b7023aa1976fdc7c8e06d452f8e Mon Sep 17 00:00:00 2001 From: Adam Moser <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:02:15 -0600 Subject: [PATCH 34/36] suggestion++ Co-authored-by: Robert Zaremba --- tests/e2e/e2e_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index af778dc101..e32af4795f 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/stretchr/testify/suite" - sdk "github.com/cosmos/cosmos-sdk/types" setup "github.com/umee-network/umee/v6/tests/e2e/setup" From 87232e4bc6f6d3c3064f1b35cb80d4944a4da247 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:17:43 -0600 Subject: [PATCH 35/36] remove eventually --- tests/e2e/e2e_leverage_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 41158705c6..0343291b3a 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -134,7 +134,7 @@ func (s *E2ETest) TestLeverageBasics() { appparams.BondDenom, sdk.NewIntFromUint64(30_000_000), ) - s.mustEventuallySucceedTx(leveragetypes.NewMsgBorrow(valAddr, asset)) + s.mustSucceedTx(leveragetypes.NewMsgBorrow(valAddr, asset)) }, ) } From 59fb3ccd18310059da29d986b311bb0db34bdf16 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:46:45 -0600 Subject: [PATCH 36/36] modify gov proposal (sets don't loop assets) --- tests/e2e/e2e_leverage_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/e2e_leverage_test.go b/tests/e2e/e2e_leverage_test.go index 0343291b3a..3765be3829 100644 --- a/tests/e2e/e2e_leverage_test.go +++ b/tests/e2e/e2e_leverage_test.go @@ -115,16 +115,17 @@ func (s *E2ETest) TestLeverageBasics() { ) s.Run( "leverage add special pairs", func() { - sets := []leveragetypes.SpecialAssetSet{ + pairs := []leveragetypes.SpecialAssetPair{ { // a set allowing UMEE to borrow more of itself - Assets: []string{appparams.BondDenom}, + Borrow: appparams.BondDenom, + Collateral: appparams.BondDenom, CollateralWeight: sdk.MustNewDecFromStr("0.75"), LiquidationThreshold: sdk.MustNewDecFromStr("0.8"), }, } s.Require().NoError( - grpc.LeverageSpecialPairsUpdate(s.Umee, sets, []leveragetypes.SpecialAssetPair{}), + grpc.LeverageSpecialPairsUpdate(s.Umee, []leveragetypes.SpecialAssetSet{}, pairs), ) }, )