Merge pull request #643 from cosmos/bucky/error-tests
types/errors_test.go
This commit is contained in:
commit
2721307e31
|
@ -0,0 +1,53 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var codeTypes = []CodeType{
|
||||
CodeInternal,
|
||||
CodeTxParse,
|
||||
CodeInvalidSequence,
|
||||
CodeUnauthorized,
|
||||
CodeInsufficientFunds,
|
||||
CodeUnknownRequest,
|
||||
CodeUnrecognizedAddress,
|
||||
CodeInvalidPubKey,
|
||||
CodeGenesisParse,
|
||||
}
|
||||
|
||||
type errFn func(msg string) Error
|
||||
|
||||
var errFns = []errFn{
|
||||
ErrInternal,
|
||||
ErrTxParse,
|
||||
ErrInvalidSequence,
|
||||
ErrUnauthorized,
|
||||
ErrInsufficientFunds,
|
||||
ErrUnknownRequest,
|
||||
ErrUnrecognizedAddress,
|
||||
ErrInvalidPubKey,
|
||||
ErrGenesisParse,
|
||||
}
|
||||
|
||||
func TestCodeType(t *testing.T) {
|
||||
assert.True(t, CodeOK.IsOK())
|
||||
|
||||
for _, c := range codeTypes {
|
||||
assert.False(t, c.IsOK())
|
||||
msg := CodeToDefaultMsg(c)
|
||||
assert.False(t, strings.HasPrefix(msg, "Unknown code"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrFn(t *testing.T) {
|
||||
for i, errFn := range errFns {
|
||||
err := errFn("")
|
||||
codeType := codeTypes[i]
|
||||
assert.Equal(t, err.ABCICode(), codeType)
|
||||
assert.Equal(t, err.Result().Code, codeType)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue