-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
refactor(x/genutil)!: remove Address.String() #19926
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -53,6 +53,7 @@ type GenTxTestSuite struct { | |||||||
} | ||||||||
|
||||||||
func (suite *GenTxTestSuite) SetupTest() { | ||||||||
valAc := codectestutil.CodecOptions{}.GetValidatorCodec() | ||||||||
suite.encodingConfig = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, genutil.AppModule{}) | ||||||||
key := storetypes.NewKVStoreKey("a_Store_Key") | ||||||||
tkey := storetypes.NewTransientStoreKey("a_transient_store") | ||||||||
|
@@ -67,11 +68,13 @@ func (suite *GenTxTestSuite) SetupTest() { | |||||||
var err error | ||||||||
amount := sdk.NewInt64Coin(sdk.DefaultBondDenom, 50) | ||||||||
one := math.OneInt() | ||||||||
suite.msg1, err = stakingtypes.NewMsgCreateValidator( | ||||||||
sdk.ValAddress(pk1.Address()).String(), pk1, amount, desc, comm, one) | ||||||||
pk1Addr, err := valAc.BytesToString(pk1.Address()) | ||||||||
suite.NoError(err) | ||||||||
suite.msg2, err = stakingtypes.NewMsgCreateValidator( | ||||||||
sdk.ValAddress(pk2.Address()).String(), pk1, amount, desc, comm, one) | ||||||||
suite.msg1, err = stakingtypes.NewMsgCreateValidator(pk1Addr, pk1, amount, desc, comm, one) | ||||||||
suite.NoError(err) | ||||||||
pk2Addr, err := valAc.BytesToString(pk2.Address()) | ||||||||
suite.NoError(err) | ||||||||
suite.msg2, err = stakingtypes.NewMsgCreateValidator(pk2Addr, pk1, amount, desc, comm, one) | ||||||||
suite.NoError(err) | ||||||||
} | ||||||||
|
||||||||
|
@@ -161,8 +164,14 @@ func (suite *GenTxTestSuite) TestValidateAccountInGenesis() { | |||||||
var ( | ||||||||
appGenesisState = make(map[string]json.RawMessage) | ||||||||
coins sdk.Coins | ||||||||
ac = codectestutil.CodecOptions{}.GetAddressCodec() | ||||||||
) | ||||||||
|
||||||||
addr1Str, err := ac.BytesToString(addr1) | ||||||||
suite.Require().NoError(err) | ||||||||
addr2Str, err := ac.BytesToString(addr2) | ||||||||
suite.Require().NoError(err) | ||||||||
|
||||||||
testCases := []struct { | ||||||||
msg string | ||||||||
malleate func() | ||||||||
|
@@ -180,7 +189,7 @@ func (suite *GenTxTestSuite) TestValidateAccountInGenesis() { | |||||||
func() { | ||||||||
coins = sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)} | ||||||||
balances := banktypes.Balance{ | ||||||||
Address: addr2.String(), | ||||||||
Address: addr2Str, | ||||||||
Coins: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}, | ||||||||
} | ||||||||
appGenesisState[banktypes.ModuleName] = suite.setAccountBalance([]banktypes.Balance{balances}) | ||||||||
|
@@ -192,7 +201,7 @@ func (suite *GenTxTestSuite) TestValidateAccountInGenesis() { | |||||||
func() { | ||||||||
coins = sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)} | ||||||||
balances := banktypes.Balance{ | ||||||||
Address: addr1.String(), | ||||||||
Address: addr1Str, | ||||||||
Coins: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}, | ||||||||
} | ||||||||
appGenesisState[banktypes.ModuleName] = suite.setAccountBalance([]banktypes.Balance{balances}) | ||||||||
|
@@ -204,7 +213,7 @@ func (suite *GenTxTestSuite) TestValidateAccountInGenesis() { | |||||||
func() { | ||||||||
coins = sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)} | ||||||||
balances := banktypes.Balance{ | ||||||||
Address: addr1.String(), | ||||||||
Address: addr1Str, | ||||||||
Coins: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}, | ||||||||
} | ||||||||
appGenesisState[banktypes.ModuleName] = suite.setAccountBalance([]banktypes.Balance{balances}) | ||||||||
|
@@ -221,10 +230,13 @@ func (suite *GenTxTestSuite) TestValidateAccountInGenesis() { | |||||||
suite.Require().NoError(err) | ||||||||
appGenesisState[stakingtypes.ModuleName] = stakingGenesis | ||||||||
|
||||||||
addr, err := addresscodec.NewBech32Codec("cosmos").BytesToString(addr1) | ||||||||
suite.Require().NoError(err) | ||||||||
|
||||||||
Comment on lines
+233
to
+235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conversion of - addr, err := addresscodec.NewBech32Codec("cosmos").BytesToString(addr1)
- suite.Require().NoError(err)
+ addr := addr1Str Committable suggestion
Suggested change
|
||||||||
tc.malleate() | ||||||||
err = genutil.ValidateAccountInGenesis( | ||||||||
appGenesisState, banktypes.GenesisBalancesIterator{}, | ||||||||
addr1, coins, cdc, | ||||||||
addr, coins, cdc, | ||||||||
) | ||||||||
|
||||||||
if tc.expPass { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert the error message to use
fmt.Errorf
with%w
to wrap the original error, enhancing error handling by preserving the original error context.Committable suggestion