From f7c17e1c65dc66e89d33c087be9ad8432f98b229 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Wed, 3 Nov 2021 14:16:50 +0100 Subject: [PATCH] go/staking: Fix incorrect non-existence check --- go/staking/api/api.go | 2 +- go/staking/api/api_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/go/staking/api/api.go b/go/staking/api/api.go index 41298234a2f..cedf6ce256e 100644 --- a/go/staking/api/api.go +++ b/go/staking/api/api.go @@ -835,7 +835,7 @@ func (sa *StakeAccumulator) AddClaimUnchecked(claim StakeClaim, thresholds []Sta // // It is an error if the stake claim does not exist. func (sa *StakeAccumulator) RemoveClaim(claim StakeClaim) error { - if sa.Claims == nil || sa.Claims[claim] == nil { + if _, exists := sa.Claims[claim]; !exists { return fmt.Errorf("staking: claim does not exist: %s", claim) } diff --git a/go/staking/api/api_test.go b/go/staking/api/api_test.go index 14c921a2642..e8214b785c4 100644 --- a/go/staking/api/api_test.go +++ b/go/staking/api/api_test.go @@ -206,6 +206,17 @@ func TestStakeAccumulator(t *testing.T) { err = acct.CheckStakeClaims(thresholds) require.NoError(err, "escrow account should check out") + // Add claim with empty threshold list. + err = acct.AddStakeClaim(thresholds, StakeClaim("claimEmptyList"), []StakeThreshold{}) + require.NoError(err, "adding an empty list stake claim should work") + err = acct.RemoveStakeClaim(StakeClaim("claimEmptyList")) + require.NoError(err, "removing an empty claim should work") + + err = acct.AddStakeClaim(thresholds, StakeClaim("claimNilList"), nil) + require.NoError(err, "adding an nil list stake claim should work") + err = acct.RemoveStakeClaim(StakeClaim("claimNilList")) + require.NoError(err, "removing an nil claim should work") + // Reduce stake. acct.Active.Balance = *quantity.NewFromUint64(5_000) err = acct.CheckStakeClaims(thresholds)