x/bank: use internal package (#4521)
Reorganise x/bank packages and leverage internal special package for enhanced encapsulation.
This commit is contained in:
parent
d5fe9b7eef
commit
1e9ca4a15b
|
@ -0,0 +1 @@
|
||||||
|
#4521 Flatten x/bank structure by hiding module internals.
|
|
@ -26,7 +26,6 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
|
"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"
|
||||||
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation"
|
|
||||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||||
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
|
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
|
@ -605,7 +604,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
|
||||||
})
|
})
|
||||||
return v
|
return v
|
||||||
}(nil),
|
}(nil),
|
||||||
banksim.SimulateMsgSend(app.accountKeeper, app.bankKeeper),
|
bank.SimulateMsgSend(app.accountKeeper, app.bankKeeper),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
func(_ *rand.Rand) int {
|
func(_ *rand.Rand) int {
|
||||||
|
@ -616,7 +615,7 @@ func testAndRunTxs(app *SimApp) []simulation.WeightedOperation {
|
||||||
})
|
})
|
||||||
return v
|
return v
|
||||||
}(nil),
|
}(nil),
|
||||||
banksim.SimulateSingleInputMsgMultiSend(app.accountKeeper, app.bankKeeper),
|
bank.SimulateSingleInputMsgMultiSend(app.accountKeeper, app.bankKeeper),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
func(_ *rand.Rand) int {
|
func(_ *rand.Rand) int {
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
package bank
|
package bank
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/keeper"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -15,22 +16,19 @@ const (
|
||||||
ModuleName = types.ModuleName
|
ModuleName = types.ModuleName
|
||||||
RouterKey = types.RouterKey
|
RouterKey = types.RouterKey
|
||||||
DefaultParamspace = types.DefaultParamspace
|
DefaultParamspace = types.DefaultParamspace
|
||||||
DefaultSendEnabled = types.DefaultSendEnabled
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// functions aliases
|
// functions aliases
|
||||||
RegisterCodec = types.RegisterCodec
|
RegisterCodec = types.RegisterCodec
|
||||||
ErrNoInputs = types.ErrNoInputs
|
ErrNoInputs = types.ErrNoInputs
|
||||||
ErrNoOutputs = types.ErrNoOutputs
|
ErrNoOutputs = types.ErrNoOutputs
|
||||||
ErrInputOutputMismatch = types.ErrInputOutputMismatch
|
ErrInputOutputMismatch = types.ErrInputOutputMismatch
|
||||||
ErrSendDisabled = types.ErrSendDisabled
|
ErrSendDisabled = types.ErrSendDisabled
|
||||||
NewMsgSend = types.NewMsgSend
|
NewBaseKeeper = keeper.NewBaseKeeper
|
||||||
NewMsgMultiSend = types.NewMsgMultiSend
|
NewInput = types.NewInput
|
||||||
NewInput = types.NewInput
|
NewOutput = types.NewOutput
|
||||||
NewOutput = types.NewOutput
|
ParamKeyTable = types.ParamKeyTable
|
||||||
ValidateInputsOutputs = types.ValidateInputsOutputs
|
|
||||||
ParamKeyTable = types.ParamKeyTable
|
|
||||||
|
|
||||||
// variable aliases
|
// variable aliases
|
||||||
ModuleCdc = types.ModuleCdc
|
ModuleCdc = types.ModuleCdc
|
||||||
|
@ -38,6 +36,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
BaseKeeper = keeper.BaseKeeper // ibc module depends on this
|
||||||
|
Keeper = keeper.Keeper
|
||||||
MsgSend = types.MsgSend
|
MsgSend = types.MsgSend
|
||||||
MsgMultiSend = types.MsgMultiSend
|
MsgMultiSend = types.MsgMultiSend
|
||||||
Input = types.Input
|
Input = types.Input
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package bank
|
package bank_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
|
"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"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -95,11 +97,11 @@ func getMockApp(t *testing.T) *mock.App {
|
||||||
}
|
}
|
||||||
|
|
||||||
// overwrite the mock init chainer
|
// overwrite the mock init chainer
|
||||||
func getInitChainer(mapp *mock.App, keeper BaseKeeper) sdk.InitChainer {
|
func getInitChainer(mapp *mock.App, keeper keeper.BaseKeeper) sdk.InitChainer {
|
||||||
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
|
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
|
||||||
mapp.InitChainer(ctx, req)
|
mapp.InitChainer(ctx, req)
|
||||||
bankGenesis := DefaultGenesisState()
|
bankGenesis := bank.DefaultGenesisState()
|
||||||
InitGenesis(ctx, keeper, bankGenesis)
|
bank.InitGenesis(ctx, keeper, bankGenesis)
|
||||||
|
|
||||||
return abci.ResponseInitChain{}
|
return abci.ResponseInitChain{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package bank
|
package bank_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -7,7 +7,9 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
|
"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"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,12 +19,12 @@ func getBenchmarkMockApp() (*mock.App, error) {
|
||||||
mapp := mock.NewApp()
|
mapp := mock.NewApp()
|
||||||
|
|
||||||
types.RegisterCodec(mapp.Cdc)
|
types.RegisterCodec(mapp.Cdc)
|
||||||
bankKeeper := NewBaseKeeper(
|
bankKeeper := keeper.NewBaseKeeper(
|
||||||
mapp.AccountKeeper,
|
mapp.AccountKeeper,
|
||||||
mapp.ParamsKeeper.Subspace(types.DefaultParamspace),
|
mapp.ParamsKeeper.Subspace(types.DefaultParamspace),
|
||||||
types.DefaultCodespace,
|
types.DefaultCodespace,
|
||||||
)
|
)
|
||||||
mapp.Router().AddRoute(types.RouterKey, NewHandler(bankKeeper))
|
mapp.Router().AddRoute(types.RouterKey, bank.NewHandler(bankKeeper))
|
||||||
mapp.SetInitChainer(getInitChainer(mapp, bankKeeper))
|
mapp.SetInitChainer(getInitChainer(mapp, bankKeeper))
|
||||||
|
|
||||||
err := mapp.CompleteSetup()
|
err := mapp.CompleteSetup()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
auth "github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterRoutes - Central function to define routes that get registered by the main application
|
// RegisterRoutes - Central function to define routes that get registered by the main application
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/tags"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewHandler returns a handler for "bank" type messages.
|
// NewHandler returns a handler for "bank" type messages.
|
||||||
func NewHandler(k Keeper) sdk.Handler {
|
func NewHandler(k keeper.Keeper) sdk.Handler {
|
||||||
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case types.MsgSend:
|
case types.MsgSend:
|
||||||
|
@ -26,7 +26,7 @@ func NewHandler(k Keeper) sdk.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle MsgSend.
|
// Handle MsgSend.
|
||||||
func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result {
|
func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgSend) sdk.Result {
|
||||||
if !k.GetSendEnabled(ctx) {
|
if !k.GetSendEnabled(ctx) {
|
||||||
return types.ErrSendDisabled(k.Codespace()).Result()
|
return types.ErrSendDisabled(k.Codespace()).Result()
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,9 @@ func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
resTags := sdk.NewTags(
|
resTags := sdk.NewTags(
|
||||||
tags.Category, tags.TxCategory,
|
types.Category, types.TxCategory,
|
||||||
tags.Sender, msg.FromAddress.String(),
|
types.Sender, msg.FromAddress.String(),
|
||||||
tags.Recipient, msg.ToAddress.String(),
|
types.Recipient, msg.ToAddress.String(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return sdk.Result{
|
return sdk.Result{
|
||||||
|
@ -47,7 +47,7 @@ func handleMsgSend(ctx sdk.Context, k Keeper, msg types.MsgSend) sdk.Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle MsgMultiSend.
|
// Handle MsgMultiSend.
|
||||||
func handleMsgMultiSend(ctx sdk.Context, k Keeper, msg types.MsgMultiSend) sdk.Result {
|
func handleMsgMultiSend(ctx sdk.Context, k keeper.Keeper, msg types.MsgMultiSend) sdk.Result {
|
||||||
// NOTE: totalIn == totalOut should already have been checked
|
// NOTE: totalIn == totalOut should already have been checked
|
||||||
if !k.GetSendEnabled(ctx) {
|
if !k.GetSendEnabled(ctx) {
|
||||||
return types.ErrSendDisabled(k.Codespace()).Result()
|
return types.ErrSendDisabled(k.Codespace()).Result()
|
||||||
|
@ -57,7 +57,7 @@ func handleMsgMultiSend(ctx sdk.Context, k Keeper, msg types.MsgMultiSend) sdk.R
|
||||||
return err.Result()
|
return err.Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
resTags = resTags.AppendTag(tags.Category, tags.TxCategory)
|
resTags = resTags.AppendTag(types.Category, types.TxCategory)
|
||||||
return sdk.Result{
|
return sdk.Result{
|
||||||
Tags: resTags,
|
Tags: resTags,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package bank
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// register bank invariants
|
// register bank invariants
|
|
@ -1,4 +1,4 @@
|
||||||
package bank
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,8 +6,7 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/tags"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -340,7 +339,7 @@ func inputOutputCoins(ctx sdk.Context, am auth.AccountKeeper, inputs []types.Inp
|
||||||
}
|
}
|
||||||
|
|
||||||
allTags = allTags.AppendTag(
|
allTags = allTags.AppendTag(
|
||||||
tags.Sender, in.Address.String(),
|
types.Sender, in.Address.String(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +349,7 @@ func inputOutputCoins(ctx sdk.Context, am auth.AccountKeeper, inputs []types.Inp
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
allTags = allTags.AppendTag(
|
allTags = allTags.AppendTag(
|
||||||
tags.Recipient, out.Address.String(),
|
types.Recipient, out.Address.String(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +385,7 @@ func delegateCoins(
|
||||||
setAccount(ctx, ak, acc)
|
setAccount(ctx, ak, acc)
|
||||||
|
|
||||||
return sdk.NewTags(
|
return sdk.NewTags(
|
||||||
sdk.TagAction, tags.ActionDelegateCoins,
|
sdk.TagAction, types.ActionDelegateCoins,
|
||||||
sdk.TagDelegator, addr.String(),
|
sdk.TagDelegator, addr.String(),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
@ -411,7 +410,7 @@ func undelegateCoins(
|
||||||
setAccount(ctx, ak, acc)
|
setAccount(ctx, ak, acc)
|
||||||
|
|
||||||
return sdk.NewTags(
|
return sdk.NewTags(
|
||||||
sdk.TagAction, tags.ActionUndelegateCoins,
|
sdk.TagAction, types.ActionUndelegateCoins,
|
||||||
sdk.TagDelegator, addr.String(),
|
sdk.TagDelegator, addr.String(),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package bank
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/store"
|
"github.com/cosmos/cosmos-sdk/store"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,13 +120,13 @@ func TestKeeper(t *testing.T) {
|
||||||
require.True(t, bankKeeper.GetCoins(ctx, addr2).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 10), sdk.NewInt64Coin("foocoin", 8))))
|
require.True(t, bankKeeper.GetCoins(ctx, addr2).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 10), sdk.NewInt64Coin("foocoin", 8))))
|
||||||
|
|
||||||
inputs := []types.Input{
|
inputs := []types.Input{
|
||||||
NewInput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 3))),
|
types.NewInput(addr, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 3))),
|
||||||
types.NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 3), sdk.NewInt64Coin("foocoin", 2))),
|
types.NewInput(addr2, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 3), sdk.NewInt64Coin("foocoin", 2))),
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs := []types.Output{
|
outputs := []types.Output{
|
||||||
NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 1))),
|
types.NewOutput(addr, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 1))),
|
||||||
NewOutput(addr3, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 2), sdk.NewInt64Coin("foocoin", 5))),
|
types.NewOutput(addr3, sdk.NewCoins(sdk.NewInt64Coin("barcoin", 2), sdk.NewInt64Coin("foocoin", 5))),
|
||||||
}
|
}
|
||||||
bankKeeper.InputOutputCoins(ctx, inputs, outputs)
|
bankKeeper.InputOutputCoins(ctx, inputs, outputs)
|
||||||
require.True(t, bankKeeper.GetCoins(ctx, addr).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 21), sdk.NewInt64Coin("foocoin", 4))))
|
require.True(t, bankKeeper.GetCoins(ctx, addr).IsEqual(sdk.NewCoins(sdk.NewInt64Coin("barcoin", 21), sdk.NewInt64Coin("foocoin", 4))))
|
||||||
|
@ -139,7 +139,7 @@ func TestSendKeeper(t *testing.T) {
|
||||||
ctx := input.ctx
|
ctx := input.ctx
|
||||||
paramSpace := input.pk.Subspace(types.DefaultParamspace)
|
paramSpace := input.pk.Subspace(types.DefaultParamspace)
|
||||||
bankKeeper := NewBaseKeeper(input.ak, paramSpace, types.DefaultCodespace)
|
bankKeeper := NewBaseKeeper(input.ak, paramSpace, types.DefaultCodespace)
|
||||||
sendKeeper := NewBaseSendKeeper(input.ak, paramSpace, DefaultCodespace)
|
sendKeeper := NewBaseSendKeeper(input.ak, paramSpace, types.DefaultCodespace)
|
||||||
bankKeeper.SetSendEnabled(ctx, true)
|
bankKeeper.SetSendEnabled(ctx, true)
|
||||||
|
|
||||||
addr := sdk.AccAddress([]byte("addr1"))
|
addr := sdk.AccAddress([]byte("addr1"))
|
||||||
|
@ -186,10 +186,10 @@ func TestSendKeeper(t *testing.T) {
|
||||||
func TestViewKeeper(t *testing.T) {
|
func TestViewKeeper(t *testing.T) {
|
||||||
input := setupTestInput()
|
input := setupTestInput()
|
||||||
ctx := input.ctx
|
ctx := input.ctx
|
||||||
paramSpace := input.pk.Subspace(DefaultParamspace)
|
paramSpace := input.pk.Subspace(types.DefaultParamspace)
|
||||||
bankKeeper := NewBaseKeeper(input.ak, paramSpace, DefaultCodespace)
|
bankKeeper := NewBaseKeeper(input.ak, paramSpace, types.DefaultCodespace)
|
||||||
bankKeeper.SetSendEnabled(ctx, true)
|
bankKeeper.SetSendEnabled(ctx, true)
|
||||||
viewKeeper := NewBaseViewKeeper(input.ak, DefaultCodespace)
|
viewKeeper := NewBaseViewKeeper(input.ak, types.DefaultCodespace)
|
||||||
|
|
||||||
addr := sdk.AccAddress([]byte("addr1"))
|
addr := sdk.AccAddress([]byte("addr1"))
|
||||||
acc := input.ak.NewAccountWithAddress(ctx, addr)
|
acc := input.ak.NewAccountWithAddress(ctx, addr)
|
||||||
|
@ -216,7 +216,7 @@ func TestVestingAccountSend(t *testing.T) {
|
||||||
|
|
||||||
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
||||||
sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
||||||
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace)
|
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace)
|
||||||
bankKeeper.SetSendEnabled(ctx, true)
|
bankKeeper.SetSendEnabled(ctx, true)
|
||||||
|
|
||||||
addr1 := sdk.AccAddress([]byte("addr1"))
|
addr1 := sdk.AccAddress([]byte("addr1"))
|
||||||
|
@ -250,7 +250,7 @@ func TestVestingAccountReceive(t *testing.T) {
|
||||||
|
|
||||||
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
||||||
sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
||||||
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace)
|
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace)
|
||||||
bankKeeper.SetSendEnabled(ctx, true)
|
bankKeeper.SetSendEnabled(ctx, true)
|
||||||
|
|
||||||
addr1 := sdk.AccAddress([]byte("addr1"))
|
addr1 := sdk.AccAddress([]byte("addr1"))
|
||||||
|
@ -284,7 +284,7 @@ func TestDelegateCoins(t *testing.T) {
|
||||||
|
|
||||||
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
||||||
delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
||||||
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace)
|
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace)
|
||||||
bankKeeper.SetSendEnabled(ctx, true)
|
bankKeeper.SetSendEnabled(ctx, true)
|
||||||
|
|
||||||
addr1 := sdk.AccAddress([]byte("addr1"))
|
addr1 := sdk.AccAddress([]byte("addr1"))
|
||||||
|
@ -321,7 +321,7 @@ func TestUndelegateCoins(t *testing.T) {
|
||||||
|
|
||||||
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
|
||||||
delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
|
||||||
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(DefaultParamspace), DefaultCodespace)
|
bankKeeper := NewBaseKeeper(input.ak, input.pk.Subspace(types.DefaultParamspace), types.DefaultCodespace)
|
||||||
bankKeeper.SetSendEnabled(ctx, true)
|
bankKeeper.SetSendEnabled(ctx, true)
|
||||||
|
|
||||||
addr1 := sdk.AccAddress([]byte("addr1"))
|
addr1 := sdk.AccAddress([]byte("addr1"))
|
|
@ -1,4 +1,4 @@
|
||||||
package tags
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
"github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/client/rest"
|
"github.com/cosmos/cosmos-sdk/x/bank/client/rest"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/internal/keeper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -29,24 +29,20 @@ type AppModuleBasic struct{}
|
||||||
var _ module.AppModuleBasic = AppModuleBasic{}
|
var _ module.AppModuleBasic = AppModuleBasic{}
|
||||||
|
|
||||||
// module name
|
// module name
|
||||||
func (AppModuleBasic) Name() string {
|
func (AppModuleBasic) Name() string { return ModuleName }
|
||||||
return types.ModuleName
|
|
||||||
}
|
|
||||||
|
|
||||||
// register module codec
|
// register module codec
|
||||||
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { RegisterCodec(cdc) }
|
||||||
types.RegisterCodec(cdc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// default genesis state
|
// default genesis state
|
||||||
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
||||||
return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState())
|
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
|
||||||
}
|
}
|
||||||
|
|
||||||
// module validate genesis
|
// module validate genesis
|
||||||
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
||||||
var data GenesisState
|
var data GenesisState
|
||||||
err := types.ModuleCdc.UnmarshalJSON(bz, &data)
|
err := ModuleCdc.UnmarshalJSON(bz, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -84,24 +80,18 @@ func NewAppModule(keeper Keeper, accountKeeper auth.AccountKeeper) AppModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// module name
|
// module name
|
||||||
func (AppModule) Name() string {
|
func (AppModule) Name() string { return ModuleName }
|
||||||
return types.ModuleName
|
|
||||||
}
|
|
||||||
|
|
||||||
// register invariants
|
// register invariants
|
||||||
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
||||||
RegisterInvariants(ir, am.accountKeeper)
|
keeper.RegisterInvariants(ir, am.accountKeeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// module message route name
|
// module message route name
|
||||||
func (AppModule) Route() string {
|
func (AppModule) Route() string { return RouterKey }
|
||||||
return types.RouterKey
|
|
||||||
}
|
|
||||||
|
|
||||||
// module handler
|
// module handler
|
||||||
func (am AppModule) NewHandler() sdk.Handler {
|
func (am AppModule) NewHandler() sdk.Handler { return NewHandler(am.keeper) }
|
||||||
return NewHandler(am.keeper)
|
|
||||||
}
|
|
||||||
|
|
||||||
// module querier route name
|
// module querier route name
|
||||||
func (AppModule) QuerierRoute() string { return "" }
|
func (AppModule) QuerierRoute() string { return "" }
|
||||||
|
@ -112,7 +102,7 @@ func (AppModule) NewQuerierHandler() sdk.Querier { return nil }
|
||||||
// module init-genesis
|
// module init-genesis
|
||||||
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
||||||
var genesisState GenesisState
|
var genesisState GenesisState
|
||||||
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
||||||
InitGenesis(ctx, am.keeper, genesisState)
|
InitGenesis(ctx, am.keeper, genesisState)
|
||||||
return []abci.ValidatorUpdate{}
|
return []abci.ValidatorUpdate{}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +110,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
|
||||||
// module export genesis
|
// module export genesis
|
||||||
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
||||||
gs := ExportGenesis(ctx, am.keeper)
|
gs := ExportGenesis(ctx, am.keeper)
|
||||||
return types.ModuleCdc.MustMarshalJSON(gs)
|
return ModuleCdc.MustMarshalJSON(gs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// module begin-block
|
// module begin-block
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package simulation
|
package bank
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -9,15 +9,16 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"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"
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
"github.com/cosmos/cosmos-sdk/x/simulation"
|
"github.com/cosmos/cosmos-sdk/x/simulation"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SendTx tests and runs a single msg send where both
|
// SendTx tests and runs a single msg send where both
|
||||||
// accounts already exist.
|
// accounts already exist.
|
||||||
func SimulateMsgSend(mapper auth.AccountKeeper, bk bank.Keeper) simulation.Operation {
|
func SimulateMsgSend(mapper auth.AccountKeeper, bk keeper.Keeper) simulation.Operation {
|
||||||
handler := bank.NewHandler(bk)
|
handler := NewHandler(bk)
|
||||||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account) (
|
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account) (
|
||||||
opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {
|
opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ func SimulateMsgSend(mapper auth.AccountKeeper, bk bank.Keeper) simulation.Opera
|
||||||
}
|
}
|
||||||
|
|
||||||
func createMsgSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, mapper auth.AccountKeeper) (
|
func createMsgSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, mapper auth.AccountKeeper) (
|
||||||
fromAcc simulation.Account, comment string, msg bank.MsgSend, ok bool) {
|
fromAcc simulation.Account, comment string, msg types.MsgSend, ok bool) {
|
||||||
|
|
||||||
fromAcc = simulation.RandomAcc(r, accs)
|
fromAcc = simulation.RandomAcc(r, accs)
|
||||||
toAcc := simulation.RandomAcc(r, accs)
|
toAcc := simulation.RandomAcc(r, accs)
|
||||||
|
@ -59,12 +60,12 @@ func createMsgSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, map
|
||||||
}
|
}
|
||||||
|
|
||||||
coins := sdk.Coins{sdk.NewCoin(initFromCoins[denomIndex].Denom, amt)}
|
coins := sdk.Coins{sdk.NewCoin(initFromCoins[denomIndex].Denom, amt)}
|
||||||
msg = bank.NewMsgSend(fromAcc.Address, toAcc.Address, coins)
|
msg = types.NewMsgSend(fromAcc.Address, toAcc.Address, coins)
|
||||||
return fromAcc, "", msg, true
|
return fromAcc, "", msg, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends and verifies the transition of a msg send.
|
// Sends and verifies the transition of a msg send.
|
||||||
func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg bank.MsgSend, ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error {
|
func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg types.MsgSend, ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error {
|
||||||
fromAcc := mapper.GetAccount(ctx, msg.FromAddress)
|
fromAcc := mapper.GetAccount(ctx, msg.FromAddress)
|
||||||
AccountNumbers := []uint64{fromAcc.GetAccountNumber()}
|
AccountNumbers := []uint64{fromAcc.GetAccountNumber()}
|
||||||
SequenceNumbers := []uint64{fromAcc.GetSequence()}
|
SequenceNumbers := []uint64{fromAcc.GetSequence()}
|
||||||
|
@ -76,7 +77,7 @@ func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg b
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
res := handler(ctx, msg)
|
res := handler(ctx, msg)
|
||||||
if !res.IsOK() {
|
if !res.IsOK() {
|
||||||
if res.Code == bank.CodeSendDisabled {
|
if res.Code == types.CodeSendDisabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: Do this in a more 'canonical' way
|
// TODO: Do this in a more 'canonical' way
|
||||||
|
@ -110,8 +111,8 @@ func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg b
|
||||||
|
|
||||||
// SingleInputSendMsg tests and runs a single msg multisend, with one input and one output, where both
|
// SingleInputSendMsg tests and runs a single msg multisend, with one input and one output, where both
|
||||||
// accounts already exist.
|
// accounts already exist.
|
||||||
func SimulateSingleInputMsgMultiSend(mapper auth.AccountKeeper, bk bank.Keeper) simulation.Operation {
|
func SimulateSingleInputMsgMultiSend(mapper auth.AccountKeeper, bk keeper.Keeper) simulation.Operation {
|
||||||
handler := bank.NewHandler(bk)
|
handler := NewHandler(bk)
|
||||||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account) (
|
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account) (
|
||||||
opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {
|
opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ func SimulateSingleInputMsgMultiSend(mapper auth.AccountKeeper, bk bank.Keeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSingleInputMsgMultiSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, mapper auth.AccountKeeper) (
|
func createSingleInputMsgMultiSend(r *rand.Rand, ctx sdk.Context, accs []simulation.Account, mapper auth.AccountKeeper) (
|
||||||
fromAcc simulation.Account, comment string, msg bank.MsgMultiSend, ok bool) {
|
fromAcc simulation.Account, comment string, msg types.MsgMultiSend, ok bool) {
|
||||||
|
|
||||||
fromAcc = simulation.RandomAcc(r, accs)
|
fromAcc = simulation.RandomAcc(r, accs)
|
||||||
toAcc := simulation.RandomAcc(r, accs)
|
toAcc := simulation.RandomAcc(r, accs)
|
||||||
|
@ -154,16 +155,16 @@ func createSingleInputMsgMultiSend(r *rand.Rand, ctx sdk.Context, accs []simulat
|
||||||
}
|
}
|
||||||
|
|
||||||
coins := sdk.Coins{sdk.NewCoin(initFromCoins[denomIndex].Denom, amt)}
|
coins := sdk.Coins{sdk.NewCoin(initFromCoins[denomIndex].Denom, amt)}
|
||||||
msg = bank.MsgMultiSend{
|
msg = types.MsgMultiSend{
|
||||||
Inputs: []bank.Input{bank.NewInput(fromAcc.Address, coins)},
|
Inputs: []types.Input{types.NewInput(fromAcc.Address, coins)},
|
||||||
Outputs: []bank.Output{bank.NewOutput(toAddr, coins)},
|
Outputs: []types.Output{types.NewOutput(toAddr, coins)},
|
||||||
}
|
}
|
||||||
return fromAcc, "", msg, true
|
return fromAcc, "", msg, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends and verifies the transition of a msg multisend. This fails if there are repeated inputs or outputs
|
// Sends and verifies the transition of a msg multisend. This fails if there are repeated inputs or outputs
|
||||||
// pass in handler as nil to handle txs, otherwise handle msgs
|
// pass in handler as nil to handle txs, otherwise handle msgs
|
||||||
func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg bank.MsgMultiSend,
|
func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg types.MsgMultiSend,
|
||||||
ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error {
|
ctx sdk.Context, privkeys []crypto.PrivKey, handler sdk.Handler) error {
|
||||||
|
|
||||||
initialInputAddrCoins := make([]sdk.Coins, len(msg.Inputs))
|
initialInputAddrCoins := make([]sdk.Coins, len(msg.Inputs))
|
||||||
|
@ -184,7 +185,7 @@ func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper,
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
res := handler(ctx, msg)
|
res := handler(ctx, msg)
|
||||||
if !res.IsOK() {
|
if !res.IsOK() {
|
||||||
if res.Code == bank.CodeSendDisabled {
|
if res.Code == types.CodeSendDisabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: Do this in a more 'canonical' way
|
// TODO: Do this in a more 'canonical' way
|
Loading…
Reference in New Issue