Skip to content

Commit

Permalink
fix: Check for host denom duplicates (#736)
Browse files Browse the repository at this point in the history
* check for host denom duplicates

* changelog
  • Loading branch information
kruspy authored Jan 22, 2024
1 parent 8b79166 commit 83091c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- [736](https://github.com/persistenceOne/pstake-native/pull/736) Check for host denom duplicates.
- [733](https://github.com/persistenceOne/pstake-native/pull/733) Add more validation for host-chain
- [729](https://github.com/persistenceOne/pstake-native/pull/729) Add rewards account query (hence autocompound)
OnChanOpenAck.
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 @@ -54,6 +54,11 @@ func (k msgServer) RegisterHostChain(
return nil, fmt.Errorf("host chain with id \"%s\" already exists", chainID)
}

_, found = k.GetHostChainFromHostDenom(ctx, msg.HostDenom)
if found {
return nil, fmt.Errorf("host chain with host denom \"%s\" already exists", msg.HostDenom)
}

// build the host chain params
hostChainParams := &types.HostChainLSParams{
DepositFee: msg.DepositFee,
Expand Down
29 changes: 27 additions & 2 deletions x/liquidstakeibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,31 @@ func (suite *IntegrationTestSuite) Test_msgServer_RegisterHostChain() {
args args
want *types.MsgRegisterHostChainResponse
wantErr bool
err error
}{
{
name: "host denom already exists",
args: args{
goCtx: ctx,
msg: &types.MsgRegisterHostChain{
Authority: suite.chainA.SenderAccount.GetAddress().String(),
ConnectionId: suite.transferPathAC.EndpointA.ConnectionID,
DepositFee: sdk.ZeroDec(),
RestakeFee: sdk.ZeroDec(),
UnstakeFee: sdk.ZeroDec(),
RedemptionFee: sdk.ZeroDec(),
ChannelId: suite.transferPathAC.EndpointA.ChannelID,
PortId: suite.transferPathAC.EndpointA.ChannelConfig.PortID,
HostDenom: "uatom",
MinimumDeposit: sdk.OneInt(),
UnbondingFactor: 4,
AutoCompoundFactor: 2,
},
},
want: nil,
wantErr: true,
err: fmt.Errorf("host chain with host denom \"%s\" already exists", "uatom"),
},
{
name: "success",
args: args{
Expand All @@ -450,7 +474,7 @@ func (suite *IntegrationTestSuite) Test_msgServer_RegisterHostChain() {
wantErr: false,
},
{
name: "already exists",
name: "host chain already exists",
args: args{
goCtx: ctx,
msg: &types.MsgRegisterHostChain{
Expand All @@ -470,6 +494,7 @@ func (suite *IntegrationTestSuite) Test_msgServer_RegisterHostChain() {
},
want: nil,
wantErr: true,
err: fmt.Errorf("host chain with id \"%s\" already exists", suite.transferPathAB.EndpointB.Chain.ChainID),
},
}
for _, tt := range tests {
Expand All @@ -479,7 +504,7 @@ func (suite *IntegrationTestSuite) Test_msgServer_RegisterHostChain() {
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)
suite.Require().Equal(tt.err, err)
}
if (err != nil) != tt.wantErr {
t.Errorf("RegisterHostChain() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit 83091c3

Please sign in to comment.