122: Fix attribute index key collision #123

Merged
telackey merged 3 commits from telackey/122 into main 2023-11-29 00:05:57 +00:00
2 changed files with 20 additions and 2 deletions

View File

@ -79,6 +79,24 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
false, false,
1, 1,
}, },
{
"Filter test for key collision (https://git.vdb.to/cerc-io/laconicd/issues/122)",
&registrytypes.QueryListRecordsRequest{
Attributes: []*registrytypes.QueryListRecordsRequest_KeyValueInput{
{
Key: "typ",
Value: &registrytypes.QueryListRecordsRequest_ValueInput{
Type: "string",
String_: "eWebsiteRegistrationRecord",
},
},
},
All: true,
},
true,
false,
0,
},
{ {
"Filter with attributes ServiceProviderRegistration", "Filter with attributes ServiceProviderRegistration",
&registrytypes.QueryListRecordsRequest{ &registrytypes.QueryListRecordsRequest{
@ -123,7 +141,7 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
} else { } else {
sr.NoError(err) sr.NoError(err)
sr.Equal(test.noOfRecords, len(resp.GetRecords())) sr.Equal(test.noOfRecords, len(resp.GetRecords()))
if test.createRecords { if test.createRecords && test.noOfRecords > 0 {
recordId = resp.GetRecords()[0].GetId() recordId = resp.GetRecords()[0].GetId()
sr.NotZero(resp.GetRecords()) sr.NotZero(resp.GetRecords())
sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId()) sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId())

View File

@ -367,7 +367,7 @@ func (k Keeper) ProcessAttributes(ctx sdk.Context, record types.RecordType) erro
} }
func GetAttributesIndexKey(key string, value interface{}) []byte { 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)...) return append(PrefixAttributesIndex, []byte(keyString)...)
} }