fix: simulation failures (#12858)
* fix: store compare bug causing simulation failures - handle err in staking/keeper/InitGenesis SetParams - handle Params type text render in staking * fix bug in x/gov simulation operations Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
parent
e2d6cbdeb5
commit
8f9a88cf22
|
@ -41,21 +41,31 @@ func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []k
|
|||
|
||||
if iterB.Valid() {
|
||||
kvB = kv.Pair{Key: iterB.Key(), Value: iterB.Value()}
|
||||
|
||||
iterB.Next()
|
||||
}
|
||||
|
||||
compareValue := true
|
||||
|
||||
for _, prefix := range prefixesToSkip {
|
||||
// Skip value comparison if we matched a prefix
|
||||
if bytes.HasPrefix(kvA.Key, prefix) || bytes.HasPrefix(kvB.Key, prefix) {
|
||||
if bytes.HasPrefix(kvA.Key, prefix) {
|
||||
compareValue = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if compareValue && (!bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value)) {
|
||||
if !compareValue {
|
||||
// We're skipping this key due to an exclusion prefix. If it's present in B, iterate past it. If it's
|
||||
// absent don't iterate.
|
||||
if bytes.Equal(kvA.Key, kvB.Key) {
|
||||
iterB.Next()
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// always iterate B when comparing
|
||||
iterB.Next()
|
||||
|
||||
if !bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value) {
|
||||
kvAs = append(kvAs, kvA)
|
||||
kvBs = append(kvBs, kvB)
|
||||
}
|
||||
|
|
|
@ -412,7 +412,7 @@ func randomDeposit(
|
|||
return nil, false, err
|
||||
}
|
||||
|
||||
minAmount = sdk.NewDecFromInt(minDepositAmount).Mul(minDepositPercent).RoundInt()
|
||||
minAmount = sdk.NewDecFromInt(minDepositAmount).Mul(minDepositPercent).TruncateInt()
|
||||
}
|
||||
|
||||
amount, err := simtypes.RandPositiveInt(r, minDepositAmount.Sub(minAmount))
|
||||
|
|
|
@ -3,9 +3,10 @@ package keeper
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
@ -26,7 +27,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) (res []ab
|
|||
// genesis.json are in block 0.
|
||||
ctx = ctx.WithBlockHeight(1 - sdk.ValidatorUpdateDelay)
|
||||
|
||||
k.SetParams(ctx, data.Params)
|
||||
if err := k.SetParams(ctx, data.Params); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
k.SetLastTotalPower(ctx, data.LastTotalPower)
|
||||
|
||||
for _, validator := range data.Validators {
|
||||
|
|
|
@ -57,6 +57,13 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
|
|||
cdc.MustUnmarshal(kvB.Value, &redB)
|
||||
|
||||
return fmt.Sprintf("%v\n%v", redA, redB)
|
||||
case bytes.Equal(kvA.Key[:1], types.ParamsKey):
|
||||
var paramsA, paramsB types.Params
|
||||
|
||||
cdc.MustUnmarshal(kvA.Value, ¶msA)
|
||||
cdc.MustUnmarshal(kvB.Value, ¶msB)
|
||||
|
||||
return fmt.Sprintf("%v\n%v", paramsA, paramsB)
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid staking key prefix %X", kvA.Key[:1]))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue