Permalink
Browse files

nil pointer exception when name does not exist

Signed-off-by: Sean Young <sean.young@monax.io>
  • Loading branch information...
seanyoung committed Sep 17, 2018
1 parent 131d8fe commit 70b2f6e6795c4408ffc400f596138b4cb8ced9c4
Showing with 13 additions and 3 deletions.
  1. +6 −1 integration/rpctransact/name_test.go
  2. +7 −2 rpc/rpcquery/query_server.go
@@ -33,13 +33,18 @@ func TestNameTxSync(t *testing.T) {
qcli := rpctest.NewQueryClient(t, testConfig.RPC.GRPC.ListenAddress)
entry, err := qcli.GetName(context.Background(), &rpcquery.GetNameParam{
Name: "n'existe pas",
})
require.Error(t, err)
entry, err = qcli.GetName(context.Background(), &rpcquery.GetNameParam{
Name: name,
})
require.NoError(t, err)
assert.Equal(t, name, entry.Name)
assert.Equal(t, data, entry.Data)
assert.Equal(t, inputAddress, entry.Owner)
assert.True(t, entry.Expires >= expiresIn, "expiry should be later than expiresIn")
}
func TestNameReg(t *testing.T) {
@@ -56,7 +61,7 @@ func TestNameReg(t *testing.T) {
txe := rpctest.UpdateName(t, tcli, inputAddress, name, data, numDesiredBlocks)
entry := txe.Result.NameEntry
assert.NotNil(t, entry, "name shoudl return")
assert.NotNil(t, entry, "name should return")
_, ok := txe.Envelope.Tx.Payload.(*payload.NameTx)
require.True(t, ok, "should be NameTx: %v", txe.Envelope.Tx.Payload)
@@ -2,6 +2,7 @@ package rpcquery
import (
"context"
"fmt"
"github.com/hyperledger/burrow/acm"
"github.com/hyperledger/burrow/acm/state"
@@ -67,8 +68,12 @@ func (qs *queryServer) ListAccounts(param *ListAccountsParam, stream Query_ListA
}
// Name registry
func (qs *queryServer) GetName(ctx context.Context, param *GetNameParam) (*names.Entry, error) {
return qs.nameReg.GetName(param.Name)
func (qs *queryServer) GetName(ctx context.Context, param *GetNameParam) (entry *names.Entry, err error) {
entry, err = qs.nameReg.GetName(param.Name)
if entry == nil && err == nil {
err = fmt.Errorf("name %s not found", param.Name)
}
return
}
func (qs *queryServer) ListNames(param *ListNamesParam, stream Query_ListNamesServer) error {

0 comments on commit 70b2f6e

Please sign in to comment.