Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Sequencing, Error Cleanup, Bash Tests Cleanup #177

Merged
merged 5 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/basecoin/modules/coin"

eyescli "github.com/tendermint/merkleeyes/client"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"

"github.com/tendermint/basecoin/modules/coin"
)

const genesisFilepath = "./testdata/genesis.json"
Expand Down
6 changes: 3 additions & 3 deletions client/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/tendermint/light-client/certifiers"
"github.com/tendermint/light-client/certifiers/files"
"github.com/tendermint/tmlibs/cli"
cmn "github.com/tendermint/tmlibs/common"

"github.com/tendermint/tendermint/types"

"github.com/tendermint/light-client/certifiers"
"github.com/tendermint/light-client/certifiers/files"
)

var (
dirPerm = os.FileMode(0700)
)

//nolint
const (
SeedFlag = "seed"
HashFlag = "valhash"
Expand Down
5 changes: 2 additions & 3 deletions client/commands/proofs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import (

wire "github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"

lc "github.com/tendermint/light-client"
"github.com/tendermint/light-client/proofs"
"github.com/tendermint/tendermint/rpc/client"

lc "github.com/tendermint/light-client"
"github.com/tendermint/basecoin/client/commands"
"github.com/tendermint/light-client/proofs"
)

// GetAndParseAppProof does most of the work of the query commands, but is quite
Expand Down
9 changes: 5 additions & 4 deletions client/commands/proofs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ import (
"github.com/spf13/cobra"

"github.com/tendermint/go-wire/data"
"github.com/tendermint/light-client/proofs"

"github.com/tendermint/basecoin/client/commands"
"github.com/tendermint/light-client/proofs"
)

var KeyCmd = &cobra.Command{
// KeyQueryCmd - CLI command to query a state by key with proof
var KeyQueryCmd = &cobra.Command{
Use: "key [key]",
Short: "Handle proofs for state of abci app",
Long: `This will look up a given key in the abci app, verify the proof,
and output it as hex.

If you want json output, use an app-specific command that knows key and value structure.`,
RunE: commands.RequireInit(doKeyQuery),
RunE: commands.RequireInit(keyQueryCmd),
}

// Note: we cannot yse GetAndParseAppProof here, as we don't use go-wire to
// parse the object, but rather return the raw bytes
func doKeyQuery(cmd *cobra.Command, args []string) error {
func keyQueryCmd(cmd *cobra.Command, args []string) error {
// parse cli
height := GetHeight()
key, err := ParseHexKey(args, "key")
Expand Down
11 changes: 7 additions & 4 deletions client/commands/proofs/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package proofs
import (
"github.com/spf13/cobra"

"github.com/tendermint/basecoin/client/commands"
"github.com/tendermint/light-client/proofs"

"github.com/tendermint/basecoin/client/commands"
)

//nolint TODO add description
var TxPresenters = proofs.NewPresenters()

var TxCmd = &cobra.Command{
// TxQueryCmd - CLI command to query a transaction with proof
var TxQueryCmd = &cobra.Command{
Use: "tx [txhash]",
Short: "Handle proofs of commited txs",
Long: `Proofs allows you to validate abci state with merkle proofs.
Expand All @@ -18,10 +21,10 @@ These proofs tie the data to a checkpoint, which is managed by "seeds".
Here we can validate these proofs and import/export them to prove specific
data to other peers as needed.
`,
RunE: commands.RequireInit(doTxQuery),
RunE: commands.RequireInit(txQueryCmd),
}

func doTxQuery(cmd *cobra.Command, args []string) error {
func txQueryCmd(cmd *cobra.Command, args []string) error {
// parse cli
height := GetHeight()
bkey, err := ParseHexKey(args, "txhash")
Expand Down
7 changes: 3 additions & 4 deletions client/commands/proxy/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"

certclient "github.com/tendermint/light-client/certifiers/client"
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core"
rpc "github.com/tendermint/tendermint/rpc/lib/server"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"

certclient "github.com/tendermint/light-client/certifiers/client"
"github.com/tendermint/basecoin/client/commands"
)

Expand Down
1 change: 1 addition & 0 deletions client/commands/rpc/insecure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rpc

import (
"github.com/spf13/cobra"

"github.com/tendermint/basecoin/client/commands"
)

Expand Down
2 changes: 1 addition & 1 deletion client/commands/rpc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"

"github.com/tendermint/go-wire/data"
certclient "github.com/tendermint/light-client/certifiers/client"
"github.com/tendermint/tendermint/rpc/client"

certclient "github.com/tendermint/light-client/certifiers/client"
"github.com/tendermint/basecoin/client/commands"
)

Expand Down
1 change: 1 addition & 0 deletions client/commands/rpc/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpc
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/basecoin/client/commands"
)

Expand Down
1 change: 1 addition & 0 deletions client/commands/seeds/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/basecoin/client/commands"
)

Expand Down
2 changes: 2 additions & 0 deletions client/commands/seeds/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/light-client/certifiers"

"github.com/tendermint/basecoin/client/commands"
)

Expand Down
2 changes: 2 additions & 0 deletions client/commands/seeds/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/light-client/certifiers"

"github.com/tendermint/basecoin/client/commands"
)

Expand Down
2 changes: 2 additions & 0 deletions client/commands/seeds/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"fmt"

"github.com/spf13/cobra"

"github.com/tendermint/light-client/certifiers"

"github.com/tendermint/basecoin/client/commands"
)

