Skip to content

Commit

Permalink
fixing find files
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Aug 1, 2024
1 parent 69dad89 commit 4d6c88f
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 4d6c88f

Please sign in to comment.