From 11585a4abd0b908c207c80894f400598e4d70aaf Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 2 Jan 2019 10:05:56 +0000 Subject: [PATCH] Introduce CodeNoSignatures --- PENDING.md | 2 ++ types/errors.go | 6 ++++++ x/auth/ante_test.go | 2 +- x/auth/stdtx.go | 2 +- x/auth/stdtx_test.go | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/PENDING.md b/PENDING.md index 07e8fc1352..1fa2197326 100644 --- a/PENDING.md +++ b/PENDING.md @@ -45,6 +45,8 @@ FEATURES * SDK * \#2996 Update the `AccountKeeper` to contain params used in the context of the ante handler. + * [\#3179](https://github.com/cosmos/cosmos-sdk/pull/3179) New CodeNoSignatures error code. + * Tendermint diff --git a/types/errors.go b/types/errors.go index a54c9d71c5..a400fec6f9 100644 --- a/types/errors.go +++ b/types/errors.go @@ -45,6 +45,7 @@ const ( CodeInsufficientFee CodeType = 14 CodeTooManySignatures CodeType = 15 CodeGasOverflow CodeType = 16 + CodeNoSignatures CodeType = 17 // CodespaceRoot is a codespace for error codes in this file only. // Notice that 0 is an "unset" codespace, which can be overridden with @@ -90,6 +91,8 @@ func CodeToDefaultMsg(code CodeType) string { return "insufficient fee" case CodeTooManySignatures: return "maximum numer of signatures exceeded" + case CodeNoSignatures: + return "no signatures supplied" default: return unknownCodeMsg(code) } @@ -145,6 +148,9 @@ func ErrInsufficientFee(msg string) Error { func ErrTooManySignatures(msg string) Error { return newErrorWithRootCodespace(CodeTooManySignatures, msg) } +func ErrNoSignatures(msg string) Error { + return newErrorWithRootCodespace(CodeNoSignatures, msg) +} func ErrGasOverflow(msg string) Error { return newErrorWithRootCodespace(CodeGasOverflow, msg) } diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index 78c9438793..f92e61274c 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -71,7 +71,7 @@ func TestAnteHandlerSigErrors(t *testing.T) { require.Equal(t, expectedSigners, stdTx.GetSigners()) // Check no signatures fails - checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeUnauthorized) + checkInvalidTx(t, anteHandler, ctx, tx, false, sdk.CodeNoSignatures) // test num sigs dont match GetSigners privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0} diff --git a/x/auth/stdtx.go b/x/auth/stdtx.go index ceba13c6df..07469f81b7 100644 --- a/x/auth/stdtx.go +++ b/x/auth/stdtx.go @@ -50,7 +50,7 @@ func (tx StdTx) ValidateBasic() sdk.Error { return sdk.ErrInsufficientFee(fmt.Sprintf("invalid fee %s amount provided", tx.Fee.Amount)) } if len(stdSigs) == 0 { - return sdk.ErrUnauthorized("no signers") + return sdk.ErrNoSignatures("no signers") } if len(stdSigs) != len(tx.GetSigners()) { return sdk.ErrUnauthorized("wrong number of signers") diff --git a/x/auth/stdtx_test.go b/x/auth/stdtx_test.go index 0cc6ced233..a1fbf4a34b 100644 --- a/x/auth/stdtx_test.go +++ b/x/auth/stdtx_test.go @@ -91,7 +91,7 @@ func TestTxValidateBasic(t *testing.T) { err = tx.ValidateBasic() require.Error(t, err) - require.Equal(t, sdk.CodeUnauthorized, err.Result().Code) + require.Equal(t, sdk.CodeNoSignatures, err.Result().Code) // require to fail validation when signatures do not match expected signers privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0, 1}, []uint64{0, 0}