Skip to content

Commit

Permalink
fix typo in val_state_change.go (#728)
Browse files Browse the repository at this point in the history
* fix: typo in val_state_change.go

* test: add test for panic in UnbondingToUnbonded function

* chore: add changelog

* test: change test code to check both cases

check unbonding to unbonded from unbonded status and bonded status

* test: delete duplicated update validator

* chore: fix typo in changelog

* chore: change logic to use range

* chore: change pr number
  • Loading branch information
loin3 authored Oct 18, 2022
1 parent d4635de commit 5ed82db
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#712](https://github.com/line/lbm-sdk/pull/712) fix x/foundation EndBlocker
* (baseapp) [\#724](https://github.com/line/lbm-sdk/pull/724) add checking pubkey type from validator params
* (x/staking) [\#726](https://github.com/line/lbm-sdk/pull/726) check allowedList size in StakeAuthorization.Accept()
* (x/staking) [\#728](https://github.com/line/lbm-sdk/pull/728) fix typo in unbondingToUnbonded() panic

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (k Keeper) unbondedToBonded(ctx sdk.Context, validator types.Validator) (ty
// UnbondingToUnbonded switches a validator from unbonding state to unbonded state
func (k Keeper) UnbondingToUnbonded(ctx sdk.Context, validator types.Validator) types.Validator {
if !validator.IsUnbonding() {
panic(fmt.Sprintf("bad state transition unbondingToBonded, validator: %v\n", validator))
panic(fmt.Sprintf("bad state transition unbondingToUnbonded, validator: %v\n", validator))
}

return k.completeUnbondingValidator(ctx, validator)
Expand Down
30 changes: 30 additions & 0 deletions x/staking/keeper/val_state_change_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package keeper_test

import (
"github.com/line/lbm-sdk/x/staking/keeper"
"github.com/line/lbm-sdk/x/staking/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestUnbondingToUnbondedPanic(t *testing.T) {
app, ctx, _, _, validators := initValidators(t, 100, 2, []int64{0, 100})

for i, validator := range validators {
validators[i] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, false)
}

assert.Equal(t, validators[0].Status, types.Unbonded)
assert.Equal(t, validators[1].Status, types.Bonded)

// unbond validator which is in unbonded status
require.Panics(t, func() {
app.StakingKeeper.UnbondingToUnbonded(ctx, validators[0])
})

// unbond validator which is in bonded status
require.Panics(t, func() {
app.StakingKeeper.UnbondingToUnbonded(ctx, validators[1])
})
}

0 comments on commit 5ed82db

Please sign in to comment.