-
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.
- Loading branch information
1 parent
051cfdd
commit 4cd4e0a
Showing
7 changed files
with
120 additions
and
52 deletions.
There are no files selected for viewing
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,90 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
"cosmossdk.io/x/circuit" | ||
"cosmossdk.io/x/circuit/keeper" | ||
"cosmossdk.io/x/circuit/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"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()) | ||
require.NoError(s.T(), 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) | ||
require.NoError(s.T(), err) | ||
|
||
var accounts []*types.GenesisAccountPermissions | ||
genAccsPerms := types.GenesisAccountPermissions{ | ||
Address: sdk.AccAddress(s.addrBytes).String(), | ||
Permissions: &perms, | ||
} | ||
accounts = append(accounts, &genAccsPerms) | ||
|
||
url := "test_url" | ||
err = s.keeper.DisableList.Set(s.ctx, url) | ||
require.NoError(s.T(), err) | ||
|
||
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) | ||
require.NoError(s.T(), 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
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