From 4d6c88fd6ed1198d65d710dbfebe8cafc78e53b0 Mon Sep 17 00:00:00 2001 From: marston Date: Thu, 1 Aug 2024 17:30:07 -0400 Subject: [PATCH] fixing find files --- x/storage/keeper/grpc_query_find_file.go | 3 ++- x/storage/keeper/grpc_query_find_file_test.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/x/storage/keeper/grpc_query_find_file.go b/x/storage/keeper/grpc_query_find_file.go index 5d8f8647..fe446fb9 100644 --- a/x/storage/keeper/grpc_query_find_file.go +++ b/x/storage/keeper/grpc_query_find_file.go @@ -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 diff --git a/x/storage/keeper/grpc_query_find_file_test.go b/x/storage/keeper/grpc_query_find_file_test.go index 5e87504e..49ca7a6e 100644 --- a/x/storage/keeper/grpc_query_find_file_test.go +++ b/x/storage/keeper/grpc_query_find_file_test.go @@ -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, @@ -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, @@ -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,