Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/authz: simulation audit changes #9107

Merged
merged 59 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4ce10ce
addressing audit changes
aleem1314 Apr 14, 2021
129eebf
address simulation genesis changes
aleem1314 Apr 14, 2021
4b87466
address simulation operations changes
aleem1314 Apr 14, 2021
d810426
fix tests
aleem1314 Apr 14, 2021
8a26d14
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 Apr 14, 2021
4f64624
typo
aleem1314 Apr 14, 2021
4b4825b
add more authorizations to operations
aleem1314 Apr 15, 2021
e81ee9a
fix tests
aleem1314 Apr 15, 2021
2226a1f
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 Apr 15, 2021
95f2d06
fix failing simulations
aleem1314 Apr 15, 2021
701a04c
WIP
aleem1314 Apr 15, 2021
70776f9
WIP
aleem1314 Apr 16, 2021
6109011
testing simulations
aleem1314 Apr 16, 2021
783c21f
test simulations
aleem1314 Apr 16, 2021
9dcdf2d
try fixing tests
aleem1314 Apr 16, 2021
6a74646
WIP
aleem1314 Apr 16, 2021
ef5258b
fix error
aleem1314 Apr 16, 2021
fef0dbc
test
aleem1314 Apr 16, 2021
50d4d38
Add exec authorization
aleem1314 Apr 16, 2021
9b074cc
WIP
aleem1314 Apr 17, 2021
55688f5
WIP
aleem1314 Apr 17, 2021
2bfad5f
fix tests
aleem1314 Apr 17, 2021
177e0fc
WIP
aleem1314 Apr 17, 2021
ad97e7f
WIP
aleem1314 Apr 19, 2021
19784e9
WIP
aleem1314 Apr 19, 2021
a3f8c43
WIP
aleem1314 Apr 19, 2021
b11df38
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 Apr 19, 2021
d4a77d7
WIP
aleem1314 Apr 19, 2021
6867174
Merge branch 'aleem/authz-simulation-audit-changes' of https://github…
aleem1314 Apr 19, 2021
d8b6046
fix errors
aleem1314 Apr 19, 2021
37c58fc
fix test
aleem1314 Apr 19, 2021
2a866ac
WIP
aleem1314 Apr 19, 2021
3bc3be5
try fix test
aleem1314 Apr 19, 2021
5e569c3
update tests
aleem1314 Apr 19, 2021
93945f9
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 7, 2021
1131dbc
fix errors
aleem1314 May 7, 2021
3c07ed7
add exec authorization
aleem1314 May 7, 2021
80edd90
fix docs
aleem1314 May 7, 2021
8224626
fix test
aleem1314 May 7, 2021
d09c51a
fix error
aleem1314 May 7, 2021
77ec9bd
try fixing simulation
aleem1314 May 7, 2021
b48a7fa
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 7, 2021
b12dab3
fix errors
aleem1314 May 7, 2021
a7981db
fixing simulations
aleem1314 May 7, 2021
809ab6c
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 7, 2021
81fab3c
fix errors
aleem1314 May 7, 2021
d4e78e5
rename GenTx -> GenerateTx
aleem1314 May 7, 2021
495d690
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 7, 2021
4677d12
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 10, 2021
1c9c022
Update x/authz/simulation/genesis.go
aleem1314 May 11, 2021
9a3c2d8
Update x/authz/simulation/genesis.go
aleem1314 May 11, 2021
c95c28f
Update x/authz/simulation/operations.go
aleem1314 May 11, 2021
f85410a
review changes
aleem1314 May 11, 2021
e81c5ea
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 11, 2021
dd5fb43
fix tests
aleem1314 May 11, 2021
b12674a
rename GenerateTx => GenTx
aleem1314 May 11, 2021
729a766
Merge branch 'master' into aleem/authz-simulation-audit-changes
atheeshp May 11, 2021
8d4b7dd
remove Authorization suffix
aleem1314 May 11, 2021
b25d776
Merge branch 'master' into aleem/authz-simulation-audit-changes
aleem1314 May 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x/authz/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
}
10 changes: 5 additions & 5 deletions x/authz/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ func TestDecodeStore(t *testing.T) {

tests := []struct {
name string
expectErr bool
expectedLog string
}{
{"Grant", fmt.Sprintf("%v\n%v", grant, grant)},
{"other", ""},
{"Grant", false, fmt.Sprintf("%v\n%v", grant, grant)},
{"other", true, ""},
}

for i, tt := range tests {
i, tt := i, tt
t.Run(tt.name, func(t *testing.T) {
switch i {
case len(tests) - 1:
if tt.expectErr {
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
default:
} else {
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
}
})
Expand Down
50 changes: 37 additions & 13 deletions x/authz/simulation/genesis.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
package simulation

import (
"encoding/json"
"fmt"
"math/rand"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

// GenAuthorizationGrant returns an empty slice of authorization grants.
func GenAuthorizationGrant(_ *rand.Rand, _ []simtypes.Account) []authz.GrantAuthorization {
return []authz.GrantAuthorization{}
// genGrant returns a slice of authorization grants.
func genGrant(r *rand.Rand, accounts []simtypes.Account) []authz.GrantAuthorization {
authorizations := make([]authz.GrantAuthorization, len(accounts)-1)
for i := 0; i < len(accounts)-1; i++ {
granter := accounts[i]
grantee := accounts[i+1]
authorizations[i] = authz.GrantAuthorization{
Granter: granter.Address.String(),
Grantee: grantee.Address.String(),
Authorization: generateRandomGrant(r),
}
}

return authorizations
}

func generateRandomGrant(r *rand.Rand) *codectypes.Any {
authorizations := make([]*codectypes.Any, 2)
authorizations[0] = newAnyAuthorization(banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1000)))))
authorizations[1] = newAnyAuthorization(authz.NewGenericAuthorization(sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{})))

return authorizations[r.Intn(len(authorizations))]
}

