Skip to content

Commit

Permalink
Added DB tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-karuna committed Nov 15, 2024
1 parent e6829f0 commit 9fee9a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/storage/postgres/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (r *Rollup) AllSeries(ctx context.Context) (items []storage.RollupHistogram
}

func (r *Rollup) RollupStatsGrouping(ctx context.Context, fltrs storage.RollupGroupStatsFilters) (results []storage.RollupGroupedStats, err error) {
query := r.DB().NewSelect().Table("leaderboard2")
query := r.DB().NewSelect().Table(storage.ViewLeaderboard)

switch fltrs.Func {
case "sum":
Expand Down
22 changes: 22 additions & 0 deletions internal/storage/postgres/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,25 @@ func (s *StorageTestSuite) TestRollupAllSeries() {
s.Require().NoError(err)
s.Require().Len(items, 5)
}

func (s *StorageTestSuite) TestRollupStatsGrouping() {
ctx, ctxCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer ctxCancel()

_, err := s.storage.Connection().Exec(ctx, "REFRESH MATERIALIZED VIEW leaderboard;")
s.Require().NoError(err)

column := "stack"
rollups, err := s.storage.Rollup.RollupStatsGrouping(ctx, storage.RollupGroupStatsFilters{
Func: "sum",
Column: column,
})
s.Require().NoError(err, column)
s.Require().Len(rollups, 2, column)

rollup := rollups[1]
s.Require().EqualValues(4000, rollup.Fee, column)
s.Require().EqualValues(52, rollup.Size, column)
s.Require().EqualValues(4, rollup.BlobsCount, column)
s.Require().EqualValues("OP Stack", rollup.Group, column)
}
3 changes: 3 additions & 0 deletions test/data/rollup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
logo: https://rollup1.com/image.png
slug: rollup_1
category: finance
stack: OP Stack
- id: 2
name: Rollup 2
description: The second
Expand All @@ -16,6 +17,7 @@
logo: https://rollup2.com/image.png
slug: rollup_2
category: gaming
stack: OP Stack
- id: 3
name: Rollup 3
description: The third
Expand All @@ -25,3 +27,4 @@
logo: https://rollup3.com/image.png
slug: rollup_3
category: nft
stack: Custom Stack

0 comments on commit 9fee9a3

Please sign in to comment.