diff --git a/.pending/breaking/sdk/3972-supply b/.pending/breaking/sdk/3972-supply index 18502d3d7d89..04ab4b9ebb5f 100644 --- a/.pending/breaking/sdk/3972-supply +++ b/.pending/breaking/sdk/3972-supply @@ -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 diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 808e07bd51a0..3025a004f52b 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -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) diff --git a/x/auth/test_common.go b/x/auth/test_common.go index 8b7b0f7901df..eef914aebe2b 100644 --- a/x/auth/test_common.go +++ b/x/auth/test_common.go @@ -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))) } diff --git a/x/bank/app_test.go b/x/bank/app_test.go index e2eec1024fe0..9097a6d0e5d4 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -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 } diff --git a/x/genaccounts/genesis_account_test.go b/x/genaccounts/genesis_account_test.go index de5aebbb3d7a..39eb4a42a431 100644 --- a/x/genaccounts/genesis_account_test.go +++ b/x/genaccounts/genesis_account_test.go @@ -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)) } diff --git a/x/mock/app_test.go b/x/mock/app_test.go index 4f555c029903..83981f039d16 100644 --- a/x/mock/app_test.go +++ b/x/mock/app_test.go @@ -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) diff --git a/x/supply/alias.go b/x/supply/alias.go index 6a0ebda3d197..c0ee07b92785 100644 --- a/x/supply/alias.go +++ b/x/supply/alias.go @@ -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 ( diff --git a/x/supply/client/cli/query.go b/x/supply/client/cli/query.go index ef508d99fe8e..de0f25d22f2b 100644 --- a/x/supply/client/cli/query.go +++ b/x/supply/client/cli/query.go @@ -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" ) diff --git a/x/supply/client/rest/query.go b/x/supply/client/rest/query.go index 84f8f91b8e30..9e109513d9e3 100644 --- a/x/supply/client/rest/query.go +++ b/x/supply/client/rest/query.go @@ -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 diff --git a/x/supply/genesis.go b/x/supply/genesis.go index 7529e1590505..07ad939404e5 100644 --- a/x/supply/genesis.go +++ b/x/supply/genesis.go @@ -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. diff --git a/x/supply/keeper/account.go b/x/supply/internal/keeper/account.go similarity index 96% rename from x/supply/keeper/account.go rename to x/supply/internal/keeper/account.go index 165888c56080..96a4ea3f52f7 100644 --- a/x/supply/keeper/account.go +++ b/x/supply/internal/keeper/account.go @@ -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 diff --git a/x/supply/keeper/bank.go b/x/supply/internal/keeper/bank.go similarity index 98% rename from x/supply/keeper/bank.go rename to x/supply/internal/keeper/bank.go index 17e3a16d7825..f8277566cee5 100644 --- a/x/supply/keeper/bank.go +++ b/x/supply/internal/keeper/bank.go @@ -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 diff --git a/x/supply/keeper/bank_test.go b/x/supply/internal/keeper/bank_test.go similarity index 93% rename from x/supply/keeper/bank_test.go rename to x/supply/internal/keeper/bank_test.go index d10ef09c9951..e7c33e9a7b21 100644 --- a/x/supply/keeper/bank_test.go +++ b/x/supply/internal/keeper/bank_test.go @@ -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)) } diff --git a/x/supply/keeper/invariants.go b/x/supply/internal/keeper/invariants.go similarity index 95% rename from x/supply/keeper/invariants.go rename to x/supply/internal/keeper/invariants.go index 6122d7b80188..51c957fa9622 100644 --- a/x/supply/keeper/invariants.go +++ b/x/supply/internal/keeper/invariants.go @@ -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 diff --git a/x/supply/keeper/keeper.go b/x/supply/internal/keeper/keeper.go similarity index 97% rename from x/supply/keeper/keeper.go rename to x/supply/internal/keeper/keeper.go index d47f0a027c32..22980d8be879 100644 --- a/x/supply/keeper/keeper.go +++ b/x/supply/internal/keeper/keeper.go @@ -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 diff --git a/x/supply/keeper/keeper_test.go b/x/supply/internal/keeper/keeper_test.go similarity index 100% rename from x/supply/keeper/keeper_test.go rename to x/supply/internal/keeper/keeper_test.go diff --git a/x/supply/keeper/key.go b/x/supply/internal/keeper/key.go similarity index 84% rename from x/supply/keeper/key.go rename to x/supply/internal/keeper/key.go index 460bfcd97463..6428d5445c05 100644 --- a/x/supply/keeper/key.go +++ b/x/supply/internal/keeper/key.go @@ -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 diff --git a/x/supply/keeper/querier.go b/x/supply/internal/keeper/querier.go similarity index 97% rename from x/supply/keeper/querier.go rename to x/supply/internal/keeper/querier.go index fe34d9a52db1..575c5fbd875b 100644 --- a/x/supply/keeper/querier.go +++ b/x/supply/internal/keeper/querier.go @@ -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 diff --git a/x/supply/keeper/querier_test.go b/x/supply/internal/keeper/querier_test.go similarity index 97% rename from x/supply/keeper/querier_test.go rename to x/supply/internal/keeper/querier_test.go index d7ee5157c45b..2a06d9ee5828 100644 --- a/x/supply/keeper/querier_test.go +++ b/x/supply/internal/keeper/querier_test.go @@ -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) { diff --git a/x/supply/keeper/test_common.go b/x/supply/internal/keeper/test_common.go similarity index 98% rename from x/supply/keeper/test_common.go rename to x/supply/internal/keeper/test_common.go index 2235f7452249..24e39b7c70db 100644 --- a/x/supply/keeper/test_common.go +++ b/x/supply/internal/keeper/test_common.go @@ -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 -} +} \ No newline at end of file diff --git a/x/supply/types/account.go b/x/supply/internal/types/account.go similarity index 100% rename from x/supply/types/account.go rename to x/supply/internal/types/account.go diff --git a/x/supply/types/account_test.go b/x/supply/internal/types/account_test.go similarity index 100% rename from x/supply/types/account_test.go rename to x/supply/internal/types/account_test.go diff --git a/x/supply/types/codec.go b/x/supply/internal/types/codec.go similarity index 100% rename from x/supply/types/codec.go rename to x/supply/internal/types/codec.go diff --git a/x/supply/types/expected_keepers.go b/x/supply/internal/types/expected_keepers.go similarity index 94% rename from x/supply/types/expected_keepers.go rename to x/supply/internal/types/expected_keepers.go index 5c11f1994b9f..bf0cc6ec328a 100644 --- a/x/supply/types/expected_keepers.go +++ b/x/supply/internal/types/expected_keepers.go @@ -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 diff --git a/x/supply/types/genesis.go b/x/supply/internal/types/genesis.go similarity index 100% rename from x/supply/types/genesis.go rename to x/supply/internal/types/genesis.go diff --git a/x/supply/types/key.go b/x/supply/internal/types/key.go similarity index 100% rename from x/supply/types/key.go rename to x/supply/internal/types/key.go diff --git a/x/supply/types/permissions.go b/x/supply/internal/types/permissions.go similarity index 100% rename from x/supply/types/permissions.go rename to x/supply/internal/types/permissions.go diff --git a/x/supply/types/querier.go b/x/supply/internal/types/querier.go similarity index 100% rename from x/supply/types/querier.go rename to x/supply/internal/types/querier.go diff --git a/x/supply/types/supply.go b/x/supply/internal/types/supply.go similarity index 100% rename from x/supply/types/supply.go rename to x/supply/internal/types/supply.go diff --git a/x/supply/types/supply_test.go b/x/supply/internal/types/supply_test.go similarity index 100% rename from x/supply/types/supply_test.go rename to x/supply/internal/types/supply_test.go diff --git a/x/supply/module.go b/x/supply/module.go index ac576537c43b..4c1b1d85524a 100644 --- a/x/supply/module.go +++ b/x/supply/module.go @@ -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 (