Expand Down
1 change: 1 addition & 0 deletions client/commands/txs/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txs

import (
"github.com/pkg/errors"

wire "github.com/tendermint/go-wire"
"github.com/tendermint/light-client/proofs"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
Expand Down
1 change: 1 addition & 0 deletions client/commands/txs/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/basecoin"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/basecli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func main() {
// Prepare queries
proofs.RootCmd.AddCommand(
// These are default parsers, but optional in your app (you can remove key)
proofs.TxCmd,
proofs.KeyCmd,
proofs.TxQueryCmd,
proofs.KeyQueryCmd,
coincmd.AccountQueryCmd,
noncecmd.NonceQueryCmd,
)
Expand Down
2 changes: 0 additions & 2 deletions cmd/basecoin/commands/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"path"
"strings"

//"github.com/pkg/errors"

"github.com/spf13/viper"

"github.com/tendermint/go-crypto"
Expand Down
3 changes: 2 additions & 1 deletion cmd/basecoin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"os"

"github.com/tendermint/tmlibs/cli"

"github.com/tendermint/basecoin/app"
"github.com/tendermint/basecoin/cmd/basecoin/commands"
"github.com/tendermint/tmlibs/cli"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/counter/cmd/countercli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func main() {
// Prepare queries
proofs.RootCmd.AddCommand(
// These are default parsers, optional in your app
proofs.TxCmd,
proofs.KeyCmd,
proofs.TxQueryCmd,
proofs.KeyQueryCmd,
coincmd.AccountQueryCmd,
noncecmd.NonceQueryCmd,

Expand Down
76 changes: 7 additions & 69 deletions errors/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,17 @@ import (
"fmt"
"reflect"

"github.com/pkg/errors"

abci "github.com/tendermint/abci/types"
)

var (
errDecoding = fmt.Errorf("Error decoding input")
errUnauthorized = fmt.Errorf("Unauthorized")
errInvalidSignature = fmt.Errorf("Invalid Signature")
errTooLarge = fmt.Errorf("Input size too large")
errNoSigners = fmt.Errorf("There are no signers")
errMissingSignature = fmt.Errorf("Signature missing")
errTooManySignatures = fmt.Errorf("Too many signatures")
errNoChain = fmt.Errorf("No chain id provided")
errTxEmpty = fmt.Errorf("The provided Tx is empty")
errWrongChain = fmt.Errorf("Wrong chain for tx")
errUnknownTxType = fmt.Errorf("Tx type unknown")
errInvalidFormat = fmt.Errorf("Invalid format")
errUnknownModule = fmt.Errorf("Unknown module")
errExpired = fmt.Errorf("Tx expired")
errUnknownKey = fmt.Errorf("Unknown key")
errDecoding = fmt.Errorf("Error decoding input")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, very correct with moving the errors

errUnauthorized = fmt.Errorf("Unauthorized")
errTooLarge = fmt.Errorf("Input size too large")
errMissingSignature = fmt.Errorf("Signature missing")
errUnknownTxType = fmt.Errorf("Tx type unknown")
errInvalidFormat = fmt.Errorf("Invalid format")
errUnknownModule = fmt.Errorf("Unknown module")

internalErr = abci.CodeType_InternalError
encodingErr = abci.CodeType_EncodingError
Expand Down Expand Up @@ -70,14 +60,6 @@ func IsUnknownModuleErr(err error) bool {
return IsSameError(errUnknownModule, err)
}

func ErrUnknownKey(mod string) TMError {
w := errors.Wrap(errUnknownKey, mod)
return WithCode(w, abci.CodeType_UnknownRequest)
}
func IsUnknownKeyErr(err error) bool {
return IsSameError(errUnknownKey, err)
}

func ErrInternal(msg string) TMError {
return New(msg, internalErr)
}
Expand All @@ -104,60 +86,16 @@ func IsUnauthorizedErr(err error) bool {
return HasErrorCode(err, unauthorized)
}

func ErrNoSigners() TMError {
return WithCode(errNoSigners, unauthorized)
}

func ErrMissingSignature() TMError {
return WithCode(errMissingSignature, unauthorized)
}
func IsMissingSignatureErr(err error) bool {
return IsSameError(errMissingSignature, err)
}

func ErrTooManySignatures() TMError {
return WithCode(errTooManySignatures, unauthorized)
}
func IsTooManySignaturesErr(err error) bool {
return IsSameError(errTooManySignatures, err)
}

func ErrInvalidSignature() TMError {
return WithCode(errInvalidSignature, unauthorized)
}
func IsInvalidSignatureErr(err error) bool {
return IsSameError(errInvalidSignature, err)
}

func ErrNoChain() TMError {
return WithCode(errNoChain, unauthorized)
}
func IsNoChainErr(err error) bool {
return IsSameError(errNoChain, err)
}

func ErrTxEmpty() TMError {
return WithCode(errTxEmpty, unauthorized)
}

func ErrWrongChain(chain string) TMError {
msg := errors.Wrap(errWrongChain, chain)
return WithCode(msg, unauthorized)
}
func IsWrongChainErr(err error) bool {
return IsSameError(errWrongChain, err)
}

func ErrTooLarge() TMError {
return WithCode(errTooLarge, encodingErr)
}
func IsTooLargeErr(err error) bool {
return IsSameError(errTooLarge, err)
}

func ErrExpired() TMError {
return WithCode(errExpired, unauthorized)
}
func IsExpiredErr(err error) bool {
return IsSameError(errExpired, err)
}
8 changes: 0 additions & 8 deletions errors/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestErrorMatches(t *testing.T) {
{errUnauthorized, ErrUnauthorized(), true},
{errMissingSignature, ErrUnauthorized(), false},
{errMissingSignature, ErrMissingSignature(), true},
{errWrongChain, ErrWrongChain("hakz"), true},
{errUnknownTxType, ErrUnknownTxType(holder{}), true},
{errUnknownTxType, ErrUnknownTxType("some text here..."), true},
{errUnknownTxType, ErrUnknownTxType(demoTx{5}.Wrap()), true},
Expand All @@ -66,13 +65,6 @@ func TestChecks(t *testing.T) {
{ErrDecoding(), IsDecodingErr, true},
{ErrUnauthorized(), IsDecodingErr, false},
{ErrUnauthorized(), IsUnauthorizedErr, true},
{ErrInvalidSignature(), IsInvalidSignatureErr, true},
// unauthorized includes InvalidSignature, but not visa versa
{ErrInvalidSignature(), IsUnauthorizedErr, true},
{ErrUnauthorized(), IsInvalidSignatureErr, false},
// make sure WrongChain works properly
{ErrWrongChain("fooz"), IsUnauthorizedErr, true},
{ErrWrongChain("barz"), IsWrongChainErr, true},
// make sure lots of things match InternalErr, but not everything
{ErrInternal("bad db connection"), IsInternalErr, true},
{Wrap(errors.New("wrapped")), IsInternalErr, true},
Expand Down
Loading