Skip to content

Commit

Permalink
Limit upper voting power
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jan 25, 2019
1 parent 72a43e7 commit 8928c71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion x/validators/msg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validators

import (
"math"
"strings"

"github.com/iov-one/weave"
Expand All @@ -23,7 +24,7 @@ func (m ValidatorUpdate) Validate() error {
strings.ToLower(m.Pubkey.Type) != "ed25519" {
return errors.WithCode(errInvalidPubKey, CodeInvalidPubKey)
}
if m.Power < 0 {
if m.Power < 0 || m.Power > math.MaxInt64/8 {
return errors.WithCode(errInvalidPower, CodeInvalidPower)
}
return nil
Expand Down
10 changes: 8 additions & 2 deletions x/validators/msg_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package validators

import (
"math"
"testing"

"github.com/tendermint/tendermint/crypto/ed25519"

"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/crypto/ed25519"
)

func TestValidate(t *testing.T) {
Expand Down Expand Up @@ -39,6 +39,12 @@ func TestValidate(t *testing.T) {
}},
expError: true,
},
"Power must not exceed max": {
src: SetValidatorsMsg{[]*ValidatorUpdate{
{Pubkey: Pubkey{Data: keyEd25519[:], Type: "ed25519"}, Power: math.MaxInt64/8 + 1},
}},
expError: true,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
Expand Down

0 comments on commit 8928c71

Please sign in to comment.