0g-chain/x/precisebank/keeper/keeper_test.go

54 lines
1.6 KiB
Go
Raw Permalink Normal View History

package keeper_test
import (
"testing"
sdkmath "cosmossdk.io/math"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
2024-09-25 15:31:20 +00:00
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/x/precisebank/keeper"
"github.com/0glabs/0g-chain/x/precisebank/types"
"github.com/0glabs/0g-chain/x/precisebank/types/mocks"
)
// testData defines necessary fields for testing keeper store methods and mocks
// for unit tests without full app setup.
type testData struct {
ctx sdk.Context
keeper keeper.Keeper
storeKey *storetypes.KVStoreKey
bk *mocks.MockBankKeeper
ak *mocks.MockAccountKeeper
}
// NewMockedTestData creates a new testData instance with mocked bank and
// account keepers.
func NewMockedTestData(t *testing.T) testData {
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)
bk := mocks.NewMockBankKeeper(t)
ak := mocks.NewMockAccountKeeper(t)
tApp := app.NewTestApp()
cdc := tApp.AppCodec()
k := keeper.NewKeeper(cdc, storeKey, bk, ak)
return testData{
ctx: ctx,
keeper: k,
storeKey: storeKey,
bk: bk,
ak: ak,
}
}
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...) }