Skip to content

Commit

Permalink
refactor(x/crisis)!: remove Address.String() (cosmos#20043)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano authored Apr 15, 2024
1 parent 1adc1f0 commit 63b4dba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### API Breaking Changes

* (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`.
* (x/genutil) [#19926](https://github.com/cosmos/cosmos-sdk/pull/19926) Removal of the Address.String() method and related changes:
* Added an address codec as an argument to `CollectTxs`, `GenAppStateFromConfig`, and `AddGenesisAccount`.
* Removed the `ValidatorAddressCodec` argument from `CollectGenTxsCmd`, now utilizing the context for this purpose.
Expand Down
7 changes: 6 additions & 1 deletion x/crisis/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

authorityAddr, err := in.AddressCodec.BytesToString(authority)
if err != nil {
panic(err)
}

k := keeper.NewKeeper(
in.Codec,
in.StoreService,
invalidCheckPeriod,
in.BankKeeper,
feeCollectorName,
authority.String(),
authorityAddr,
in.AddressCodec,
)

Expand Down
10 changes: 7 additions & 3 deletions x/crisis/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func (s *KeeperTestSuite) SetupTest() {
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, crisis.AppModule{})
keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String(), addresscodec.NewBech32Codec("cosmos"))
addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString([]byte("addr1_______________"))
s.Require().NoError(err)
keeper := keeper.NewKeeper(encCfg.Codec, storeService, 5, supplyKeeper, "", addr, addresscodec.NewBech32Codec("cosmos"))

s.ctx = testCtx.Ctx
s.keeper = keeper
Expand All @@ -57,6 +59,8 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() {
testutil.CreateKeyringAccounts(s.T(), kr, 1)

sender := testutil.CreateKeyringAccounts(s.T(), kr, 1)[0]
senderAddr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(sender.Address)
s.Require().NoError(err)

s.supplyKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2)
s.keeper.RegisterRoute("bank", "total-supply", func(sdk.Context) (string, bool) { return "", false })
Expand Down Expand Up @@ -90,7 +94,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() {
{
name: "unregistered invariant route",
input: &types.MsgVerifyInvariant{
Sender: sender.Address.String(),
Sender: senderAddr,
InvariantModuleName: "module",
InvariantRoute: "invalidroute",
},
Expand All @@ -100,7 +104,7 @@ func (s *KeeperTestSuite) TestMsgVerifyInvariant() {
{
name: "valid invariant",
input: &types.MsgVerifyInvariant{
Sender: sender.Address.String(),
Sender: senderAddr,
InvariantModuleName: "bank",
InvariantRoute: "total-supply",
},
Expand Down
4 changes: 2 additions & 2 deletions x/crisis/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ var (
)

// NewMsgVerifyInvariant creates a new MsgVerifyInvariant object
func NewMsgVerifyInvariant(sender sdk.AccAddress, invModeName, invRoute string) *MsgVerifyInvariant {
func NewMsgVerifyInvariant(sender, invModeName, invRoute string) *MsgVerifyInvariant {
return &MsgVerifyInvariant{
Sender: sender.String(),
Sender: sender,
InvariantModuleName: invModeName,
InvariantRoute: invRoute,
}
Expand Down

0 comments on commit 63b4dba

Please sign in to comment.