From 62db5c66a5e9ce0528f310485c1b9ea728cc95f7 Mon Sep 17 00:00:00 2001 From: Servio Date: Tue, 30 Apr 2024 14:45:40 -0400 Subject: [PATCH] AddCommittedToken was edited to avoid amount duplicate on Lockup --- x/commitment/types/commitments.go | 1 - x/commitment/types/commitments_test.go | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/x/commitment/types/commitments.go b/x/commitment/types/commitments.go index 960c620f8..8fd260515 100644 --- a/x/commitment/types/commitments.go +++ b/x/commitment/types/commitments.go @@ -51,7 +51,6 @@ func (c *Commitments) AddCommittedTokens(denom string, amount math.Int, unlockTi li++ continue } else if lockup.UnlockTimestamp == unlockTime { - c.CommittedTokens[i].Lockups[li].Amount = lockup.Amount.Add(amount) return } else { break diff --git a/x/commitment/types/commitments_test.go b/x/commitment/types/commitments_test.go index bd4136f1a..792425bd9 100644 --- a/x/commitment/types/commitments_test.go +++ b/x/commitment/types/commitments_test.go @@ -25,6 +25,15 @@ func TestCommitments_AddCommittedTokens(t *testing.T) { require.Equal(t, commitments.CommittedTokens[0].Lockups[0].Amount.String(), "100") require.Equal(t, commitments.CommittedTokens[0].Lockups[0].UnlockTimestamp, uint64(100)) require.Len(t, commitments.CommittedTokens[1].Lockups, 1) + + commitments.AddCommittedTokens("lp/3", sdk.NewInt(1000), 100) + commitments.AddCommittedTokens("lp/3", sdk.NewInt(2000), 120) + commitments.AddCommittedTokens("lp/3", sdk.NewInt(3000), 130) + + require.Equal(t, commitments.CommittedTokens[2].Lockups[0].Amount.String(), "1000") + require.Equal(t, commitments.CommittedTokens[2].Lockups[1].Amount.String(), "2000") + require.Equal(t, commitments.CommittedTokens[2].Lockups[2].Amount.String(), "3000") + } func TestCommitments_WithdrawCommitedTokens(t *testing.T) {