Add tests for types
This commit is contained in:
parent
75674a9ec3
commit
f837c16760
|
@ -8,6 +8,7 @@ const (
|
|||
// Staking errors reserve 300 - 399.
|
||||
CodeEmptyValidator sdk.CodeType = 300
|
||||
CodeInvalidUnbond sdk.CodeType = 301
|
||||
CodeEmptyStake sdk.CodeType = 302
|
||||
)
|
||||
|
||||
func ErrEmptyValidator() sdk.Error {
|
||||
|
@ -18,6 +19,10 @@ func ErrInvalidUnbond() sdk.Error {
|
|||
return newError(CodeInvalidUnbond, "")
|
||||
}
|
||||
|
||||
func ErrEmptyStake() sdk.Error {
|
||||
return newError(CodeEmptyStake, "")
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Helpers
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@ func (msg BondMsg) Type() string {
|
|||
}
|
||||
|
||||
func (msg BondMsg) ValidateBasic() sdk.Error {
|
||||
if msg.Stake.IsZero() {
|
||||
return ErrEmptyStake()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package staking
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func TestBondMsgValidation(t *testing.T) {
|
||||
privKey := crypto.GenPrivKeyEd25519()
|
||||
cases := []struct {
|
||||
valid bool
|
||||
bondMsg BondMsg
|
||||
}{
|
||||
{true, NewBondMsg(sdk.Address{}, sdk.Coin{"mycoin", 5}, privKey.PubKey())},
|
||||
{false, NewBondMsg(sdk.Address{}, sdk.Coin{"mycoin", 0}, privKey.PubKey())},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
err := tc.bondMsg.ValidateBasic()
|
||||
if tc.valid {
|
||||
assert.Nil(t, err, "%d: %+v", i, err)
|
||||
} else {
|
||||
assert.NotNil(t, err, "%d", i)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue