Skip to content

Commit e51a633

Browse files
committed
Rework tests that mocked historical_balances_changes to now mock historical_balances
1 parent b2f01fd commit e51a633

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

lib/sanbase/balances/balance.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ defmodule Sanbase.Balance do
153153
balances
154154
|> Enum.chunk_every(2, 1, :discard)
155155
|> Enum.map(fn [%{balance: previous}, %{balance: current, datetime: dt}] ->
156-
%{datetime: dt, balance: current - previous}
156+
%{
157+
datetime: dt,
158+
balance_change_amount: current - previous,
159+
balance_change_percent: Sanbase.Math.percent_change(previous, current)
160+
}
157161
end)
158162

159163
{:ok, changes}

lib/sanbase/balances/balance_sql_query.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ defmodule Sanbase.Balance.SqlQuery do
1010
"bitcoin" -> "btc_balances"
1111
"litecoin" -> "ltc_balances"
1212
"dogecoin" -> "doge_balances"
13+
"bitcoin-cash" -> "bch_balances"
14+
"binance" -> "bep20_balances"
1315
end
1416
end
1517

test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ defmodule SanbaseWeb.Graphql.ProjectApiEthSpentOverTimeTest do
2121
end
2222

2323
test "project eth spent over time", context do
24-
[dt1, dt2, dt3, dt4, dt5, dt6] =
25-
generate_datetimes(~U[2017-05-13T00:00:00Z], "1d", 6) |> Enum.map(&DateTime.to_unix/1)
24+
[dt0, dt1, dt2, dt3, dt4, dt5, dt6] =
25+
generate_datetimes(~U[2017-05-12T00:00:00Z], "1d", 7) |> Enum.map(&DateTime.to_unix/1)
2626

27+
# Historical Balances Changes uses internally the historical balances query,
28+
# so that's what needs to be mocked
2729
rows = [
28-
[dt1, -500],
29-
[dt2, -1500],
30-
[dt3, -6000],
31-
[dt4, 0],
32-
[dt5, 0],
33-
[dt6, -6500]
30+
[dt0, 20000, 1],
31+
[dt1, 19500, 1],
32+
[dt2, 18000, 1],
33+
[dt3, 12000, 1],
34+
[dt4, 0, 0],
35+
[dt5, 0, 0],
36+
[dt6, 5500, 1]
3437
]
3538

3639
Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}})

test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,19 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do
123123
end
124124

125125
test "eth spent over time by erc20 projects", context do
126-
[dt1, dt2, dt3, dt4, dt5] =
127-
generate_datetimes(Timex.shift(Timex.now(), days: -4), "1d", 5)
126+
[dt0, dt1, dt2, dt3, dt4, dt5] =
127+
generate_datetimes(Timex.shift(Timex.now(), days: -5), "1d", 6)
128128
|> Enum.map(&DateTime.to_unix/1)
129129

130+
# Historical Balances Changes uses internally the historical balances query,
131+
# so that's what needs to be mocked
130132
rows = [
131-
[dt1, -16_500],
132-
[dt2, -5500],
133-
[dt3, -3500],
134-
[dt4, -2500],
135-
[dt5, -500]
133+
[dt0, 50_000, 1],
134+
[dt1, 33_500, 1],
135+
[dt2, 28_000, 1],
136+
[dt3, 24_500, 1],
137+
[dt4, 22_000, 1],
138+
[dt5, 21_500, 1]
136139
]
137140

138141
Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}})

0 commit comments

Comments
 (0)