From 57db8ff010c2ed10924bd96332d9d9d22fc8991a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 18:52:42 +0200 Subject: [PATCH 01/11] refactore(leverage): rename ExchangeToken --- x/incentive/expected_keepers.go | 2 +- x/incentive/keeper/grpc_query.go | 2 +- x/incentive/keeper/mock_test.go | 4 +- x/leverage/keeper/borrows.go | 6 +- x/leverage/keeper/collateral.go | 6 +- x/leverage/keeper/exchange_rate.go | 19 ++-- x/leverage/keeper/grpc_query.go | 2 +- x/leverage/keeper/incentive.go | 2 +- x/leverage/keeper/keeper.go | 8 +- x/leverage/keeper/limits.go | 4 +- x/leverage/keeper/oracle.go | 2 +- x/leverage/keeper/supply.go | 6 +- x/metoken/expected_keepers.go | 4 +- x/metoken/keeper/intest/interest_test.go | 2 +- x/metoken/keeper/mocks_test.go | 4 +- x/metoken/keeper/redeem.go | 2 +- x/metoken/mocks/keepers.go | 128 +++++++++++------------ x/uibc/expected_keepers.go | 2 +- x/uibc/mocks/keepers.go | 12 +-- x/uibc/quota/keeper/intest/quota_test.go | 4 +- x/uibc/quota/keeper/mocks_test.go | 2 +- x/uibc/quota/keeper/quota.go | 2 +- 22 files changed, 112 insertions(+), 113 deletions(-) diff --git a/x/incentive/expected_keepers.go b/x/incentive/expected_keepers.go index bb310be1eb..0db3188e8e 100644 --- a/x/incentive/expected_keepers.go +++ b/x/incentive/expected_keepers.go @@ -21,5 +21,5 @@ type LeverageKeeper interface { GetTokenSettings(ctx sdk.Context, denom string) (leveragetypes.Token, error) // These are used for APY queries only TotalTokenValue(ctx sdk.Context, coins sdk.Coins, mode leveragetypes.PriceMode) (sdk.Dec, error) - ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) } diff --git a/x/incentive/keeper/grpc_query.go b/x/incentive/keeper/grpc_query.go index 49990f64b6..a8210c76a5 100644 --- a/x/incentive/keeper/grpc_query.go +++ b/x/incentive/keeper/grpc_query.go @@ -263,7 +263,7 @@ func (q Querier) ActualRates( } // compute oracle price ratio of rewards to reference bond amount - referenceToken, err := k.leverageKeeper.ExchangeUToken(ctx, referenceUToken) + referenceToken, err := k.leverageKeeper.UToken2TokenRate(ctx, referenceUToken) if err != nil { return nil, err } diff --git a/x/incentive/keeper/mock_test.go b/x/incentive/keeper/mock_test.go index 423e1b758c..e23c5a3f27 100644 --- a/x/incentive/keeper/mock_test.go +++ b/x/incentive/keeper/mock_test.go @@ -218,8 +218,8 @@ func (m *mockLeverageKeeper) TotalTokenValue(_ sdk.Context, coins sdk.Coins, _ l return total, nil } -// ExchangeUToken implements the expected leverage keeper, with uToken exchange rates always equal to 1 -func (m *mockLeverageKeeper) ExchangeUToken(_ sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { +// UToken2TokenRate implements the expected leverage keeper, with uToken exchange rates always equal to 1 +func (m *mockLeverageKeeper) UToken2TokenRate(_ sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if !leveragetypes.HasUTokenPrefix(uToken.Denom) { return uToken, leveragetypes.ErrUToken } diff --git a/x/leverage/keeper/borrows.go b/x/leverage/keeper/borrows.go index dcf3419654..d1bc1e39eb 100644 --- a/x/leverage/keeper/borrows.go +++ b/x/leverage/keeper/borrows.go @@ -134,7 +134,7 @@ func (k Keeper) CalculateBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.UToken2TokenRate(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -170,7 +170,7 @@ func (k Keeper) VisibleBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk.D for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.UToken2TokenRate(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -208,7 +208,7 @@ func (k Keeper) CalculateLiquidationThreshold(ctx sdk.Context, collateral sdk.Co for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.UToken2TokenRate(ctx, coin) if err != nil { return sdk.ZeroDec(), err } diff --git a/x/leverage/keeper/collateral.go b/x/leverage/keeper/collateral.go index 31786d4d99..ed6a03c230 100644 --- a/x/leverage/keeper/collateral.go +++ b/x/leverage/keeper/collateral.go @@ -80,7 +80,7 @@ func (k Keeper) CalculateCollateralValue(ctx sdk.Context, collateral sdk.Coins, for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.UToken2TokenRate(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -107,7 +107,7 @@ func (k Keeper) VisibleCollateralValue(ctx sdk.Context, collateral sdk.Coins, mo for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.ExchangeUToken(ctx, coin) + baseAsset, err := k.UToken2TokenRate(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -251,7 +251,7 @@ func (k Keeper) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (s // Get module collateral for the uDenom totalCollateral := k.GetTotalCollateral(ctx, spendableUTokens.Denom) - totalTokenCollateral, err := k.ExchangeUTokens(ctx, sdk.NewCoins(totalCollateral)) + totalTokenCollateral, err := k.Tokens2uTokensRate(ctx, sdk.NewCoins(totalCollateral)) if err != nil { return sdk.ZeroInt(), err } diff --git a/x/leverage/keeper/exchange_rate.go b/x/leverage/keeper/exchange_rate.go index 8cfb9b03fe..29f431633f 100644 --- a/x/leverage/keeper/exchange_rate.go +++ b/x/leverage/keeper/exchange_rate.go @@ -6,9 +6,9 @@ import ( "github.com/umee-network/umee/v5/x/leverage/types" ) -// ExchangeToken converts an sdk.Coin containing a base asset to its value as a -// uToken. -func (k Keeper) ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { +// Token2uTokenRate returns a uToken amount user would receive when supplying the token. +// Returns error if the token is not a Token. +func (k Keeper) Token2uTokenRate(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { if err := token.Validate(); err != nil { return sdk.Coin{}, err } @@ -19,14 +19,13 @@ func (k Keeper) ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) } exchangeRate := k.DeriveExchangeRate(ctx, token.Denom) - uTokenAmount := toDec(token.Amount).Quo(exchangeRate).TruncateInt() return sdk.NewCoin(uTokenDenom, uTokenAmount), nil } -// ExchangeUToken converts an sdk.Coin containing a uToken to its value in a base -// token. -func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { +// UToken2TokenRate returns a token amount user would receive when supplying the uToken. +// Returns error if the uToken is not a uToken. +func (k Keeper) UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if err := uToken.Validate(); err != nil { return sdk.Coin{}, err } @@ -42,16 +41,16 @@ func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, erro return sdk.NewCoin(tokenDenom, tokenAmount), nil } -// ExchangeUTokens converts an sdk.Coins containing uTokens to their values in base +// Tokens2uTokensRate converts an sdk.Coins containing uTokens to their values in base // tokens. -func (k Keeper) ExchangeUTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { +func (k Keeper) Tokens2uTokensRate(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { if err := uTokens.Validate(); err != nil { return sdk.Coins{}, err } tokens := sdk.Coins{} for _, coin := range uTokens { - token, err := k.ExchangeUToken(ctx, coin) + token, err := k.UToken2TokenRate(ctx, coin) if err != nil { return sdk.Coins{}, err } diff --git a/x/leverage/keeper/grpc_query.go b/x/leverage/keeper/grpc_query.go index 45cd997bde..3b671d36fb 100644 --- a/x/leverage/keeper/grpc_query.go +++ b/x/leverage/keeper/grpc_query.go @@ -362,7 +362,7 @@ func (q Querier) MaxWithdraw( // On non-nil error here, max withdraw is zero. uToken, _, err := q.Keeper.userMaxWithdraw(ctx, addr, denom) if err == nil && uToken.IsPositive() { - token, err := q.Keeper.ExchangeUToken(ctx, uToken) + token, err := q.Keeper.UToken2TokenRate(ctx, uToken) if err != nil { return nil, err } diff --git a/x/leverage/keeper/incentive.go b/x/leverage/keeper/incentive.go index 2266477193..fce4686160 100644 --- a/x/leverage/keeper/incentive.go +++ b/x/leverage/keeper/incentive.go @@ -7,7 +7,7 @@ import ( // DonateCollateral burns some collateral uTokens already present in the module, then adds their equivalent amount // in tokens reserves. Currently, this is only used as the penalty for incentive module's MsgEmergencyUnbond. func (k Keeper) DonateCollateral(ctx sdk.Context, fromAddr sdk.AccAddress, uToken sdk.Coin) error { - token, err := k.ExchangeUToken(ctx, uToken) + token, err := k.UToken2TokenRate(ctx, uToken) if err != nil { return err } diff --git a/x/leverage/keeper/keeper.go b/x/leverage/keeper/keeper.go index d3713b18dd..d6c71ddf3e 100644 --- a/x/leverage/keeper/keeper.go +++ b/x/leverage/keeper/keeper.go @@ -91,7 +91,7 @@ func (k Keeper) Supply(ctx sdk.Context, supplierAddr sdk.AccAddress, coin sdk.Co } // determine uToken amount to mint - uToken, err := k.ExchangeToken(ctx, coin) + uToken, err := k.Token2uTokenRate(ctx, coin) if err != nil { return sdk.Coin{}, err } @@ -129,7 +129,7 @@ func (k Keeper) SupplyFromModule(ctx sdk.Context, fromModule string, coin sdk.Co } // determine uToken amount to mint - uToken, err := k.ExchangeToken(ctx, coin) + uToken, err := k.Token2uTokenRate(ctx, coin) if err != nil { return sdk.Coin{}, true, err } @@ -176,7 +176,7 @@ func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sd } // calculate base asset amount to withdraw - token, err := k.ExchangeUToken(ctx, uToken) + token, err := k.UToken2TokenRate(ctx, uToken) if err != nil { return sdk.Coin{}, isFromCollateral, err } @@ -256,7 +256,7 @@ func (k Keeper) WithdrawToModule(ctx sdk.Context, toModule string, uToken sdk.Co } // calculate base asset amount to withdraw - token, err := k.ExchangeUToken(ctx, uToken) + token, err := k.UToken2TokenRate(ctx, uToken) if err != nil { return sdk.Coin{}, true, err } diff --git a/x/leverage/keeper/limits.go b/x/leverage/keeper/limits.go index 16cb9030ba..9a1a79766f 100644 --- a/x/leverage/keeper/limits.go +++ b/x/leverage/keeper/limits.go @@ -13,7 +13,7 @@ import ( func (k *Keeper) userMaxWithdraw(ctx sdk.Context, addr sdk.AccAddress, denom string) (sdk.Coin, sdk.Coin, error) { uDenom := types.ToUTokenDenom(denom) availableTokens := sdk.NewCoin(denom, k.AvailableLiquidity(ctx, denom)) - availableUTokens, err := k.ExchangeToken(ctx, availableTokens) + availableUTokens, err := k.Token2uTokenRate(ctx, availableTokens) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } @@ -282,7 +282,7 @@ func (k Keeper) ModuleAvailableLiquidity(ctx sdk.Context, denom string) (sdkmath // Get module collateral for the associated uToken totalCollateral := k.GetTotalCollateral(ctx, types.ToUTokenDenom(denom)) - totalTokenCollateral, err := k.ExchangeUTokens(ctx, sdk.NewCoins(totalCollateral)) + totalTokenCollateral, err := k.Tokens2uTokensRate(ctx, sdk.NewCoins(totalCollateral)) if err != nil { return sdkmath.Int{}, err } diff --git a/x/leverage/keeper/oracle.go b/x/leverage/keeper/oracle.go index 7b27072b2e..7e42ff3b3a 100644 --- a/x/leverage/keeper/oracle.go +++ b/x/leverage/keeper/oracle.go @@ -167,7 +167,7 @@ func (k Keeper) VisibleUTokensValue(ctx sdk.Context, uTokens sdk.Coins, mode typ tokens := sdk.NewCoins() for _, u := range uTokens { - t, err := k.ExchangeUToken(ctx, u) + t, err := k.UToken2TokenRate(ctx, u) if err != nil { return sdk.ZeroDec(), err } diff --git a/x/leverage/keeper/supply.go b/x/leverage/keeper/supply.go index bb4cfc3b7d..c836207211 100644 --- a/x/leverage/keeper/supply.go +++ b/x/leverage/keeper/supply.go @@ -19,7 +19,7 @@ func (k Keeper) GetSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress, denom collateral := k.GetCollateral(ctx, supplierAddr, uDenom) // convert uTokens to tokens - return k.ExchangeUToken(ctx, balance.Add(collateral)) + return k.UToken2TokenRate(ctx, balance.Add(collateral)) } // GetAllSupplied returns the total tokens supplied by a user, including @@ -38,7 +38,7 @@ func (k Keeper) GetAllSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress) (sd } // convert the sum of found uTokens to base tokens - return k.ExchangeUTokens(ctx, collateral.Add(uTokens...)) + return k.Tokens2uTokensRate(ctx, collateral.Add(uTokens...)) } // GetTotalSupply returns the total supplied by all suppliers in a given denom, @@ -50,7 +50,7 @@ func (k Keeper) GetTotalSupply(ctx sdk.Context, denom string) (sdk.Coin, error) // convert associated uToken's total supply to base tokens uTokenDenom := types.ToUTokenDenom(denom) - return k.ExchangeUToken(ctx, k.GetUTokenSupply(ctx, uTokenDenom)) + return k.UToken2TokenRate(ctx, k.GetUTokenSupply(ctx, uTokenDenom)) } // checkMaxSupply returns the appropriate error if a token denom's diff --git a/x/metoken/expected_keepers.go b/x/metoken/expected_keepers.go index 0db126576b..2328b38f87 100644 --- a/x/metoken/expected_keepers.go +++ b/x/metoken/expected_keepers.go @@ -22,8 +22,8 @@ type BankKeeper interface { // LeverageKeeper interface for interacting with x/leverage type LeverageKeeper interface { GetTokenSettings(ctx sdk.Context, denom string) (ltypes.Token, error) - ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) - ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + Token2uTokenRate(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) + UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) SupplyFromModule(ctx sdk.Context, fromModule string, coin sdk.Coin) (sdk.Coin, bool, error) WithdrawToModule(ctx sdk.Context, toModule string, uToken sdk.Coin) (sdk.Coin, bool, error) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (sdkmath.Int, error) diff --git a/x/metoken/keeper/intest/interest_test.go b/x/metoken/keeper/intest/interest_test.go index d0247d2ac1..a9936b6b8e 100644 --- a/x/metoken/keeper/intest/interest_test.go +++ b/x/metoken/keeper/intest/interest_test.go @@ -75,7 +75,7 @@ func TestInterestClaiming(t *testing.T) { ) require.NoError(t, err) - uTokens, err := app.LeverageKeeper.ExchangeToken(ctx, borrowerSupply) + uTokens, err := app.LeverageKeeper.Token2uTokenRate(ctx, borrowerSupply) require.NoError(t, err) err = app.LeverageKeeper.Collateralize(ctx, borrower, uTokens) diff --git a/x/metoken/keeper/mocks_test.go b/x/metoken/keeper/mocks_test.go index 0d3f18fdb4..9e0e614a77 100644 --- a/x/metoken/keeper/mocks_test.go +++ b/x/metoken/keeper/mocks_test.go @@ -33,11 +33,11 @@ func (l Leverage) GetTokenSettings(_ sdk.Context, denom string) (ltypes.Token, e return ts, nil } -func (l Leverage) ExchangeToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) Token2uTokenRate(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } -func (l Leverage) ExchangeUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) UToken2TokenRate(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } diff --git a/x/metoken/keeper/redeem.go b/x/metoken/keeper/redeem.go index a56bd7ee55..2ca3057f83 100644 --- a/x/metoken/keeper/redeem.go +++ b/x/metoken/keeper/redeem.go @@ -150,7 +150,7 @@ func (k Keeper) redeem(userAddr sdk.AccAddress, meToken sdk.Coin, assetDenom str // - tokensWithdrawn: the amount tokens withdrawn from x/leverage. // - error func (k Keeper) withdrawFromLeverage(tokensToWithdraw sdk.Coin) (sdk.Coin, error) { - uTokensFromLeverage, err := k.leverageKeeper.ExchangeToken(*k.ctx, tokensToWithdraw) + uTokensFromLeverage, err := k.leverageKeeper.Token2uTokenRate(*k.ctx, tokensToWithdraw) if err != nil { return sdk.Coin{}, errors.Wrap(err, true) } diff --git a/x/metoken/mocks/keepers.go b/x/metoken/mocks/keepers.go index 8db05124a0..91ec3ff1c6 100644 --- a/x/metoken/mocks/keepers.go +++ b/x/metoken/mocks/keepers.go @@ -555,12 +555,12 @@ func (c BankKeeperSendCoinsFromModuleToAccountFuncCall) Results() []interface{} // interface (from the package github.com/umee-network/umee/v5/x/metoken) // used for unit testing. type MockLeverageKeeper struct { - // ExchangeTokenFunc is an instance of a mock function object - // controlling the behavior of the method ExchangeToken. - ExchangeTokenFunc *LeverageKeeperExchangeTokenFunc - // ExchangeUTokenFunc is an instance of a mock function object - // controlling the behavior of the method ExchangeUToken. - ExchangeUTokenFunc *LeverageKeeperExchangeUTokenFunc + // Token2uTokenRateFunc is an instance of a mock function object + // controlling the behavior of the method Token2uTokenRate. + Token2uTokenRateFunc *LeverageKeeperExchangeTokenFunc + // UToken2TokenRateFunc is an instance of a mock function object + // controlling the behavior of the method UToken2TokenRate. + UToken2TokenRateFunc *LeverageKeeperUToken2TokenRateFunc // GetAllSuppliedFunc is an instance of a mock function object // controlling the behavior of the method GetAllSupplied. GetAllSuppliedFunc *LeverageKeeperGetAllSuppliedFunc @@ -585,12 +585,12 @@ type MockLeverageKeeper struct { // All methods return zero values for all results, unless overwritten. func NewMockLeverageKeeper() *MockLeverageKeeper { return &MockLeverageKeeper{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ + Token2uTokenRateFunc: &LeverageKeeperExchangeTokenFunc{ defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { return }, }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ + UToken2TokenRateFunc: &LeverageKeeperUToken2TokenRateFunc{ defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { return }, @@ -632,14 +632,14 @@ func NewMockLeverageKeeper() *MockLeverageKeeper { // interface. All methods panic on invocation, unless overwritten. func NewStrictMockLeverageKeeper() *MockLeverageKeeper { return &MockLeverageKeeper{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ + Token2uTokenRateFunc: &LeverageKeeperExchangeTokenFunc{ defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.ExchangeToken") + panic("unexpected invocation of MockLeverageKeeper.Token2uTokenRate") }, }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ + UToken2TokenRateFunc: &LeverageKeeperUToken2TokenRateFunc{ defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.ExchangeUToken") + panic("unexpected invocation of MockLeverageKeeper.UToken2TokenRate") }, }, GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ @@ -680,11 +680,11 @@ func NewStrictMockLeverageKeeper() *MockLeverageKeeper { // overwritten. func NewMockLeverageKeeperFrom(i metoken.LeverageKeeper) *MockLeverageKeeper { return &MockLeverageKeeper{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: i.ExchangeToken, + Token2uTokenRateFunc: &LeverageKeeperExchangeTokenFunc{ + defaultHook: i.Token2uTokenRate, }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - defaultHook: i.ExchangeUToken, + UToken2TokenRateFunc: &LeverageKeeperUToken2TokenRateFunc{ + defaultHook: i.UToken2TokenRate, }, GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ defaultHook: i.GetAllSupplied, @@ -707,36 +707,36 @@ func NewMockLeverageKeeperFrom(i metoken.LeverageKeeper) *MockLeverageKeeper { } } -// LeverageKeeperExchangeTokenFunc describes the behavior when the -// ExchangeToken method of the parent MockLeverageKeeper instance is +// LeverageKeeperToken2uTokenRateFunc describes the behavior when the +// Token2uTokenRate method of the parent MockLeverageKeeper instance is // invoked. -type LeverageKeeperExchangeTokenFunc struct { +type LeverageKeeperToken2uTokenRateFunc struct { defaultHook func(types.Context, types.Coin) (types.Coin, error) hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperExchangeTokenFuncCall + history []LeverageKeeperToken2uTokenRateFuncCall mutex sync.Mutex } -// ExchangeToken delegates to the next hook function in the queue and stores +// Token2uTokenRate delegates to the next hook function in the queue and stores // the parameter and result values of this invocation. -func (m *MockLeverageKeeper) ExchangeToken(v0 types.Context, v1 types.Coin) (types.Coin, error) { - r0, r1 := m.ExchangeTokenFunc.nextHook()(v0, v1) - m.ExchangeTokenFunc.appendCall(LeverageKeeperExchangeTokenFuncCall{v0, v1, r0, r1}) +func (m *MockLeverageKeeper) Token2uTokenRate(v0 types.Context, v1 types.Coin) (types.Coin, error) { + r0, r1 := m.Token2uTokenRateFunc.nextHook()(v0, v1) + m.Token2uTokenRateFunc.appendCall(LeverageKeeperExchangeTokenFuncCall{v0, v1, r0, r1}) return r0, r1 } -// SetDefaultHook sets function that is called when the ExchangeToken method +// SetDefaultHook sets function that is called when the Token2uTokenRate method // of the parent MockLeverageKeeper instance is invoked and the hook queue // is empty. -func (f *LeverageKeeperExchangeTokenFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { +func (f *LeverageKeeperToken2uTokenRateFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// ExchangeToken method of the parent MockLeverageKeeper instance invokes +// Token2uTokenRate method of the parent MockLeverageKeeper instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperExchangeTokenFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { +func (f *LeverageKeeperToken2uTokenRateFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -744,20 +744,20 @@ func (f *LeverageKeeperExchangeTokenFunc) PushHook(hook func(types.Context, type // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *LeverageKeeperExchangeTokenFunc) SetDefaultReturn(r0 types.Coin, r1 error) { +func (f *LeverageKeeperToken2uTokenRateFunc) SetDefaultReturn(r0 types.Coin, r1 error) { f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperExchangeTokenFunc) PushReturn(r0 types.Coin, r1 error) { +func (f *LeverageKeeperToken2uTokenRateFunc) PushReturn(r0 types.Coin, r1 error) { f.PushHook(func(types.Context, types.Coin) (types.Coin, error) { return r0, r1 }) } -func (f *LeverageKeeperExchangeTokenFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { +func (f *LeverageKeeperToken2uTokenRateFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -770,26 +770,26 @@ func (f *LeverageKeeperExchangeTokenFunc) nextHook() func(types.Context, types.C return hook } -func (f *LeverageKeeperExchangeTokenFunc) appendCall(r0 LeverageKeeperExchangeTokenFuncCall) { +func (f *LeverageKeeperToken2uTokenRateFunc) appendCall(r0 LeverageKeeperExchangeTokenFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of LeverageKeeperExchangeTokenFuncCall objects +// History returns a sequence of LeverageKeeperToken2uTokenRateFuncCall objects // describing the invocations of this function. -func (f *LeverageKeeperExchangeTokenFunc) History() []LeverageKeeperExchangeTokenFuncCall { +func (f *LeverageKeeperToken2uTokenRateFunc) History() []LeverageKeeperExchangeTokenFuncCall { f.mutex.Lock() - history := make([]LeverageKeeperExchangeTokenFuncCall, len(f.history)) + history := make([]LeverageKeeperToken2uTokenRateFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// LeverageKeeperExchangeTokenFuncCall is an object that describes an -// invocation of method ExchangeToken on an instance of MockLeverageKeeper. -type LeverageKeeperExchangeTokenFuncCall struct { +// LeverageKeeperToken2uTokenRateFuncCall is an object that describes an +// invocation of method Token2uTokenRate on an instance of MockLeverageKeeper. +type LeverageKeeperToken2uTokenRateFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 types.Context @@ -806,46 +806,46 @@ type LeverageKeeperExchangeTokenFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c LeverageKeeperExchangeTokenFuncCall) Args() []interface{} { +func (c LeverageKeeperToken2uTokenRateFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1} } // Results returns an interface slice containing the results of this // invocation. -func (c LeverageKeeperExchangeTokenFuncCall) Results() []interface{} { +func (c LeverageKeeperToken2uTokenRateFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } -// LeverageKeeperExchangeUTokenFunc describes the behavior when the -// ExchangeUToken method of the parent MockLeverageKeeper instance is +// LeverageKeeperUToken2TokenRateFunc describes the behavior when the +// UToken2TokenRate method of the parent MockLeverageKeeper instance is // invoked. -type LeverageKeeperExchangeUTokenFunc struct { +type LeverageKeeperUToken2TokenRateFunc struct { defaultHook func(types.Context, types.Coin) (types.Coin, error) hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperExchangeUTokenFuncCall + history []LeverageKeeperUToken2TokenRateFuncCall mutex sync.Mutex } -// ExchangeUToken delegates to the next hook function in the queue and +// UToken2TokenRate delegates to the next hook function in the queue and // stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) ExchangeUToken(v0 types.Context, v1 types.Coin) (types.Coin, error) { - r0, r1 := m.ExchangeUTokenFunc.nextHook()(v0, v1) - m.ExchangeUTokenFunc.appendCall(LeverageKeeperExchangeUTokenFuncCall{v0, v1, r0, r1}) +func (m *MockLeverageKeeper) UToken2TokenRate(v0 types.Context, v1 types.Coin) (types.Coin, error) { + r0, r1 := m.UToken2TokenRateFunc.nextHook()(v0, v1) + m.UToken2TokenRateFunc.appendCall(LeverageKeeperUToken2TokenRateFuncCall{v0, v1, r0, r1}) return r0, r1 } -// SetDefaultHook sets function that is called when the ExchangeUToken +// SetDefaultHook sets function that is called when the UToken2TokenRate // method of the parent MockLeverageKeeper instance is invoked and the hook // queue is empty. -func (f *LeverageKeeperExchangeUTokenFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { +func (f *LeverageKeeperUToken2TokenRateFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { f.defaultHook = hook } // PushHook adds a function to the end of hook queue. Each invocation of the -// ExchangeUToken method of the parent MockLeverageKeeper instance invokes +// UToken2TokenRate method of the parent MockLeverageKeeper instance invokes // the hook at the front of the queue and discards it. After the queue is // empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperExchangeUTokenFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { +func (f *LeverageKeeperUToken2TokenRateFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { f.mutex.Lock() f.hooks = append(f.hooks, hook) f.mutex.Unlock() @@ -853,20 +853,20 @@ func (f *LeverageKeeperExchangeUTokenFunc) PushHook(hook func(types.Context, typ // SetDefaultReturn calls SetDefaultHook with a function that returns the // given values. -func (f *LeverageKeeperExchangeUTokenFunc) SetDefaultReturn(r0 types.Coin, r1 error) { +func (f *LeverageKeeperUToken2TokenRateFunc) SetDefaultReturn(r0 types.Coin, r1 error) { f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { return r0, r1 }) } // PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperExchangeUTokenFunc) PushReturn(r0 types.Coin, r1 error) { +func (f *LeverageKeeperUToken2TokenRateFunc) PushReturn(r0 types.Coin, r1 error) { f.PushHook(func(types.Context, types.Coin) (types.Coin, error) { return r0, r1 }) } -func (f *LeverageKeeperExchangeUTokenFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { +func (f *LeverageKeeperUToken2TokenRateFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -879,26 +879,26 @@ func (f *LeverageKeeperExchangeUTokenFunc) nextHook() func(types.Context, types. return hook } -func (f *LeverageKeeperExchangeUTokenFunc) appendCall(r0 LeverageKeeperExchangeUTokenFuncCall) { +func (f *LeverageKeeperUToken2TokenRateFunc) appendCall(r0 LeverageKeeperUToken2TokenRateFuncCall) { f.mutex.Lock() f.history = append(f.history, r0) f.mutex.Unlock() } -// History returns a sequence of LeverageKeeperExchangeUTokenFuncCall +// History returns a sequence of LeverageKeeperUToken2TokenRateFuncCall // objects describing the invocations of this function. -func (f *LeverageKeeperExchangeUTokenFunc) History() []LeverageKeeperExchangeUTokenFuncCall { +func (f *LeverageKeeperUToken2TokenRateFunc) History() []LeverageKeeperUToken2TokenRateFuncCall { f.mutex.Lock() - history := make([]LeverageKeeperExchangeUTokenFuncCall, len(f.history)) + history := make([]LeverageKeeperUToken2TokenRateFuncCall, len(f.history)) copy(history, f.history) f.mutex.Unlock() return history } -// LeverageKeeperExchangeUTokenFuncCall is an object that describes an -// invocation of method ExchangeUToken on an instance of MockLeverageKeeper. -type LeverageKeeperExchangeUTokenFuncCall struct { +// LeverageKeeperUToken2TokenRateFuncCall is an object that describes an +// invocation of method UToken2TokenRate on an instance of MockLeverageKeeper. +type LeverageKeeperUToken2TokenRateFuncCall struct { // Arg0 is the value of the 1st argument passed to this method // invocation. Arg0 types.Context @@ -915,13 +915,13 @@ type LeverageKeeperExchangeUTokenFuncCall struct { // Args returns an interface slice containing the arguments of this // invocation. -func (c LeverageKeeperExchangeUTokenFuncCall) Args() []interface{} { +func (c LeverageKeeperUToken2TokenRateFuncCall) Args() []interface{} { return []interface{}{c.Arg0, c.Arg1} } // Results returns an interface slice containing the results of this // invocation. -func (c LeverageKeeperExchangeUTokenFuncCall) Results() []interface{} { +func (c LeverageKeeperUToken2TokenRateFuncCall) Results() []interface{} { return []interface{}{c.Result0, c.Result1} } diff --git a/x/uibc/expected_keepers.go b/x/uibc/expected_keepers.go index 2b8f61a655..a61c3a0a19 100644 --- a/x/uibc/expected_keepers.go +++ b/x/uibc/expected_keepers.go @@ -16,7 +16,7 @@ type BankKeeper interface { type Leverage interface { GetTokenSettings(ctx sdk.Context, baseDenom string) (ltypes.Token, error) - ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) DeriveExchangeRate(ctx sdk.Context, denom string) sdk.Dec } diff --git a/x/uibc/mocks/keepers.go b/x/uibc/mocks/keepers.go index cd0a9be211..7acbbc5428 100644 --- a/x/uibc/mocks/keepers.go +++ b/x/uibc/mocks/keepers.go @@ -112,19 +112,19 @@ func (mr *MockLeverageKeeperMockRecorder) DeriveExchangeRate(ctx, denom interfac return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeriveExchangeRate", reflect.TypeOf((*MockLeverageKeeper)(nil).DeriveExchangeRate), ctx, denom) } -// ExchangeUToken mocks base method. -func (m *MockLeverageKeeper) ExchangeUToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { +// UToken2TokenRate mocks base method. +func (m *MockLeverageKeeper) UToken2TokenRate(ctx types.Context, uToken types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExchangeUToken", ctx, uToken) + ret := m.ctrl.Call(m, "UToken2TokenRate", ctx, uToken) ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// ExchangeUToken indicates an expected call of ExchangeUToken. -func (mr *MockLeverageKeeperMockRecorder) ExchangeUToken(ctx, uToken interface{}) *gomock.Call { +// UToken2TokenRate indicates an expected call of UToken2TokenRate. +func (mr *MockLeverageKeeperMockRecorder) UToken2TokenRate(ctx, uToken interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExchangeUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ExchangeUToken), ctx, uToken) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UToken2TokenRate", reflect.TypeOf((*MockLeverageKeeper)(nil).UToken2TokenRate), ctx, uToken) } // GetTokenSettings mocks base method. diff --git a/x/uibc/quota/keeper/intest/quota_test.go b/x/uibc/quota/keeper/intest/quota_test.go index 7fb32c0d65..07cfd3ed94 100644 --- a/x/uibc/quota/keeper/intest/quota_test.go +++ b/x/uibc/quota/keeper/intest/quota_test.go @@ -53,14 +53,14 @@ func TestKeeper_CheckAndUpdateQuota(t *testing.T) { assert.NilError(t, err) // invalid token, returns error from mock leverage - leverageMock.EXPECT().ExchangeUToken(ctx, invalidToken).Return(sdk.Coin{}, ltypes.ErrNotUToken).AnyTimes() + leverageMock.EXPECT().UToken2TokenRate(ctx, invalidToken).Return(sdk.Coin{}, ltypes.ErrNotUToken).AnyTimes() err = k.CheckAndUpdateQuota(invalidToken.Denom, invalidToken.Amount) assert.ErrorIs(t, err, ltypes.ErrNotUToken) // UMEE uToken, exchanges correctly, but returns ErrNotRegisteredToken when trying to get Token's settings // from leverage mock keeper - leverageMock.EXPECT().ExchangeUToken(ctx, umeeUToken).Return( + leverageMock.EXPECT().UToken2TokenRate(ctx, umeeUToken).Return( sdk.NewCoin("umee", sdkmath.NewInt(100)), nil, ).AnyTimes() diff --git a/x/uibc/quota/keeper/mocks_test.go b/x/uibc/quota/keeper/mocks_test.go index 33c2df0e3c..2050b6af02 100644 --- a/x/uibc/quota/keeper/mocks_test.go +++ b/x/uibc/quota/keeper/mocks_test.go @@ -22,7 +22,7 @@ func (k LeverageKeeper) GetTokenSettings(_ sdk.Context, baseDenom string) (ltype return ts, nil } -func (k LeverageKeeper) ExchangeUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (k LeverageKeeper) UToken2TokenRate(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index 57395916bf..61a6e8885f 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -141,7 +141,7 @@ func (k Keeper) getExchangePrice(denom string, amount sdkmath.Int) (sdk.Dec, err // convert to base asset if it is `uToken` if ltypes.HasUTokenPrefix(denom) { // NOTE: to avoid ctx, we can use similar approach: create a leverage keeper builder - transferCoin, err = k.leverage.ExchangeUToken(*k.ctx, transferCoin) + transferCoin, err = k.leverage.UToken2TokenRate(*k.ctx, transferCoin) if err != nil { return sdk.Dec{}, err } From 75dbb7957df05ba44c83901208265f472418cce1 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 18:56:27 +0200 Subject: [PATCH 02/11] mockgen --- x/metoken/mocks/keepers.go | 1846 ++++-------------------------------- x/uibc/mocks/keepers.go | 56 +- 2 files changed, 217 insertions(+), 1685 deletions(-) diff --git a/x/metoken/mocks/keepers.go b/x/metoken/mocks/keepers.go index 91ec3ff1c6..84915ffeef 100644 --- a/x/metoken/mocks/keepers.go +++ b/x/metoken/mocks/keepers.go @@ -1,1744 +1,276 @@ -// Code generated by go-mockgen 1.3.7; DO NOT EDIT. +// Code generated by MockGen. DO NOT EDIT. +// Source: ./x/metoken/expected_keepers.go +// Package mocks is a generated GoMock package. package mocks import ( - "sync" + reflect "reflect" math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/types" - types1 "github.com/umee-network/umee/v5/x/leverage/types" - metoken "github.com/umee-network/umee/v5/x/metoken" - types2 "github.com/umee-network/umee/v5/x/oracle/types" + gomock "github.com/golang/mock/gomock" + types0 "github.com/umee-network/umee/v5/x/leverage/types" + types1 "github.com/umee-network/umee/v5/x/oracle/types" ) -// MockBankKeeper is a mock implementation of the BankKeeper interface (from -// the package github.com/umee-network/umee/v5/x/metoken) used for unit -// testing. +// MockBankKeeper is a mock of BankKeeper interface. type MockBankKeeper struct { - // BurnCoinsFunc is an instance of a mock function object controlling - // the behavior of the method BurnCoins. - BurnCoinsFunc *BankKeeperBurnCoinsFunc - // MintCoinsFunc is an instance of a mock function object controlling - // the behavior of the method MintCoins. - MintCoinsFunc *BankKeeperMintCoinsFunc - // SendCoinsFromAccountToModuleFunc is an instance of a mock function - // object controlling the behavior of the method - // SendCoinsFromAccountToModule. - SendCoinsFromAccountToModuleFunc *BankKeeperSendCoinsFromAccountToModuleFunc - // SendCoinsFromModuleToAccountFunc is an instance of a mock function - // object controlling the behavior of the method - // SendCoinsFromModuleToAccount. - SendCoinsFromModuleToAccountFunc *BankKeeperSendCoinsFromModuleToAccountFunc + ctrl *gomock.Controller + recorder *MockBankKeeperMockRecorder } -// NewMockBankKeeper creates a new mock of the BankKeeper interface. All -// methods return zero values for all results, unless overwritten. -func NewMockBankKeeper() *MockBankKeeper { - return &MockBankKeeper{ - BurnCoinsFunc: &BankKeeperBurnCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) (r0 error) { - return - }, - }, - MintCoinsFunc: &BankKeeperMintCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) (r0 error) { - return - }, - }, - SendCoinsFromAccountToModuleFunc: &BankKeeperSendCoinsFromAccountToModuleFunc{ - defaultHook: func(types.Context, types.AccAddress, string, types.Coins) (r0 error) { - return - }, - }, - SendCoinsFromModuleToAccountFunc: &BankKeeperSendCoinsFromModuleToAccountFunc{ - defaultHook: func(types.Context, string, types.AccAddress, types.Coins) (r0 error) { - return - }, - }, - } +// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper. +type MockBankKeeperMockRecorder struct { + mock *MockBankKeeper } -// NewStrictMockBankKeeper creates a new mock of the BankKeeper interface. -// All methods panic on invocation, unless overwritten. -func NewStrictMockBankKeeper() *MockBankKeeper { - return &MockBankKeeper{ - BurnCoinsFunc: &BankKeeperBurnCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.BurnCoins") - }, - }, - MintCoinsFunc: &BankKeeperMintCoinsFunc{ - defaultHook: func(types.Context, string, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.MintCoins") - }, - }, - SendCoinsFromAccountToModuleFunc: &BankKeeperSendCoinsFromAccountToModuleFunc{ - defaultHook: func(types.Context, types.AccAddress, string, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.SendCoinsFromAccountToModule") - }, - }, - SendCoinsFromModuleToAccountFunc: &BankKeeperSendCoinsFromModuleToAccountFunc{ - defaultHook: func(types.Context, string, types.AccAddress, types.Coins) error { - panic("unexpected invocation of MockBankKeeper.SendCoinsFromModuleToAccount") - }, - }, - } +// NewMockBankKeeper creates a new mock instance. +func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper { + mock := &MockBankKeeper{ctrl: ctrl} + mock.recorder = &MockBankKeeperMockRecorder{mock} + return mock } -// NewMockBankKeeperFrom creates a new mock of the MockBankKeeper interface. -// All methods delegate to the given implementation, unless overwritten. -func NewMockBankKeeperFrom(i metoken.BankKeeper) *MockBankKeeper { - return &MockBankKeeper{ - BurnCoinsFunc: &BankKeeperBurnCoinsFunc{ - defaultHook: i.BurnCoins, - }, - MintCoinsFunc: &BankKeeperMintCoinsFunc{ - defaultHook: i.MintCoins, - }, - SendCoinsFromAccountToModuleFunc: &BankKeeperSendCoinsFromAccountToModuleFunc{ - defaultHook: i.SendCoinsFromAccountToModule, - }, - SendCoinsFromModuleToAccountFunc: &BankKeeperSendCoinsFromModuleToAccountFunc{ - defaultHook: i.SendCoinsFromModuleToAccount, - }, - } +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { + return m.recorder } -// BankKeeperBurnCoinsFunc describes the behavior when the BurnCoins method -// of the parent MockBankKeeper instance is invoked. -type BankKeeperBurnCoinsFunc struct { - defaultHook func(types.Context, string, types.Coins) error - hooks []func(types.Context, string, types.Coins) error - history []BankKeeperBurnCoinsFuncCall - mutex sync.Mutex +// BurnCoins mocks base method. +func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amounts types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amounts) + ret0, _ := ret[0].(error) + return ret0 } -// BurnCoins delegates to the next hook function in the queue and stores the -// parameter and result values of this invocation. -func (m *MockBankKeeper) BurnCoins(v0 types.Context, v1 string, v2 types.Coins) error { - r0 := m.BurnCoinsFunc.nextHook()(v0, v1, v2) - m.BurnCoinsFunc.appendCall(BankKeeperBurnCoinsFuncCall{v0, v1, v2, r0}) - return r0 +// BurnCoins indicates an expected call of BurnCoins. +func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amounts interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), ctx, moduleName, amounts) } -// SetDefaultHook sets function that is called when the BurnCoins method of -// the parent MockBankKeeper instance is invoked and the hook queue is -// empty. -func (f *BankKeeperBurnCoinsFunc) SetDefaultHook(hook func(types.Context, string, types.Coins) error) { - f.defaultHook = hook +// MintCoins mocks base method. +func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amounts types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amounts) + ret0, _ := ret[0].(error) + return ret0 } -// PushHook adds a function to the end of hook queue. Each invocation of the -// BurnCoins method of the parent MockBankKeeper instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *BankKeeperBurnCoinsFunc) PushHook(hook func(types.Context, string, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// MintCoins indicates an expected call of MintCoins. +func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amounts interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), ctx, moduleName, amounts) } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperBurnCoinsFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, string, types.Coins) error { - return r0 - }) +// SendCoinsFromAccountToModule mocks base method. +func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt) + ret0, _ := ret[0].(error) + return ret0 } -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperBurnCoinsFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, string, types.Coins) error { - return r0 - }) +// SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) } -func (f *BankKeeperBurnCoinsFunc) nextHook() func(types.Context, string, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperBurnCoinsFunc) appendCall(r0 BankKeeperBurnCoinsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of BankKeeperBurnCoinsFuncCall objects -// describing the invocations of this function. -func (f *BankKeeperBurnCoinsFunc) History() []BankKeeperBurnCoinsFuncCall { - f.mutex.Lock() - history := make([]BankKeeperBurnCoinsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperBurnCoinsFuncCall is an object that describes an invocation of -// method BurnCoins on an instance of MockBankKeeper. -type BankKeeperBurnCoinsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperBurnCoinsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperBurnCoinsFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// BankKeeperMintCoinsFunc describes the behavior when the MintCoins method -// of the parent MockBankKeeper instance is invoked. -type BankKeeperMintCoinsFunc struct { - defaultHook func(types.Context, string, types.Coins) error - hooks []func(types.Context, string, types.Coins) error - history []BankKeeperMintCoinsFuncCall - mutex sync.Mutex -} - -// MintCoins delegates to the next hook function in the queue and stores the -// parameter and result values of this invocation. -func (m *MockBankKeeper) MintCoins(v0 types.Context, v1 string, v2 types.Coins) error { - r0 := m.MintCoinsFunc.nextHook()(v0, v1, v2) - m.MintCoinsFunc.appendCall(BankKeeperMintCoinsFuncCall{v0, v1, v2, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the MintCoins method of -// the parent MockBankKeeper instance is invoked and the hook queue is -// empty. -func (f *BankKeeperMintCoinsFunc) SetDefaultHook(hook func(types.Context, string, types.Coins) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// MintCoins method of the parent MockBankKeeper instance invokes the hook -// at the front of the queue and discards it. After the queue is empty, the -// default hook function is invoked for any future action. -func (f *BankKeeperMintCoinsFunc) PushHook(hook func(types.Context, string, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperMintCoinsFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, string, types.Coins) error { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperMintCoinsFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, string, types.Coins) error { - return r0 - }) -} - -func (f *BankKeeperMintCoinsFunc) nextHook() func(types.Context, string, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperMintCoinsFunc) appendCall(r0 BankKeeperMintCoinsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of BankKeeperMintCoinsFuncCall objects -// describing the invocations of this function. -func (f *BankKeeperMintCoinsFunc) History() []BankKeeperMintCoinsFuncCall { - f.mutex.Lock() - history := make([]BankKeeperMintCoinsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperMintCoinsFuncCall is an object that describes an invocation of -// method MintCoins on an instance of MockBankKeeper. -type BankKeeperMintCoinsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperMintCoinsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperMintCoinsFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// BankKeeperSendCoinsFromAccountToModuleFunc describes the behavior when -// the SendCoinsFromAccountToModule method of the parent MockBankKeeper -// instance is invoked. -type BankKeeperSendCoinsFromAccountToModuleFunc struct { - defaultHook func(types.Context, types.AccAddress, string, types.Coins) error - hooks []func(types.Context, types.AccAddress, string, types.Coins) error - history []BankKeeperSendCoinsFromAccountToModuleFuncCall - mutex sync.Mutex -} - -// SendCoinsFromAccountToModule delegates to the next hook function in the -// queue and stores the parameter and result values of this invocation. -func (m *MockBankKeeper) SendCoinsFromAccountToModule(v0 types.Context, v1 types.AccAddress, v2 string, v3 types.Coins) error { - r0 := m.SendCoinsFromAccountToModuleFunc.nextHook()(v0, v1, v2, v3) - m.SendCoinsFromAccountToModuleFunc.appendCall(BankKeeperSendCoinsFromAccountToModuleFuncCall{v0, v1, v2, v3, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the -// SendCoinsFromAccountToModule method of the parent MockBankKeeper instance -// is invoked and the hook queue is empty. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) SetDefaultHook(hook func(types.Context, types.AccAddress, string, types.Coins) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// SendCoinsFromAccountToModule method of the parent MockBankKeeper instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) PushHook(hook func(types.Context, types.AccAddress, string, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, types.AccAddress, string, types.Coins) error { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, types.AccAddress, string, types.Coins) error { - return r0 - }) -} - -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) nextHook() func(types.Context, types.AccAddress, string, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) appendCall(r0 BankKeeperSendCoinsFromAccountToModuleFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// BankKeeperSendCoinsFromAccountToModuleFuncCall objects describing the -// invocations of this function. -func (f *BankKeeperSendCoinsFromAccountToModuleFunc) History() []BankKeeperSendCoinsFromAccountToModuleFuncCall { - f.mutex.Lock() - history := make([]BankKeeperSendCoinsFromAccountToModuleFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperSendCoinsFromAccountToModuleFuncCall is an object that -// describes an invocation of method SendCoinsFromAccountToModule on an -// instance of MockBankKeeper. -type BankKeeperSendCoinsFromAccountToModuleFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.AccAddress - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 string - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperSendCoinsFromAccountToModuleFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperSendCoinsFromAccountToModuleFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// BankKeeperSendCoinsFromModuleToAccountFunc describes the behavior when -// the SendCoinsFromModuleToAccount method of the parent MockBankKeeper -// instance is invoked. -type BankKeeperSendCoinsFromModuleToAccountFunc struct { - defaultHook func(types.Context, string, types.AccAddress, types.Coins) error - hooks []func(types.Context, string, types.AccAddress, types.Coins) error - history []BankKeeperSendCoinsFromModuleToAccountFuncCall - mutex sync.Mutex -} - -// SendCoinsFromModuleToAccount delegates to the next hook function in the -// queue and stores the parameter and result values of this invocation. -func (m *MockBankKeeper) SendCoinsFromModuleToAccount(v0 types.Context, v1 string, v2 types.AccAddress, v3 types.Coins) error { - r0 := m.SendCoinsFromModuleToAccountFunc.nextHook()(v0, v1, v2, v3) - m.SendCoinsFromModuleToAccountFunc.appendCall(BankKeeperSendCoinsFromModuleToAccountFuncCall{v0, v1, v2, v3, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the -// SendCoinsFromModuleToAccount method of the parent MockBankKeeper instance -// is invoked and the hook queue is empty. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) SetDefaultHook(hook func(types.Context, string, types.AccAddress, types.Coins) error) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// SendCoinsFromModuleToAccount method of the parent MockBankKeeper instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) PushHook(hook func(types.Context, string, types.AccAddress, types.Coins) error) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// SendCoinsFromModuleToAccount mocks base method. +func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt) + ret0, _ := ret[0].(error) + return ret0 } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) SetDefaultReturn(r0 error) { - f.SetDefaultHook(func(types.Context, string, types.AccAddress, types.Coins) error { - return r0 - }) +// SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, amt interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), ctx, senderModule, recipientAddr, amt) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) PushReturn(r0 error) { - f.PushHook(func(types.Context, string, types.AccAddress, types.Coins) error { - return r0 - }) -} - -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) nextHook() func(types.Context, string, types.AccAddress, types.Coins) error { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) appendCall(r0 BankKeeperSendCoinsFromModuleToAccountFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of -// BankKeeperSendCoinsFromModuleToAccountFuncCall objects describing the -// invocations of this function. -func (f *BankKeeperSendCoinsFromModuleToAccountFunc) History() []BankKeeperSendCoinsFromModuleToAccountFuncCall { - f.mutex.Lock() - history := make([]BankKeeperSendCoinsFromModuleToAccountFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// BankKeeperSendCoinsFromModuleToAccountFuncCall is an object that -// describes an invocation of method SendCoinsFromModuleToAccount on an -// instance of MockBankKeeper. -type BankKeeperSendCoinsFromModuleToAccountFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.AccAddress - // Arg3 is the value of the 4th argument passed to this method - // invocation. - Arg3 types.Coins - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c BankKeeperSendCoinsFromModuleToAccountFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2, c.Arg3} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c BankKeeperSendCoinsFromModuleToAccountFuncCall) Results() []interface{} { - return []interface{}{c.Result0} -} - -// MockLeverageKeeper is a mock implementation of the LeverageKeeper -// interface (from the package github.com/umee-network/umee/v5/x/metoken) -// used for unit testing. +// MockLeverageKeeper is a mock of LeverageKeeper interface. type MockLeverageKeeper struct { - // Token2uTokenRateFunc is an instance of a mock function object - // controlling the behavior of the method Token2uTokenRate. - Token2uTokenRateFunc *LeverageKeeperExchangeTokenFunc - // UToken2TokenRateFunc is an instance of a mock function object - // controlling the behavior of the method UToken2TokenRate. - UToken2TokenRateFunc *LeverageKeeperUToken2TokenRateFunc - // GetAllSuppliedFunc is an instance of a mock function object - // controlling the behavior of the method GetAllSupplied. - GetAllSuppliedFunc *LeverageKeeperGetAllSuppliedFunc - // GetTokenSettingsFunc is an instance of a mock function object - // controlling the behavior of the method GetTokenSettings. - GetTokenSettingsFunc *LeverageKeeperGetTokenSettingsFunc - // GetTotalSupplyFunc is an instance of a mock function object - // controlling the behavior of the method GetTotalSupply. - GetTotalSupplyFunc *LeverageKeeperGetTotalSupplyFunc - // ModuleMaxWithdrawFunc is an instance of a mock function object - // controlling the behavior of the method ModuleMaxWithdraw. - ModuleMaxWithdrawFunc *LeverageKeeperModuleMaxWithdrawFunc - // SupplyFromModuleFunc is an instance of a mock function object - // controlling the behavior of the method SupplyFromModule. - SupplyFromModuleFunc *LeverageKeeperSupplyFromModuleFunc - // WithdrawToModuleFunc is an instance of a mock function object - // controlling the behavior of the method WithdrawToModule. - WithdrawToModuleFunc *LeverageKeeperWithdrawToModuleFunc -} - -// NewMockLeverageKeeper creates a new mock of the LeverageKeeper interface. -// All methods return zero values for all results, unless overwritten. -func NewMockLeverageKeeper() *MockLeverageKeeper { - return &MockLeverageKeeper{ - Token2uTokenRateFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { - return - }, - }, - UToken2TokenRateFunc: &LeverageKeeperUToken2TokenRateFunc{ - defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { - return - }, - }, - GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ - defaultHook: func(types.Context, types.AccAddress) (r0 types.Coins, r1 error) { - return - }, - }, - GetTokenSettingsFunc: &LeverageKeeperGetTokenSettingsFunc{ - defaultHook: func(types.Context, string) (r0 types1.Token, r1 error) { - return - }, - }, - GetTotalSupplyFunc: &LeverageKeeperGetTotalSupplyFunc{ - defaultHook: func(types.Context, string) (r0 types.Coin, r1 error) { - return - }, - }, - ModuleMaxWithdrawFunc: &LeverageKeeperModuleMaxWithdrawFunc{ - defaultHook: func(types.Context, types.Coin) (r0 math.Int, r1 error) { - return - }, - }, - SupplyFromModuleFunc: &LeverageKeeperSupplyFromModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (r0 types.Coin, r1 bool, r2 error) { - return - }, - }, - WithdrawToModuleFunc: &LeverageKeeperWithdrawToModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (r0 types.Coin, r1 bool, r2 error) { - return - }, - }, - } + ctrl *gomock.Controller + recorder *MockLeverageKeeperMockRecorder } -// NewStrictMockLeverageKeeper creates a new mock of the LeverageKeeper -// interface. All methods panic on invocation, unless overwritten. -func NewStrictMockLeverageKeeper() *MockLeverageKeeper { - return &MockLeverageKeeper{ - Token2uTokenRateFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.Token2uTokenRate") - }, - }, - UToken2TokenRateFunc: &LeverageKeeperUToken2TokenRateFunc{ - defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.UToken2TokenRate") - }, - }, - GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ - defaultHook: func(types.Context, types.AccAddress) (types.Coins, error) { - panic("unexpected invocation of MockLeverageKeeper.GetAllSupplied") - }, - }, - GetTokenSettingsFunc: &LeverageKeeperGetTokenSettingsFunc{ - defaultHook: func(types.Context, string) (types1.Token, error) { - panic("unexpected invocation of MockLeverageKeeper.GetTokenSettings") - }, - }, - GetTotalSupplyFunc: &LeverageKeeperGetTotalSupplyFunc{ - defaultHook: func(types.Context, string) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.GetTotalSupply") - }, - }, - ModuleMaxWithdrawFunc: &LeverageKeeperModuleMaxWithdrawFunc{ - defaultHook: func(types.Context, types.Coin) (math.Int, error) { - panic("unexpected invocation of MockLeverageKeeper.ModuleMaxWithdraw") - }, - }, - SupplyFromModuleFunc: &LeverageKeeperSupplyFromModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (types.Coin, bool, error) { - panic("unexpected invocation of MockLeverageKeeper.SupplyFromModule") - }, - }, - WithdrawToModuleFunc: &LeverageKeeperWithdrawToModuleFunc{ - defaultHook: func(types.Context, string, types.Coin) (types.Coin, bool, error) { - panic("unexpected invocation of MockLeverageKeeper.WithdrawToModule") - }, - }, - } +// MockLeverageKeeperMockRecorder is the mock recorder for MockLeverageKeeper. +type MockLeverageKeeperMockRecorder struct { + mock *MockLeverageKeeper } -// NewMockLeverageKeeperFrom creates a new mock of the MockLeverageKeeper -// interface. All methods delegate to the given implementation, unless -// overwritten. -func NewMockLeverageKeeperFrom(i metoken.LeverageKeeper) *MockLeverageKeeper { - return &MockLeverageKeeper{ - Token2uTokenRateFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: i.Token2uTokenRate, - }, - UToken2TokenRateFunc: &LeverageKeeperUToken2TokenRateFunc{ - defaultHook: i.UToken2TokenRate, - }, - GetAllSuppliedFunc: &LeverageKeeperGetAllSuppliedFunc{ - defaultHook: i.GetAllSupplied, - }, - GetTokenSettingsFunc: &LeverageKeeperGetTokenSettingsFunc{ - defaultHook: i.GetTokenSettings, - }, - GetTotalSupplyFunc: &LeverageKeeperGetTotalSupplyFunc{ - defaultHook: i.GetTotalSupply, - }, - ModuleMaxWithdrawFunc: &LeverageKeeperModuleMaxWithdrawFunc{ - defaultHook: i.ModuleMaxWithdraw, - }, - SupplyFromModuleFunc: &LeverageKeeperSupplyFromModuleFunc{ - defaultHook: i.SupplyFromModule, - }, - WithdrawToModuleFunc: &LeverageKeeperWithdrawToModuleFunc{ - defaultHook: i.WithdrawToModule, - }, - } +// NewMockLeverageKeeper creates a new mock instance. +func NewMockLeverageKeeper(ctrl *gomock.Controller) *MockLeverageKeeper { + mock := &MockLeverageKeeper{ctrl: ctrl} + mock.recorder = &MockLeverageKeeperMockRecorder{mock} + return mock } -// LeverageKeeperToken2uTokenRateFunc describes the behavior when the -// Token2uTokenRate method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperToken2uTokenRateFunc struct { - defaultHook func(types.Context, types.Coin) (types.Coin, error) - hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperToken2uTokenRateFuncCall - mutex sync.Mutex +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLeverageKeeper) EXPECT() *MockLeverageKeeperMockRecorder { + return m.recorder } -// Token2uTokenRate delegates to the next hook function in the queue and stores -// the parameter and result values of this invocation. -func (m *MockLeverageKeeper) Token2uTokenRate(v0 types.Context, v1 types.Coin) (types.Coin, error) { - r0, r1 := m.Token2uTokenRateFunc.nextHook()(v0, v1) - m.Token2uTokenRateFunc.appendCall(LeverageKeeperExchangeTokenFuncCall{v0, v1, r0, r1}) - return r0, r1 +// GetAllSupplied mocks base method. +func (m *MockLeverageKeeper) GetAllSupplied(ctx types.Context, supplierAddr types.AccAddress) (types.Coins, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAllSupplied", ctx, supplierAddr) + ret0, _ := ret[0].(types.Coins) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultHook sets function that is called when the Token2uTokenRate method -// of the parent MockLeverageKeeper instance is invoked and the hook queue -// is empty. -func (f *LeverageKeeperToken2uTokenRateFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.defaultHook = hook +// GetAllSupplied indicates an expected call of GetAllSupplied. +func (mr *MockLeverageKeeperMockRecorder) GetAllSupplied(ctx, supplierAddr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllSupplied", reflect.TypeOf((*MockLeverageKeeper)(nil).GetAllSupplied), ctx, supplierAddr) } -// PushHook adds a function to the end of hook queue. Each invocation of the -// Token2uTokenRate method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperToken2uTokenRateFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// GetTokenSettings mocks base method. +func (m *MockLeverageKeeper) GetTokenSettings(ctx types.Context, denom string) (types0.Token, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTokenSettings", ctx, denom) + ret0, _ := ret[0].(types0.Token) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperToken2uTokenRateFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// GetTokenSettings indicates an expected call of GetTokenSettings. +func (mr *MockLeverageKeeperMockRecorder) GetTokenSettings(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTokenSettings), ctx, denom) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperToken2uTokenRateFunc) PushReturn(r0 types.Coin, r1 error) { - f.PushHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// GetTotalSupply mocks base method. +func (m *MockLeverageKeeper) GetTotalSupply(ctx types.Context, denom string) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTotalSupply", ctx, denom) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -func (f *LeverageKeeperToken2uTokenRateFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperToken2uTokenRateFunc) appendCall(r0 LeverageKeeperExchangeTokenFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperToken2uTokenRateFuncCall objects -// describing the invocations of this function. -func (f *LeverageKeeperToken2uTokenRateFunc) History() []LeverageKeeperExchangeTokenFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperToken2uTokenRateFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history +// GetTotalSupply indicates an expected call of GetTotalSupply. +func (mr *MockLeverageKeeperMockRecorder) GetTotalSupply(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTotalSupply", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTotalSupply), ctx, denom) } -// LeverageKeeperToken2uTokenRateFuncCall is an object that describes an -// invocation of method Token2uTokenRate on an instance of MockLeverageKeeper. -type LeverageKeeperToken2uTokenRateFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error +// ModuleMaxWithdraw mocks base method. +func (m *MockLeverageKeeper) ModuleMaxWithdraw(ctx types.Context, spendableUTokens types.Coin) (math.Int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ModuleMaxWithdraw", ctx, spendableUTokens) + ret0, _ := ret[0].(math.Int) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperToken2uTokenRateFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} +// ModuleMaxWithdraw indicates an expected call of ModuleMaxWithdraw. +func (mr *MockLeverageKeeperMockRecorder) ModuleMaxWithdraw(ctx, spendableUTokens interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModuleMaxWithdraw", reflect.TypeOf((*MockLeverageKeeper)(nil).ModuleMaxWithdraw), ctx, spendableUTokens) } -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperToken2uTokenRateFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} +// SupplyFromModule mocks base method. +func (m *MockLeverageKeeper) SupplyFromModule(ctx types.Context, fromModule string, coin types.Coin) (types.Coin, bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SupplyFromModule", ctx, fromModule, coin) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(bool) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } -// LeverageKeeperUToken2TokenRateFunc describes the behavior when the -// UToken2TokenRate method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperUToken2TokenRateFunc struct { - defaultHook func(types.Context, types.Coin) (types.Coin, error) - hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperUToken2TokenRateFuncCall - mutex sync.Mutex +// SupplyFromModule indicates an expected call of SupplyFromModule. +func (mr *MockLeverageKeeperMockRecorder) SupplyFromModule(ctx, fromModule, coin interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupplyFromModule", reflect.TypeOf((*MockLeverageKeeper)(nil).SupplyFromModule), ctx, fromModule, coin) } -// UToken2TokenRate delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) UToken2TokenRate(v0 types.Context, v1 types.Coin) (types.Coin, error) { - r0, r1 := m.UToken2TokenRateFunc.nextHook()(v0, v1) - m.UToken2TokenRateFunc.appendCall(LeverageKeeperUToken2TokenRateFuncCall{v0, v1, r0, r1}) - return r0, r1 +// Token2uTokenRate mocks base method. +func (m *MockLeverageKeeper) Token2uTokenRate(ctx types.Context, token types.Coin) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Token2uTokenRate", ctx, token) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultHook sets function that is called when the UToken2TokenRate -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperUToken2TokenRateFunc) SetDefaultHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.defaultHook = hook +// Token2uTokenRate indicates an expected call of Token2uTokenRate. +func (mr *MockLeverageKeeperMockRecorder) Token2uTokenRate(ctx, token interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Token2uTokenRate", reflect.TypeOf((*MockLeverageKeeper)(nil).Token2uTokenRate), ctx, token) } -// PushHook adds a function to the end of hook queue. Each invocation of the -// UToken2TokenRate method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperUToken2TokenRateFunc) PushHook(hook func(types.Context, types.Coin) (types.Coin, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// UToken2TokenRate mocks base method. +func (m *MockLeverageKeeper) UToken2TokenRate(ctx types.Context, uToken types.Coin) (types.Coin, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UToken2TokenRate", ctx, uToken) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperUToken2TokenRateFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// UToken2TokenRate indicates an expected call of UToken2TokenRate. +func (mr *MockLeverageKeeperMockRecorder) UToken2TokenRate(ctx, uToken interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UToken2TokenRate", reflect.TypeOf((*MockLeverageKeeper)(nil).UToken2TokenRate), ctx, uToken) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperUToken2TokenRateFunc) PushReturn(r0 types.Coin, r1 error) { - f.PushHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// WithdrawToModule mocks base method. +func (m *MockLeverageKeeper) WithdrawToModule(ctx types.Context, toModule string, uToken types.Coin) (types.Coin, bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WithdrawToModule", ctx, toModule, uToken) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(bool) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } -func (f *LeverageKeeperUToken2TokenRateFunc) nextHook() func(types.Context, types.Coin) (types.Coin, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook +// WithdrawToModule indicates an expected call of WithdrawToModule. +func (mr *MockLeverageKeeperMockRecorder) WithdrawToModule(ctx, toModule, uToken interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithdrawToModule", reflect.TypeOf((*MockLeverageKeeper)(nil).WithdrawToModule), ctx, toModule, uToken) } -func (f *LeverageKeeperUToken2TokenRateFunc) appendCall(r0 LeverageKeeperUToken2TokenRateFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperUToken2TokenRateFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperUToken2TokenRateFunc) History() []LeverageKeeperUToken2TokenRateFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperUToken2TokenRateFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperUToken2TokenRateFuncCall is an object that describes an -// invocation of method UToken2TokenRate on an instance of MockLeverageKeeper. -type LeverageKeeperUToken2TokenRateFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperUToken2TokenRateFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperUToken2TokenRateFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperGetAllSuppliedFunc describes the behavior when the -// GetAllSupplied method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperGetAllSuppliedFunc struct { - defaultHook func(types.Context, types.AccAddress) (types.Coins, error) - hooks []func(types.Context, types.AccAddress) (types.Coins, error) - history []LeverageKeeperGetAllSuppliedFuncCall - mutex sync.Mutex -} - -// GetAllSupplied delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) GetAllSupplied(v0 types.Context, v1 types.AccAddress) (types.Coins, error) { - r0, r1 := m.GetAllSuppliedFunc.nextHook()(v0, v1) - m.GetAllSuppliedFunc.appendCall(LeverageKeeperGetAllSuppliedFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetAllSupplied -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperGetAllSuppliedFunc) SetDefaultHook(hook func(types.Context, types.AccAddress) (types.Coins, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetAllSupplied method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperGetAllSuppliedFunc) PushHook(hook func(types.Context, types.AccAddress) (types.Coins, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperGetAllSuppliedFunc) SetDefaultReturn(r0 types.Coins, r1 error) { - f.SetDefaultHook(func(types.Context, types.AccAddress) (types.Coins, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperGetAllSuppliedFunc) PushReturn(r0 types.Coins, r1 error) { - f.PushHook(func(types.Context, types.AccAddress) (types.Coins, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperGetAllSuppliedFunc) nextHook() func(types.Context, types.AccAddress) (types.Coins, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperGetAllSuppliedFunc) appendCall(r0 LeverageKeeperGetAllSuppliedFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperGetAllSuppliedFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperGetAllSuppliedFunc) History() []LeverageKeeperGetAllSuppliedFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperGetAllSuppliedFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperGetAllSuppliedFuncCall is an object that describes an -// invocation of method GetAllSupplied on an instance of MockLeverageKeeper. -type LeverageKeeperGetAllSuppliedFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.AccAddress - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coins - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperGetAllSuppliedFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperGetAllSuppliedFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperGetTokenSettingsFunc describes the behavior when the -// GetTokenSettings method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperGetTokenSettingsFunc struct { - defaultHook func(types.Context, string) (types1.Token, error) - hooks []func(types.Context, string) (types1.Token, error) - history []LeverageKeeperGetTokenSettingsFuncCall - mutex sync.Mutex -} - -// GetTokenSettings delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) GetTokenSettings(v0 types.Context, v1 string) (types1.Token, error) { - r0, r1 := m.GetTokenSettingsFunc.nextHook()(v0, v1) - m.GetTokenSettingsFunc.appendCall(LeverageKeeperGetTokenSettingsFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetTokenSettings -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperGetTokenSettingsFunc) SetDefaultHook(hook func(types.Context, string) (types1.Token, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetTokenSettings method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperGetTokenSettingsFunc) PushHook(hook func(types.Context, string) (types1.Token, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperGetTokenSettingsFunc) SetDefaultReturn(r0 types1.Token, r1 error) { - f.SetDefaultHook(func(types.Context, string) (types1.Token, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperGetTokenSettingsFunc) PushReturn(r0 types1.Token, r1 error) { - f.PushHook(func(types.Context, string) (types1.Token, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperGetTokenSettingsFunc) nextHook() func(types.Context, string) (types1.Token, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperGetTokenSettingsFunc) appendCall(r0 LeverageKeeperGetTokenSettingsFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperGetTokenSettingsFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperGetTokenSettingsFunc) History() []LeverageKeeperGetTokenSettingsFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperGetTokenSettingsFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperGetTokenSettingsFuncCall is an object that describes an -// invocation of method GetTokenSettings on an instance of -// MockLeverageKeeper. -type LeverageKeeperGetTokenSettingsFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types1.Token - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperGetTokenSettingsFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperGetTokenSettingsFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperGetTotalSupplyFunc describes the behavior when the -// GetTotalSupply method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperGetTotalSupplyFunc struct { - defaultHook func(types.Context, string) (types.Coin, error) - hooks []func(types.Context, string) (types.Coin, error) - history []LeverageKeeperGetTotalSupplyFuncCall - mutex sync.Mutex -} - -// GetTotalSupply delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) GetTotalSupply(v0 types.Context, v1 string) (types.Coin, error) { - r0, r1 := m.GetTotalSupplyFunc.nextHook()(v0, v1) - m.GetTotalSupplyFunc.appendCall(LeverageKeeperGetTotalSupplyFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the GetTotalSupply -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperGetTotalSupplyFunc) SetDefaultHook(hook func(types.Context, string) (types.Coin, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// GetTotalSupply method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperGetTotalSupplyFunc) PushHook(hook func(types.Context, string) (types.Coin, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperGetTotalSupplyFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, string) (types.Coin, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperGetTotalSupplyFunc) PushReturn(r0 types.Coin, r1 error) { - f.PushHook(func(types.Context, string) (types.Coin, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperGetTotalSupplyFunc) nextHook() func(types.Context, string) (types.Coin, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperGetTotalSupplyFunc) appendCall(r0 LeverageKeeperGetTotalSupplyFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperGetTotalSupplyFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperGetTotalSupplyFunc) History() []LeverageKeeperGetTotalSupplyFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperGetTotalSupplyFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperGetTotalSupplyFuncCall is an object that describes an -// invocation of method GetTotalSupply on an instance of MockLeverageKeeper. -type LeverageKeeperGetTotalSupplyFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperGetTotalSupplyFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperGetTotalSupplyFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperModuleMaxWithdrawFunc describes the behavior when the -// ModuleMaxWithdraw method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperModuleMaxWithdrawFunc struct { - defaultHook func(types.Context, types.Coin) (math.Int, error) - hooks []func(types.Context, types.Coin) (math.Int, error) - history []LeverageKeeperModuleMaxWithdrawFuncCall - mutex sync.Mutex -} - -// ModuleMaxWithdraw delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) ModuleMaxWithdraw(v0 types.Context, v1 types.Coin) (math.Int, error) { - r0, r1 := m.ModuleMaxWithdrawFunc.nextHook()(v0, v1) - m.ModuleMaxWithdrawFunc.appendCall(LeverageKeeperModuleMaxWithdrawFuncCall{v0, v1, r0, r1}) - return r0, r1 -} - -// SetDefaultHook sets function that is called when the ModuleMaxWithdraw -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperModuleMaxWithdrawFunc) SetDefaultHook(hook func(types.Context, types.Coin) (math.Int, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// ModuleMaxWithdraw method of the parent MockLeverageKeeper instance -// invokes the hook at the front of the queue and discards it. After the -// queue is empty, the default hook function is invoked for any future -// action. -func (f *LeverageKeeperModuleMaxWithdrawFunc) PushHook(hook func(types.Context, types.Coin) (math.Int, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperModuleMaxWithdrawFunc) SetDefaultReturn(r0 math.Int, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (math.Int, error) { - return r0, r1 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperModuleMaxWithdrawFunc) PushReturn(r0 math.Int, r1 error) { - f.PushHook(func(types.Context, types.Coin) (math.Int, error) { - return r0, r1 - }) -} - -func (f *LeverageKeeperModuleMaxWithdrawFunc) nextHook() func(types.Context, types.Coin) (math.Int, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperModuleMaxWithdrawFunc) appendCall(r0 LeverageKeeperModuleMaxWithdrawFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperModuleMaxWithdrawFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperModuleMaxWithdrawFunc) History() []LeverageKeeperModuleMaxWithdrawFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperModuleMaxWithdrawFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperModuleMaxWithdrawFuncCall is an object that describes an -// invocation of method ModuleMaxWithdraw on an instance of -// MockLeverageKeeper. -type LeverageKeeperModuleMaxWithdrawFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 math.Int - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperModuleMaxWithdrawFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperModuleMaxWithdrawFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1} -} - -// LeverageKeeperSupplyFromModuleFunc describes the behavior when the -// SupplyFromModule method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperSupplyFromModuleFunc struct { - defaultHook func(types.Context, string, types.Coin) (types.Coin, bool, error) - hooks []func(types.Context, string, types.Coin) (types.Coin, bool, error) - history []LeverageKeeperSupplyFromModuleFuncCall - mutex sync.Mutex -} - -// SupplyFromModule delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) SupplyFromModule(v0 types.Context, v1 string, v2 types.Coin) (types.Coin, bool, error) { - r0, r1, r2 := m.SupplyFromModuleFunc.nextHook()(v0, v1, v2) - m.SupplyFromModuleFunc.appendCall(LeverageKeeperSupplyFromModuleFuncCall{v0, v1, v2, r0, r1, r2}) - return r0, r1, r2 -} - -// SetDefaultHook sets function that is called when the SupplyFromModule -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperSupplyFromModuleFunc) SetDefaultHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// SupplyFromModule method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperSupplyFromModuleFunc) PushHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperSupplyFromModuleFunc) SetDefaultReturn(r0 types.Coin, r1 bool, r2 error) { - f.SetDefaultHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperSupplyFromModuleFunc) PushReturn(r0 types.Coin, r1 bool, r2 error) { - f.PushHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -func (f *LeverageKeeperSupplyFromModuleFunc) nextHook() func(types.Context, string, types.Coin) (types.Coin, bool, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperSupplyFromModuleFunc) appendCall(r0 LeverageKeeperSupplyFromModuleFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperSupplyFromModuleFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperSupplyFromModuleFunc) History() []LeverageKeeperSupplyFromModuleFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperSupplyFromModuleFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperSupplyFromModuleFuncCall is an object that describes an -// invocation of method SupplyFromModule on an instance of -// MockLeverageKeeper. -type LeverageKeeperSupplyFromModuleFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 bool - // Result2 is the value of the 3rd result returned from this method - // invocation. - Result2 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperSupplyFromModuleFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperSupplyFromModuleFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1, c.Result2} -} - -// LeverageKeeperWithdrawToModuleFunc describes the behavior when the -// WithdrawToModule method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperWithdrawToModuleFunc struct { - defaultHook func(types.Context, string, types.Coin) (types.Coin, bool, error) - hooks []func(types.Context, string, types.Coin) (types.Coin, bool, error) - history []LeverageKeeperWithdrawToModuleFuncCall - mutex sync.Mutex -} - -// WithdrawToModule delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockLeverageKeeper) WithdrawToModule(v0 types.Context, v1 string, v2 types.Coin) (types.Coin, bool, error) { - r0, r1, r2 := m.WithdrawToModuleFunc.nextHook()(v0, v1, v2) - m.WithdrawToModuleFunc.appendCall(LeverageKeeperWithdrawToModuleFuncCall{v0, v1, v2, r0, r1, r2}) - return r0, r1, r2 -} - -// SetDefaultHook sets function that is called when the WithdrawToModule -// method of the parent MockLeverageKeeper instance is invoked and the hook -// queue is empty. -func (f *LeverageKeeperWithdrawToModuleFunc) SetDefaultHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// WithdrawToModule method of the parent MockLeverageKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *LeverageKeeperWithdrawToModuleFunc) PushHook(hook func(types.Context, string, types.Coin) (types.Coin, bool, error)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *LeverageKeeperWithdrawToModuleFunc) SetDefaultReturn(r0 types.Coin, r1 bool, r2 error) { - f.SetDefaultHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperWithdrawToModuleFunc) PushReturn(r0 types.Coin, r1 bool, r2 error) { - f.PushHook(func(types.Context, string, types.Coin) (types.Coin, bool, error) { - return r0, r1, r2 - }) -} - -func (f *LeverageKeeperWithdrawToModuleFunc) nextHook() func(types.Context, string, types.Coin) (types.Coin, bool, error) { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *LeverageKeeperWithdrawToModuleFunc) appendCall(r0 LeverageKeeperWithdrawToModuleFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperWithdrawToModuleFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperWithdrawToModuleFunc) History() []LeverageKeeperWithdrawToModuleFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperWithdrawToModuleFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history -} - -// LeverageKeeperWithdrawToModuleFuncCall is an object that describes an -// invocation of method WithdrawToModule on an instance of -// MockLeverageKeeper. -type LeverageKeeperWithdrawToModuleFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Arg1 is the value of the 2nd argument passed to this method - // invocation. - Arg1 string - // Arg2 is the value of the 3rd argument passed to this method - // invocation. - Arg2 types.Coin - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types.Coin - // Result1 is the value of the 2nd result returned from this method - // invocation. - Result1 bool - // Result2 is the value of the 3rd result returned from this method - // invocation. - Result2 error -} - -// Args returns an interface slice containing the arguments of this -// invocation. -func (c LeverageKeeperWithdrawToModuleFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1, c.Arg2} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperWithdrawToModuleFuncCall) Results() []interface{} { - return []interface{}{c.Result0, c.Result1, c.Result2} -} - -// MockOracleKeeper is a mock implementation of the OracleKeeper interface -// (from the package github.com/umee-network/umee/v5/x/metoken) used for -// unit testing. +// MockOracleKeeper is a mock of OracleKeeper interface. type MockOracleKeeper struct { - // AllMedianPricesFunc is an instance of a mock function object - // controlling the behavior of the method AllMedianPrices. - AllMedianPricesFunc *OracleKeeperAllMedianPricesFunc + ctrl *gomock.Controller + recorder *MockOracleKeeperMockRecorder } -// NewMockOracleKeeper creates a new mock of the OracleKeeper interface. All -// methods return zero values for all results, unless overwritten. -func NewMockOracleKeeper() *MockOracleKeeper { - return &MockOracleKeeper{ - AllMedianPricesFunc: &OracleKeeperAllMedianPricesFunc{ - defaultHook: func(types.Context) (r0 types2.Prices) { - return - }, - }, - } +// MockOracleKeeperMockRecorder is the mock recorder for MockOracleKeeper. +type MockOracleKeeperMockRecorder struct { + mock *MockOracleKeeper } -// NewStrictMockOracleKeeper creates a new mock of the OracleKeeper -// interface. All methods panic on invocation, unless overwritten. -func NewStrictMockOracleKeeper() *MockOracleKeeper { - return &MockOracleKeeper{ - AllMedianPricesFunc: &OracleKeeperAllMedianPricesFunc{ - defaultHook: func(types.Context) types2.Prices { - panic("unexpected invocation of MockOracleKeeper.AllMedianPrices") - }, - }, - } -} - -// NewMockOracleKeeperFrom creates a new mock of the MockOracleKeeper -// interface. All methods delegate to the given implementation, unless -// overwritten. -func NewMockOracleKeeperFrom(i metoken.OracleKeeper) *MockOracleKeeper { - return &MockOracleKeeper{ - AllMedianPricesFunc: &OracleKeeperAllMedianPricesFunc{ - defaultHook: i.AllMedianPrices, - }, - } -} - -// OracleKeeperAllMedianPricesFunc describes the behavior when the -// AllMedianPrices method of the parent MockOracleKeeper instance is -// invoked. -type OracleKeeperAllMedianPricesFunc struct { - defaultHook func(types.Context) types2.Prices - hooks []func(types.Context) types2.Prices - history []OracleKeeperAllMedianPricesFuncCall - mutex sync.Mutex -} - -// AllMedianPrices delegates to the next hook function in the queue and -// stores the parameter and result values of this invocation. -func (m *MockOracleKeeper) AllMedianPrices(v0 types.Context) types2.Prices { - r0 := m.AllMedianPricesFunc.nextHook()(v0) - m.AllMedianPricesFunc.appendCall(OracleKeeperAllMedianPricesFuncCall{v0, r0}) - return r0 -} - -// SetDefaultHook sets function that is called when the AllMedianPrices -// method of the parent MockOracleKeeper instance is invoked and the hook -// queue is empty. -func (f *OracleKeeperAllMedianPricesFunc) SetDefaultHook(hook func(types.Context) types2.Prices) { - f.defaultHook = hook -} - -// PushHook adds a function to the end of hook queue. Each invocation of the -// AllMedianPrices method of the parent MockOracleKeeper instance invokes -// the hook at the front of the queue and discards it. After the queue is -// empty, the default hook function is invoked for any future action. -func (f *OracleKeeperAllMedianPricesFunc) PushHook(hook func(types.Context) types2.Prices) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() -} - -// SetDefaultReturn calls SetDefaultHook with a function that returns the -// given values. -func (f *OracleKeeperAllMedianPricesFunc) SetDefaultReturn(r0 types2.Prices) { - f.SetDefaultHook(func(types.Context) types2.Prices { - return r0 - }) -} - -// PushReturn calls PushHook with a function that returns the given values. -func (f *OracleKeeperAllMedianPricesFunc) PushReturn(r0 types2.Prices) { - f.PushHook(func(types.Context) types2.Prices { - return r0 - }) -} - -func (f *OracleKeeperAllMedianPricesFunc) nextHook() func(types.Context) types2.Prices { - f.mutex.Lock() - defer f.mutex.Unlock() - - if len(f.hooks) == 0 { - return f.defaultHook - } - - hook := f.hooks[0] - f.hooks = f.hooks[1:] - return hook -} - -func (f *OracleKeeperAllMedianPricesFunc) appendCall(r0 OracleKeeperAllMedianPricesFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of OracleKeeperAllMedianPricesFuncCall objects -// describing the invocations of this function. -func (f *OracleKeeperAllMedianPricesFunc) History() []OracleKeeperAllMedianPricesFuncCall { - f.mutex.Lock() - history := make([]OracleKeeperAllMedianPricesFuncCall, len(f.history)) - copy(history, f.history) - f.mutex.Unlock() - - return history +// NewMockOracleKeeper creates a new mock instance. +func NewMockOracleKeeper(ctrl *gomock.Controller) *MockOracleKeeper { + mock := &MockOracleKeeper{ctrl: ctrl} + mock.recorder = &MockOracleKeeperMockRecorder{mock} + return mock } -// OracleKeeperAllMedianPricesFuncCall is an object that describes an -// invocation of method AllMedianPrices on an instance of MockOracleKeeper. -type OracleKeeperAllMedianPricesFuncCall struct { - // Arg0 is the value of the 1st argument passed to this method - // invocation. - Arg0 types.Context - // Result0 is the value of the 1st result returned from this method - // invocation. - Result0 types2.Prices +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockOracleKeeper) EXPECT() *MockOracleKeeperMockRecorder { + return m.recorder } -// Args returns an interface slice containing the arguments of this -// invocation. -func (c OracleKeeperAllMedianPricesFuncCall) Args() []interface{} { - return []interface{}{c.Arg0} +// AllMedianPrices mocks base method. +func (m *MockOracleKeeper) AllMedianPrices(ctx types.Context) types1.Prices { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AllMedianPrices", ctx) + ret0, _ := ret[0].(types1.Prices) + return ret0 } -// Results returns an interface slice containing the results of this -// invocation. -func (c OracleKeeperAllMedianPricesFuncCall) Results() []interface{} { - return []interface{}{c.Result0} +// AllMedianPrices indicates an expected call of AllMedianPrices. +func (mr *MockOracleKeeperMockRecorder) AllMedianPrices(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllMedianPrices", reflect.TypeOf((*MockOracleKeeper)(nil).AllMedianPrices), ctx) } diff --git a/x/uibc/mocks/keepers.go b/x/uibc/mocks/keepers.go index 7acbbc5428..9268265895 100644 --- a/x/uibc/mocks/keepers.go +++ b/x/uibc/mocks/keepers.go @@ -75,31 +75,31 @@ func (mr *MockBankKeeperMockRecorder) SetDenomMetaData(ctx, denomMetaData interf return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).SetDenomMetaData), ctx, denomMetaData) } -// MockLeverageKeeper is a mock of LeverageKeeper interface. -type MockLeverageKeeper struct { +// MockLeverage is a mock of Leverage interface. +type MockLeverage struct { ctrl *gomock.Controller - recorder *MockLeverageKeeperMockRecorder + recorder *MockLeverageMockRecorder } -// MockLeverageKeeperMockRecorder is the mock recorder for MockLeverageKeeper. -type MockLeverageKeeperMockRecorder struct { - mock *MockLeverageKeeper +// MockLeverageMockRecorder is the mock recorder for MockLeverage. +type MockLeverageMockRecorder struct { + mock *MockLeverage } -// NewMockLeverageKeeper creates a new mock instance. -func NewMockLeverageKeeper(ctrl *gomock.Controller) *MockLeverageKeeper { - mock := &MockLeverageKeeper{ctrl: ctrl} - mock.recorder = &MockLeverageKeeperMockRecorder{mock} +// NewMockLeverage creates a new mock instance. +func NewMockLeverage(ctrl *gomock.Controller) *MockLeverage { + mock := &MockLeverage{ctrl: ctrl} + mock.recorder = &MockLeverageMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockLeverageKeeper) EXPECT() *MockLeverageKeeperMockRecorder { +func (m *MockLeverage) EXPECT() *MockLeverageMockRecorder { return m.recorder } // DeriveExchangeRate mocks base method. -func (m *MockLeverageKeeper) DeriveExchangeRate(ctx types.Context, denom string) types.Dec { +func (m *MockLeverage) DeriveExchangeRate(ctx types.Context, denom string) types.Dec { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeriveExchangeRate", ctx, denom) ret0, _ := ret[0].(types.Dec) @@ -107,39 +107,39 @@ func (m *MockLeverageKeeper) DeriveExchangeRate(ctx types.Context, denom string) } // DeriveExchangeRate indicates an expected call of DeriveExchangeRate. -func (mr *MockLeverageKeeperMockRecorder) DeriveExchangeRate(ctx, denom interface{}) *gomock.Call { +func (mr *MockLeverageMockRecorder) DeriveExchangeRate(ctx, denom interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeriveExchangeRate", reflect.TypeOf((*MockLeverageKeeper)(nil).DeriveExchangeRate), ctx, denom) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeriveExchangeRate", reflect.TypeOf((*MockLeverage)(nil).DeriveExchangeRate), ctx, denom) } -// UToken2TokenRate mocks base method. -func (m *MockLeverageKeeper) UToken2TokenRate(ctx types.Context, uToken types.Coin) (types.Coin, error) { +// GetTokenSettings mocks base method. +func (m *MockLeverage) GetTokenSettings(ctx types.Context, baseDenom string) (types1.Token, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UToken2TokenRate", ctx, uToken) - ret0, _ := ret[0].(types.Coin) + ret := m.ctrl.Call(m, "GetTokenSettings", ctx, baseDenom) + ret0, _ := ret[0].(types1.Token) ret1, _ := ret[1].(error) return ret0, ret1 } -// UToken2TokenRate indicates an expected call of UToken2TokenRate. -func (mr *MockLeverageKeeperMockRecorder) UToken2TokenRate(ctx, uToken interface{}) *gomock.Call { +// GetTokenSettings indicates an expected call of GetTokenSettings. +func (mr *MockLeverageMockRecorder) GetTokenSettings(ctx, baseDenom interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UToken2TokenRate", reflect.TypeOf((*MockLeverageKeeper)(nil).UToken2TokenRate), ctx, uToken) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverage)(nil).GetTokenSettings), ctx, baseDenom) } -// GetTokenSettings mocks base method. -func (m *MockLeverageKeeper) GetTokenSettings(ctx types.Context, baseDenom string) (types1.Token, error) { +// UToken2TokenRate mocks base method. +func (m *MockLeverage) UToken2TokenRate(ctx types.Context, uToken types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTokenSettings", ctx, baseDenom) - ret0, _ := ret[0].(types1.Token) + ret := m.ctrl.Call(m, "UToken2TokenRate", ctx, uToken) + ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetTokenSettings indicates an expected call of GetTokenSettings. -func (mr *MockLeverageKeeperMockRecorder) GetTokenSettings(ctx, baseDenom interface{}) *gomock.Call { +// UToken2TokenRate indicates an expected call of UToken2TokenRate. +func (mr *MockLeverageMockRecorder) UToken2TokenRate(ctx, uToken interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTokenSettings), ctx, baseDenom) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UToken2TokenRate", reflect.TypeOf((*MockLeverage)(nil).UToken2TokenRate), ctx, uToken) } // MockOracle is a mock of Oracle interface. From d1ee393c352eeed13638cf7402a65bc24fe499d4 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 18:59:23 +0200 Subject: [PATCH 03/11] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9667f7d7ab..72150d4839 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - `/umee/ugov/v1/min-gas-price` --> `/umee/ugov/v1/min_gas_price` - `/umee/ugov/v1/emergency-group` --> `/umee/ugov/v1/emergency_group` - `/umee/uibc/v1/all-outflows` --> `/umee/uibc/v1/all_outflows` +- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Kepeer.ExchangeToken -> Token2uTokenRate`, `Kepeer.ExchangeUToken -> UToken2TokenRate` and `Kepeer.ExchangeTokens -> Tokens2uTokensRate`. ## [v5.1.0](https://github.com/umee-network/umee/releases/tag/v5.1.0) - 2023-07-07 From 1853ab38f655756eacfb7e90305300d34ea7268d Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 19:11:56 +0200 Subject: [PATCH 04/11] rename based on review --- CHANGELOG.md | 2 +- x/incentive/expected_keepers.go | 2 +- x/incentive/keeper/grpc_query.go | 2 +- x/incentive/keeper/mock_test.go | 4 ++-- x/leverage/keeper/borrows.go | 6 +++--- x/leverage/keeper/collateral.go | 4 ++-- x/leverage/keeper/exchange_rate.go | 10 +++++----- x/leverage/keeper/grpc_query.go | 2 +- x/leverage/keeper/incentive.go | 2 +- x/leverage/keeper/keeper.go | 8 ++++---- x/leverage/keeper/limits.go | 2 +- x/leverage/keeper/oracle.go | 2 +- x/leverage/keeper/supply.go | 4 ++-- x/metoken/expected_keepers.go | 4 ++-- x/metoken/keeper/intest/interest_test.go | 2 +- x/metoken/keeper/mocks_test.go | 4 ++-- x/metoken/keeper/redeem.go | 2 +- x/metoken/mocks/keepers.go | 24 ++++++++++++------------ x/uibc/expected_keepers.go | 2 +- x/uibc/mocks/keepers.go | 12 ++++++------ x/uibc/quota/keeper/intest/quota_test.go | 4 ++-- x/uibc/quota/keeper/mocks_test.go | 2 +- x/uibc/quota/keeper/quota.go | 2 +- 23 files changed, 54 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72150d4839..3737318d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - `/umee/ugov/v1/min-gas-price` --> `/umee/ugov/v1/min_gas_price` - `/umee/ugov/v1/emergency-group` --> `/umee/ugov/v1/emergency_group` - `/umee/uibc/v1/all-outflows` --> `/umee/uibc/v1/all_outflows` -- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Kepeer.ExchangeToken -> Token2uTokenRate`, `Kepeer.ExchangeUToken -> UToken2TokenRate` and `Kepeer.ExchangeTokens -> Tokens2uTokensRate`. +- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Kepeer.ExchangeToken -> ToUToken`, `Kepeer.ExchangeUToken -> ToTokenRate` and `Kepeer.ExchangeTokens -> ToUTokens`. ## [v5.1.0](https://github.com/umee-network/umee/releases/tag/v5.1.0) - 2023-07-07 diff --git a/x/incentive/expected_keepers.go b/x/incentive/expected_keepers.go index 0db3188e8e..f31203f31f 100644 --- a/x/incentive/expected_keepers.go +++ b/x/incentive/expected_keepers.go @@ -21,5 +21,5 @@ type LeverageKeeper interface { GetTokenSettings(ctx sdk.Context, denom string) (leveragetypes.Token, error) // These are used for APY queries only TotalTokenValue(ctx sdk.Context, coins sdk.Coins, mode leveragetypes.PriceMode) (sdk.Dec, error) - UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) } diff --git a/x/incentive/keeper/grpc_query.go b/x/incentive/keeper/grpc_query.go index a8210c76a5..bc3a5ecd10 100644 --- a/x/incentive/keeper/grpc_query.go +++ b/x/incentive/keeper/grpc_query.go @@ -263,7 +263,7 @@ func (q Querier) ActualRates( } // compute oracle price ratio of rewards to reference bond amount - referenceToken, err := k.leverageKeeper.UToken2TokenRate(ctx, referenceUToken) + referenceToken, err := k.leverageKeeper.ToToken(ctx, referenceUToken) if err != nil { return nil, err } diff --git a/x/incentive/keeper/mock_test.go b/x/incentive/keeper/mock_test.go index e23c5a3f27..767d5ce5f5 100644 --- a/x/incentive/keeper/mock_test.go +++ b/x/incentive/keeper/mock_test.go @@ -218,8 +218,8 @@ func (m *mockLeverageKeeper) TotalTokenValue(_ sdk.Context, coins sdk.Coins, _ l return total, nil } -// UToken2TokenRate implements the expected leverage keeper, with uToken exchange rates always equal to 1 -func (m *mockLeverageKeeper) UToken2TokenRate(_ sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { +// ToToken implements the expected leverage keeper, with uToken exchange rates always equal to 1 +func (m *mockLeverageKeeper) ToToken(_ sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if !leveragetypes.HasUTokenPrefix(uToken.Denom) { return uToken, leveragetypes.ErrUToken } diff --git a/x/leverage/keeper/borrows.go b/x/leverage/keeper/borrows.go index d1bc1e39eb..92e358066e 100644 --- a/x/leverage/keeper/borrows.go +++ b/x/leverage/keeper/borrows.go @@ -134,7 +134,7 @@ func (k Keeper) CalculateBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.UToken2TokenRate(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -170,7 +170,7 @@ func (k Keeper) VisibleBorrowLimit(ctx sdk.Context, collateral sdk.Coins) (sdk.D for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.UToken2TokenRate(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -208,7 +208,7 @@ func (k Keeper) CalculateLiquidationThreshold(ctx sdk.Context, collateral sdk.Co for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.UToken2TokenRate(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } diff --git a/x/leverage/keeper/collateral.go b/x/leverage/keeper/collateral.go index ed6a03c230..0c2e2165b9 100644 --- a/x/leverage/keeper/collateral.go +++ b/x/leverage/keeper/collateral.go @@ -80,7 +80,7 @@ func (k Keeper) CalculateCollateralValue(ctx sdk.Context, collateral sdk.Coins, for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.UToken2TokenRate(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } @@ -107,7 +107,7 @@ func (k Keeper) VisibleCollateralValue(ctx sdk.Context, collateral sdk.Coins, mo for _, coin := range collateral { // convert uToken collateral to base assets - baseAsset, err := k.UToken2TokenRate(ctx, coin) + baseAsset, err := k.ToToken(ctx, coin) if err != nil { return sdk.ZeroDec(), err } diff --git a/x/leverage/keeper/exchange_rate.go b/x/leverage/keeper/exchange_rate.go index 29f431633f..1fde250010 100644 --- a/x/leverage/keeper/exchange_rate.go +++ b/x/leverage/keeper/exchange_rate.go @@ -6,9 +6,9 @@ import ( "github.com/umee-network/umee/v5/x/leverage/types" ) -// Token2uTokenRate returns a uToken amount user would receive when supplying the token. +// ToUToken returns a uToken amount user would receive when supplying the token. // Returns error if the token is not a Token. -func (k Keeper) Token2uTokenRate(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { +func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { if err := token.Validate(); err != nil { return sdk.Coin{}, err } @@ -23,9 +23,9 @@ func (k Keeper) Token2uTokenRate(ctx sdk.Context, token sdk.Coin) (sdk.Coin, err return sdk.NewCoin(uTokenDenom, uTokenAmount), nil } -// UToken2TokenRate returns a token amount user would receive when supplying the uToken. +// ToToken returns a token amount user would receive when supplying the uToken. // Returns error if the uToken is not a uToken. -func (k Keeper) UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { +func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if err := uToken.Validate(); err != nil { return sdk.Coin{}, err } @@ -50,7 +50,7 @@ func (k Keeper) Tokens2uTokensRate(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coin tokens := sdk.Coins{} for _, coin := range uTokens { - token, err := k.UToken2TokenRate(ctx, coin) + token, err := k.ToToken(ctx, coin) if err != nil { return sdk.Coins{}, err } diff --git a/x/leverage/keeper/grpc_query.go b/x/leverage/keeper/grpc_query.go index 3b671d36fb..b8b2d143d1 100644 --- a/x/leverage/keeper/grpc_query.go +++ b/x/leverage/keeper/grpc_query.go @@ -362,7 +362,7 @@ func (q Querier) MaxWithdraw( // On non-nil error here, max withdraw is zero. uToken, _, err := q.Keeper.userMaxWithdraw(ctx, addr, denom) if err == nil && uToken.IsPositive() { - token, err := q.Keeper.UToken2TokenRate(ctx, uToken) + token, err := q.Keeper.ToToken(ctx, uToken) if err != nil { return nil, err } diff --git a/x/leverage/keeper/incentive.go b/x/leverage/keeper/incentive.go index fce4686160..c33b39bd67 100644 --- a/x/leverage/keeper/incentive.go +++ b/x/leverage/keeper/incentive.go @@ -7,7 +7,7 @@ import ( // DonateCollateral burns some collateral uTokens already present in the module, then adds their equivalent amount // in tokens reserves. Currently, this is only used as the penalty for incentive module's MsgEmergencyUnbond. func (k Keeper) DonateCollateral(ctx sdk.Context, fromAddr sdk.AccAddress, uToken sdk.Coin) error { - token, err := k.UToken2TokenRate(ctx, uToken) + token, err := k.ToToken(ctx, uToken) if err != nil { return err } diff --git a/x/leverage/keeper/keeper.go b/x/leverage/keeper/keeper.go index d6c71ddf3e..c1ad5e8f94 100644 --- a/x/leverage/keeper/keeper.go +++ b/x/leverage/keeper/keeper.go @@ -91,7 +91,7 @@ func (k Keeper) Supply(ctx sdk.Context, supplierAddr sdk.AccAddress, coin sdk.Co } // determine uToken amount to mint - uToken, err := k.Token2uTokenRate(ctx, coin) + uToken, err := k.ToUToken(ctx, coin) if err != nil { return sdk.Coin{}, err } @@ -129,7 +129,7 @@ func (k Keeper) SupplyFromModule(ctx sdk.Context, fromModule string, coin sdk.Co } // determine uToken amount to mint - uToken, err := k.Token2uTokenRate(ctx, coin) + uToken, err := k.ToUToken(ctx, coin) if err != nil { return sdk.Coin{}, true, err } @@ -176,7 +176,7 @@ func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sd } // calculate base asset amount to withdraw - token, err := k.UToken2TokenRate(ctx, uToken) + token, err := k.ToToken(ctx, uToken) if err != nil { return sdk.Coin{}, isFromCollateral, err } @@ -256,7 +256,7 @@ func (k Keeper) WithdrawToModule(ctx sdk.Context, toModule string, uToken sdk.Co } // calculate base asset amount to withdraw - token, err := k.UToken2TokenRate(ctx, uToken) + token, err := k.ToToken(ctx, uToken) if err != nil { return sdk.Coin{}, true, err } diff --git a/x/leverage/keeper/limits.go b/x/leverage/keeper/limits.go index 9a1a79766f..8f2a189cb1 100644 --- a/x/leverage/keeper/limits.go +++ b/x/leverage/keeper/limits.go @@ -13,7 +13,7 @@ import ( func (k *Keeper) userMaxWithdraw(ctx sdk.Context, addr sdk.AccAddress, denom string) (sdk.Coin, sdk.Coin, error) { uDenom := types.ToUTokenDenom(denom) availableTokens := sdk.NewCoin(denom, k.AvailableLiquidity(ctx, denom)) - availableUTokens, err := k.Token2uTokenRate(ctx, availableTokens) + availableUTokens, err := k.ToUToken(ctx, availableTokens) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } diff --git a/x/leverage/keeper/oracle.go b/x/leverage/keeper/oracle.go index 7e42ff3b3a..9e98e6dbb3 100644 --- a/x/leverage/keeper/oracle.go +++ b/x/leverage/keeper/oracle.go @@ -167,7 +167,7 @@ func (k Keeper) VisibleUTokensValue(ctx sdk.Context, uTokens sdk.Coins, mode typ tokens := sdk.NewCoins() for _, u := range uTokens { - t, err := k.UToken2TokenRate(ctx, u) + t, err := k.ToToken(ctx, u) if err != nil { return sdk.ZeroDec(), err } diff --git a/x/leverage/keeper/supply.go b/x/leverage/keeper/supply.go index c836207211..e14f9bf9ee 100644 --- a/x/leverage/keeper/supply.go +++ b/x/leverage/keeper/supply.go @@ -19,7 +19,7 @@ func (k Keeper) GetSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress, denom collateral := k.GetCollateral(ctx, supplierAddr, uDenom) // convert uTokens to tokens - return k.UToken2TokenRate(ctx, balance.Add(collateral)) + return k.ToToken(ctx, balance.Add(collateral)) } // GetAllSupplied returns the total tokens supplied by a user, including @@ -50,7 +50,7 @@ func (k Keeper) GetTotalSupply(ctx sdk.Context, denom string) (sdk.Coin, error) // convert associated uToken's total supply to base tokens uTokenDenom := types.ToUTokenDenom(denom) - return k.UToken2TokenRate(ctx, k.GetUTokenSupply(ctx, uTokenDenom)) + return k.ToToken(ctx, k.GetUTokenSupply(ctx, uTokenDenom)) } // checkMaxSupply returns the appropriate error if a token denom's diff --git a/x/metoken/expected_keepers.go b/x/metoken/expected_keepers.go index 2328b38f87..1635f98af6 100644 --- a/x/metoken/expected_keepers.go +++ b/x/metoken/expected_keepers.go @@ -22,8 +22,8 @@ type BankKeeper interface { // LeverageKeeper interface for interacting with x/leverage type LeverageKeeper interface { GetTokenSettings(ctx sdk.Context, denom string) (ltypes.Token, error) - Token2uTokenRate(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) - UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) + ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) SupplyFromModule(ctx sdk.Context, fromModule string, coin sdk.Coin) (sdk.Coin, bool, error) WithdrawToModule(ctx sdk.Context, toModule string, uToken sdk.Coin) (sdk.Coin, bool, error) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (sdkmath.Int, error) diff --git a/x/metoken/keeper/intest/interest_test.go b/x/metoken/keeper/intest/interest_test.go index a9936b6b8e..435a7ac2ed 100644 --- a/x/metoken/keeper/intest/interest_test.go +++ b/x/metoken/keeper/intest/interest_test.go @@ -75,7 +75,7 @@ func TestInterestClaiming(t *testing.T) { ) require.NoError(t, err) - uTokens, err := app.LeverageKeeper.Token2uTokenRate(ctx, borrowerSupply) + uTokens, err := app.LeverageKeeper.ToUToken(ctx, borrowerSupply) require.NoError(t, err) err = app.LeverageKeeper.Collateralize(ctx, borrower, uTokens) diff --git a/x/metoken/keeper/mocks_test.go b/x/metoken/keeper/mocks_test.go index 9e0e614a77..dedd940e5e 100644 --- a/x/metoken/keeper/mocks_test.go +++ b/x/metoken/keeper/mocks_test.go @@ -33,11 +33,11 @@ func (l Leverage) GetTokenSettings(_ sdk.Context, denom string) (ltypes.Token, e return ts, nil } -func (l Leverage) Token2uTokenRate(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) ToUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } -func (l Leverage) UToken2TokenRate(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) ToToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } diff --git a/x/metoken/keeper/redeem.go b/x/metoken/keeper/redeem.go index 2ca3057f83..c77ee8fe82 100644 --- a/x/metoken/keeper/redeem.go +++ b/x/metoken/keeper/redeem.go @@ -150,7 +150,7 @@ func (k Keeper) redeem(userAddr sdk.AccAddress, meToken sdk.Coin, assetDenom str // - tokensWithdrawn: the amount tokens withdrawn from x/leverage. // - error func (k Keeper) withdrawFromLeverage(tokensToWithdraw sdk.Coin) (sdk.Coin, error) { - uTokensFromLeverage, err := k.leverageKeeper.Token2uTokenRate(*k.ctx, tokensToWithdraw) + uTokensFromLeverage, err := k.leverageKeeper.ToUToken(*k.ctx, tokensToWithdraw) if err != nil { return sdk.Coin{}, errors.Wrap(err, true) } diff --git a/x/metoken/mocks/keepers.go b/x/metoken/mocks/keepers.go index 84915ffeef..f19a4a0fc8 100644 --- a/x/metoken/mocks/keepers.go +++ b/x/metoken/mocks/keepers.go @@ -192,34 +192,34 @@ func (mr *MockLeverageKeeperMockRecorder) SupplyFromModule(ctx, fromModule, coin return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupplyFromModule", reflect.TypeOf((*MockLeverageKeeper)(nil).SupplyFromModule), ctx, fromModule, coin) } -// Token2uTokenRate mocks base method. -func (m *MockLeverageKeeper) Token2uTokenRate(ctx types.Context, token types.Coin) (types.Coin, error) { +// ToUToken mocks base method. +func (m *MockLeverageKeeper) ToUToken(ctx types.Context, token types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Token2uTokenRate", ctx, token) + ret := m.ctrl.Call(m, "ToUToken", ctx, token) ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// Token2uTokenRate indicates an expected call of Token2uTokenRate. -func (mr *MockLeverageKeeperMockRecorder) Token2uTokenRate(ctx, token interface{}) *gomock.Call { +// ToUToken indicates an expected call of ToUToken. +func (mr *MockLeverageKeeperMockRecorder) ToUToken(ctx, token interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Token2uTokenRate", reflect.TypeOf((*MockLeverageKeeper)(nil).Token2uTokenRate), ctx, token) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToUToken), ctx, token) } -// UToken2TokenRate mocks base method. -func (m *MockLeverageKeeper) UToken2TokenRate(ctx types.Context, uToken types.Coin) (types.Coin, error) { +// ToToken mocks base method. +func (m *MockLeverageKeeper) ToToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UToken2TokenRate", ctx, uToken) + ret := m.ctrl.Call(m, "ToToken", ctx, uToken) ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// UToken2TokenRate indicates an expected call of UToken2TokenRate. -func (mr *MockLeverageKeeperMockRecorder) UToken2TokenRate(ctx, uToken interface{}) *gomock.Call { +// ToToken indicates an expected call of ToToken. +func (mr *MockLeverageKeeperMockRecorder) ToToken(ctx, uToken interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UToken2TokenRate", reflect.TypeOf((*MockLeverageKeeper)(nil).UToken2TokenRate), ctx, uToken) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToToken), ctx, uToken) } // WithdrawToModule mocks base method. diff --git a/x/uibc/expected_keepers.go b/x/uibc/expected_keepers.go index a61c3a0a19..6c9b3931a9 100644 --- a/x/uibc/expected_keepers.go +++ b/x/uibc/expected_keepers.go @@ -16,7 +16,7 @@ type BankKeeper interface { type Leverage interface { GetTokenSettings(ctx sdk.Context, baseDenom string) (ltypes.Token, error) - UToken2TokenRate(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) + ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) DeriveExchangeRate(ctx sdk.Context, denom string) sdk.Dec } diff --git a/x/uibc/mocks/keepers.go b/x/uibc/mocks/keepers.go index 9268265895..0f0154c282 100644 --- a/x/uibc/mocks/keepers.go +++ b/x/uibc/mocks/keepers.go @@ -127,19 +127,19 @@ func (mr *MockLeverageMockRecorder) GetTokenSettings(ctx, baseDenom interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenSettings", reflect.TypeOf((*MockLeverage)(nil).GetTokenSettings), ctx, baseDenom) } -// UToken2TokenRate mocks base method. -func (m *MockLeverage) UToken2TokenRate(ctx types.Context, uToken types.Coin) (types.Coin, error) { +// ToToken mocks base method. +func (m *MockLeverage) ToToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UToken2TokenRate", ctx, uToken) + ret := m.ctrl.Call(m, "ToToken", ctx, uToken) ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// UToken2TokenRate indicates an expected call of UToken2TokenRate. -func (mr *MockLeverageMockRecorder) UToken2TokenRate(ctx, uToken interface{}) *gomock.Call { +// ToToken indicates an expected call of ToToken. +func (mr *MockLeverageMockRecorder) ToToken(ctx, uToken interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UToken2TokenRate", reflect.TypeOf((*MockLeverage)(nil).UToken2TokenRate), ctx, uToken) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToToken", reflect.TypeOf((*MockLeverage)(nil).ToToken), ctx, uToken) } // MockOracle is a mock of Oracle interface. diff --git a/x/uibc/quota/keeper/intest/quota_test.go b/x/uibc/quota/keeper/intest/quota_test.go index 07cfd3ed94..e38a6da4cb 100644 --- a/x/uibc/quota/keeper/intest/quota_test.go +++ b/x/uibc/quota/keeper/intest/quota_test.go @@ -53,14 +53,14 @@ func TestKeeper_CheckAndUpdateQuota(t *testing.T) { assert.NilError(t, err) // invalid token, returns error from mock leverage - leverageMock.EXPECT().UToken2TokenRate(ctx, invalidToken).Return(sdk.Coin{}, ltypes.ErrNotUToken).AnyTimes() + leverageMock.EXPECT().ToToken(ctx, invalidToken).Return(sdk.Coin{}, ltypes.ErrNotUToken).AnyTimes() err = k.CheckAndUpdateQuota(invalidToken.Denom, invalidToken.Amount) assert.ErrorIs(t, err, ltypes.ErrNotUToken) // UMEE uToken, exchanges correctly, but returns ErrNotRegisteredToken when trying to get Token's settings // from leverage mock keeper - leverageMock.EXPECT().UToken2TokenRate(ctx, umeeUToken).Return( + leverageMock.EXPECT().ToToken(ctx, umeeUToken).Return( sdk.NewCoin("umee", sdkmath.NewInt(100)), nil, ).AnyTimes() diff --git a/x/uibc/quota/keeper/mocks_test.go b/x/uibc/quota/keeper/mocks_test.go index 2050b6af02..2f51d13ac1 100644 --- a/x/uibc/quota/keeper/mocks_test.go +++ b/x/uibc/quota/keeper/mocks_test.go @@ -22,7 +22,7 @@ func (k LeverageKeeper) GetTokenSettings(_ sdk.Context, baseDenom string) (ltype return ts, nil } -func (k LeverageKeeper) UToken2TokenRate(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (k LeverageKeeper) ToToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } diff --git a/x/uibc/quota/keeper/quota.go b/x/uibc/quota/keeper/quota.go index 61a6e8885f..4df66fffdb 100644 --- a/x/uibc/quota/keeper/quota.go +++ b/x/uibc/quota/keeper/quota.go @@ -141,7 +141,7 @@ func (k Keeper) getExchangePrice(denom string, amount sdkmath.Int) (sdk.Dec, err // convert to base asset if it is `uToken` if ltypes.HasUTokenPrefix(denom) { // NOTE: to avoid ctx, we can use similar approach: create a leverage keeper builder - transferCoin, err = k.leverage.UToken2TokenRate(*k.ctx, transferCoin) + transferCoin, err = k.leverage.ToToken(*k.ctx, transferCoin) if err != nil { return sdk.Dec{}, err } From 457bbf831176f9d188821622b49377c4a4560851 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 19:25:40 +0200 Subject: [PATCH 05/11] Apply suggestions from code review Co-authored-by: Adam Moser <63419657+toteki@users.noreply.github.com> --- CHANGELOG.md | 2 +- x/leverage/keeper/exchange_rate.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3737318d92..50f1bbf0cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - `/umee/ugov/v1/min-gas-price` --> `/umee/ugov/v1/min_gas_price` - `/umee/ugov/v1/emergency-group` --> `/umee/ugov/v1/emergency_group` - `/umee/uibc/v1/all-outflows` --> `/umee/uibc/v1/all_outflows` -- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Kepeer.ExchangeToken -> ToUToken`, `Kepeer.ExchangeUToken -> ToTokenRate` and `Kepeer.ExchangeTokens -> ToUTokens`. +- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Keeper.ExchangeToken -> ToUToken`, `Keeper.ExchangeUToken -> ToToken` and `Keeper.ExchangeTokens -> ToUTokens`. ## [v5.1.0](https://github.com/umee-network/umee/releases/tag/v5.1.0) - 2023-07-07 diff --git a/x/leverage/keeper/exchange_rate.go b/x/leverage/keeper/exchange_rate.go index 1fde250010..be2c1165f3 100644 --- a/x/leverage/keeper/exchange_rate.go +++ b/x/leverage/keeper/exchange_rate.go @@ -6,8 +6,9 @@ import ( "github.com/umee-network/umee/v5/x/leverage/types" ) -// ToUToken returns a uToken amount user would receive when supplying the token. -// Returns error if the token is not a Token. +// ToUToken converts a token to uTokens at the current uToken exchange rate. +// This is the uToken amount a user would receive when supplying the token. +// Returns error if the input is not a Token. func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { if err := token.Validate(); err != nil { return sdk.Coin{}, err @@ -23,8 +24,9 @@ func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { return sdk.NewCoin(uTokenDenom, uTokenAmount), nil } -// ToToken returns a token amount user would receive when supplying the uToken. -// Returns error if the uToken is not a uToken. +// ToToken converts a uToken to tokens at the current uToken exchange rate. +// This is the token amount a user would receive when withdrawing the uToken. +// Returns error if the input is not a uToken. func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if err := uToken.Validate(); err != nil { return sdk.Coin{}, err @@ -41,7 +43,9 @@ func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { return sdk.NewCoin(tokenDenom, tokenAmount), nil } -// Tokens2uTokensRate converts an sdk.Coins containing uTokens to their values in base +// ToToken converts an sdk.Coins containing uTokens to tokens using uToken exchange rates. +// These are the token amounts a user would receive when withdrawing the uTokens. +// Returns error if any of the inputs are uTokens. // tokens. func (k Keeper) Tokens2uTokensRate(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { if err := uTokens.Validate(); err != nil { From 0ad5bbf4e0d15f209b7617e3562a3b59069d95ac Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 19:26:23 +0200 Subject: [PATCH 06/11] mockgen --- x/metoken/mocks/keepers.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/x/metoken/mocks/keepers.go b/x/metoken/mocks/keepers.go index f19a4a0fc8..08dc92019d 100644 --- a/x/metoken/mocks/keepers.go +++ b/x/metoken/mocks/keepers.go @@ -192,34 +192,34 @@ func (mr *MockLeverageKeeperMockRecorder) SupplyFromModule(ctx, fromModule, coin return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupplyFromModule", reflect.TypeOf((*MockLeverageKeeper)(nil).SupplyFromModule), ctx, fromModule, coin) } -// ToUToken mocks base method. -func (m *MockLeverageKeeper) ToUToken(ctx types.Context, token types.Coin) (types.Coin, error) { +// ToToken mocks base method. +func (m *MockLeverageKeeper) ToToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ToUToken", ctx, token) + ret := m.ctrl.Call(m, "ToToken", ctx, uToken) ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// ToUToken indicates an expected call of ToUToken. -func (mr *MockLeverageKeeperMockRecorder) ToUToken(ctx, token interface{}) *gomock.Call { +// ToToken indicates an expected call of ToToken. +func (mr *MockLeverageKeeperMockRecorder) ToToken(ctx, uToken interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToUToken), ctx, token) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToToken), ctx, uToken) } -// ToToken mocks base method. -func (m *MockLeverageKeeper) ToToken(ctx types.Context, uToken types.Coin) (types.Coin, error) { +// ToUToken mocks base method. +func (m *MockLeverageKeeper) ToUToken(ctx types.Context, token types.Coin) (types.Coin, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ToToken", ctx, uToken) + ret := m.ctrl.Call(m, "ToUToken", ctx, token) ret0, _ := ret[0].(types.Coin) ret1, _ := ret[1].(error) return ret0, ret1 } -// ToToken indicates an expected call of ToToken. -func (mr *MockLeverageKeeperMockRecorder) ToToken(ctx, uToken interface{}) *gomock.Call { +// ToUToken indicates an expected call of ToUToken. +func (mr *MockLeverageKeeperMockRecorder) ToUToken(ctx, token interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToToken), ctx, uToken) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToUToken), ctx, token) } // WithdrawToModule mocks base method. From 462bf39d31e0f67849bfc7359d18ee365049091a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 19:47:25 +0200 Subject: [PATCH 07/11] fix integration tests in metoken --- app/inflation/inflation_test.go | 3 +- x/metoken/keeper/intest/keeper_test.go | 12 +- x/metoken/keeper/intest/msg_server_test.go | 140 +++++++++++---------- 3 files changed, 84 insertions(+), 71 deletions(-) diff --git a/app/inflation/inflation_test.go b/app/inflation/inflation_test.go index 6122be1324..5e8aff07c9 100644 --- a/app/inflation/inflation_test.go +++ b/app/inflation/inflation_test.go @@ -9,6 +9,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/golang/mock/gomock" + "gotest.tools/v3/assert" + "github.com/umee-network/umee/v5/app/inflation" mocks "github.com/umee-network/umee/v5/app/inflation/mocks" appparams "github.com/umee-network/umee/v5/app/params" @@ -16,7 +18,6 @@ import ( "github.com/umee-network/umee/v5/util/bpmath" "github.com/umee-network/umee/v5/util/coin" "github.com/umee-network/umee/v5/x/ugov" - "gotest.tools/v3/assert" ) func TestAdjustInflation(t *testing.T) { diff --git a/x/metoken/keeper/intest/keeper_test.go b/x/metoken/keeper/intest/keeper_test.go index e706e3a15c..5f9629b2c2 100644 --- a/x/metoken/keeper/intest/keeper_test.go +++ b/x/metoken/keeper/intest/keeper_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -42,8 +43,15 @@ func initTestSuite(t *testing.T, registry []metoken.Index, balances []metoken.In }, ).WithBlockTime(time.Now()) - oracleMock := mocks.NewMockOracleKeeper() - oracleMock.AllMedianPricesFunc.SetDefaultHook(mocks.ValidPricesFunc()) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + oracleMock := mocks.NewMockOracleKeeper(ctrl) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(mocks.ValidPrices()). + AnyTimes() kb := keeper.NewKeeperBuilder( app.AppCodec(), diff --git a/x/metoken/keeper/intest/msg_server_test.go b/x/metoken/keeper/intest/msg_server_test.go index 7e62b55151..5db93126f9 100644 --- a/x/metoken/keeper/intest/msg_server_test.go +++ b/x/metoken/keeper/intest/msg_server_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" @@ -558,40 +559,38 @@ func TestMsgServer_Swap_Depegging(t *testing.T) { } // after initial swaps IST price is dropped to 0.64 USD - oracleMock := mocks.NewMockOracleKeeper() - oracleMock.AllMedianPricesFunc.SetDefaultHook( - func(ctx sdk.Context) otypes.Prices { - prices := otypes.Prices{} - median := otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDTSymbolDenom, - mocks.USDTPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDCSymbolDenom, - mocks.USDCPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.ISTSymbolDenom, - sdk.MustNewDecFromStr("0.64"), - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - return prices + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + initialPrices := otypes.Prices{ + otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDTSymbolDenom, + mocks.USDTPrice, + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDCSymbolDenom, + mocks.USDCPrice, + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.ISTSymbolDenom, + sdk.MustNewDecFromStr("0.64"), + ), + BlockNum: uint64(1), }, - ) + } + + oracleMock := mocks.NewMockOracleKeeper(ctrl) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(initialPrices). + AnyTimes() kb := keeper.NewKeeperBuilder( app.AppCodec(), @@ -683,7 +682,11 @@ func TestMsgServer_Swap_Depegging(t *testing.T) { } // after some swaps with depegged price, all is back to normal - oracleMock.AllMedianPricesFunc.SetDefaultHook(mocks.ValidPricesFunc()) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(mocks.ValidPrices()). + AnyTimes() kb = keeper.NewKeeperBuilder( app.AppCodec(), @@ -1252,40 +1255,37 @@ func TestMsgServer_Redeem_Depegging(t *testing.T) { } // after initial swaps USDT price is dropped to 0.73 USD - oracleMock := mocks.NewMockOracleKeeper() - oracleMock.AllMedianPricesFunc.SetDefaultHook( - func(ctx sdk.Context) otypes.Prices { - prices := otypes.Prices{} - median := otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDTSymbolDenom, - sdk.MustNewDecFromStr("0.73"), - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.USDCSymbolDenom, - mocks.USDCPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - median = otypes.Price{ - ExchangeRateTuple: otypes.NewExchangeRateTuple( - mocks.ISTSymbolDenom, - mocks.ISTPrice, - ), - BlockNum: uint64(1), - } - prices = append(prices, median) - - return prices + + initialPrices := otypes.Prices{ + otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDTSymbolDenom, + sdk.MustNewDecFromStr("0.73"), + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.USDCSymbolDenom, + mocks.USDCPrice, + ), + BlockNum: uint64(1), + }, otypes.Price{ + ExchangeRateTuple: otypes.NewExchangeRateTuple( + mocks.ISTSymbolDenom, + mocks.ISTPrice, + ), + BlockNum: uint64(1), }, - ) + } + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + oracleMock := mocks.NewMockOracleKeeper(ctrl) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(initialPrices). + AnyTimes() kb := keeper.NewKeeperBuilder( app.AppCodec(), @@ -1377,7 +1377,11 @@ func TestMsgServer_Redeem_Depegging(t *testing.T) { } // after some redemptions with depegged price, all is back to normal - oracleMock.AllMedianPricesFunc.SetDefaultHook(mocks.ValidPricesFunc()) + oracleMock. + EXPECT(). + AllMedianPrices(gomock.Any()). + Return(mocks.ValidPrices()). + AnyTimes() kb = keeper.NewKeeperBuilder( app.AppCodec(), From c19c034050f9e6135ccd0ee4457bfff92fed9e9a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 19:53:01 +0200 Subject: [PATCH 08/11] fix quota integration tests --- x/uibc/quota/keeper/intest/quota_test.go | 26 ++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/x/uibc/quota/keeper/intest/quota_test.go b/x/uibc/quota/keeper/intest/quota_test.go index e38a6da4cb..4ad263650b 100644 --- a/x/uibc/quota/keeper/intest/quota_test.go +++ b/x/uibc/quota/keeper/intest/quota_test.go @@ -38,14 +38,12 @@ func TestKeeper_CheckAndUpdateQuota(t *testing.T) { umeeUToken := sdk.NewCoin("u/umee", sdkmath.NewInt(100)) atomToken := sdk.NewCoin("atom", sdkmath.NewInt(1000)) daiToken := sdk.NewCoin("dai", sdkmath.NewInt(50)) - // gomock initializations - leverageCtrl := gomock.NewController(t) - defer leverageCtrl.Finish() - leverageMock := mocks.NewMockLeverageKeeper(leverageCtrl) - oracleCtrl := gomock.NewController(t) - defer oracleCtrl.Finish() - oracleMock := mocks.NewMockOracle(oracleCtrl) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + leverageMock := mocks.NewMockLeverage(ctrl) + oracleMock := mocks.NewMockOracle(ctrl) marshaller := codec.NewProtoCodec(nil) ctx, k := initKeeper(t, marshaller, nil, leverageMock, oracleMock) @@ -102,14 +100,12 @@ func TestKeeper_UndoUpdateQuota(t *testing.T) { umeeQuota := sdkmath.NewInt(10000) umeeToken := sdk.NewCoin("umee", umeeAmount) umeeExponent := 6 - // gomock initializations - leverageCtrl := gomock.NewController(t) - defer leverageCtrl.Finish() - leverageMock := mocks.NewMockLeverageKeeper(leverageCtrl) - - oracleCtrl := gomock.NewController(t) - defer oracleCtrl.Finish() - oracleMock := mocks.NewMockOracle(oracleCtrl) + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + leverageMock := mocks.NewMockLeverage(ctrl) + oracleMock := mocks.NewMockOracle(ctrl) marshaller := codec.NewProtoCodec(nil) ctx, k := initKeeper(t, marshaller, nil, leverageMock, oracleMock) From d6472fff9543ef8949bb626ccd700367a2347503 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 19:55:12 +0200 Subject: [PATCH 09/11] Update CHANGELOG.md Co-authored-by: Adam Moser <63419657+toteki@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50f1bbf0cc..6f62826b76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - `/umee/ugov/v1/min-gas-price` --> `/umee/ugov/v1/min_gas_price` - `/umee/ugov/v1/emergency-group` --> `/umee/ugov/v1/emergency_group` - `/umee/uibc/v1/all-outflows` --> `/umee/uibc/v1/all_outflows` -- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Keeper.ExchangeToken -> ToUToken`, `Keeper.ExchangeUToken -> ToToken` and `Keeper.ExchangeTokens -> ToUTokens`. +- [2180](https://github.com/umee-network/umee/pull/2180) Rename leverage `Keeper.ExchangeToken -> ToUToken`, `Keeper.ExchangeUToken -> ToToken` and `Keeper.ExchangeUTokens -> ToTokens`. ## [v5.1.0](https://github.com/umee-network/umee/releases/tag/v5.1.0) - 2023-07-07 From dc0d4db9f1acfff92ccff87384592a6478f3767a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 2 Aug 2023 20:00:34 +0200 Subject: [PATCH 10/11] rename to ToTokens --- x/leverage/keeper/collateral.go | 2 +- x/leverage/keeper/exchange_rate.go | 13 +++++-------- x/leverage/keeper/limits.go | 2 +- x/leverage/keeper/supply.go | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/x/leverage/keeper/collateral.go b/x/leverage/keeper/collateral.go index 0c2e2165b9..cc6d2f1240 100644 --- a/x/leverage/keeper/collateral.go +++ b/x/leverage/keeper/collateral.go @@ -251,7 +251,7 @@ func (k Keeper) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (s // Get module collateral for the uDenom totalCollateral := k.GetTotalCollateral(ctx, spendableUTokens.Denom) - totalTokenCollateral, err := k.Tokens2uTokensRate(ctx, sdk.NewCoins(totalCollateral)) + totalTokenCollateral, err := k.ToTokens(ctx, sdk.NewCoins(totalCollateral)) if err != nil { return sdk.ZeroInt(), err } diff --git a/x/leverage/keeper/exchange_rate.go b/x/leverage/keeper/exchange_rate.go index be2c1165f3..89897dcbb6 100644 --- a/x/leverage/keeper/exchange_rate.go +++ b/x/leverage/keeper/exchange_rate.go @@ -6,8 +6,7 @@ import ( "github.com/umee-network/umee/v5/x/leverage/types" ) -// ToUToken converts a token to uTokens at the current uToken exchange rate. -// This is the uToken amount a user would receive when supplying the token. +// ToUToken returns uToken in the amount a user would receive when supplying the token. // Returns error if the input is not a Token. func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { if err := token.Validate(); err != nil { @@ -24,8 +23,7 @@ func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) { return sdk.NewCoin(uTokenDenom, uTokenAmount), nil } -// ToToken converts a uToken to tokens at the current uToken exchange rate. -// This is the token amount a user would receive when withdrawing the uToken. +// ToToken returns Token in the amount a user would receive when withdrawing the uToken. // Returns error if the input is not a uToken. func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { if err := uToken.Validate(); err != nil { @@ -43,11 +41,10 @@ func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { return sdk.NewCoin(tokenDenom, tokenAmount), nil } -// ToToken converts an sdk.Coins containing uTokens to tokens using uToken exchange rates. -// These are the token amounts a user would receive when withdrawing the uTokens. +// ToToken returns list of Tokens in the amount a user would receive when withdrawing the +// list of uTokens. // Returns error if any of the inputs are uTokens. -// tokens. -func (k Keeper) Tokens2uTokensRate(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { +func (k Keeper) ToTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { if err := uTokens.Validate(); err != nil { return sdk.Coins{}, err } diff --git a/x/leverage/keeper/limits.go b/x/leverage/keeper/limits.go index 8f2a189cb1..32884e97ea 100644 --- a/x/leverage/keeper/limits.go +++ b/x/leverage/keeper/limits.go @@ -282,7 +282,7 @@ func (k Keeper) ModuleAvailableLiquidity(ctx sdk.Context, denom string) (sdkmath // Get module collateral for the associated uToken totalCollateral := k.GetTotalCollateral(ctx, types.ToUTokenDenom(denom)) - totalTokenCollateral, err := k.Tokens2uTokensRate(ctx, sdk.NewCoins(totalCollateral)) + totalTokenCollateral, err := k.ToTokens(ctx, sdk.NewCoins(totalCollateral)) if err != nil { return sdkmath.Int{}, err } diff --git a/x/leverage/keeper/supply.go b/x/leverage/keeper/supply.go index e14f9bf9ee..709822cf6a 100644 --- a/x/leverage/keeper/supply.go +++ b/x/leverage/keeper/supply.go @@ -38,7 +38,7 @@ func (k Keeper) GetAllSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress) (sd } // convert the sum of found uTokens to base tokens - return k.Tokens2uTokensRate(ctx, collateral.Add(uTokens...)) + return k.ToTokens(ctx, collateral.Add(uTokens...)) } // GetTotalSupply returns the total supplied by all suppliers in a given denom, From c50332b5c093f6897ea9de820637c687e7dac251 Mon Sep 17 00:00:00 2001 From: Adam Moser <63419657+toteki@users.noreply.github.com> Date: Wed, 2 Aug 2023 12:06:40 -0600 Subject: [PATCH 11/11] name matches comment --- x/leverage/keeper/exchange_rate.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/leverage/keeper/exchange_rate.go b/x/leverage/keeper/exchange_rate.go index 89897dcbb6..769c6f3fde 100644 --- a/x/leverage/keeper/exchange_rate.go +++ b/x/leverage/keeper/exchange_rate.go @@ -41,9 +41,9 @@ func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) { return sdk.NewCoin(tokenDenom, tokenAmount), nil } -// ToToken returns list of Tokens in the amount a user would receive when withdrawing the +// ToTokens returns list of Tokens in the amount a user would receive when withdrawing the // list of uTokens. -// Returns error if any of the inputs are uTokens. +// Returns error if any of the inputs are tokens. func (k Keeper) ToTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { if err := uTokens.Validate(); err != nil { return sdk.Coins{}, err