96 lines
3.7 KiB
Go
96 lines
3.7 KiB
Go
// nolint:deadcode unused
|
|
package keeper
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
dbm "github.com/tendermint/tm-db"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
"github.com/cosmos/cosmos-sdk/x/mint/internal/types"
|
|
"github.com/cosmos/cosmos-sdk/x/params"
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
"github.com/cosmos/cosmos-sdk/x/supply"
|
|
)
|
|
|
|
type testInput struct {
|
|
ctx sdk.Context
|
|
cdc *codec.Codec
|
|
mintKeeper Keeper
|
|
}
|
|
|
|
func newTestInput(t *testing.T) testInput {
|
|
db := dbm.NewMemDB()
|
|
|
|
keyAcc := sdk.NewKVStoreKey(auth.StoreKey)
|
|
keySupply := sdk.NewKVStoreKey(supply.StoreKey)
|
|
keyStaking := sdk.NewKVStoreKey(staking.StoreKey)
|
|
tkeyStaking := sdk.NewTransientStoreKey(staking.TStoreKey)
|
|
keyParams := sdk.NewKVStoreKey(params.StoreKey)
|
|
tkeyParams := sdk.NewTransientStoreKey(params.TStoreKey)
|
|
keyMint := sdk.NewKVStoreKey(types.StoreKey)
|
|
|
|
ms := store.NewCommitMultiStore(db)
|
|
ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(tkeyStaking, sdk.StoreTypeTransient, nil)
|
|
ms.MountStoreWithDB(keyStaking, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(keySupply, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(keyMint, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
|
|
err := ms.LoadLatestVersion()
|
|
require.Nil(t, err)
|
|
|
|
ctx := sdk.NewContext(ms, abci.Header{Time: time.Unix(0, 0)}, false, log.NewTMLogger(os.Stdout))
|
|
|
|
feeCollectorAcc := supply.NewEmptyModuleAccount(auth.FeeCollectorName)
|
|
notBondedPool := supply.NewEmptyModuleAccount(staking.NotBondedPoolName, supply.Burner, supply.Staking)
|
|
bondPool := supply.NewEmptyModuleAccount(staking.BondedPoolName, supply.Burner, supply.Staking)
|
|
minterAcc := supply.NewEmptyModuleAccount(types.ModuleName, supply.Minter)
|
|
|
|
blacklistedAddrs := make(map[string]bool)
|
|
blacklistedAddrs[feeCollectorAcc.String()] = true
|
|
blacklistedAddrs[notBondedPool.String()] = true
|
|
blacklistedAddrs[bondPool.String()] = true
|
|
blacklistedAddrs[minterAcc.String()] = true
|
|
|
|
paramsKeeper := params.NewKeeper(types.ModuleCdc, keyParams, tkeyParams, params.DefaultCodespace)
|
|
accountKeeper := auth.NewAccountKeeper(types.ModuleCdc, keyAcc, paramsKeeper.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
|
|
bankKeeper := bank.NewBaseKeeper(accountKeeper, paramsKeeper.Subspace(bank.DefaultParamspace), bank.DefaultCodespace, blacklistedAddrs)
|
|
maccPerms := map[string][]string{
|
|
auth.FeeCollectorName: nil,
|
|
types.ModuleName: {supply.Minter},
|
|
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
|
|
staking.BondedPoolName: {supply.Burner, supply.Staking},
|
|
}
|
|
supplyKeeper := supply.NewKeeper(types.ModuleCdc, keySupply, accountKeeper, bankKeeper, maccPerms)
|
|
supplyKeeper.SetSupply(ctx, supply.NewSupply(sdk.Coins{}))
|
|
|
|
stakingKeeper := staking.NewKeeper(
|
|
types.ModuleCdc, keyStaking, tkeyStaking, supplyKeeper, paramsKeeper.Subspace(staking.DefaultParamspace), staking.DefaultCodespace,
|
|
)
|
|
mintKeeper := NewKeeper(types.ModuleCdc, keyMint, paramsKeeper.Subspace(types.DefaultParamspace), &stakingKeeper, supplyKeeper, auth.FeeCollectorName)
|
|
|
|
// set module accounts
|
|
supplyKeeper.SetModuleAccount(ctx, feeCollectorAcc)
|
|
supplyKeeper.SetModuleAccount(ctx, minterAcc)
|
|
supplyKeeper.SetModuleAccount(ctx, notBondedPool)
|
|
supplyKeeper.SetModuleAccount(ctx, bondPool)
|
|
|
|
mintKeeper.SetParams(ctx, types.DefaultParams())
|
|
mintKeeper.SetMinter(ctx, types.DefaultInitialMinter())
|
|
|
|
return testInput{ctx, types.ModuleCdc, mintKeeper}
|
|
}
|