Skip to content

Commit

Permalink
Merge pull request #177 from tendermint/feature/104-autoseq
Browse files Browse the repository at this point in the history
Auto Sequencing, Error Cleanup, Bash Tests Cleanup
  • Loading branch information
ethanfrey authored Jul 19, 2017
2 parents 942506c + d712d6f commit 29273e5
Show file tree
Hide file tree
Showing 52 changed files with 516 additions and 383 deletions.
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")
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

0 comments on commit 29273e5

Please sign in to comment.