func newAnyAuthorization(a authz.Authorization) *codectypes.Any {
any, err := codectypes.NewAnyWithValue(a)
if err != nil {
panic(err)
}

return any
}

// RandomizedGenState generates a random GenesisState for authz.
func RandomizedGenState(simState *module.SimulationState) {
var grants []authz.GrantAuthorization

simState.AppParams.GetOrGenerate(
simState.Cdc, "authz", &grants, simState.Rand,
func(r *rand.Rand) { grants = GenAuthorizationGrant(r, simState.Accounts) },
func(r *rand.Rand) { grants = genGrant(r, simState.Accounts) },
)
authzGrantsGenesis := authz.NewGenesisState(grants)

bz, err := json.MarshalIndent(&authzGrantsGenesis, "", " ")
if err != nil {
panic(err)
}
authzGrantsGenesis := authz.NewGenesisState(grants)

fmt.Printf("Selected randomly generated %s parameters:\n%s\n", authz.ModuleName, bz)
simState.GenState[authz.ModuleName] = simState.Cdc.MustMarshalJSON(authzGrantsGenesis)
}
10 changes: 4 additions & 6 deletions x/authz/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ import (

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/authz/simulation"
)

func TestRandomizedGenState(t *testing.T) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
app := simapp.Setup(false)

s := rand.NewSource(1)
r := rand.New(s)

simState := module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: cdc,
Cdc: app.AppCodec(),
Rand: r,
NumBonded: 3,
Accounts: simtypes.RandomAccounts(r, 3),
Expand All @@ -36,5 +34,5 @@ func TestRandomizedGenState(t *testing.T) {
var authzGenesis authz.GenesisState
simState.Cdc.MustUnmarshalJSON(simState.GenState[authz.ModuleName], &authzGenesis)

require.Len(t, authzGenesis.Authorization, 0)
require.Len(t, authzGenesis.Authorization, len(simState.Accounts) - 1)
}
Loading