types/errors_test.go

This commit is contained in:
Ethan Buchman 2018-03-18 02:03:25 +01:00
parent 64852138b6
commit 1491de4522
1 changed files with 53 additions and 0 deletions

53
types/errors_test.go Normal file
View File

@ -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)
}
}