Merge PR #4661: x/supply: use internal package

This commit is contained in:
Federico Kunze 2019-07-02 18:24:13 +02:00 committed by Alexander Bezobchuk
parent 66e85c592d
commit 179476d6b0
31 changed files with 65 additions and 36 deletions

View File

@ -1,4 +1,6 @@
#4255 Add supply module that passively tracks the supplies of a chain
- Renamed `x/distribution` `ModuleName`
- Genesis JSON and CLI now use `distribution` instead of `distr`
- Introduce `ModuleAccount` type, which tracks the flow of coins held within a module
- Replaced `FeeCollectorKeeper` for a `ModuleAccount`
- Replaced the staking `Pool`, which coins are now held by the `BondedPool` and `NotBonded` module accounts

View File

@ -910,7 +910,6 @@ func TestAppImportExport(t *testing.T) {
if err != nil {
panic(err)
}
fmt.Printf("debug genesisState: %s\n", genesisState)
ctxB := newApp.NewContext(true, abci.Header{})
newApp.mm.InitGenesis(ctxB, genesisState)

View File

@ -5,6 +5,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
@ -12,7 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
supplytypes "github.com/cosmos/cosmos-sdk/x/supply/types"
)
type testInput struct {
@ -22,12 +22,32 @@ type testInput struct {
sk types.SupplyKeeper
}
// moduleAccount defines an account for modules that holds coins on a pool
type moduleAccount struct {
*types.BaseAccount
Name string `json:"name"` // name of the module
Permission string `json:"permission"` // permission of module account (minter/burner/holder)
}
// GetName returns the the name of the holder's module
func (ma moduleAccount) GetName() string {
return ma.Name
}
// GetPermission returns permission granted to the module account (holder/minter/burner)
func (ma moduleAccount) GetPermission() string {
return ma.Permission
}
func setupTestInput() testInput {
db := dbm.NewMemDB()
cdc := codec.New()
types.RegisterCodec(cdc)
supplytypes.RegisterCodec(cdc)
cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil)
cdc.RegisterConcrete(&moduleAccount{}, "cosmos-sdk/ModuleAccount", nil)
codec.RegisterCrypto(cdc)
authCapKey := sdk.NewKVStoreKey("authCapKey")
@ -101,8 +121,16 @@ func (sk DummySupplyKeeper) GetModuleAccount(ctx sdk.Context, moduleName string)
}
}
moduleAddress := sk.GetModuleAddress(moduleName)
baseAcc := types.NewBaseAccountWithAddress(moduleAddress)
// create a new module account
macc := supplytypes.NewEmptyModuleAccount(moduleName, "basic")
macc := &moduleAccount{
BaseAccount: &baseAcc,
Name: moduleName,
Permission: "basic",
}
maccI := (sk.ak.NewAccount(ctx, macc)).(exported.ModuleAccountI)
sk.ak.SetAccount(ctx, maccI)
return maccI
@ -110,5 +138,5 @@ func (sk DummySupplyKeeper) GetModuleAccount(ctx sdk.Context, moduleName string)
// GetModuleAddress for dummy supply keeper
func (sk DummySupplyKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
return supplytypes.NewModuleAddress(moduleName)
return sdk.AccAddress(crypto.AddressHash([]byte(moduleName)))
}

View File

