Skip to content

Commit

Permalink
fix: genesis validate, deposits validate. (#730)
Browse files Browse the repository at this point in the history
* fix genesis validate, deposits validate.

* add CHANGELOG.md
  • Loading branch information
puneet2019 authored Jan 19, 2024
1 parent c2de3df commit 8ef9742
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- [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
removing the Deposit entry.
- [726](https://github.com/persistenceOne/pstake-native/pull/726) Fix minimal unbondings.
Expand Down
6 changes: 4 additions & 2 deletions x/liquidstakeibc/types/liquidstakeibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func DefaultRewardsAccountPortOwner(chainID string) string {

func (deposit *Deposit) Validate() error {
if deposit.State != Deposit_DEPOSIT_PENDING &&
deposit.State != Deposit_DEPOSIT_SENT &&
deposit.State != Deposit_DEPOSIT_RECEIVED &&
deposit.State != Deposit_DEPOSIT_DELEGATING {
return fmt.Errorf(
Expand All @@ -57,9 +58,10 @@ func (deposit *Deposit) Validate() error {
deposit.State,
)
}
if deposit.Amount.Amount.LT(sdk.ZeroInt()) {
return fmt.Errorf("deposit for chain %s has negative amount", deposit.ChainId)
if err := deposit.Amount.Validate(); err != nil {
return fmt.Errorf("deposit amount is invalid, err: %v", err)
}

return nil
}

Expand Down
10 changes: 10 additions & 0 deletions x/liquidstakeibc/types/liquidstakeibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ func TestDeposit_Validate(t *testing.T) {
},
wantErr: true,
},
{
name: "invalid state",
fields: fields{
ChainId: "chain-1",
Amount: validCoin,
Epoch: 0,
State: 1,
IbcSequenceId: "",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8ef9742

Please sign in to comment.