From cd144330aaf72e42a694b7a272992423872c79aa Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 28 Nov 2023 13:27:37 -0600 Subject: [PATCH 1/2] 118: queryRecords should return [] when no matching records exist, not an error --- x/registry/keeper/keeper.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/registry/keeper/keeper.go b/x/registry/keeper/keeper.go index 727bb8c2..ebeaaa93 100644 --- a/x/registry/keeper/keeper.go +++ b/x/registry/keeper/keeper.go @@ -20,6 +20,7 @@ import ( auth "github.com/cosmos/cosmos-sdk/x/auth/keeper" bank "github.com/cosmos/cosmos-sdk/x/bank/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/tendermint/tendermint/libs/log" ) var ( @@ -96,6 +97,11 @@ func NewKeeper(cdc codec.BinaryCodec, accountKeeper auth.AccountKeeper, bankKeep } } +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", types.ModuleName) +} + // GetRecordIndexKey Generates Bond ID -> Bond index key. func GetRecordIndexKey(id string) []byte { return append(PrefixCIDToRecordIndex, []byte(id)...) @@ -389,7 +395,8 @@ func (k Keeper) GetAttributeMapping(ctx sdk.Context, key []byte) ([]string, erro store := ctx.KVStore(k.storeKey) if !store.Has(key) { - return nil, fmt.Errorf("store doesn't have key: %q", key) + k.Logger(ctx).Debug(fmt.Sprintf("store doesn't have key: %q", key)) + return []string{}, nil } var recordIds []string -- 2.45.2 From 113c9125e4e4095ac13959696280b972a9908502 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Tue, 28 Nov 2023 14:44:37 -0600 Subject: [PATCH 2/2] 122: Fix attribute index key collision --- x/registry/keeper/grpc_query_test.go | 20 +++++++++++++++++++- x/registry/keeper/keeper.go | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/x/registry/keeper/grpc_query_test.go b/x/registry/keeper/grpc_query_test.go index 4e580432..6d5073de 100644 --- a/x/registry/keeper/grpc_query_test.go +++ b/x/registry/keeper/grpc_query_test.go @@ -79,6 +79,24 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() { false, 1, }, + { + "Filter test for key collision (https://git.vdb.to/cerc-io/laconicd/issues/122)", + ®istrytypes.QueryListRecordsRequest{ + Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{ + { + Key: "typ", + Value: ®istrytypes.QueryListRecordsRequest_ValueInput{ + Type: "string", + String_: "eWebsiteRegistrationRecord", + }, + }, + }, + All: true, + }, + true, + false, + 0, + }, { "Filter with attributes ServiceProviderRegistration", ®istrytypes.QueryListRecordsRequest{ @@ -123,7 +141,7 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() { } else { sr.NoError(err) sr.Equal(test.noOfRecords, len(resp.GetRecords())) - if test.createRecords { + if test.createRecords && test.noOfRecords > 0 { recordId = resp.GetRecords()[0].GetId() sr.NotZero(resp.GetRecords()) sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId()) diff --git a/x/registry/keeper/keeper.go b/x/registry/keeper/keeper.go index ebeaaa93..f3ec26f1 100644 --- a/x/registry/keeper/keeper.go +++ b/x/registry/keeper/keeper.go @@ -367,7 +367,7 @@ func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) erro } func GetAttributesIndexKey(key string, value interface{}) []byte { - keyString := fmt.Sprintf("%s%s", key, value) + keyString := fmt.Sprintf("%s=%s", key, value) return append(PrefixAttributesIndex, []byte(keyString)...) } -- 2.45.2