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

refactor(x/bank)!: remove Address.String() #19954

Merged
merged 6 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
5 changes: 4 additions & 1 deletion simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ func initGenFiles(
var bankGenState banktypes.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)

bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances)
bankGenState.Balances, err = banktypes.SanitizeGenesisBalances(genBalances, clientCtx.AddressCodec)
if err != nil {
return err
}
Comment on lines +394 to +397
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for SanitizeGenesisBalances by checking the returned error.

+ if err != nil {
+   return err
+ }

This change introduces necessary error handling for the SanitizeGenesisBalances function, ensuring that any errors encountered during balance sanitization are properly managed and propagated up the call stack.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
bankGenState.Balances, err = banktypes.SanitizeGenesisBalances(genBalances, clientCtx.AddressCodec)
if err != nil {
return err
}
bankGenState.Balances, err = banktypes.SanitizeGenesisBalances(genBalances, clientCtx.AddressCodec)
if err != nil {
return err
}

for _, bal := range bankGenState.Balances {
bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...)
}
Expand Down
111 changes: 66 additions & 45 deletions tests/integration/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,6 @@ var (
halfCoins = sdk.Coins{sdk.NewInt64Coin("foocoin", 5)}

sendMsg1 = types.NewMsgSend(addr1.String(), addr2.String(), coins)

multiSendMsg1 = &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1, coins)},
Outputs: []types.Output{types.NewOutput(addr2, coins)},
}
multiSendMsg2 = &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1, coins)},
Outputs: []types.Output{
types.NewOutput(addr2, halfCoins),
types.NewOutput(addr3, halfCoins),
},
}
multiSendMsg3 = &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr2, coins)},
Outputs: []types.Output{
types.NewOutput(addr1, coins),
},
}
multiSendMsg4 = &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1, coins)},
Outputs: []types.Output{
types.NewOutput(moduleAccAddr, coins),
},
}
invalidMultiSendMsg = &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1, coins), types.NewInput(addr2, coins)},
Outputs: []types.Output{},
}
)

type suite struct {
Expand Down Expand Up @@ -191,17 +163,25 @@ func TestSendNotEnoughBalance(t *testing.T) {
}

func TestMsgMultiSendWithAccounts(t *testing.T) {
addr1Str, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
require.NoError(t, err)
acc := &authtypes.BaseAccount{
Address: addr1.String(),
Address: addr1Str,
}

addr2Str, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
require.NoError(t, err)

moduleStrAddr, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(moduleAccAddr)
require.NoError(t, err)
Comment on lines +166 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure error handling is consistent and informative when converting addresses to strings in test setup.

+	require.NoError(t, err, "failed to convert address to string")

Add this assertion after each address conversion to ensure clarity and consistency in error handling.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addr1Str, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
require.NoError(t, err)
acc := &authtypes.BaseAccount{
Address: addr1.String(),
Address: addr1Str,
}
addr2Str, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
require.NoError(t, err)
moduleStrAddr, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(moduleAccAddr)
require.NoError(t, err)
addr1Str, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
require.NoError(t, err, "failed to convert address to string")
acc := &authtypes.BaseAccount{
Address: addr1Str,
}
addr2Str, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
require.NoError(t, err, "failed to convert address to string")
moduleStrAddr, err := cdctestutil.CodecOptions{}.GetAddressCodec().BytesToString(moduleAccAddr)
require.NoError(t, err, "failed to convert address to string")


genAccs := []authtypes.GenesisAccount{acc}
s := createTestSuite(t, genAccs)
baseApp := s.App.BaseApp
ctx := baseApp.NewContext(false)

require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
_, err := baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
require.NoError(t, err)
_, err = baseApp.Commit()
require.NoError(t, err)
Expand All @@ -212,8 +192,11 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {

testCases := []appTestCase{
{
desc: "make a valid tx",
msgs: []sdk.Msg{multiSendMsg1},
desc: "make a valid tx",
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
}},
accNums: []uint64{0},
accSeqs: []uint64{0},
expSimPass: true,
Expand All @@ -225,26 +208,37 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
},
},
{
desc: "wrong accNum should pass Simulate, but not Deliver",
msgs: []sdk.Msg{multiSendMsg1},
desc: "wrong accNum should pass Simulate, but not Deliver",
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
}},
accNums: []uint64{1}, // wrong account number
accSeqs: []uint64{1},
expSimPass: true, // doesn't check signature
expPass: false,
privKeys: []cryptotypes.PrivKey{priv1},
},
{
desc: "wrong accSeq should not pass Simulate",
msgs: []sdk.Msg{multiSendMsg4},
desc: "wrong accSeq should not pass Simulate",
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{
types.NewOutput(moduleStrAddr, coins),
},
}},
accNums: []uint64{0},
accSeqs: []uint64{0}, // wrong account sequence
expSimPass: false,
expPass: false,
privKeys: []cryptotypes.PrivKey{priv1},
},
{
desc: "multiple inputs not allowed",
msgs: []sdk.Msg{invalidMultiSendMsg},
desc: "multiple inputs not allowed",
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins), types.NewInput(addr2Str, coins)},
Outputs: []types.Output{},
}},
accNums: []uint64{0},
accSeqs: []uint64{0},
expSimPass: false,
Expand Down Expand Up @@ -272,12 +266,19 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
}

