Skip to content

Commit

Permalink
go/staking: Fix incorrect non-existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Nov 3, 2021
1 parent aa0e4ef commit f7c17e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/staking/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 11 additions & 0 deletions go/staking/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f7c17e1

Please sign in to comment.