Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jul 20, 2022
1 parent 4987c3a commit 97dcf3e
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 62 deletions.
2 changes: 1 addition & 1 deletion x/bank/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (k BaseKeeper) SpendableBalances(ctx context.Context, req *types.QuerySpend
accountStore := k.getAccountStore(sdkCtx, addr)
zeroAmt := sdk.ZeroInt()

pageRes, err := query.Paginate(accountStore, req.Pagination, func(key, value []byte) error {
pageRes, err := query.Paginate(accountStore, req.Pagination, func(key, _ []byte) error {
balances = append(balances, sdk.NewCoin(string(key), zeroAmt))
return nil
})
Expand Down
22 changes: 11 additions & 11 deletions x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
req: &types.QuerySendEnabledRequest{Denoms: []string{}},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"falsestcoin", false},
{"truestcoin", true},
{Denom: "falsestcoin", Enabled: false},
{Denom: "truestcoin", Enabled: true},
},
Pagination: &query.PageResponse{
NextKey: nil,
Expand All @@ -484,8 +484,8 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
req: &types.QuerySendEnabledRequest{Denoms: []string{}},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"falsestcoin", false},
{"truestcoin", true},
{Denom: "falsestcoin", Enabled: false},
{Denom: "truestcoin", Enabled: true},
},
Pagination: &query.PageResponse{
NextKey: nil,
Expand All @@ -503,7 +503,7 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"falsestcoin", false},
{Denom: "falsestcoin", Enabled: false},
},
Pagination: &query.PageResponse{
NextKey: []byte("truestcoin"),
Expand All @@ -516,7 +516,7 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
req: &types.QuerySendEnabledRequest{Denoms: []string{"truestcoin"}},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"truestcoin", true},
{Denom: "truestcoin", Enabled: true},
},
Pagination: nil,
},
Expand All @@ -526,7 +526,7 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
req: &types.QuerySendEnabledRequest{Denoms: []string{"falsestcoin"}},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"falsestcoin", false},
{Denom: "falsestcoin", Enabled: false},
},
Pagination: nil,
},
Expand All @@ -544,8 +544,8 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
req: &types.QuerySendEnabledRequest{Denoms: []string{"truestcoin", "falsestcoin"}},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"truestcoin", true},
{"falsestcoin", false},
{Denom: "truestcoin", Enabled: true},
{Denom: "falsestcoin", Enabled: false},
},
Pagination: nil,
},
Expand All @@ -555,8 +555,8 @@ func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
req: &types.QuerySendEnabledRequest{Denoms: []string{"truestcoin", "falsestcoin", "unknownestcoin"}},
exp: &types.QuerySendEnabledResponse{
SendEnabled: []*types.SendEnabled{
{"truestcoin", true},
{"falsestcoin", false},
{Denom: "truestcoin", Enabled: true},
{Denom: "falsestcoin", Enabled: false},
},
Pagination: nil,
},
Expand Down
53 changes: 28 additions & 25 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/cosmos/cosmos-sdk/x/bank/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)
Expand Down Expand Up @@ -74,6 +75,7 @@ type IntegrationTestSuite struct {
app *simapp.SimApp
ctx sdk.Context
queryClient types.QueryClient
msgServer types.MsgServer
}

