Use own ErrNoData, not from light-client

This commit is contained in:
Ethan Frey
2017-10-25 19:35:36 +02:00
parent ad04aba0a4
commit 7fad21d800
8 changed files with 53 additions and 15 deletions
+22
View File
@@ -0,0 +1,22 @@
package client
import (
"fmt"
"github.com/pkg/errors"
)
//--------------------------------------------
var errNoData = fmt.Errorf("No data returned for query")
// IsNoDataErr checks whether an error is due to a query returning empty data
func IsNoDataErr(err error) bool {
return errors.Cause(err) == errNoData
}
func ErrNoData() error {
return errors.WithStack(errNoData)
}
//--------------------------------------------
+18
View File
@@ -0,0 +1,18 @@
package client
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrorNoData(t *testing.T) {
e1 := ErrNoData()
e1.Error()
assert.True(t, IsNoDataErr(e1))
e2 := errors.New("foobar")
assert.False(t, IsNoDataErr(e2))
assert.False(t, IsNoDataErr(nil))
}
+2 -2
View File
@@ -38,7 +38,7 @@ func GetWithProof(key []byte, reqHeight int, node client.Client,
return
}
if len(resp.Key) == 0 || len(resp.Proof) == 0 {
err = lc.ErrNoData()
err = ErrNoData()
return
}
if resp.Height == 0 {
@@ -84,7 +84,7 @@ func GetWithProof(key []byte, reqHeight int, node client.Client,
err = errors.Wrap(err, "Couldn't verify proof")
return
}
err = lc.ErrNoData()
err = ErrNoData()
proof = aproof
}
+3 -3
View File
@@ -9,14 +9,14 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/go-wire"
lc "github.com/tendermint/light-client"
"github.com/tendermint/light-client/certifiers"
certclient "github.com/tendermint/light-client/certifiers/client"
"github.com/tendermint/tmlibs/log"
nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/rpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log"
sdkapp "github.com/cosmos/cosmos-sdk/app"
"github.com/cosmos/cosmos-sdk/modules/eyes"
@@ -98,7 +98,7 @@ func TestAppProofs(t *testing.T) {
// Test non-existing key.
missing := []byte("my-missing-key")
bs, _, proof, err = GetWithProof(missing, 0, cl, cert)
require.True(lc.IsNoDataErr(err))
require.True(IsNoDataErr(err))
require.Nil(bs)
require.NotNil(proof)
err = proof.Verify(missing, nil, rootHash)