Skip to content

Commit

Permalink
add observe slashed amounts to genesis export
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Feb 2, 2024
1 parent 85608a5 commit 7fb0ffc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
13 changes: 13 additions & 0 deletions x/emissions/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"testing"

sdkmath "cosmossdk.io/math"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
Expand All @@ -26,6 +27,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "",
},
Expand Down Expand Up @@ -54,6 +56,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "min bond factor cannot be lower that 0.75",
},
Expand All @@ -68,6 +71,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "invalid block time",
},
Expand All @@ -82,6 +86,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "block time cannot be less than or equal to 0",
},
Expand All @@ -96,6 +101,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "target bond ratio cannot be more than 100 percent",
},
Expand All @@ -110,6 +116,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "target bond ratio cannot be less than 0 percent",
},
Expand All @@ -124,6 +131,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "validator emission percentage cannot be more than 100 percent",
},
Expand All @@ -138,6 +146,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "validator emission percentage cannot be less than 0 percent",
},
Expand All @@ -152,6 +161,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "-00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "observer emission percentage cannot be less than 0 percent",
},
Expand All @@ -166,6 +176,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "150.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "observer emission percentage cannot be more than 100 percent",
},
Expand All @@ -180,6 +191,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "102.22",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "tss emission percentage cannot be more than 100 percent",
},
Expand All @@ -194,6 +206,7 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "-102.22",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "tss emission percentage cannot be less than 0 percent",
},
Expand Down
1 change: 1 addition & 0 deletions x/emissions/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
ParamObserverEmissionPercentage = "ObserverEmissionPercentage"
ParamTssSignerEmissionPercentage = "SignerEmissionPercentage"
ParamDurationFactorConstant = "DurationFactorConstant"
ParamObserverSlashAmount = "ObserverSlashAmount"
)

var (
Expand Down
14 changes: 11 additions & 3 deletions x/emissions/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyPrefix(ParamObserverEmissionPercentage), &p.ObserverEmissionPercentage, validateObserverEmissionPercentage),
paramtypes.NewParamSetPair(KeyPrefix(ParamTssSignerEmissionPercentage), &p.TssSignerEmissionPercentage, validateTssEmissonPercentage),
paramtypes.NewParamSetPair(KeyPrefix(ParamDurationFactorConstant), &p.DurationFactorConstant, validateDurationFactorConstant),
paramtypes.NewParamSetPair(KeyPrefix(ParamObserverSlashAmount), &p.ObserverSlashAmount, validateObserverSlashAmount),
}
}

Expand All @@ -71,6 +72,16 @@ func (p Params) String() string {
return string(out)
}

func validateObserverSlashAmount(i interface{}) error {
v, ok := i.(sdkmath.Int)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.LT(sdk.ZeroInt()) {
return fmt.Errorf("slash amount cannot be less than 0")
}
return nil
}
func validateDurationFactorConstant(i interface{}) error {
_, ok := i.(string)
if !ok {
Expand All @@ -96,9 +107,6 @@ func validateMinBondFactor(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
decMaxBond := sdk.MustNewDecFromStr(v)
if decMaxBond.LT(sdk.MustNewDecFromStr("0.75")) {
return fmt.Errorf("min bond factor cannot be lower that 0.75")
Expand Down

0 comments on commit 7fb0ffc

Please sign in to comment.