Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Sep 11, 2023
1 parent c8c7f3e commit b5930de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
44 changes: 22 additions & 22 deletions tests/e2e/e2e_leverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
22 changes: 21 additions & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b5930de

Please sign in to comment.