func TestMsgMultiSendMultipleOut(t *testing.T) {
ac := cdctestutil.CodecOptions{}.GetAddressCodec()
addr1Str, err := ac.BytesToString(addr1)
require.NoError(t, err)
acc1 := &authtypes.BaseAccount{
Address: addr1.String(),
Address: addr1Str,
}
addr2Str, err := ac.BytesToString(addr2)
require.NoError(t, err)
acc2 := &authtypes.BaseAccount{
Address: addr2.String(),
Address: addr2Str,
}
addr3Str, err := ac.BytesToString(addr3)
require.NoError(t, err)

genAccs := []authtypes.GenesisAccount{acc1, acc2}
s := createTestSuite(t, genAccs)
Expand All @@ -286,14 +287,20 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {

require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr2, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
_, err := baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: baseApp.LastBlockHeight() + 1})
require.NoError(t, err)
_, err = baseApp.Commit()
require.NoError(t, err)

testCases := []appTestCase{
{
msgs: []sdk.Msg{multiSendMsg2},
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{
types.NewOutput(addr2Str, halfCoins),
types.NewOutput(addr3Str, halfCoins),
},
}},
accNums: []uint64{0},
accSeqs: []uint64{0},
expSimPass: true,
Expand All @@ -320,9 +327,15 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
}

func TestMsgMultiSendDependent(t *testing.T) {
ac := cdctestutil.CodecOptions{}.GetAddressCodec()
addr1Str, err := ac.BytesToString(addr1)
require.NoError(t, err)
addr2Str, err := ac.BytesToString(addr2)
require.NoError(t, err)

acc1 := authtypes.NewBaseAccountWithAddress(addr1)
acc2 := authtypes.NewBaseAccountWithAddress(addr2)
err := acc2.SetAccountNumber(1)
err = acc2.SetAccountNumber(1)
require.NoError(t, err)

genAccs := []authtypes.GenesisAccount{acc1, acc2}
Expand All @@ -338,7 +351,10 @@ func TestMsgMultiSendDependent(t *testing.T) {

testCases := []appTestCase{
{
msgs: []sdk.Msg{multiSendMsg1},
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
}},
accNums: []uint64{0},
accSeqs: []uint64{0},
expSimPass: true,
Expand All @@ -350,7 +366,12 @@ func TestMsgMultiSendDependent(t *testing.T) {
},
},
{
msgs: []sdk.Msg{multiSendMsg3},
msgs: []sdk.Msg{&types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr2Str, coins)},
Outputs: []types.Output{
types.NewOutput(addr1Str, coins),
},
}},
accNums: []uint64{1},
accSeqs: []uint64{0},
expSimPass: true,
Expand Down
15 changes: 13 additions & 2 deletions tests/integration/bank/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
authtypes "cosmossdk.io/x/auth/types"
_ "cosmossdk.io/x/bank"
"cosmossdk.io/x/bank/testutil"
"cosmossdk.io/x/bank/types"
stakingtypes "cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -123,17 +124,22 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
// b.Skip("Skipping benchmark with buggy code reported at https://github.com/cosmos/cosmos-sdk/issues/10023")
b.ReportAllocs()

addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
require.NoError(b, err)
Comment on lines +127 to +128
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
+	addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
+	require.NoError(b, err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
require.NoError(b, err)
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
require.NoError(b, err)

acc := authtypes.BaseAccount{
Address: addr1.String(),
}

addr2Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
require.NoError(b, err)
Comment on lines +133 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addr2Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
+	addr2Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
+	require.NoError(b, err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addr2Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
require.NoError(b, err)
addr2Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr2)
require.NoError(b, err)


// construct genesis state
genAccs := []authtypes.GenesisAccount{&acc}
s := createTestSuite(&testing.T{}, genAccs)
baseApp := s.App.BaseApp
ctx := baseApp.NewContext(false)

_, err := baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
_, err = baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
require.NoError(b, err)

require.NoError(b, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))
Expand All @@ -144,8 +150,13 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
txGen := moduletestutil.MakeTestTxConfig(codectestutil.CodecOptions{})
txEncoder := txGen.TxEncoder()

multiSendMsg := &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
}
Comment on lines +153 to +156
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a variable for repeated sdk.Coins values to reduce redundancy and improve maintainability.

+	coins := sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))
 	multiSendMsg := &types.MsgMultiSend{
-		Inputs:  []types.Input{types.NewInput(addr1Str, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)))},
-		Outputs: []types.Output{types.NewOutput(addr2Str, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000)))},
+		Inputs:  []types.Input{types.NewInput(addr1Str, coins)},
+		Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
 	}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
multiSendMsg := &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
}
coins := sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))
multiSendMsg := &types.MsgMultiSend{
Inputs: []types.Input{types.NewInput(addr1Str, coins)},
Outputs: []types.Output{types.NewOutput(addr2Str, coins)},
}


// pre-compute all txs
txs, err := genSequenceOfTxs(txGen, []sdk.Msg{multiSendMsg1}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
txs, err := genSequenceOfTxs(txGen, []sdk.Msg{multiSendMsg}, []uint64{0}, []uint64{uint64(0)}, b.N, priv1)
require.NoError(b, err)
b.ResetTimer()

Expand Down
32 changes: 25 additions & 7 deletions tests/integration/bank/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,35 @@ func TestGRPCQueryBalance(t *testing.T) {
coin := getCoin(rt)
fundAccount(f, addr, coin)

req := banktypes.NewQueryBalanceRequest(addr, coin.GetDenom())
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)

Comment on lines +153 to +155
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

req := banktypes.NewQueryBalanceRequest(addrStr, coin.GetDenom())

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Balance, 0, true)
})

addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
assert.NilError(t, err)

Comment on lines +161 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
assert.NilError(t, err)
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

fundAccount(f, addr1, coin1)
req := banktypes.NewQueryBalanceRequest(addr1, coin1.GetDenom())
req := banktypes.NewQueryBalanceRequest(addr1Str, coin1.GetDenom())
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Balance, 1087, false)
}

