2024-05-16 22:30:31 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
2024-05-21 21:11:13 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-05-24 19:03:09 +00:00
|
|
|
sdkmath "cosmossdk.io/math"
|
2024-05-16 22:30:31 +00:00
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/precisebank/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/precisebank/types"
|
2024-05-21 21:11:13 +00:00
|
|
|
"github.com/kava-labs/kava/x/precisebank/types/mocks"
|
2024-05-16 22:30:31 +00:00
|
|
|
)
|
|
|
|
|
2024-05-21 21:11:13 +00:00
|
|
|
// testData defines necessary fields for testing keeper store methods and mocks
|
|
|
|
// for unit tests without full app setup.
|
|
|
|
type testData struct {
|
2024-05-16 22:30:31 +00:00
|
|
|
ctx sdk.Context
|
|
|
|
keeper keeper.Keeper
|
|
|
|
storeKey *storetypes.KVStoreKey
|
2024-05-21 21:11:13 +00:00
|
|
|
bk *mocks.MockBankKeeper
|
|
|
|
ak *mocks.MockAccountKeeper
|
2024-05-16 22:30:31 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 21:11:13 +00:00
|
|
|
// NewMockedTestData creates a new testData instance with mocked bank and
|
|
|
|
// account keepers.
|
|
|
|
func NewMockedTestData(t *testing.T) testData {
|
2024-05-16 22:30:31 +00:00
|
|
|
storeKey := sdk.NewKVStoreKey(types.ModuleName)
|
|
|
|
// Not required by module, but needs to be non-nil for context
|
|
|
|
tKey := sdk.NewTransientStoreKey("transient_test")
|
|
|
|
ctx := testutil.DefaultContext(storeKey, tKey)
|
|
|
|
|
2024-05-21 21:11:13 +00:00
|
|
|
bk := mocks.NewMockBankKeeper(t)
|
|
|
|
ak := mocks.NewMockAccountKeeper(t)
|
|
|
|
|
2024-05-16 22:30:31 +00:00
|
|
|
tApp := app.NewTestApp()
|
|
|
|
cdc := tApp.AppCodec()
|
2024-05-21 21:11:13 +00:00
|
|
|
k := keeper.NewKeeper(cdc, storeKey, bk, ak)
|
2024-05-16 22:30:31 +00:00
|
|
|
|
2024-05-21 21:11:13 +00:00
|
|
|
return testData{
|
2024-05-16 22:30:31 +00:00
|
|
|
ctx: ctx,
|
|
|
|
keeper: k,
|
|
|
|
storeKey: storeKey,
|
2024-05-21 21:11:13 +00:00
|
|
|
bk: bk,
|
|
|
|
ak: ak,
|
2024-05-16 22:30:31 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-24 19:03:09 +00:00
|
|
|
|
|
|
|
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
|
|
|
|
func ci(denom string, amount sdkmath.Int) sdk.Coin { return sdk.NewCoin(denom, amount) }
|
|
|
|
func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) }
|