func (suite *IntegrationTestSuite) initKeepersWithmAccPerms(blockedAddrs map[string]bool) (authkeeper.AccountKeeper, keeper.BaseKeeper) {
Expand Down Expand Up @@ -111,6 +113,7 @@ func (suite *IntegrationTestSuite) SetupTest() {
suite.app = app
suite.ctx = ctx
suite.queryClient = queryClient
suite.msgServer = keeper.NewMsgServerImpl(app.BankKeeper)
}

func (suite *IntegrationTestSuite) TestSupply() {
Expand Down Expand Up @@ -1147,9 +1150,9 @@ func (suite *IntegrationTestSuite) getTestMetadata() []types.Metadata {
Symbol: "ATOM",
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*types.DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
{Denom: "uatom", Exponent: uint32(0), Aliases: []string{"microatom"}},
{Denom: "matom", Exponent: uint32(3), Aliases: []string{"milliatom"}},
{Denom: "atom", Exponent: uint32(6), Aliases: nil},
},
Base: "uatom",
Display: "atom",
Expand All @@ -1159,9 +1162,9 @@ func (suite *IntegrationTestSuite) getTestMetadata() []types.Metadata {
Symbol: "TOKEN",
Description: "The native staking token of the Token Hub.",
DenomUnits: []*types.DenomUnit{
{"1token", uint32(5), []string{"decitoken"}},
{"2token", uint32(4), []string{"centitoken"}},
{"3token", uint32(7), []string{"dekatoken"}},
{Denom: "1token", Exponent: uint32(5), Aliases: []string{"decitoken"}},
{Denom: "2token", Exponent: uint32(4), Aliases: []string{"centitoken"}},
{Denom: "3token", Exponent: uint32(7), Aliases: []string{"dekatoken"}},
},
Base: "utoken",
Display: "token",
Expand Down Expand Up @@ -1194,7 +1197,7 @@ func (suite *IntegrationTestSuite) TestMintCoinRestrictions() {
}{
{
"restriction",
func(ctx sdk.Context, coins sdk.Coins) error {
func(_ sdk.Context, coins sdk.Coins) error {
for _, coin := range coins {
if coin.Denom != fooDenom {
return fmt.Errorf("Module %s only has perms for minting %s coins, tried minting %s coins", types.ModuleName, fooDenom, coin.Denom)
Expand Down Expand Up @@ -1406,41 +1409,41 @@ func (suite *IntegrationTestSuite) TestSetAllSendEnabled() {
{
name: "one true",
sendEnableds: []*types.SendEnabled{
{"aonecoin", true},
{Denom: "aonecoin", Enabled: true},
},
},
{
name: "one false",
sendEnableds: []*types.SendEnabled{
{"bonecoin", false},
{Denom: "bonecoin", Enabled: false},
},
},
{
name: "two true",
sendEnableds: []*types.SendEnabled{
{"conecoin", true},
{"ctwocoin", true},
{Denom: "conecoin", Enabled: true},
{Denom: "ctwocoin", Enabled: true},
},
},
{
name: "two true false",
sendEnableds: []*types.SendEnabled{
{"donecoin", true},
{"dtwocoin", false},
{Denom: "donecoin", Enabled: true},
{Denom: "dtwocoin", Enabled: false},
},
},
{
name: "two false true",
sendEnableds: []*types.SendEnabled{
{"eonecoin", false},
{"etwocoin", true},
{Denom: "eonecoin", Enabled: false},
{Denom: "etwocoin", Enabled: true},
},
},
{
name: "two false",
sendEnableds: []*types.SendEnabled{
{"fonecoin", false},
{"ftwocoin", false},
{Denom: "fonecoin", Enabled: false},
{Denom: "ftwocoin", Enabled: false},
},
},
}
Expand Down Expand Up @@ -1481,7 +1484,7 @@ func (suite *IntegrationTestSuite) TestIterateSendEnabledEntries() {

suite.T().Run("no entries to iterate", func(t *testing.T) {
count := 0
bankKeeper.IterateSendEnabledEntries(ctx, func(denom string, sendEnabled bool) (stop bool) {
bankKeeper.IterateSendEnabledEntries(ctx, func(_ string, _ bool) (stop bool) {
count++
return false
})
Expand Down Expand Up @@ -1523,7 +1526,7 @@ func (suite *IntegrationTestSuite) TestIterateSendEnabledEntries() {

suite.T().Run("no entries to iterate again after deleting all of them", func(t *testing.T) {
count := 0
bankKeeper.IterateSendEnabledEntries(ctx, func(denom string, sendEnabled bool) (stop bool) {
bankKeeper.IterateSendEnabledEntries(ctx, func(_ string, _ bool) (stop bool) {
count++
return false
})
Expand Down Expand Up @@ -1585,7 +1588,7 @@ func (suite *IntegrationTestSuite) TestMigrator_Migrate3to4() {
params := types.Params{DefaultSendEnabled: def}
suite.Require().NoError(bankKeeper.SetParams(ctx, params))
suite.T().Run(fmt.Sprintf("default %t does not change", def), func(t *testing.T) {
migrator := keeper.NewMigrator(bankKeeper.(keeper.BaseKeeper))
migrator := keeper.NewMigrator(bankKeeper.(keeper.BaseKeeper), suite.app.GetSubspace(banktypes.ModuleName))
require.NoError(t, migrator.Migrate3to4(ctx))
actual := bankKeeper.GetParams(ctx)
assert.Equal(t, params.DefaultSendEnabled, actual.DefaultSendEnabled)
Expand All @@ -1595,13 +1598,13 @@ func (suite *IntegrationTestSuite) TestMigrator_Migrate3to4() {
for _, def := range []bool{true, false} {
params := types.Params{
SendEnabled: []*types.SendEnabled{
{fmt.Sprintf("truecoin%t", def), true},
{fmt.Sprintf("falsecoin%t", def), false},
{Denom: fmt.Sprintf("truecoin%t", def), Enabled: true},
{Denom: fmt.Sprintf("falsecoin%t", def), Enabled: false},
},
}
suite.Require().NoError(bankKeeper.SetParams(ctx, params))
suite.T().Run(fmt.Sprintf("default %t send enabled info moved to store", def), func(t *testing.T) {
migrator := keeper.NewMigrator(bankKeeper.(keeper.BaseKeeper))
migrator := keeper.NewMigrator(bankKeeper.(keeper.BaseKeeper), suite.app.GetSubspace(banktypes.ModuleName))
require.NoError(t, migrator.Migrate3to4(ctx))
newParams := bankKeeper.GetParams(ctx)
assert.Len(t, newParams.SendEnabled, 0)
Expand All @@ -1617,8 +1620,8 @@ func (suite *IntegrationTestSuite) TestSetParams() {
ctx, bankKeeper := suite.ctx, suite.app.BankKeeper
params := types.NewParams(true)
params.SendEnabled = []*types.SendEnabled{
{"paramscointrue", true},
{"paramscoinfalse", false},
{Denom: "paramscointrue", Enabled: true},
{Denom: "paramscoinfalse", Enabled: false},
}
suite.Require().NoError(bankKeeper.SetParams(ctx, params))

Expand Down
15 changes: 10 additions & 5 deletions x/bank/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/exported"
v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2"
v3 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v3"
v4 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v4"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper BaseKeeper
keeper BaseKeeper
legacySubspace exported.Subspace
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper BaseKeeper) Migrator {
return Migrator{keeper: keeper}
func NewMigrator(keeper BaseKeeper, legacySubspace exported.Subspace) Migrator {
return Migrator{keeper: keeper, legacySubspace: legacySubspace}
}

// Migrate1to2 migrates from version 1 to 2.
Expand All @@ -31,13 +34,15 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error {

// Migrate3to4 migrates x/bank storage from version 3 to 4.
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
if err := v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc); err != nil {
return err
}

oldParams := m.keeper.GetParams(ctx)
m.keeper.SetAllSendEnabled(ctx, oldParams.GetSendEnabled())
if err := m.keeper.SetParams(ctx, banktypes.NewParams(oldParams.DefaultSendEnabled)); err != nil {
return fmt.Errorf("failed to set params: %w", err)
}

// TODO

return nil
}
62 changes: 62 additions & 0 deletions x/bank/keeper/msg_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package keeper_test

import (
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

func (suite *IntegrationTestSuite) TestMsgUpdateParams() {
// default params
params := types.DefaultParams()

testCases := []struct {
name string
input *types.MsgUpdateParams
expErr bool
expErrMsg string
}{
{
name: "invalid authority",
input: &types.MsgUpdateParams{
Authority: "invalid",
Params: params,
},
expErr: true,
expErrMsg: "invalid authority",
},
{
name: "send enabled param",
input: &types.MsgUpdateParams{
Authority: suite.app.BankKeeper.GetAuthority(),
Params: types.Params{
SendEnabled: []*types.SendEnabled{
{Denom: "foo", Enabled: true},
},
},
},
expErr: true,
expErrMsg: "use of send_enabled in params is no longer supported",
},
{
name: "all good",
input: &types.MsgUpdateParams{
Authority: suite.app.BankKeeper.GetAuthority(),
Params: params,
},
expErr: false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
_, err := suite.msgServer.UpdateParams(suite.ctx, tc.input)

if tc.expErr {
suite.Require().Error(err)
suite.Require().Contains(err.Error(), tc.expErrMsg)
} else {
suite.Require().NoError(err)
}
})
}
}
Loading

0 comments on commit 97dcf3e

Please sign in to comment.