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] ++ --- 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