Skip to content

Commit

Permalink
fixing find files query (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
dahn510 authored Aug 1, 2024
2 parents 69dad89 + 4d6c88f commit 40d9585
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion x/storage/keeper/grpc_query_find_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ func (k Keeper) FindFile(goCtx context.Context, req *types.QueryFindFile) (*type

store := prefix.NewStore(ctx.KVStore(k.storeKey), types.FilesMerklePrefix(req.Merkle))

iterator := sdk.KVStoreReversePrefixIterator(store, []byte{})
iterator := store.Iterator(nil, nil)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {

var file types.UnifiedFile
if err := k.cdc.Unmarshal(iterator.Value(), &file); err != nil {
continue
Expand Down
17 changes: 16 additions & 1 deletion x/storage/keeper/grpc_query_find_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,21 @@ func (suite *KeeperTestSuite) TestFindFile() {
Note: "test",
}

badF := types.UnifiedFile{
Merkle: []byte("bad_merkle"),
Owner: testAccount,
Start: 0,
Expires: 0,
FileSize: 1024,
ProofInterval: 400,
ProofType: 0,
Proofs: make([]string, 0),
MaxProofs: 3,
Note: "test",
}

suite.storageKeeper.SetFile(suite.ctx, f)
suite.storageKeeper.SetFile(suite.ctx, badF)

suite.storageKeeper.SetProviders(suite.ctx, types.Providers{
Address: providerAccount,
Expand All @@ -68,6 +82,7 @@ func (suite *KeeperTestSuite) TestFindFile() {
})

f.AddProver(suite.ctx, suite.storageKeeper, providerAccount)
badF.AddProver(suite.ctx, suite.storageKeeper, providerAccount)

pg := query.PageRequest{
Offset: 0,
Expand All @@ -79,7 +94,7 @@ func (suite *KeeperTestSuite) TestFindFile() {
})
suite.Require().NoError(err)

suite.Require().Equal(1, len(res.Files))
suite.Require().Equal(2, len(res.Files))

mres, err := suite.queryClient.AllFilesByMerkle(context.Background(), &types.QueryAllFilesByMerkle{
Pagination: &pg,
Expand Down

0 comments on commit 40d9585

Please sign in to comment.