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:
@@ -7,28 +7,28 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||
"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/testutil"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
func TestDecodeStore(t *testing.T) {
|
||||
var cdc codec.Codec
|
||||
depinject.Inject(testutil.AppConfig, &cdc)
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
|
||||
dec := simulation.NewDecodeStore(cdc)
|
||||
dec := simulation.NewDecodeStore(encCfg.Codec)
|
||||
|
||||
now := time.Now().UTC()
|
||||
e := now.Add(1)
|
||||
sendAuthz := banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123)), nil)
|
||||
grant, _ := authz.NewGrant(now, sendAuthz, &e)
|
||||
grantBz, err := cdc.Marshal(&grant)
|
||||
grantBz, err := encCfg.Codec.Marshal(&grant)
|
||||
require.NoError(t, err)
|
||||
kvPairs := kv.Pairs{
|
||||
Pairs: []kv.Pair{
|
||||
|
||||
@@ -7,26 +7,27 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"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/testutil"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
func TestRandomizedGenState(t *testing.T) {
|
||||
var cdc codec.Codec
|
||||
depinject.Inject(testutil.AppConfig, &cdc)
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{})
|
||||
banktypes.RegisterInterfaces(encCfg.InterfaceRegistry)
|
||||
|
||||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
simState := module.SimulationState{
|
||||
AppParams: make(simtypes.AppParams),
|
||||
Cdc: cdc,
|
||||
Cdc: encCfg.Codec,
|
||||
Rand: r,
|
||||
NumBonded: 3,
|
||||
Accounts: simtypes.RandomAccounts(r, 3),
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
)
|
||||
|
||||
type SimTestSuite struct {
|
||||
@@ -37,7 +36,6 @@ type SimTestSuite struct {
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
accountKeeper authkeeper.AccountKeeper
|
||||
bankKeeper bankkeeper.Keeper
|
||||
stakingKeeper *stakingkeeper.Keeper
|
||||
authzKeeper authzkeeper.Keeper
|
||||
}
|
||||
|
||||
@@ -49,7 +47,6 @@ func (suite *SimTestSuite) SetupTest() {
|
||||
&suite.interfaceRegistry,
|
||||
&suite.accountKeeper,
|
||||
&suite.bankKeeper,
|
||||
&suite.stakingKeeper,
|
||||
&suite.authzKeeper,
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
@@ -98,7 +95,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
|
||||
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))
|
||||
|
||||
// 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))
|
||||
|
||||
granter := accounts[0]
|
||||
@@ -191,7 +188,7 @@ func (suite *SimTestSuite) TestSimulateExec() {
|
||||
// begin a new block
|
||||
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))
|
||||
|
||||
granter := accounts[0]
|
||||
|
||||
Reference in New Issue
Block a user