Skip to content

Commit

Permalink
fixing open query
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Oct 11, 2024
1 parent 8b03d85 commit 291518d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
10 changes: 6 additions & 4 deletions x/storage/keeper/grpc_query_active_deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,8 @@ func (k Keeper) OpenFiles(c context.Context, req *types.QueryOpenFiles) (*types.
}

var i uint64
var total uint64
k.IterateFilesByMerkle(ctx, reverse, func(_ []byte, val []byte) bool {
if i >= limit {
return true
}

var file types.UnifiedFile
if err := k.cdc.Unmarshal(val, &file); err != nil {
Expand All @@ -165,6 +163,10 @@ func (k Keeper) OpenFiles(c context.Context, req *types.QueryOpenFiles) (*types.
}

if len(file.Proofs) < int(file.MaxProofs) {
total++
if i >= limit {
return false
}
files = append(files, file)
} else {
return false
Expand All @@ -177,7 +179,7 @@ func (k Keeper) OpenFiles(c context.Context, req *types.QueryOpenFiles) (*types.

qpr := query.PageResponse{
NextKey: nil,
Total: i,
Total: total,
}

return &types.QueryAllFilesResponse{Files: files, Pagination: &qpr}, nil
Expand Down
65 changes: 65 additions & 0 deletions x/storage/keeper/grpc_query_active_deals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"context"
"encoding/json"
"fmt"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -143,6 +144,70 @@ func (suite *KeeperTestSuite) TestAllFiles() {
suite.reset()
}

func (suite *KeeperTestSuite) TestOpenFiles() {
suite.SetupSuite()

testAddresses, err := testutil.CreateTestAddresses("cosmos", 2)
suite.Require().NoError(err)

testAccount := testAddresses[0]
depoAccount := testAddresses[1]

coins := sdk.NewCoins(sdk.NewCoin("ujkl", sdk.NewInt(100000000000))) // Send some coins to their account
testAcc, _ := sdk.AccAddressFromBech32(testAccount)
err = suite.bankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, testAcc, coins)
suite.Require().NoError(err)

suite.storageKeeper.SetParams(suite.ctx, types.Params{
DepositAccount: depoAccount,
ProofWindow: 50,
ChunkSize: 1024,
PriceFeed: "jklprice",
MissesToBurn: 3,
MaxContractAgeInBlocks: 100,
PricePerTbPerMonth: 8,
CollateralPrice: 2,
CheckWindow: 11,
ReferralCommission: 25,
PolRatio: 40,
})

const count = 1000

for i := 0; i < count; i++ {
merkle := []byte(fmt.Sprintf("%dmerkle%d", i, i))

suite.storageKeeper.SetFile(suite.ctx, types.UnifiedFile{
Merkle: merkle,
Owner: testAccount,
Start: 0,
Expires: 0,
FileSize: 1024,
ProofInterval: 400,
ProofType: 0,
Proofs: make([]string, 0),
MaxProofs: 3,
Note: "{}",
})
}

pg := query.PageRequest{
Offset: 0,
Reverse: false,
Limit: 200,
}

res, err := suite.queryClient.OpenFiles(context.Background(), &types.QueryOpenFiles{
Pagination: &pg,
})
suite.Require().NoError(err)

suite.Require().Equal(200, len(res.Files))
suite.Require().Equal(count, int(res.Pagination.Total))

suite.reset()
}

func (suite *KeeperTestSuite) TestFileNotes() {
suite.SetupSuite()

Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/grpc_query_storage_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (suite *KeeperTestSuite) TestStorageStats() {
suite.Require().Equal(uint64(2), res.ActiveUsers)
suite.Require().Equal(uint64(3), res.UniqueUsers)
suite.Require().Equal(uint64(fs*6), res.Used)
suite.Require().Equal(uint64(fs*3+mm), res.Purchased)
suite.Require().Equal(fs*3+mm, int64(res.Purchased))

suite.reset()
}
Expand Down

0 comments on commit 291518d

Please sign in to comment.