-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: x/circuit audit changes (#16901)
- Loading branch information
1 parent
eb0260a
commit 60bbbb8
Showing
12 changed files
with
154 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
"cosmossdk.io/x/circuit" | ||
"cosmossdk.io/x/circuit/keeper" | ||
"cosmossdk.io/x/circuit/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address" | ||
"github.com/cosmos/cosmos-sdk/runtime" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
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" | ||
) | ||
|
||
type GenesisTestSuite struct { | ||
suite.Suite | ||
|
||
ctx context.Context | ||
keeper keeper.Keeper | ||
cdc *codec.ProtoCodec | ||
addrBytes []byte | ||
} | ||
|
||
func TestGenesisTestSuite(t *testing.T) { | ||
suite.Run(t, new(GenesisTestSuite)) | ||
} | ||
|
||
func (s *GenesisTestSuite) SetupTest() { | ||
key := storetypes.NewKVStoreKey(types.StoreKey) | ||
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) | ||
encCfg := moduletestutil.MakeTestEncodingConfig(circuit.AppModuleBasic{}) | ||
|
||
sdkCtx := testCtx.Ctx | ||
s.ctx = sdkCtx | ||
s.cdc = codec.NewProtoCodec(encCfg.InterfaceRegistry) | ||
authority := authtypes.NewModuleAddress("gov") | ||
ac := addresscodec.NewBech32Codec("cosmos") | ||
|
||
bz, err := ac.StringToBytes(authority.String()) | ||
s.Require().NoError(err) | ||
s.addrBytes = bz | ||
|
||
s.keeper = keeper.NewKeeper(s.cdc, runtime.NewKVStoreService(key), authority.String(), ac) | ||
} | ||
|
||
func (s *GenesisTestSuite) TestInitExportGenesis() { | ||
perms := types.Permissions{ | ||
Level: 3, | ||
LimitTypeUrls: []string{"test"}, | ||
} | ||
err := s.keeper.Permissions.Set(s.ctx, s.addrBytes, perms) | ||
s.Require().NoError(err) | ||
|
||
var accounts []*types.GenesisAccountPermissions | ||
genAccsPerms := types.GenesisAccountPermissions{ | ||
Address: sdk.AccAddress(s.addrBytes).String(), | ||
Permissions: &perms, | ||
} | ||
accounts = append(accounts, &genAccsPerms) | ||
|
||
url := "test_url" | ||
|
||
genesisState := &types.GenesisState{ | ||
AccountPermissions: accounts, | ||
DisabledTypeUrls: []string{url}, | ||
} | ||
|
||
s.keeper.InitGenesis(s.ctx, genesisState) | ||
|
||
exported := s.keeper.ExportGenesis(s.ctx) | ||
bz, err := s.cdc.MarshalJSON(exported) | ||
s.Require().NoError(err) | ||
|
||
var exportedGenesisState types.GenesisState | ||
err = s.cdc.UnmarshalJSON(bz, &exportedGenesisState) | ||
s.Require().NoError(err) | ||
|
||
s.Require().Equal(genesisState.AccountPermissions, exportedGenesisState.AccountPermissions) | ||
s.Require().Equal(genesisState.DisabledTypeUrls, exportedGenesisState.DisabledTypeUrls) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.