Skip to content

Commit

Permalink
Merge pull request #1000 from maticnetwork/raneet10/test-fixes
Browse files Browse the repository at this point in the history
gov,types: fix tests
  • Loading branch information
Raneet10 committed Jun 8, 2023
2 parents a5545a1 + 2fd20a2 commit b84aac3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
6 changes: 3 additions & 3 deletions gov/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func NormalizeVoteOption(option string) string {
}
}

//NormalizeProposalType - normalize user specified proposal type
// NormalizeProposalType - normalize user specified proposal type
func NormalizeProposalType(proposalType string) string {
switch proposalType {
default:
return ""
return proposalType
}
}

//NormalizeProposalStatus - normalize user specified proposal status
// NormalizeProposalStatus - normalize user specified proposal status
func NormalizeProposalStatus(status string) string {
switch status {
case "DepositPeriod", "deposit_period":
Expand Down
3 changes: 2 additions & 1 deletion types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/ethereum/go-ethereum/common"
)

// Validator heimdall validator
Expand Down Expand Up @@ -76,7 +77,7 @@ func (v *Validator) ValidateBasic() bool {
return false
}

if bytes.Equal(v.Signer.Bytes(), []byte("")) {
if bytes.Equal(v.Signer.Bytes(), HeimdallAddress(common.Address{}).Bytes()) {
return false
}

Expand Down
29 changes: 9 additions & 20 deletions types/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type valInput struct {
startEpoch uint64
endEpoch uint64
power int64
nonce uint64
pubKey PubKey
signer HeimdallAddress
}
Expand All @@ -32,29 +33,32 @@ func TestNewValidator(t *testing.T) {
in: valInput{
id: ValidatorID(uint64(0)),
signer: BytesToHeimdallAddress([]byte("12345678909876543210")),
nonce: uint64(0),
},
out: &Validator{Signer: BytesToHeimdallAddress([]byte("12345678909876543210"))},
out: &Validator{Signer: BytesToHeimdallAddress([]byte("12345678909876543210")), Nonce: uint64(0)},
msg: "testing for exact HeimdallAddress",
},
{
in: valInput{
id: ValidatorID(uint64(0)),
signer: BytesToHeimdallAddress([]byte("1")),
nonce: uint64(1),
},
out: &Validator{Signer: BytesToHeimdallAddress([]byte("1"))},
out: &Validator{Signer: BytesToHeimdallAddress([]byte("1")), Nonce: uint64(1)},
msg: "testing for small HeimdallAddress",
},
{
in: valInput{
id: ValidatorID(uint64(0)),
signer: BytesToHeimdallAddress([]byte("123456789098765432101")),
nonce: uint64(32),
},
out: &Validator{Signer: BytesToHeimdallAddress([]byte("123456789098765432101"))},
out: &Validator{Signer: BytesToHeimdallAddress([]byte("123456789098765432101")), Nonce: uint64(32)},
msg: "testing for excessively long HeimdallAddress, max length is supposed to be 20",
},
}
for _, c := range tc {
out := NewValidator(c.in.id, c.in.startEpoch, c.in.endEpoch, 1, c.in.power, c.in.pubKey, c.in.signer)
out := NewValidator(c.in.id, c.in.startEpoch, c.in.endEpoch, c.in.nonce, c.in.power, c.in.pubKey, c.in.signer)
assert.Equal(t, c.out, out)
}
}
Expand Down Expand Up @@ -91,8 +95,6 @@ func TestSortValidatorByAddress(t *testing.T) {
func TestValidateBasic(t *testing.T) {
t.Parallel()

neg1, uNeg1 := uint64(1), uint64(0)
uNeg1 = uNeg1 - neg1
tc := []struct {
in Validator
out bool
Expand All @@ -113,28 +115,15 @@ func TestValidateBasic(t *testing.T) {
out: false,
msg: "Invalid PubKey",
},

// {
// in: Validator{StartEpoch: uNeg1, EndEpoch: 5, PubKey: NewPubKey([]byte("nonZeroTestPubKey")), Signer: BytesToHeimdallAddress([]byte("3"))},
// out: false,
// msg: "Invalid StartEpoch",
// },
{
// do we allow for endEpoch to be smaller than startEpoch ??
in: Validator{StartEpoch: 1, EndEpoch: uNeg1, Nonce: 0, PubKey: NewPubKey([]byte("nonZeroTestPubKey")), Signer: BytesToHeimdallAddress([]byte("3"))},
out: false,
msg: "Invalid endEpoch",
},
{
// in: Validator{StartEpoch: 1, EndEpoch: 1, PubKey: NewPubKey([]byte("nonZeroTestPubKey")), Signer: HeimdallAddress(BytesToHeimdallAddress([]byte(string(""))))},
in: Validator{StartEpoch: 1, EndEpoch: 1, Nonce: 0, PubKey: NewPubKey([]byte("nonZeroTestPubKey")), Signer: BytesToHeimdallAddress([]byte(""))},
out: false,
msg: "Invalid Signer",
},
{
in: Validator{},
out: false,
msg: "Valid basic validator test",
msg: "Invalid basic validator test",
},
}

Expand Down

0 comments on commit b84aac3

Please sign in to comment.