Skip to content

Commit

Permalink
add validation for redelegation delta (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
puneet2019 authored Jan 22, 2024
1 parent 751fd17 commit 8b79166
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 48 deletions.
14 changes: 8 additions & 6 deletions x/liquidstakeibc/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ func TestGenesis(t *testing.T) {
ChainId: "chainA-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
RedelegationAcceptableDelta: sdk.ZeroInt(),
MaxEntries: 7,
},
HostDenom: "uatom",
ChannelId: "channel-1",
Expand Down
9 changes: 5 additions & 4 deletions x/liquidstakeibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ func (k msgServer) RegisterHostChain(

// build the host chain params
hostChainParams := &types.HostChainLSParams{
DepositFee: msg.DepositFee,
RestakeFee: msg.RestakeFee,
UnstakeFee: msg.UnstakeFee,
RedemptionFee: msg.RedemptionFee,
DepositFee: msg.DepositFee,
RestakeFee: msg.RestakeFee,
UnstakeFee: msg.UnstakeFee,
RedemptionFee: msg.RedemptionFee,
RedelegationAcceptableDelta: sdktypes.ZeroInt(),
}

hc := &types.HostChain{
Expand Down
13 changes: 7 additions & 6 deletions x/liquidstakeibc/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,13 @@ func ValidGenesis() *types.GenesisState {
ChainId: "chainA-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
LsmValidatorCap: sdk.NewDec(1),
LsmBondFactor: sdk.NewDec(-1),
RedelegationAcceptableDelta: sdk.OneInt(),
},
HostDenom: "uatom",
ChannelId: "channel-1",
Expand Down
3 changes: 3 additions & 0 deletions x/liquidstakeibc/types/liquidstakeibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func (params *HostChainLSParams) Validate() error {
if params.UnstakeFee.LT(sdk.ZeroDec()) || params.UnstakeFee.GT(sdk.OneDec()) {
return fmt.Errorf("host chain lsparams has invalid unstake fee, should be 0<=fee<=1\"")
}
if params.RedelegationAcceptableDelta.LT(sdk.ZeroInt()) {
return fmt.Errorf("host chain has invalid redelegation acceptable delta expected >= 0")
}
return nil
}

Expand Down
83 changes: 51 additions & 32 deletions x/liquidstakeibc/types/liquidstakeibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ func TestHostChain_Validate(t *testing.T) {
ChainId: "chain-1",
ConnectionId: "connection-1",
Params: &types.HostChainLSParams{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
RedelegationAcceptableDelta: sdk.OneInt(),
},
HostDenom: "uatom",
ChannelId: "channel-1",
Expand Down Expand Up @@ -635,10 +636,11 @@ func TestValidatorUnbonding_Validate(t *testing.T) {

func TestHostChainLSParams_Validate(t *testing.T) {
type fields struct {
DepositFee sdk.Dec
RestakeFee sdk.Dec
UnstakeFee sdk.Dec
RedemptionFee sdk.Dec
DepositFee sdk.Dec
RestakeFee sdk.Dec
UnstakeFee sdk.Dec
RedemptionFee sdk.Dec
RedelegationDelta math.Int
}
tests := []struct {
name string
Expand All @@ -648,61 +650,78 @@ func TestHostChainLSParams_Validate(t *testing.T) {
{
name: "valid",
fields: fields{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
RedelegationDelta: sdk.OneInt(),
},
wantErr: false,
},
{
name: "invalid deposit fee",
fields: fields{
DepositFee: sdk.MustNewDecFromStr("-1"),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
DepositFee: sdk.MustNewDecFromStr("-1"),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
RedelegationDelta: sdk.OneInt(),
},
wantErr: true,
},
{
name: "invalid restake fee",
fields: fields{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.MustNewDecFromStr("1.1"),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.MustNewDecFromStr("1.1"),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
RedelegationDelta: sdk.OneInt(),
},
wantErr: true,
},
{
name: "invalid unstake fee",
fields: fields{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.MustNewDecFromStr("-1"),
RedemptionFee: sdk.ZeroDec(),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.MustNewDecFromStr("-1"),
RedemptionFee: sdk.ZeroDec(),
RedelegationDelta: sdk.OneInt(),
},
wantErr: true,
},
{
name: "invalid redemption fee",
fields: fields{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.MustNewDecFromStr("1.2"),
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.MustNewDecFromStr("1.2"),
RedelegationDelta: sdk.OneInt(),
},
wantErr: true,
},
{
name: "invalid redelegation delta",
fields: fields{
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
RedelegationDelta: sdk.NewInt(-1),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
params := &types.HostChainLSParams{
DepositFee: tt.fields.DepositFee,
RestakeFee: tt.fields.RestakeFee,
UnstakeFee: tt.fields.UnstakeFee,
RedemptionFee: tt.fields.RedemptionFee,
DepositFee: tt.fields.DepositFee,
RestakeFee: tt.fields.RestakeFee,
UnstakeFee: tt.fields.UnstakeFee,
RedemptionFee: tt.fields.RedemptionFee,
RedelegationAcceptableDelta: tt.fields.RedelegationDelta,
}
if err := params.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit 8b79166

Please sign in to comment.