@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/internal/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
"github.com/cosmos/cosmos-sdk/x/mock"
supplytypes "github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/stretchr/testify/require"
@ -93,7 +93,7 @@ var (
// initialize the mock application for this module
func getMockApp(t *testing.T) *mock.App {
mapp, err := getBenchmarkMockApp()
supplytypes.RegisterCodec(mapp.Cdc)
supply.RegisterCodec(mapp.Cdc)
require.NoError(t, err)
return mapp
}

View File

@ -11,7 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
supplytypes "github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply"
)
func TestGenesisAccountValidate(t *testing.T) {
@ -28,7 +28,7 @@ func TestGenesisAccountValidate(t *testing.T) {
},
{
"valid module account",
NewGenesisAccountRaw(addr, sdk.NewCoins(), sdk.NewCoins(), 0, 0, "mint", supplytypes.Minter),
NewGenesisAccountRaw(addr, sdk.NewCoins(), sdk.NewCoins(), 0, 0, "mint", supply.Minter),
nil,
},
{
@ -88,10 +88,10 @@ func TestToAccount(t *testing.T) {
require.Equal(t, vacc, acc.(*auth.ContinuousVestingAccount))
// module account
macc := supplytypes.NewEmptyModuleAccount("mint", supplytypes.Minter)
macc := supply.NewEmptyModuleAccount("mint", supply.Minter)
genAcc, err = NewGenesisAccountI(macc)
require.NoError(t, err)
acc = genAcc.ToAccount()
require.IsType(t, &supplytypes.ModuleAccount{}, acc)
require.Equal(t, macc, acc.(*supplytypes.ModuleAccount))
require.IsType(t, &supply.ModuleAccount{}, acc)
require.Equal(t, macc, acc.(*supply.ModuleAccount))
}

View File

@ -8,7 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
supplytypes "github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
)
const msgRoute = "testMsg"
@ -52,7 +52,7 @@ func getMockApp(t *testing.T) *App {
func TestCheckAndDeliverGenTx(t *testing.T) {
mApp := getMockApp(t)
mApp.Cdc.RegisterConcrete(testMsg{}, "mock/testMsg", nil)
supplytypes.RegisterCodec(mApp.Cdc)
mApp.Cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil)
SetGenesis(mApp, accs)
ctxCheck := mApp.BaseApp.NewContext(true, abci.Header{})
@ -92,7 +92,7 @@ func TestCheckAndDeliverGenTx(t *testing.T) {
func TestCheckGenTx(t *testing.T) {
mApp := getMockApp(t)
mApp.Cdc.RegisterConcrete(testMsg{}, "mock/testMsg", nil)
supplytypes.RegisterCodec(mApp.Cdc)
mApp.Cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil)
SetGenesis(mApp, accs)

View File

@ -1,13 +1,13 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/types
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/internal/keeper
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/supply/internal/types
package supply
import (
"github.com/cosmos/cosmos-sdk/x/supply/keeper"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/keeper"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
const (

View File

@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
"github.com/spf13/cobra"
)

View File

@ -8,7 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// RegisterRoutes registers staking-related REST handlers to a router

View File

@ -3,7 +3,7 @@ package supply
import (
sdk "github.com/cosmos/cosmos-sdk/types"
autypes "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// InitGenesis sets supply information for genesis.

View File

@ -3,7 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/exported"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// GetModuleAddress returns a an address based on the name

View File

@ -4,7 +4,7 @@ import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress

View File

@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
const initialPower = int64(100)
@ -63,11 +63,12 @@ func TestSendCoins(t *testing.T) {
err = keeper.SendCoinsFromModuleToAccount(ctx, types.Burner, baseAcc.GetAddress(), initCoins)
require.NoError(t, err)
require.Equal(t, sdk.Coins(nil), getCoinsByName(ctx, keeper, types.Burner))
require.Equal(t, initCoins, keeper.bk.GetCoins(ctx, baseAcc.GetAddress()))
require.Equal(t, initCoins, keeper.ak.GetAccount(ctx, baseAcc.GetAddress()).GetCoins())
err = keeper.SendCoinsFromAccountToModule(ctx, baseAcc.GetAddress(), types.Burner, initCoins)
require.NoError(t, err)
require.Equal(t, sdk.Coins(nil), keeper.bk.GetCoins(ctx, baseAcc.GetAddress()))
require.Equal(t, sdk.Coins(nil), keeper.ak.GetAccount(ctx, baseAcc.GetAddress()).GetCoins())
require.Equal(t, initCoins, getCoinsByName(ctx, keeper, types.Burner))
}

View File

@ -5,7 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// RegisterInvariants register all supply invariants

View File

@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// Keeper of the supply store

View File

@ -2,7 +2,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// DefaultCodespace from the supply module

View File

@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
// NewQuerier creates a querier for supply REST endpoints

View File

@ -8,7 +8,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
func TestNewQuerier(t *testing.T) {

View File

@ -16,7 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -91,4 +91,4 @@ func createTestAccs(ctx sdk.Context, numAccs int, initialCoins sdk.Coins, ak *au
ak.SetAccount(ctx, &acc)
}
return
}
}

View File

@ -15,7 +15,6 @@ type AccountKeeper interface {
// BankKeeper defines the expected bank keeper (noalias)
type BankKeeper interface {
GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) sdk.Error
DelegateCoins(ctx sdk.Context, fromAdd, toAddr sdk.AccAddress, amt sdk.Coins) sdk.Error
UndelegateCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) sdk.Error

View File

@ -14,7 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/supply/client/cli"
"github.com/cosmos/cosmos-sdk/x/supply/client/rest"
"github.com/cosmos/cosmos-sdk/x/supply/types"
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
)
var (