From 8ef97425c8bd38914f483aa6d5f6ac772cb335cb Mon Sep 17 00:00:00 2001 From: Puneet <59960662+puneet2019@users.noreply.github.com> Date: Fri, 19 Jan 2024 20:39:25 +0530 Subject: [PATCH] fix: genesis validate, deposits validate. (#730) * fix genesis validate, deposits validate. * add CHANGELOG.md --- CHANGELOG.md | 1 + x/liquidstakeibc/types/liquidstakeibc.go | 6 ++++-- x/liquidstakeibc/types/liquidstakeibc_test.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62380eb6b..e5c125723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/x/liquidstakeibc/types/liquidstakeibc.go b/x/liquidstakeibc/types/liquidstakeibc.go index 75eaa529a..7c693ae10 100644 --- a/x/liquidstakeibc/types/liquidstakeibc.go +++ b/x/liquidstakeibc/types/liquidstakeibc.go @@ -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( @@ -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 } diff --git a/x/liquidstakeibc/types/liquidstakeibc_test.go b/x/liquidstakeibc/types/liquidstakeibc_test.go index 9d11a9c9c..8bd0e432c 100644 --- a/x/liquidstakeibc/types/liquidstakeibc_test.go +++ b/x/liquidstakeibc/types/liquidstakeibc_test.go @@ -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) {