diff --git a/CHANGELOG.md b/CHANGELOG.md index 9667f7d7ab..6f62826b76 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 `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 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/incentive/expected_keepers.go b/x/incentive/expected_keepers.go index bb310be1eb..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) - ExchangeUToken(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 49990f64b6..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.ExchangeUToken(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 423e1b758c..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 } -// 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) { +// 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 dcf3419654..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.ExchangeUToken(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.ExchangeUToken(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.ExchangeUToken(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 31786d4d99..cc6d2f1240 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.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.ExchangeUToken(ctx, coin) + baseAsset, err := k.ToToken(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.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 8cfb9b03fe..769c6f3fde 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) { +// 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 { 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) { +// 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 { return sdk.Coin{}, err } @@ -42,16 +41,17 @@ 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 -// tokens. -func (k Keeper) ExchangeUTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) { +// 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 tokens. +func (k Keeper) ToTokens(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.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 45cd997bde..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.ExchangeUToken(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 2266477193..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.ExchangeUToken(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 d3713b18dd..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.ExchangeToken(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.ExchangeToken(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.ExchangeUToken(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.ExchangeUToken(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 16cb9030ba..32884e97ea 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.ToUToken(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.ToTokens(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..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.ExchangeUToken(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 bb4cfc3b7d..709822cf6a 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.ToToken(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.ToTokens(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.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 0db126576b..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) - ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) - ExchangeUToken(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 d0247d2ac1..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.ExchangeToken(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/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(), diff --git a/x/metoken/keeper/mocks_test.go b/x/metoken/keeper/mocks_test.go index 0d3f18fdb4..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) ExchangeToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { +func (l Leverage) ToUToken(_ sdk.Context, _ sdk.Coin) (sdk.Coin, error) { panic("not implemented") } -func (l Leverage) ExchangeUToken(_ 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 a56bd7ee55..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.ExchangeToken(*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 8db05124a0..08dc92019d 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 { - // 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 - // 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{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: func(types.Context, types.Coin) (r0 types.Coin, r1 error) { - return - }, - }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - 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{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.ExchangeToken") - }, - }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - defaultHook: func(types.Context, types.Coin) (types.Coin, error) { - panic("unexpected invocation of MockLeverageKeeper.ExchangeUToken") - }, - }, - 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{ - ExchangeTokenFunc: &LeverageKeeperExchangeTokenFunc{ - defaultHook: i.ExchangeToken, - }, - ExchangeUTokenFunc: &LeverageKeeperExchangeUTokenFunc{ - defaultHook: i.ExchangeUToken, - }, - 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 } -// LeverageKeeperExchangeTokenFunc describes the behavior when the -// ExchangeToken method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperExchangeTokenFunc struct { - defaultHook func(types.Context, types.Coin) (types.Coin, error) - hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperExchangeTokenFuncCall - mutex sync.Mutex +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLeverageKeeper) EXPECT() *MockLeverageKeeperMockRecorder { + return m.recorder } -// ExchangeToken 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}) - 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 ExchangeToken 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)) { - 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 -// ExchangeToken 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)) { - 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 *LeverageKeeperExchangeTokenFunc) 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 *LeverageKeeperExchangeTokenFunc) 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 *LeverageKeeperExchangeTokenFunc) 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 *LeverageKeeperExchangeTokenFunc) appendCall(r0 LeverageKeeperExchangeTokenFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperExchangeTokenFuncCall objects -// describing the invocations of this function. -func (f *LeverageKeeperExchangeTokenFunc) History() []LeverageKeeperExchangeTokenFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperExchangeTokenFuncCall, 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) } -// LeverageKeeperExchangeTokenFuncCall is an object that describes an -// invocation of method ExchangeToken on an instance of MockLeverageKeeper. -type LeverageKeeperExchangeTokenFuncCall 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 LeverageKeeperExchangeTokenFuncCall) 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 LeverageKeeperExchangeTokenFuncCall) 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 } -// LeverageKeeperExchangeUTokenFunc describes the behavior when the -// ExchangeUToken method of the parent MockLeverageKeeper instance is -// invoked. -type LeverageKeeperExchangeUTokenFunc struct { - defaultHook func(types.Context, types.Coin) (types.Coin, error) - hooks []func(types.Context, types.Coin) (types.Coin, error) - history []LeverageKeeperExchangeUTokenFuncCall - 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) } -// ExchangeUToken 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}) - return r0, r1 +// 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, "ToToken", ctx, uToken) + ret0, _ := ret[0].(types.Coin) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// SetDefaultHook sets function that is called when the ExchangeUToken -// 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)) { - f.defaultHook = hook +// 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, "ToToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToToken), ctx, uToken) } -// PushHook adds a function to the end of hook queue. Each invocation of the -// ExchangeUToken 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)) { - f.mutex.Lock() - f.hooks = append(f.hooks, hook) - f.mutex.Unlock() +// 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, "ToUToken", ctx, token) + 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 *LeverageKeeperExchangeUTokenFunc) SetDefaultReturn(r0 types.Coin, r1 error) { - f.SetDefaultHook(func(types.Context, types.Coin) (types.Coin, error) { - return r0, r1 - }) +// 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, "ToUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ToUToken), ctx, token) } -// PushReturn calls PushHook with a function that returns the given values. -func (f *LeverageKeeperExchangeUTokenFunc) 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 *LeverageKeeperExchangeUTokenFunc) 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 *LeverageKeeperExchangeUTokenFunc) appendCall(r0 LeverageKeeperExchangeUTokenFuncCall) { - f.mutex.Lock() - f.history = append(f.history, r0) - f.mutex.Unlock() -} - -// History returns a sequence of LeverageKeeperExchangeUTokenFuncCall -// objects describing the invocations of this function. -func (f *LeverageKeeperExchangeUTokenFunc) History() []LeverageKeeperExchangeUTokenFuncCall { - f.mutex.Lock() - history := make([]LeverageKeeperExchangeUTokenFuncCall, 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 { - // 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 LeverageKeeperExchangeUTokenFuncCall) Args() []interface{} { - return []interface{}{c.Arg0, c.Arg1} -} - -// Results returns an interface slice containing the results of this -// invocation. -func (c LeverageKeeperExchangeUTokenFuncCall) 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/expected_keepers.go b/x/uibc/expected_keepers.go index 2b8f61a655..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) - ExchangeUToken(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 cd0a9be211..0f0154c282 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) } -// ExchangeUToken mocks base method. -func (m *MockLeverageKeeper) ExchangeUToken(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, "ExchangeUToken", 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 } -// ExchangeUToken indicates an expected call of ExchangeUToken. -func (mr *MockLeverageKeeperMockRecorder) ExchangeUToken(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, "ExchangeUToken", reflect.TypeOf((*MockLeverageKeeper)(nil).ExchangeUToken), 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) { +// 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, "GetTokenSettings", ctx, baseDenom) - ret0, _ := ret[0].(types1.Token) + ret := m.ctrl.Call(m, "ToToken", 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 { +// 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, "GetTokenSettings", reflect.TypeOf((*MockLeverageKeeper)(nil).GetTokenSettings), ctx, baseDenom) + 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 7fb32c0d65..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) @@ -53,14 +51,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().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().ExchangeUToken(ctx, umeeUToken).Return( + leverageMock.EXPECT().ToToken(ctx, umeeUToken).Return( sdk.NewCoin("umee", sdkmath.NewInt(100)), nil, ).AnyTimes() @@ -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) diff --git a/x/uibc/quota/keeper/mocks_test.go b/x/uibc/quota/keeper/mocks_test.go index 33c2df0e3c..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) ExchangeUToken(_ 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 57395916bf..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.ExchangeUToken(*k.ctx, transferCoin) + transferCoin, err = k.leverage.ToToken(*k.ctx, transferCoin) if err != nil { return sdk.Dec{}, err }