Skip to content

Commit

Permalink
fix: fix IS tests (#13420)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Oct 4, 2022
1 parent c6ccc62 commit a6e5fe2
Show file tree
Hide file tree
Showing 12 changed files with 790 additions and 502 deletions.
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/simapp v0.0.0-20220908203654-84d4bf5accad
github.com/cosmos/cosmos-sdk v0.0.0-00010101000000-000000000000
github.com/cosmos/gogoproto v1.4.2
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
Expand Down Expand Up @@ -67,7 +68,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
Expand Down
404 changes: 404 additions & 0 deletions tests/integration/staking/keeper/unbonding_test.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions x/staking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ Store entries prefixed with "Last" must remain unchanged until EndBlock.
ValidatorUpdates contains the validator updates returned to ABCI at the end of every block.
The values are overwritten in every block.

* ValidatorUpdates `0x51 -> []abci.ValidatorUpdate`
* ValidatorUpdates `0x61 -> []abci.ValidatorUpdate`

## UnbondingId
## UnbondingID

UnbondingId stores the ID of the latest unbonding operation. It enables to create unique IDs for unbonding operation, i.e., UnbondingId is incremented every time a new unbonding operation (validator unbonding, unbonding delegation, redelegation) is initiated.
UnbondingID stores the ID of the latest unbonding operation. It enables to create unique IDs for unbonding operation, i.e., UnbondingID is incremented every time a new unbonding operation (validator unbonding, unbonding delegation, redelegation) is initiated.

* UnbondingId: `0x37 -> uint64`
* UnbondingID: `0x37 -> uint64`

## Params

Expand Down Expand Up @@ -126,14 +126,14 @@ records within a block.
* ValidatorsByConsAddr: `0x22 | ConsAddrLen (1 byte) | ConsAddr -> OperatorAddr`
* ValidatorsByPower: `0x23 | BigEndian(ConsensusPower) | OperatorAddrLen (1 byte) | OperatorAddr -> OperatorAddr`
* LastValidatorsPower: `0x11 | OperatorAddrLen (1 byte) | OperatorAddr -> ProtocolBuffer(ConsensusPower)`
* ValidatorsByUnbondingId: `0x38 | UnbondingId -> 0x21 | OperatorAddrLen (1 byte) | OperatorAddr`
* ValidatorsByUnbondingID: `0x38 | UnbondingID -> 0x21 | OperatorAddrLen (1 byte) | OperatorAddr`

`Validators` is the primary index - it ensures that each operator can have only one
associated validator, where the public key of that validator can change in the
future. Delegators can refer to the immutable operator of the validator, without
concern for the changing public key.

`ValidatorsByUnbondingId` is an additional index that enables lookups for
`ValidatorsByUnbondingID` is an additional index that enables lookups for
validators by the unbonding IDs corresponding to their current unbonding.

`ValidatorByConsAddr` is an additional index that enables lookups for slashing.
Expand Down
20 changes: 10 additions & 10 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,17 @@ func (k Keeper) HasMaxUnbondingDelegationEntries(ctx sdk.Context, delegatorAddr

// SetUnbondingDelegation sets the unbonding delegation and associated index.
func (k Keeper) SetUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDelegation) {
delegatorAddress := sdk.MustAccAddressFromBech32(ubd.DelegatorAddress)
delAddr := sdk.MustAccAddressFromBech32(ubd.DelegatorAddress)

store := ctx.KVStore(k.storeKey)
bz := types.MustMarshalUBD(k.cdc, ubd)
addr, err := sdk.ValAddressFromBech32(ubd.ValidatorAddress)
valAddr, err := sdk.ValAddressFromBech32(ubd.ValidatorAddress)
if err != nil {
panic(err)
}
key := types.GetUBDKey(delegatorAddress, addr)
key := types.GetUBDKey(delAddr, valAddr)
store.Set(key, bz)
store.Set(types.GetUBDByValIndexKey(delegatorAddress, addr), []byte{}) // index, store empty bytes
store.Set(types.GetUBDByValIndexKey(delAddr, valAddr), []byte{}) // index, store empty bytes
}

// RemoveUnbondingDelegation removes the unbonding delegation object and associated index.
Expand All @@ -305,7 +305,7 @@ func (k Keeper) SetUnbondingDelegationEntry(
creationHeight int64, minTime time.Time, balance math.Int,
) types.UnbondingDelegation {
ubd, found := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
id := k.IncrementUnbondingId(ctx)
id := k.IncrementUnbondingID(ctx)
if found {
ubd.AddEntry(creationHeight, minTime, balance, id)
} else {
Expand All @@ -315,10 +315,10 @@ func (k Keeper) SetUnbondingDelegationEntry(
k.SetUnbondingDelegation(ctx, ubd)

// Add to the UBDByUnbondingOp index to look up the UBD by the UBDE ID
k.SetUnbondingDelegationByUnbondingId(ctx, ubd, id)
k.SetUnbondingDelegationByUnbondingID(ctx, ubd, id)

// Call hook
k.AfterUnbondingInitiated(ctx, id)
k.Hooks().AfterUnbondingInitiated(ctx, id)

return ubd
}
Expand Down Expand Up @@ -495,7 +495,7 @@ func (k Keeper) SetRedelegationEntry(ctx sdk.Context,
sharesSrc, sharesDst sdk.Dec,
) types.Redelegation {
red, found := k.GetRedelegation(ctx, delegatorAddr, validatorSrcAddr, validatorDstAddr)
id := k.IncrementUnbondingId(ctx)
id := k.IncrementUnbondingID(ctx)
if found {
red.AddEntry(creationHeight, minTime, balance, sharesDst, id)
} else {
Expand All @@ -506,10 +506,10 @@ func (k Keeper) SetRedelegationEntry(ctx sdk.Context,
k.SetRedelegation(ctx, red)

// Add to the UBDByEntry index to look up the UBD by the UBDE ID
k.SetRedelegationByUnbondingId(ctx, red, id)
k.SetRedelegationByUnbondingID(ctx, red, id)

// Call hook
k.AfterUnbondingInitiated(ctx, id)
k.Hooks().AfterUnbondingInitiated(ctx, id)

return red
}
Expand Down
8 changes: 4 additions & 4 deletions x/staking/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func (k Keeper) MaxEntries(ctx sdk.Context) uint32 {

// HistoricalEntries = number of historical info entries
// to persist in store
func (k Keeper) HistoricalEntries(ctx sdk.Context) (res uint32) {
func (k Keeper) HistoricalEntries(ctx sdk.Context) uint32 {
return k.GetParams(ctx).HistoricalEntries
}

// BondDenom - Bondable coin denomination
func (k Keeper) BondDenom(ctx sdk.Context) (res string) {
func (k Keeper) BondDenom(ctx sdk.Context) string {
return k.GetParams(ctx).BondDenom
}

Expand Down Expand Up @@ -70,9 +70,9 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
return
}

k.cdc.MustUnmarshal(bz, &params)
return params
return
}
Loading

0 comments on commit a6e5fe2

Please sign in to comment.