Skip to content

Commit

Permalink
Merge pull request cosmos#643 from cosmos/bucky/error-tests
Browse files Browse the repository at this point in the history
types/errors_test.go
  • Loading branch information
ebuchman authored Mar 18, 2018
2 parents 572143f + 1491de4 commit 2721307
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions types/errors_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 2721307

Please sign in to comment.