func TestGRPCQueryAllBalances(t *testing.T) {
t.Parallel()
f := initDeterministicFixture(t)
addressCodec := codectestutil.CodecOptions{}.GetAddressCodec()

rapid.Check(t, func(rt *rapid.T) {
addr := testdata.AddressGenerator(rt).Draw(rt, "address")
numCoins := rapid.IntRange(1, 10).Draw(rt, "num-count")
coins := make(sdk.Coins, 0, numCoins)

addrStr, err := addressCodec.BytesToString(addr)
assert.NilError(t, err)

Comment on lines +179 to +181
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addrStr, err := addressCodec.BytesToString(addr)
assert.NilError(t, err)
addrStr, err := addressCodec.BytesToString(addr)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

for i := 0; i < numCoins; i++ {
coin := getCoin(rt)

Expand All @@ -178,7 +188,7 @@ func TestGRPCQueryAllBalances(t *testing.T) {

fundAccount(f, addr, coins...)

req := banktypes.NewQueryAllBalancesRequest(addr, testdata.PaginationGenerator(rt, uint64(numCoins)).Draw(rt, "pagination"), false)
req := banktypes.NewQueryAllBalancesRequest(addrStr, testdata.PaginationGenerator(rt, uint64(numCoins)).Draw(rt, "pagination"), false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.AllBalances, 0, true)
})

Expand All @@ -188,7 +198,10 @@ func TestGRPCQueryAllBalances(t *testing.T) {
)

fundAccount(f, addr1, coins...)
req := banktypes.NewQueryAllBalancesRequest(addr1, nil, false)
addr1Str, err := addressCodec.BytesToString(addr1)
assert.NilError(t, err)

Comment on lines +201 to +203
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addr1Str, err := addressCodec.BytesToString(addr1)
assert.NilError(t, err)
addr1Str, err := addressCodec.BytesToString(addr1)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

req := banktypes.NewQueryAllBalancesRequest(addr1Str, nil, false)

testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.AllBalances, 357, false)
}
Expand All @@ -199,6 +212,8 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {

rapid.Check(t, func(rt *rapid.T) {
addr := testdata.AddressGenerator(rt).Draw(rt, "address")
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)
Comment on lines +215 to +216
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}


// Denoms must be unique, otherwise sdk.NewCoins will panic.
denoms := rapid.SliceOfNDistinct(rapid.StringMatching(denomRegex), 1, 10, rapid.ID[string]).Draw(rt, "denoms")
Expand All @@ -213,10 +228,10 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
coins = sdk.NewCoins(append(coins, coin)...)
}

err := banktestutil.FundAccount(f.ctx, f.bankKeeper, addr, coins)
err = banktestutil.FundAccount(f.ctx, f.bankKeeper, addr, coins)
assert.NilError(t, err)

req := banktypes.NewQuerySpendableBalancesRequest(addr, testdata.PaginationGenerator(rt, uint64(len(denoms))).Draw(rt, "pagination"))
req := banktypes.NewQuerySpendableBalancesRequest(addrStr, testdata.PaginationGenerator(rt, uint64(len(denoms))).Draw(rt, "pagination"))
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 0, true)
})

Expand All @@ -228,7 +243,10 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
err := banktestutil.FundAccount(f.ctx, f.bankKeeper, addr1, coins)
assert.NilError(t, err)

req := banktypes.NewQuerySpendableBalancesRequest(addr1, nil)
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
assert.NilError(t, err)
Comment on lines +246 to +247
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
assert.NilError(t, err)
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}


req := banktypes.NewQuerySpendableBalancesRequest(addr1Str, nil)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 1777, false)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/sims/authz/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (suite *SimTestSuite) TestSimulateRevoke() {

granter := accounts[0]
grantee := accounts[1]
a := banktypes.NewSendAuthorization(initCoins, nil)
a := banktypes.NewSendAuthorization(initCoins, nil, suite.accountKeeper.AddressCodec())
expire := time.Now().Add(30 * time.Hour)

err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire)
Expand Down Expand Up @@ -200,7 +200,7 @@ func (suite *SimTestSuite) TestSimulateExec() {

granter := accounts[0]
grantee := accounts[1]
a := banktypes.NewSendAuthorization(initCoins, nil)
a := banktypes.NewSendAuthorization(initCoins, nil, suite.accountKeeper.AddressCodec())
expire := suite.ctx.HeaderInfo().Time.Add(1 * time.Hour)

err := suite.authzKeeper.SaveGrant(suite.ctx, grantee.Address, granter.Address, a, &expire)
Expand Down
Loading
Loading