Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/supply: use internal package #4661

Merged
merged 4 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pending/breaking/sdk/3972-supply
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 32 additions & 4 deletions x/auth/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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"
sdk "github.com/cosmos/cosmos-sdk/types"
"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 {
Expand All @@ -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")
Expand Down Expand Up @@ -101,14 +121,22 @@ 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
}

// GetModuleAddress for dummy supply keeper
func (sk DummySupplyKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
return supplytypes.NewModuleAddress(moduleName)
return sdk.AccAddress(crypto.AddressHash([]byte(moduleName)))
}
4 changes: 2 additions & 2 deletions x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions x/genaccounts/genesis_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
},
{
Expand Down Expand Up @@ -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))
}
6 changes: 3 additions & 3 deletions x/mock/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions x/supply/alias.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion x/supply/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion x/supply/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/supply/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion x/supply/keeper/key.go → x/supply/internal/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -91,4 +91,4 @@ func createTestAccs(ctx sdk.Context, numAccs int, initialCoins sdk.Coins, ak *au
ak.SetAccount(ctx, &acc)
}
return
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion x/supply/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down