Skip to content

Commit

Permalink
fix: Host chain duplication check (#734)
Browse files Browse the repository at this point in the history
* host chain duplication check

* changelog

---------

Co-authored-by: Puneet <[email protected]>
  • Loading branch information
kruspy and puneet2019 authored Jan 22, 2024
1 parent ca1b386 commit 751fd17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- [734](https://github.com/persistenceOne/pstake-native/pull/734) Host chain duplication check.
- [731](https://github.com/persistenceOne/pstake-native/pull/731) Set limit to LSM deposit filtering.
- [730](https://github.com/persistenceOne/pstake-native/pull/730) Fix deposit validate.
- [728](https://github.com/persistenceOne/pstake-native/pull/728) Fix prevent users from liquid-staking funds by
Expand Down
5 changes: 5 additions & 0 deletions x/liquidstakeibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func (k msgServer) RegisterHostChain(
return nil, fmt.Errorf("chain id not found for connection \"%s\": \"%w\"", msg.ConnectionId, err)
}

_, found := k.GetHostChain(ctx, chainID)
if found {
return nil, fmt.Errorf("host chain with id \"%s\" already exists", chainID)
}

// build the host chain params
hostChainParams := &types.HostChainLSParams{
DepositFee: msg.DepositFee,
Expand Down
27 changes: 27 additions & 0 deletions x/liquidstakeibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"context"
"fmt"
"reflect"
"testing"

Expand Down Expand Up @@ -448,12 +449,38 @@ func (suite *IntegrationTestSuite) Test_msgServer_RegisterHostChain() {
want: &types.MsgRegisterHostChainResponse{},
wantErr: false,
},
{
name: "already exists",
args: args{
goCtx: ctx,
msg: &types.MsgRegisterHostChain{
Authority: suite.chainA.SenderAccount.GetAddress().String(),
ConnectionId: suite.transferPathAB.EndpointA.ConnectionID,
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
ChannelId: suite.transferPathAB.EndpointA.ChannelID,
PortId: suite.transferPathAB.EndpointA.ChannelConfig.PortID,
HostDenom: "uosmo",
MinimumDeposit: sdk.OneInt(),
UnbondingFactor: 4,
AutoCompoundFactor: 2,
},
},
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {
k := keeper.NewMsgServerImpl(pstakeapp.LiquidStakeIBCKeeper)

got, err := k.RegisterHostChain(tt.args.goCtx, tt.args.msg)
if err != nil {
suite.Require().NotNil(err)
suite.Require().Equal(fmt.Errorf("host chain with id \"%s\" already exists", suite.transferPathAB.EndpointB.Chain.ChainID), err)
}
if (err != nil) != tt.wantErr {
t.Errorf("RegisterHostChain() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down

0 comments on commit 751fd17

Please sign in to comment.