refactor: Use mocks for x/authz testing (#12799)
## Description Closes: #12761 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
2bb48e8cd2
commit
f7e46ae6d3
|
@ -17,5 +17,6 @@ $mockgen_cmd -source=x/params/proposal_handler_test.go -package testutil -destin
|
||||||
$mockgen_cmd -source=x/crisis/types/expected_keepers.go -package testutil -destination x/crisis/testutil/expected_keepers_mocks.go
|
$mockgen_cmd -source=x/crisis/types/expected_keepers.go -package testutil -destination x/crisis/testutil/expected_keepers_mocks.go
|
||||||
$mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destination x/auth/testutil/expected_keepers_mocks.go
|
$mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destination x/auth/testutil/expected_keepers_mocks.go
|
||||||
$mockgen_cmd -source=x/auth/ante/expected_keepers.go -package testutil -destination x/auth/ante/testutil/expected_keepers_mocks.go
|
$mockgen_cmd -source=x/auth/ante/expected_keepers.go -package testutil -destination x/auth/ante/testutil/expected_keepers_mocks.go
|
||||||
|
$mockgen_cmd -source=x/authz/expected_keepers.go -package testutil -destination x/authz/testutil/expected_keepers_mocks.go
|
||||||
$mockgen_cmd -source=x/bank/types/expected_keepers.go -package testutil -destination x/bank/testutil/expected_keepers_mocks.go
|
$mockgen_cmd -source=x/bank/types/expected_keepers.go -package testutil -destination x/bank/testutil/expected_keepers_mocks.go
|
||||||
$mockgen_cmd -source=x/evidence/types/expected_keepers.go -package testutil -destination x/evidence/testutil/expected_keepers_mocks.go
|
$mockgen_cmd -source=x/evidence/types/expected_keepers.go -package testutil -destination x/evidence/testutil/expected_keepers_mocks.go
|
||||||
|
|
|
@ -5,14 +5,19 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||||
|
authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
||||||
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenesisTestSuite struct {
|
type GenesisTestSuite struct {
|
||||||
|
@ -20,16 +25,35 @@ type GenesisTestSuite struct {
|
||||||
|
|
||||||
ctx sdk.Context
|
ctx sdk.Context
|
||||||
keeper keeper.Keeper
|
keeper keeper.Keeper
|
||||||
|
baseApp *baseapp.BaseApp
|
||||||
|
accountKeeper *authztestutil.MockAccountKeeper
|
||||||
|
encCfg moduletestutil.TestEncodingConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *GenesisTestSuite) SetupTest() {
|
func (suite *GenesisTestSuite) SetupTest() {
|
||||||
app, err := simtestutil.Setup(
|
key := sdk.NewKVStoreKey(keeper.StoreKey)
|
||||||
testutil.AppConfig,
|
testCtx := testutil.DefaultContextWithDB(suite.T(), key, sdk.NewTransientStoreKey("transient_test"))
|
||||||
&suite.keeper,
|
suite.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{Height: 1})
|
||||||
)
|
suite.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||||
suite.Require().NoError(err)
|
|
||||||
|
|
||||||
suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{Height: 1})
|
// gomock initializations
|
||||||
|
ctrl := gomock.NewController(suite.T())
|
||||||
|
suite.accountKeeper = authztestutil.NewMockAccountKeeper(ctrl)
|
||||||
|
|
||||||
|
suite.baseApp = baseapp.NewBaseApp(
|
||||||
|
"authz",
|
||||||
|
log.NewNopLogger(),
|
||||||
|
testCtx.DB,
|
||||||
|
suite.encCfg.TxConfig.TxDecoder(),
|
||||||
|
)
|
||||||
|
suite.baseApp.SetCMS(testCtx.CMS)
|
||||||
|
|
||||||
|
bank.RegisterInterfaces(suite.encCfg.InterfaceRegistry)
|
||||||
|
|
||||||
|
msr := suite.baseApp.MsgServiceRouter()
|
||||||
|
msr.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry)
|
||||||
|
|
||||||
|
suite.keeper = keeper.NewKeeper(key, suite.encCfg.Codec, msr, suite.accountKeeper)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -69,7 +69,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorization() {
|
||||||
func(require *require.Assertions, res *authz.QueryGrantsResponse) {
|
func(require *require.Assertions, res *authz.QueryGrantsResponse) {
|
||||||
var auth authz.Authorization
|
var auth authz.Authorization
|
||||||
require.Equal(1, len(res.Grants))
|
require.Equal(1, len(res.Grants))
|
||||||
err := suite.interfaceRegistry.UnpackAny(res.Grants[0].Authorization, &auth)
|
err := suite.encCfg.InterfaceRegistry.UnpackAny(res.Grants[0].Authorization, &auth)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
require.NotNil(auth)
|
require.NotNil(auth)
|
||||||
require.Equal(auth.String(), expAuthorization.String())
|
require.Equal(auth.String(), expAuthorization.String())
|
||||||
|
@ -135,7 +135,7 @@ func (suite *TestSuite) TestGRPCQueryAuthorizations() {
|
||||||
func(res *authz.QueryGrantsResponse) {
|
func(res *authz.QueryGrantsResponse) {
|
||||||
var auth authz.Authorization
|
var auth authz.Authorization
|
||||||
suite.Require().Equal(1, len(res.Grants))
|
suite.Require().Equal(1, len(res.Grants))
|
||||||
err := suite.interfaceRegistry.UnpackAny(res.Grants[0].Authorization, &auth)
|
err := suite.encCfg.InterfaceRegistry.UnpackAny(res.Grants[0].Authorization, &auth)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().NotNil(auth)
|
suite.Require().NotNil(auth)
|
||||||
suite.Require().Equal(auth.String(), expAuthorization.String())
|
suite.Require().Equal(auth.String(), expAuthorization.String())
|
||||||
|
|
|
@ -4,21 +4,23 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
tmtime "github.com/tendermint/tendermint/libs/time"
|
tmtime "github.com/tendermint/tendermint/libs/time"
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
||||||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,34 +36,46 @@ type TestSuite struct {
|
||||||
ctx sdk.Context
|
ctx sdk.Context
|
||||||
addrs []sdk.AccAddress
|
addrs []sdk.AccAddress
|
||||||
authzKeeper authzkeeper.Keeper
|
authzKeeper authzkeeper.Keeper
|
||||||
bankKeeper bankkeeper.Keeper
|
accountKeeper *authztestutil.MockAccountKeeper
|
||||||
|
bankKeeper *authztestutil.MockBankKeeper
|
||||||
interfaceRegistry codectypes.InterfaceRegistry
|
interfaceRegistry codectypes.InterfaceRegistry
|
||||||
|
baseApp *baseapp.BaseApp
|
||||||
|
encCfg moduletestutil.TestEncodingConfig
|
||||||
queryClient authz.QueryClient
|
queryClient authz.QueryClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TestSuite) SetupTest() {
|
func (s *TestSuite) SetupTest() {
|
||||||
var stakingKeeper *stakingkeeper.Keeper
|
key := sdk.NewKVStoreKey(authzkeeper.StoreKey)
|
||||||
|
testCtx := testutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test"))
|
||||||
|
s.ctx = testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()})
|
||||||
|
s.encCfg = moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||||
|
|
||||||
app, err := simtestutil.Setup(
|
s.baseApp = baseapp.NewBaseApp(
|
||||||
testutil.AppConfig,
|
"authz",
|
||||||
&s.bankKeeper,
|
log.NewNopLogger(),
|
||||||
&stakingKeeper,
|
testCtx.DB,
|
||||||
&s.authzKeeper,
|
s.encCfg.TxConfig.TxDecoder(),
|
||||||
&s.interfaceRegistry,
|
|
||||||
)
|
)
|
||||||
s.Require().NoError(err)
|
s.baseApp.SetCMS(testCtx.CMS)
|
||||||
|
s.baseApp.SetInterfaceRegistry(s.encCfg.InterfaceRegistry)
|
||||||
|
|
||||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
s.addrs = simtestutil.CreateIncrementalAccounts(3)
|
||||||
now := tmtime.Now()
|
|
||||||
ctx = ctx.WithBlockHeader(tmproto.Header{Time: now})
|
// gomock initializations
|
||||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.interfaceRegistry)
|
ctrl := gomock.NewController(s.T())
|
||||||
|
s.accountKeeper = authztestutil.NewMockAccountKeeper(ctrl)
|
||||||
|
s.bankKeeper = authztestutil.NewMockBankKeeper(ctrl)
|
||||||
|
banktypes.RegisterInterfaces(s.encCfg.InterfaceRegistry)
|
||||||
|
banktypes.RegisterMsgServer(s.baseApp.MsgServiceRouter(), s.bankKeeper)
|
||||||
|
|
||||||
|
s.authzKeeper = authzkeeper.NewKeeper(key, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper)
|
||||||
|
|
||||||
|
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.encCfg.InterfaceRegistry)
|
||||||
authz.RegisterQueryServer(queryHelper, s.authzKeeper)
|
authz.RegisterQueryServer(queryHelper, s.authzKeeper)
|
||||||
queryClient := authz.NewQueryClient(queryHelper)
|
queryClient := authz.NewQueryClient(queryHelper)
|
||||||
s.queryClient = queryClient
|
s.queryClient = queryClient
|
||||||
|
|
||||||
s.ctx = ctx
|
|
||||||
s.queryClient = queryClient
|
s.queryClient = queryClient
|
||||||
s.addrs = simtestutil.AddTestAddrsIncremental(s.bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(30000000))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TestSuite) TestKeeper() {
|
func (s *TestSuite) TestKeeper() {
|
||||||
|
@ -147,8 +161,6 @@ func (s *TestSuite) TestDispatchAction() {
|
||||||
recipientAddr := addrs[2]
|
recipientAddr := addrs[2]
|
||||||
a := banktypes.NewSendAuthorization(coins100, nil)
|
a := banktypes.NewSendAuthorization(coins100, nil)
|
||||||
|
|
||||||
require.NoError(banktestutil.FundAccount(s.bankKeeper, s.ctx, granterAddr, coins1000))
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
req authz.MsgExec
|
req authz.MsgExec
|
||||||
|
@ -291,7 +303,6 @@ func (s *TestSuite) TestDispatchedEvents() {
|
||||||
granterAddr := addrs[0]
|
granterAddr := addrs[0]
|
||||||
granteeAddr := addrs[1]
|
granteeAddr := addrs[1]
|
||||||
recipientAddr := addrs[2]
|
recipientAddr := addrs[2]
|
||||||
require.NoError(banktestutil.FundAccount(s.bankKeeper, s.ctx, granterAddr, coins1000))
|
|
||||||
expiration := s.ctx.BlockTime().Add(1 * time.Second) // must be in the future
|
expiration := s.ctx.BlockTime().Add(1 * time.Second) // must be in the future
|
||||||
|
|
||||||
msgs := authz.NewMsgExec(granteeAddr, []sdk.Msg{
|
msgs := authz.NewMsgExec(granteeAddr, []sdk.Msg{
|
||||||
|
@ -321,13 +332,11 @@ func (s *TestSuite) TestDispatchedEvents() {
|
||||||
events := s.ctx.EventManager().Events()
|
events := s.ctx.EventManager().Events()
|
||||||
|
|
||||||
// get last 5 events (events that occur *after* the grant)
|
// get last 5 events (events that occur *after* the grant)
|
||||||
events = events[len(events)-5:]
|
events = events[len(events)-2:]
|
||||||
|
|
||||||
requiredEvents := map[string]bool{
|
requiredEvents := map[string]bool{
|
||||||
"coin_spent": false,
|
"cosmos.authz.v1beta1.EventGrant": true,
|
||||||
"coin_received": false,
|
"cosmos.authz.v1beta1.EventRevoke": true,
|
||||||
"transfer": false,
|
|
||||||
"message": false,
|
|
||||||
}
|
}
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
requiredEvents[e.Type] = true
|
requiredEvents[e.Type] = true
|
||||||
|
|
|
@ -5,37 +5,42 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
"github.com/cosmos/cosmos-sdk/testutil"
|
||||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
authztestutil "github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
||||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
"github.com/golang/mock/gomock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/proto/tendermint/types"
|
"github.com/tendermint/tendermint/proto/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExpiredGrantsQueue(t *testing.T) {
|
func TestExpiredGrantsQueue(t *testing.T) {
|
||||||
var interfaceRegistry codectypes.InterfaceRegistry
|
|
||||||
var authzKeeper keeper.Keeper
|
|
||||||
var bankKeeper bankkeeper.Keeper
|
|
||||||
var stakingKeeper *stakingkeeper.Keeper
|
|
||||||
|
|
||||||
app, err := simtestutil.Setup(
|
key := sdk.NewKVStoreKey(keeper.StoreKey)
|
||||||
testutil.AppConfig,
|
testCtx := testutil.DefaultContextWithDB(t, key, sdk.NewTransientStoreKey("transient_test"))
|
||||||
&interfaceRegistry,
|
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||||
&authzKeeper,
|
ctx := testCtx.Ctx.WithBlockHeader(types.Header{})
|
||||||
&bankKeeper,
|
|
||||||
&stakingKeeper,
|
baseApp := baseapp.NewBaseApp(
|
||||||
|
"authz",
|
||||||
|
log.NewNopLogger(),
|
||||||
|
testCtx.DB,
|
||||||
|
encCfg.TxConfig.TxDecoder(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
baseApp.SetCMS(testCtx.CMS)
|
||||||
|
baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
||||||
|
|
||||||
ctx := app.BaseApp.NewContext(false, types.Header{})
|
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||||
addrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 5, sdk.NewInt(30000000))
|
|
||||||
|
addrs := simtestutil.CreateIncrementalAccounts(5)
|
||||||
granter := addrs[0]
|
granter := addrs[0]
|
||||||
grantee1 := addrs[1]
|
grantee1 := addrs[1]
|
||||||
grantee2 := addrs[2]
|
grantee2 := addrs[2]
|
||||||
|
@ -46,6 +51,16 @@ func TestExpiredGrantsQueue(t *testing.T) {
|
||||||
smallCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 10))
|
smallCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 10))
|
||||||
sendAuthz := banktypes.NewSendAuthorization(smallCoins, nil)
|
sendAuthz := banktypes.NewSendAuthorization(smallCoins, nil)
|
||||||
|
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
accountKeeper := authztestutil.NewMockAccountKeeper(ctrl)
|
||||||
|
accountKeeper.EXPECT().GetAccount(gomock.Any(), granter).Return(authtypes.NewBaseAccountWithAddress(granter)).AnyTimes()
|
||||||
|
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee1).Return(authtypes.NewBaseAccountWithAddress(grantee1)).AnyTimes()
|
||||||
|
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee2).Return(authtypes.NewBaseAccountWithAddress(grantee2)).AnyTimes()
|
||||||
|
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee3).Return(authtypes.NewBaseAccountWithAddress(grantee3)).AnyTimes()
|
||||||
|
accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee4).Return(authtypes.NewBaseAccountWithAddress(grantee4)).AnyTimes()
|
||||||
|
|
||||||
|
authzKeeper := keeper.NewKeeper(key, encCfg.Codec, baseApp.MsgServiceRouter(), accountKeeper)
|
||||||
|
|
||||||
save := func(grantee sdk.AccAddress, exp *time.Time) {
|
save := func(grantee sdk.AccAddress, exp *time.Time) {
|
||||||
err := authzKeeper.SaveGrant(ctx, grantee, granter, sendAuthz, exp)
|
err := authzKeeper.SaveGrant(ctx, grantee, granter, sendAuthz, exp)
|
||||||
require.NoError(t, err, "Grant from %s", grantee.String())
|
require.NoError(t, err, "Grant from %s", grantee.String())
|
||||||
|
@ -55,7 +70,7 @@ func TestExpiredGrantsQueue(t *testing.T) {
|
||||||
save(grantee3, &expiration2)
|
save(grantee3, &expiration2)
|
||||||
save(grantee4, nil)
|
save(grantee4, nil)
|
||||||
|
|
||||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry)
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry)
|
||||||
authz.RegisterQueryServer(queryHelper, authzKeeper)
|
authz.RegisterQueryServer(queryHelper, authzKeeper)
|
||||||
queryClient := authz.NewQueryClient(queryHelper)
|
queryClient := authz.NewQueryClient(queryHelper)
|
||||||
|
|
||||||
|
|
|
@ -7,28 +7,28 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"cosmossdk.io/depinject"
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
"github.com/cosmos/cosmos-sdk/x/authz/keeper"
|
||||||
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
|
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
|
||||||
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDecodeStore(t *testing.T) {
|
func TestDecodeStore(t *testing.T) {
|
||||||
var cdc codec.Codec
|
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||||
depinject.Inject(testutil.AppConfig, &cdc)
|
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||||
|
|
||||||
dec := simulation.NewDecodeStore(cdc)
|
dec := simulation.NewDecodeStore(encCfg.Codec)
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
e := now.Add(1)
|
e := now.Add(1)
|
||||||
sendAuthz := banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123)), nil)
|
sendAuthz := banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123)), nil)
|
||||||
grant, _ := authz.NewGrant(now, sendAuthz, &e)
|
grant, _ := authz.NewGrant(now, sendAuthz, &e)
|
||||||
grantBz, err := cdc.Marshal(&grant)
|
grantBz, err := encCfg.Codec.Marshal(&grant)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
kvPairs := kv.Pairs{
|
kvPairs := kv.Pairs{
|
||||||
Pairs: []kv.Pair{
|
Pairs: []kv.Pair{
|
||||||
|
|
|
@ -7,26 +7,27 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"cosmossdk.io/depinject"
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||||
|
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
|
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz/testutil"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
|
||||||
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRandomizedGenState(t *testing.T) {
|
func TestRandomizedGenState(t *testing.T) {
|
||||||
var cdc codec.Codec
|
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||||
depinject.Inject(testutil.AppConfig, &cdc)
|
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||||
|
|
||||||
s := rand.NewSource(1)
|
s := rand.NewSource(1)
|
||||||
r := rand.New(s)
|
r := rand.New(s)
|
||||||
|
|
||||||
simState := module.SimulationState{
|
simState := module.SimulationState{
|
||||||
AppParams: make(simtypes.AppParams),
|
AppParams: make(simtypes.AppParams),
|
||||||
Cdc: cdc,
|
Cdc: encCfg.Codec,
|
||||||
Rand: r,
|
Rand: r,
|
||||||
NumBonded: 3,
|
NumBonded: 3,
|
||||||
Accounts: simtypes.RandomAccounts(r, 3),
|
Accounts: simtypes.RandomAccounts(r, 3),
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimTestSuite struct {
|
type SimTestSuite struct {
|
||||||
|
@ -37,7 +36,6 @@ type SimTestSuite struct {
|
||||||
interfaceRegistry codectypes.InterfaceRegistry
|
interfaceRegistry codectypes.InterfaceRegistry
|
||||||
accountKeeper authkeeper.AccountKeeper
|
accountKeeper authkeeper.AccountKeeper
|
||||||
bankKeeper bankkeeper.Keeper
|
bankKeeper bankkeeper.Keeper
|
||||||
stakingKeeper *stakingkeeper.Keeper
|
|
||||||
authzKeeper authzkeeper.Keeper
|
authzKeeper authzkeeper.Keeper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +47,6 @@ func (suite *SimTestSuite) SetupTest() {
|
||||||
&suite.interfaceRegistry,
|
&suite.interfaceRegistry,
|
||||||
&suite.accountKeeper,
|
&suite.accountKeeper,
|
||||||
&suite.bankKeeper,
|
&suite.bankKeeper,
|
||||||
&suite.stakingKeeper,
|
|
||||||
&suite.authzKeeper,
|
&suite.authzKeeper,
|
||||||
)
|
)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
@ -98,7 +95,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||||
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
|
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
|
||||||
accounts := simtypes.RandomAccounts(r, n)
|
accounts := simtypes.RandomAccounts(r, n)
|
||||||
|
|
||||||
initAmt := suite.stakingKeeper.TokensFromConsensusPower(suite.ctx, 200000)
|
initAmt := sdk.TokensFromConsensusPower(200000, sdk.DefaultPowerReduction)
|
||||||
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
|
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
|
||||||
|
|
||||||
// add coins to the accounts
|
// add coins to the accounts
|
||||||
|
@ -156,7 +153,7 @@ func (suite *SimTestSuite) TestSimulateRevoke() {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
initAmt := suite.stakingKeeper.TokensFromConsensusPower(suite.ctx, 200000)
|
initAmt := sdk.TokensFromConsensusPower(200000, sdk.DefaultPowerReduction)
|
||||||
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
|
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
|
||||||
|
|
||||||
granter := accounts[0]
|
granter := accounts[0]
|
||||||
|
@ -191,7 +188,7 @@ func (suite *SimTestSuite) TestSimulateExec() {
|
||||||
// begin a new block
|
// begin a new block
|
||||||
suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}})
|
suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}})
|
||||||
|
|
||||||
initAmt := suite.stakingKeeper.TokensFromConsensusPower(suite.ctx, 200000)
|
initAmt := sdk.TokensFromConsensusPower(200000, sdk.DefaultPowerReduction)
|
||||||
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
|
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
|
||||||
|
|
||||||
granter := accounts[0]
|
granter := accounts[0]
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package testutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ bank.MsgServer = MockBankKeeper{}
|
||||||
|
|
||||||
|
func (k MockBankKeeper) Send(goCtx context.Context, msg *bank.MsgSend) (*bank.MsgSendResponse, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k MockBankKeeper) MultiSend(goCtx context.Context, msg *bank.MsgMultiSend) (*bank.MsgMultiSendResponse, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k MockBankKeeper) UpdateParams(goCtx context.Context, req *bank.MsgUpdateParams) (*bank.MsgUpdateParamsResponse, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
|
// Source: x/authz/expected_keepers.go
|
||||||
|
|
||||||
|
// Package testutil is a generated GoMock package.
|
||||||
|
package testutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
reflect "reflect"
|
||||||
|
|
||||||
|
types "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
types0 "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockAccountKeeper is a mock of AccountKeeper interface.
|
||||||
|
type MockAccountKeeper struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockAccountKeeperMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper.
|
||||||
|
type MockAccountKeeperMockRecorder struct {
|
||||||
|
mock *MockAccountKeeper
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockAccountKeeper creates a new mock instance.
|
||||||
|
func NewMockAccountKeeper(ctrl *gomock.Controller) *MockAccountKeeper {
|
||||||
|
mock := &MockAccountKeeper{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockAccountKeeperMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccount mocks base method.
|
||||||
|
func (m *MockAccountKeeper) GetAccount(ctx types.Context, addr types.AccAddress) types0.AccountI {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "GetAccount", ctx, addr)
|
||||||
|
ret0, _ := ret[0].(types0.AccountI)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccount indicates an expected call of GetAccount.
|
||||||
|
func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).GetAccount), ctx, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAccountWithAddress mocks base method.
|
||||||
|
func (m *MockAccountKeeper) NewAccountWithAddress(ctx types.Context, addr types.AccAddress) types0.AccountI {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "NewAccountWithAddress", ctx, addr)
|
||||||
|
ret0, _ := ret[0].(types0.AccountI)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAccountWithAddress indicates an expected call of NewAccountWithAddress.
|
||||||
|
func (mr *MockAccountKeeperMockRecorder) NewAccountWithAddress(ctx, addr interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAccountWithAddress", reflect.TypeOf((*MockAccountKeeper)(nil).NewAccountWithAddress), ctx, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccount mocks base method.
|
||||||
|
func (m *MockAccountKeeper) SetAccount(ctx types.Context, acc types0.AccountI) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
m.ctrl.Call(m, "SetAccount", ctx, acc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccount indicates an expected call of SetAccount.
|
||||||
|
func (mr *MockAccountKeeperMockRecorder) SetAccount(ctx, acc interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetAccount), ctx, acc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockBankKeeper is a mock of BankKeeper interface.
|
||||||
|
type MockBankKeeper struct {
|
||||||
|
ctrl *gomock.Controller
|
||||||
|
recorder *MockBankKeeperMockRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// MockBankKeeperMockRecorder is the mock recorder for MockBankKeeper.
|
||||||
|
type MockBankKeeperMockRecorder struct {
|
||||||
|
mock *MockBankKeeper
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockBankKeeper creates a new mock instance.
|
||||||
|
func NewMockBankKeeper(ctrl *gomock.Controller) *MockBankKeeper {
|
||||||
|
mock := &MockBankKeeper{ctrl: ctrl}
|
||||||
|
mock.recorder = &MockBankKeeperMockRecorder{mock}
|
||||||
|
return mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
|
func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
|
||||||
|
return m.recorder
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSendEnabledCoins mocks base method.
|
||||||
|
func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
varargs := []interface{}{ctx}
|
||||||
|
for _, a := range coins {
|
||||||
|
varargs = append(varargs, a)
|
||||||
|
}
|
||||||
|
ret := m.ctrl.Call(m, "IsSendEnabledCoins", varargs...)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSendEnabledCoins indicates an expected call of IsSendEnabledCoins.
|
||||||
|
func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins ...interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
varargs := append([]interface{}{ctx}, coins...)
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSendEnabledCoins", reflect.TypeOf((*MockBankKeeper)(nil).IsSendEnabledCoins), varargs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpendableCoins mocks base method.
|
||||||
|
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
|
||||||
|
ret0, _ := ret[0].(types.Coins)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpendableCoins indicates an expected call of SpendableCoins.
|
||||||
|
func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpendableCoins", reflect.TypeOf((*MockBankKeeper)(nil).SpendableCoins), ctx, addr)
|
||||||
|
}
|
Loading…
Reference in New Issue