Skip to content

Commit a968cff

Browse files
committed
test: use require for assertions and add changelog entry
- Refactor integration tests to use testify/require instead of gotest.tools/assert - Add breaking change entry to CHANGELOG.md for bond_denom validation - This addresses reviewer feedback for strict failure modes in tests Signed-off-by: bit2swaz <bit2swaz@gmail.com>
1 parent 9115824 commit a968cff

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4040

4141
### Breaking Changes
4242

43+
* (x/staking) [#25724](https://github.com/cosmos/cosmos-sdk/issues/25724) Validate `BondDenom` in `MsgUpdateParams` to prevent setting non-existent or zero-supply denoms.
4344
* [#25090](https://github.com/cosmos/cosmos-sdk/pull/25090) Moved deprecated modules to `./contrib`. These modules are still available but will no longer be actively maintained or supported in the Cosmos SDK Bug Bounty program.
4445
* `x/group`
4546
* `x/nft`

tests/integration/staking/keeper/msg_server_params_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package keeper_test
33
import (
44
"testing"
55

6-
"gotest.tools/v3/assert"
6+
"github.com/stretchr/testify/require"
77

88
"cosmossdk.io/math"
99

@@ -38,7 +38,7 @@ func TestMsgUpdateParams_BondDenomValidation(t *testing.T) {
3838
setupFunc: func() {
3939
// Mint coins to create supply for "validcoin"
4040
mintCoins := sdk.NewCoins(sdk.NewInt64Coin("validcoin", 1000000))
41-
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, types.ModuleName, mintCoins))
41+
require.NoError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, types.ModuleName, mintCoins))
4242
},
4343
bondDenom: "validcoin",
4444
expectErr: false,
@@ -58,14 +58,14 @@ func TestMsgUpdateParams_BondDenomValidation(t *testing.T) {
5858
// The default bond denom "stake" should already have supply from test setup
5959
// Just ensure it has supply
6060
currentParams, err := f.stakingKeeper.GetParams(ctx)
61-
assert.NilError(t, err)
61+
require.NoError(t, err)
6262
if currentParams.BondDenom == "stake" {
6363
// Already has supply from initialization
6464
return
6565
}
6666
// Otherwise mint some
6767
mintCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000000))
68-
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, types.ModuleName, mintCoins))
68+
require.NoError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, types.ModuleName, mintCoins))
6969
},
7070
bondDenom: "stake",
7171
expectErr: false,
@@ -94,16 +94,16 @@ func TestMsgUpdateParams_BondDenomValidation(t *testing.T) {
9494

9595
// Check expectations
9696
if tc.expectErr {
97-
assert.Assert(t, err != nil, "expected error but got none")
98-
assert.ErrorContains(t, err, tc.errMsg)
99-
assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest)
97+
require.Error(t, err, "expected error but got none")
98+
require.ErrorContains(t, err, tc.errMsg)
99+
require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest)
100100
} else {
101-
assert.NilError(t, err)
101+
require.NoError(t, err)
102102

103103
// Verify params were actually updated
104104
updatedParams, err := f.stakingKeeper.GetParams(ctx)
105-
assert.NilError(t, err)
106-
assert.Equal(t, tc.bondDenom, updatedParams.BondDenom)
105+
require.NoError(t, err)
106+
require.Equal(t, tc.bondDenom, updatedParams.BondDenom)
107107
}
108108
})
109109
}
@@ -120,9 +120,9 @@ func TestMsgUpdateParams_OtherValidations(t *testing.T) {
120120

121121
// Ensure default bond denom has supply
122122
currentParams, err := f.stakingKeeper.GetParams(ctx)
123-
assert.NilError(t, err)
123+
require.NoError(t, err)
124124
mintCoins := sdk.NewCoins(sdk.NewInt64Coin(currentParams.BondDenom, 1000000))
125-
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, types.ModuleName, mintCoins))
125+
require.NoError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, types.ModuleName, mintCoins))
126126

127127
testCases := []struct {
128128
name string
@@ -187,10 +187,10 @@ func TestMsgUpdateParams_OtherValidations(t *testing.T) {
187187
_, err := msgServer.UpdateParams(ctx, msg)
188188

189189
if tc.expectErr {
190-
assert.Assert(t, err != nil, "expected error but got none")
191-
assert.ErrorContains(t, err, tc.errMsg)
190+
require.Error(t, err, "expected error but got none")
191+
require.ErrorContains(t, err, tc.errMsg)
192192
} else {
193-
assert.NilError(t, err)
193+
require.NoError(t, err)
194194
}
195195
})
196196
}

0 commit comments

Comments
 (0)