Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Dec 17, 2021
1 parent 9c65aec commit 73e5a5e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 71 deletions.
20 changes: 10 additions & 10 deletions errors/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func (s *abciTestSuite) TestABCInfo() {
wantLog string
}{
"plain SDK error": {
err: errUnauthorized,
err: ErrUnauthorized,
debug: false,
wantLog: "unauthorized",
wantCode: errUnauthorized.code,
wantCode: ErrUnauthorized.code,
wantSpace: testCodespace,
},
"wrapped SDK error": {
err: Wrap(Wrap(errUnauthorized, "foo"), "bar"),
err: Wrap(Wrap(ErrUnauthorized, "foo"), "bar"),
debug: false,
wantLog: "bar: foo: unauthorized",
wantCode: errUnauthorized.code,
wantCode: ErrUnauthorized.code,
wantSpace: testCodespace,
},
"nil is empty message": {
Expand Down Expand Up @@ -118,13 +118,13 @@ func (s *abciTestSuite) TestABCIInfoStacktrace() {
wantErrMsg string
}{
"wrapped SDK error in debug mode provides stacktrace": {
err: Wrap(errUnauthorized, "wrapped"),
err: Wrap(ErrUnauthorized, "wrapped"),
debug: true,
wantStacktrace: true,
wantErrMsg: "wrapped: unauthorized",
},
"wrapped SDK error in non-debug mode does not have stacktrace": {
err: Wrap(errUnauthorized, "wrapped"),
err: Wrap(ErrUnauthorized, "wrapped"),
debug: false,
wantStacktrace: false,
wantErrMsg: "wrapped: unauthorized",
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s *abciTestSuite) TestABCIInfoStacktrace() {
}

func (s *abciTestSuite) TestABCIInfoHidesStacktrace() {
err := Wrap(errUnauthorized, "wrapped")
err := Wrap(ErrUnauthorized, "wrapped")
_, _, log := ABCIInfo(err, false)
s.Require().Equal("wrapped: unauthorized", log)
}
Expand All @@ -174,7 +174,7 @@ func (s *abciTestSuite) TestRedact() {
changed: errPanicWithMsg,
},
"sdk errors untouched": {
err: Wrap(errUnauthorized, "cannot drop db"),
err: Wrap(ErrUnauthorized, "cannot drop db"),
untouched: true,
},
"pass though custom errors with ABCI code": {
Expand Down Expand Up @@ -206,8 +206,8 @@ func (s *abciTestSuite) TestRedact() {
func (s *abciTestSuite) TestABCIInfoSerializeErr() {
var (
// Create errors with stacktrace for equal comparison.
myErrDecode = Wrap(errTxDecode, "test")
myErrAddr = Wrap(errInvalidAddress, "tester")
myErrDecode = Wrap(ErrTxDecode, "test")
myErrAddr = Wrap(ErrInvalidAddress, "tester")
myPanic = ErrPanic
)

Expand Down
86 changes: 60 additions & 26 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func (s *errorsTestSuite) TestCause() {
root error
}{
"Errors are self-causing": {
err: errUnauthorized,
root: errUnauthorized,
err: ErrUnauthorized,
root: ErrUnauthorized,
},
"Wrap reveals root cause": {
err: Wrap(errUnauthorized, "foo"),
root: errUnauthorized,
err: Wrap(ErrUnauthorized, "foo"),
root: ErrUnauthorized,
},
"Cause works for stderr as root": {
err: Wrap(std, "Some helpful text"),
Expand All @@ -54,32 +54,32 @@ func (s *errorsTestSuite) TestErrorIs() {
wantIs bool
}{
"instance of the same error": {
a: errUnauthorized,
b: errUnauthorized,
a: ErrUnauthorized,
b: ErrUnauthorized,
wantIs: true,
},
"two different coded errors": {
a: errUnauthorized,
b: errOutOfGas,
a: ErrUnauthorized,
b: ErrOutOfGas,
wantIs: false,
},
"successful comparison to a wrapped error": {
a: errUnauthorized,
b: errors.Wrap(errUnauthorized, "gone"),
a: ErrUnauthorized,
b: errors.Wrap(ErrUnauthorized, "gone"),
wantIs: true,
},
"unsuccessful comparison to a wrapped error": {
a: errUnauthorized,
b: errors.Wrap(errInsufficientFee, "too big"),
a: ErrUnauthorized,
b: errors.Wrap(ErrInsufficientFee, "too big"),
wantIs: false,
},
"not equal to stdlib error": {
a: errUnauthorized,
a: ErrUnauthorized,
b: fmt.Errorf("stdlib error"),
wantIs: false,
},
"not equal to a wrapped stdlib error": {
a: errUnauthorized,
a: ErrUnauthorized,
b: errors.Wrap(fmt.Errorf("stdlib error"), "wrapped"),
wantIs: false,
},
Expand All @@ -95,11 +95,11 @@ func (s *errorsTestSuite) TestErrorIs() {
},
"nil is not not-nil": {
a: nil,
b: errUnauthorized,
b: ErrUnauthorized,
wantIs: false,
},
"not-nil is not nil": {
a: errUnauthorized,
a: ErrUnauthorized,
b: nil,
wantIs: false,
},
Expand All @@ -113,7 +113,7 @@ func (s *errorsTestSuite) TestIsOf() {
require := s.Require()

var errNil *Error
var err = errInvalidAddress
var err = ErrInvalidAddress
var errW = Wrap(ErrLogic, "more info")

require.False(IsOf(errNil), "nil error should always have no causer")
Expand Down Expand Up @@ -152,7 +152,7 @@ func (s *errorsTestSuite) TestWrappedIs() {
err = Wrap(err, "even more context")
require.True(stdlib.Is(err, ErrTxTooLarge))

err = Wrap(errInsufficientFee, "...")
err = Wrap(ErrInsufficientFee, "...")
require.False(stdlib.Is(err, ErrTxTooLarge))

errs := stdlib.New("other")
Expand All @@ -161,10 +161,10 @@ func (s *errorsTestSuite) TestWrappedIs() {
errw := &wrappedError{"msg", errs}
require.True(errw.Is(errw), "should match itself")

require.True(stdlib.Is(errInsufficientFee.Wrap("wrapped"), errInsufficientFee))
require.True(IsOf(errInsufficientFee.Wrap("wrapped"), errInsufficientFee))
require.True(stdlib.Is(errInsufficientFee.Wrapf("wrapped"), errInsufficientFee))
require.True(IsOf(errInsufficientFee.Wrapf("wrapped"), errInsufficientFee))
require.True(stdlib.Is(ErrInsufficientFee.Wrap("wrapped"), ErrInsufficientFee))
require.True(IsOf(ErrInsufficientFee.Wrap("wrapped"), ErrInsufficientFee))
require.True(stdlib.Is(ErrInsufficientFee.Wrapf("wrapped"), ErrInsufficientFee))
require.True(IsOf(ErrInsufficientFee.Wrapf("wrapped"), ErrInsufficientFee))
}

func (s *errorsTestSuite) TestWrappedIsMultiple() {
Expand Down Expand Up @@ -207,8 +207,8 @@ func (s *errorsTestSuite) TestABCIError() {
}

func ExampleWrap() {
err1 := Wrap(errInsufficientFunds, "90 is smaller than 100")
err2 := errors.Wrap(errInsufficientFunds, "90 is smaller than 100")
err1 := Wrap(ErrInsufficientFunds, "90 is smaller than 100")
err2 := errors.Wrap(ErrInsufficientFunds, "90 is smaller than 100")
fmt.Println(err1.Error())
fmt.Println(err2.Error())
// Output:
Expand All @@ -217,11 +217,45 @@ func ExampleWrap() {
}

func ExampleWrapf() {
err1 := Wrap(errInsufficientFunds, "90 is smaller than 100")
err2 := errors.Wrap(errInsufficientFunds, "90 is smaller than 100")
err1 := Wrap(ErrInsufficientFunds, "90 is smaller than 100")
err2 := errors.Wrap(ErrInsufficientFunds, "90 is smaller than 100")
fmt.Println(err1.Error())
fmt.Println(err2.Error())
// Output:
// 90 is smaller than 100: insufficient funds
// 90 is smaller than 100: insufficient funds
}

const testCodespace = "testtesttest"

var (
ErrTxDecode = Register(testCodespace, 2, "tx parse error")
ErrInvalidSequence = Register(testCodespace, 3, "invalid sequence")
ErrUnauthorized = Register(testCodespace, 4, "unauthorized")
ErrInsufficientFunds = Register(testCodespace, 5, "insufficient funds")
ErrUnknownRequest = Register(testCodespace, 6, "unknown request")
ErrInvalidAddress = Register(testCodespace, 7, "invalid address")
ErrInvalidPubKey = Register(testCodespace, 8, "invalid pubkey")
ErrUnknownAddress = Register(testCodespace, 9, "unknown address")
ErrInvalidCoins = Register(testCodespace, 10, "invalid coins")
ErrOutOfGas = Register(testCodespace, 11, "out of gas")
ErrInsufficientFee = Register(testCodespace, 13, "insufficient fee")
ErrTooManySignatures = Register(testCodespace, 14, "maximum number of signatures exceeded")
ErrNoSignatures = Register(testCodespace, 15, "no signatures supplied")
ErrJSONMarshal = Register(testCodespace, 16, "failed to marshal JSON bytes")
ErrJSONUnmarshal = Register(testCodespace, 17, "failed to unmarshal JSON bytes")
ErrInvalidRequest = Register(testCodespace, 18, "invalid request")
ErrMempoolIsFull = Register(testCodespace, 20, "mempool is full")
ErrTxTooLarge = Register(testCodespace, 21, "tx too large")
ErrKeyNotFound = Register(testCodespace, 22, "key not found")
ErrorInvalidSigner = Register(testCodespace, 24, "tx intended signer does not match the given signer")
ErrInvalidChainID = Register(testCodespace, 28, "invalid chain-id")
ErrInvalidType = Register(testCodespace, 29, "invalid type")
ErrUnknownExtensionOptions = Register(testCodespace, 31, "unknown extension options")
ErrPackAny = Register(testCodespace, 33, "failed packing protobuf message to Any")
ErrLogic = Register(testCodespace, 35, "internal logic error")
ErrConflict = Register(testCodespace, 36, "conflict")
ErrNotSupported = Register(testCodespace, 37, "feature not supported")
ErrNotFound = Register(testCodespace, 38, "not found")
ErrIO = Register(testCodespace, 39, "Internal IO error")
)
35 changes: 0 additions & 35 deletions errors/testerrors.go

This file was deleted.

3 changes: 3 additions & 0 deletions x/group/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
github.com/confio/ics23/go v0.6.6 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
github.com/cosmos/cosmos-sdk/db v0.0.0 // indirect
github.com/cosmos/cosmos-sdk/errors v0.0.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/iavl v0.17.3 // indirect
github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect
Expand Down Expand Up @@ -150,3 +151,5 @@ replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alp
replace github.com/cosmos/cosmos-sdk => ../../

replace github.com/cosmos/cosmos-sdk/db => ../../db

replace github.com/cosmos/cosmos-sdk/errors => ../../errors

0 comments on commit 73e5a5e

Please sign in to comment.