From 83bef7aa662d7555a8783291b548ed3a2de33c0f Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 18 May 2020 12:25:58 +0300 Subject: [PATCH 01/12] Start migration Ecto 2.x -> Ecto 3.x --- .iex.exs | 1 - config/config.exs | 3 +- config/dev.exs | 3 +- config/elasticsearch_config.exs | 9 -- config/test.exs | 4 - lib/sanbase/auth/user.ex | 3 +- lib/sanbase/billing/graphql_schema.ex | 6 +- lib/sanbase/clickhouse_repo.ex | 95 +++++++----- lib/sanbase/ecto/uri_type.ex | 24 --- lib/sanbase/elasticsearch/cluster.ex | 3 - lib/sanbase/elasticsearch/elasticsearch.ex | 93 ------------ .../elasticsearch/elasticsearch_api_mock.ex | 58 -------- lib/sanbase/elasticsearch/query.ex | 138 ------------------ lib/sanbase/insight/post.ex | 2 +- lib/sanbase/model/ico.ex | 6 +- lib/sanbase/model/latest_btc_wallet_data.ex | 2 +- .../model/latest_coinmarketcap_data.ex | 2 +- lib/sanbase/model/project/roi.ex | 4 +- lib/sanbase/repo.ex | 2 +- lib/sanbase/utils/datetime/utils.ex | 5 +- lib/sanbase/voting/vote.ex | 3 +- lib/sanbase/web.ex | 3 - lib/sanbase_web/admin/billing/plan.ex | 2 +- lib/sanbase_web/admin/billing/product.ex | 2 +- lib/sanbase_web/admin/billing/promo_trial.ex | 2 +- .../admin/billing/sign_up_trial.ex | 2 +- lib/sanbase_web/admin/billing/stripe_event.ex | 2 +- lib/sanbase_web/admin/billing/subscription.ex | 2 +- lib/sanbase_web/admin/chart/configuration.ex | 2 +- .../admin/comments/notification.ex | 2 +- .../admin/exchanges/market_pair_mapping.ex | 2 +- lib/sanbase_web/admin/insights/comment.ex | 2 +- lib/sanbase_web/admin/insights/post.ex | 2 +- .../admin/insights/post_comment.ex | 2 +- lib/sanbase_web/admin/model/ico.ex | 4 +- .../admin/model/project_market_segment.ex | 2 +- .../admin/notifications/notification.ex | 2 +- .../admin/signals/historical_activity.ex | 2 +- lib/sanbase_web/admin/signals/user_trigger.ex | 2 +- lib/sanbase_web/admin/timeline_event.ex | 2 +- .../resolvers/elasticsearch_resolver.ex | 11 -- lib/sanbase_web/graphql/schema.ex | 1 + .../graphql/schema/custom_types/date.ex | 30 ++++ .../graphql/schema/custom_types/datetime.ex | 49 ------- .../schema/queries/social_data_queries.ex | 15 +- .../schema/types/elasticsearch_types.ex | 12 -- .../graphql/schema/types/project_types.ex | 8 +- mix.exs | 19 ++- mix.lock | 53 +++---- .../billing/query_access_level_test.exs | 1 - .../elasticsearch_stats_test.exs | 43 ------ 51 files changed, 171 insertions(+), 578 deletions(-) delete mode 100644 config/elasticsearch_config.exs delete mode 100644 lib/sanbase/ecto/uri_type.ex delete mode 100644 lib/sanbase/elasticsearch/cluster.ex delete mode 100644 lib/sanbase/elasticsearch/elasticsearch.ex delete mode 100644 lib/sanbase/elasticsearch/elasticsearch_api_mock.ex delete mode 100644 lib/sanbase/elasticsearch/query.ex delete mode 100644 lib/sanbase_web/graphql/resolvers/elasticsearch_resolver.ex create mode 100644 lib/sanbase_web/graphql/schema/custom_types/date.ex delete mode 100644 lib/sanbase_web/graphql/schema/types/elasticsearch_types.ex delete mode 100644 test/sanbase_web/graphql/elasticsearch/elasticsearch_stats_test.exs diff --git a/.iex.exs b/.iex.exs index 00144eb41f..b3bd250557 100644 --- a/.iex.exs +++ b/.iex.exs @@ -102,7 +102,6 @@ alias SanbaseWeb.Graphql.Resolvers.{ UserResolver, ApikeyResolver, EthAccountResolver, - ElasticsearchResolver, EtherbiResolver, FileResolver, GithubResolver, diff --git a/config/config.exs b/config/config.exs index 781d5dee7d..77ecc77ef7 100644 --- a/config/config.exs +++ b/config/config.exs @@ -14,7 +14,7 @@ config :sanbase, ecto_repos: [Sanbase.Repo] config :phoenix, :json_library, Jason -config :ecto, json_library: Jason +config :postgrex, :json_library, Jason config :sanbase, Sanbase, environment: "#{Mix.env()}" @@ -179,7 +179,6 @@ import_config "ex_admin_config.exs" import_config "influxdb_config.exs" import_config "scrapers_config.exs" import_config "notifications_config.exs" -import_config "elasticsearch_config.exs" import_config "prometheus_config.exs" import_config "stripe_config.exs" import_config "scheduler_config.exs" diff --git a/config/dev.exs b/config/dev.exs index 36d40ab61c..28f2411dfa 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -71,7 +71,8 @@ config :sanbase, Sanbase.ClickhouseRepo, password: "", pool_timeout: 60_000, timeout: 60_000, - pool_size: {:system, "CLICKHOUSE_POOL_SIZE", "3"} + pool_size: {:system, "CLICKHOUSE_POOL_SIZE", "3"}, + show_sensitive_data_on_connection_error: true config :ex_admin, basic_auth: [ diff --git a/config/elasticsearch_config.exs b/config/elasticsearch_config.exs deleted file mode 100644 index bf2acd3d57..0000000000 --- a/config/elasticsearch_config.exs +++ /dev/null @@ -1,9 +0,0 @@ -import Config - -config :sanbase, Sanbase.Elasticsearch.Cluster, - url: "http://managed-elasticsearch-scraping-data.default.svc.cluster.local", - api: Elasticsearch.API.HTTP, - json_library: Jason - -config :sanbase, Sanbase.Elasticsearch, - indices: {:system, "ELASTICSEARCH_STATS_INDICES", "reddit"} diff --git a/config/test.exs b/config/test.exs index 3c3232e6ba..691cbd25dd 100644 --- a/config/test.exs +++ b/config/test.exs @@ -60,10 +60,6 @@ config :arc, storage: Arc.Storage.Local, storage_dir: "/tmp/sanbase/filestore-test/" -config :sanbase, Sanbase.Elasticsearch.Cluster, api: Sanbase.ElasticsearchMock - -config :sanbase, Sanbase.Elasticsearch, indices: "index1,index2,index3,index4" - config :sanbase, SanbaseWeb.Plug.VerifyStripeWebhook, webhook_secret: "stripe_webhook_secret" config :sanbase, Sanbase.Signal, email_channel_enabled: {:system, "EMAIL_CHANNEL_ENABLED", "true"} diff --git a/lib/sanbase/auth/user.ex b/lib/sanbase/auth/user.ex index 248ee68838..a11296c52c 100644 --- a/lib/sanbase/auth/user.ex +++ b/lib/sanbase/auth/user.ex @@ -1,6 +1,7 @@ defmodule Sanbase.Auth.User do use Ecto.Schema - use Timex.Ecto.Timestamps + + # use Timex.Ecto.Timestamps import Ecto.Changeset import Ecto.Query diff --git a/lib/sanbase/billing/graphql_schema.ex b/lib/sanbase/billing/graphql_schema.ex index b65e1e7958..afdf9ba440 100644 --- a/lib/sanbase/billing/graphql_schema.ex +++ b/lib/sanbase/billing/graphql_schema.ex @@ -9,8 +9,10 @@ defmodule Sanbase.Billing.GraphqlSchema do require SanbaseWeb.Graphql.Schema - @query_type Absinthe.Schema.lookup_type(SanbaseWeb.Graphql.Schema, :query) - @fields @query_type.fields |> Map.keys() + # @query_type Absinthe.Schema.lookup_type(SanbaseWeb.Graphql.Schema, :query) + # @fields @query_type.fields |> Map.keys() + @query_type %{fields: []} + @fields [] @doc ~s""" Return a map of {query, product_id} key-value pairs. The key is a query that diff --git a/lib/sanbase/clickhouse_repo.ex b/lib/sanbase/clickhouse_repo.ex index 27db589d1d..134b7da61e 100644 --- a/lib/sanbase/clickhouse_repo.ex +++ b/lib/sanbase/clickhouse_repo.ex @@ -1,5 +1,5 @@ defmodule Sanbase.ClickhouseRepo do - use Ecto.Repo, otp_app: :sanbase + use Ecto.Repo, otp_app: :sanbase, adapter: ClickhouseEcto require Sanbase.Utils.Config, as: Config @@ -23,6 +23,9 @@ defmodule Sanbase.ClickhouseRepo do try do require Sanbase.ClickhouseRepo, as: ClickhouseRepo + ordered_params = ClickhouseRepo.order_params(query, args) + sanitized_query = ClickhouseRepo.sanitize_query(query) + ClickhouseRepo.query(query, args) |> case do {:ok, result} -> @@ -46,55 +49,67 @@ defmodule Sanbase.ClickhouseRepo do end end - defmacro query_transform(query, args, transform_fn) do - quote bind_quoted: [query: query, args: args, transform_fn: transform_fn] do - try do - require Sanbase.ClickhouseRepo, as: ClickhouseRepo + def query_transform(query, args, transform_fn) do + try do + ordered_params = order_params(query, args) + sanitized_query = sanitize_query(query) - ClickhouseRepo.query(query, args) - |> case do - {:ok, result} -> - result = - Enum.map( - result.rows, - transform_fn - ) + Ecto.Adapters.SQL.query(__MODULE__, sanitized_query, ordered_params) + |> case do + {:ok, result} -> {:ok, Enum.map(result.rows, transform_fn)} + {:error, error} -> {:error, error} + end + rescue + e -> {:error, "Cannot execute ClickHouse query. Reason: #{Exception.message(e)}"} + end + end - {:ok, result} + def query_reduce(query, args, init, reducer) do + try do + ordered_params = order_params(query, args) + sanitized_query = sanitize_query(query) - {:error, error} -> - {:error, error} - end - rescue - e -> {:error, "Cannot execute ClickHouse query. Reason: #{Exception.message(e)}"} + __MODULE__.query(sanitized_query, ordered_params) + |> case do + {:ok, result} -> {:ok, Enum.reduce(result.rows, init, reducer)} + {:error, error} -> {:error, error} end + rescue + e -> + {:error, "Cannot execute ClickHouse query. Reason: #{Exception.message(e)}"} end end - defmacro query_reduce(query, args, init, reducer) do - quote bind_quoted: [query: query, args: args, init: init, reducer: reducer] do - try do - require Sanbase.ClickhouseRepo, as: ClickhouseRepo + def sanitize_query(query) do + query + |> IO.iodata_to_binary() + |> String.replace(~r/(\?([0-9]+))(?=(?:[^\\"']|[\\"'][^\\"']*[\\"'])*$)/, "?") + end - ClickhouseRepo.query(query, args) - |> case do - {:ok, result} -> - result = - Enum.reduce( - result.rows, - init, - reducer - ) + def order_params(query, params) do + sanitised = + Regex.replace(~r/(([^\\]|^))["'].*?[^\\]['"]/, IO.iodata_to_binary(query), "\\g{1}") - {:ok, result} + ordering = + Regex.scan(~r/\?([0-9]+)/, sanitised) + |> Enum.map(fn [_, x] -> String.to_integer(x) end) - {:error, error} -> - {:error, error} - end - rescue - e -> - {:error, "Cannot execute ClickHouse query. Reason: #{Exception.message(e)}"} - end + ordering_count = Enum.max_by(ordering, fn x -> x end, fn -> 0 end) + + if ordering_count != length(params) do + raise "\nError: number of params received (#{length(params)}) does not match expected (#{ + ordering_count + })" + end + + ordered_params = + ordering + |> Enum.reduce([], fn ix, acc -> [Enum.at(params, ix - 1) | acc] end) + |> Enum.reverse() + + case ordered_params do + [] -> params + _ -> ordered_params end end end diff --git a/lib/sanbase/ecto/uri_type.ex b/lib/sanbase/ecto/uri_type.ex deleted file mode 100644 index e43f8c3490..0000000000 --- a/lib/sanbase/ecto/uri_type.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule Sanbase.Ecto.Type.URI do - @behaviour Ecto.Type - def type, do: :map - - def cast(uri) when is_binary(uri) do - {:ok, URI.parse(uri)} - end - - def cast(%URI{} = uri), do: {:ok, uri} - - def cast(_), do: :error - - def load(data) when is_map(data) do - data = - for {key, val} <- data do - {String.to_existing_atom(key), val} - end - - {:ok, struct!(URI, data)} - end - - def dump(%URI{} = uri), do: {:ok, Map.from_struct(uri)} - def dump(_), do: :error -end diff --git a/lib/sanbase/elasticsearch/cluster.ex b/lib/sanbase/elasticsearch/cluster.ex deleted file mode 100644 index ec8b668aad..0000000000 --- a/lib/sanbase/elasticsearch/cluster.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Sanbase.Elasticsearch.Cluster do - use Elasticsearch.Cluster, otp_app: :sanbase -end diff --git a/lib/sanbase/elasticsearch/elasticsearch.ex b/lib/sanbase/elasticsearch/elasticsearch.ex deleted file mode 100644 index d9045e511a..0000000000 --- a/lib/sanbase/elasticsearch/elasticsearch.ex +++ /dev/null @@ -1,93 +0,0 @@ -defmodule Sanbase.Elasticsearch do - @moduledoc ~s""" - Module providing API to Santiment's managed elasticsearch instance. - """ - - @type stats :: %{ - documents_count: non_neg_integer, - size_in_megabytes: non_neg_integer, - telegram_channels_count: non_neg_integer, - subreddits_count: non_neg_integer, - discord_channels_count: non_neg_integer, - average_documents_per_day: non_neg_integer - } - - require Sanbase.Utils.Config, as: Config - alias Sanbase.Elasticsearch.Cluster - alias Sanbase.Math - - @bytes_in_megabyte 1024 * 1024 - @indices Config.get(:indices) - - @doc ~s""" - Provides statistics for a predefined indices, displayed on sanbase. - """ - @spec stats(%DateTime{}, %DateTime{}) :: stats - def stats(%DateTime{} = from, %DateTime{} = to) do - {:ok, stats} = Elasticsearch.get(Cluster, "/#{@indices}/_stats") - size_in_bytes = get_in(stats, ["_all", "total", "store", "size_in_bytes"]) - size_in_megabytes = (size_in_bytes / @bytes_in_megabyte) |> Math.to_integer() - - documents_count = documents_count(from, to) - days_difference = Timex.diff(from, to, :days) |> abs() - - %{ - documents_count: documents_count, - size_in_megabytes: size_in_megabytes, - telegram_channels_count: telegram_channels_count(from, to), - subreddits_count: subreddits_count(from, to), - discord_channels_count: discord_channels_count(from, to), - average_documents_per_day: (documents_count / days_difference) |> Math.to_integer() - } - end - - # Private functions - - defp documents_count(from, to) do - {:ok, data} = - Elasticsearch.post( - Cluster, - "/#{@indices}/_search", - Sanbase.Elasticsearch.Query.documents_count_in_interval(from, to) - ) - - %{"hits" => %{"total" => total}} = data - total - end - - defp telegram_channels_count(from, to) do - {:ok, data} = - Elasticsearch.post( - Cluster, - "/telegram/_search", - Sanbase.Elasticsearch.Query.telegram_channels_count(from, to) - ) - - %{"aggregations" => %{"chat_titles" => %{"buckets" => buckets}}} = data - Enum.count(buckets) - end - - defp subreddits_count(from, to) do - {:ok, data} = - Elasticsearch.post( - Cluster, - "/reddit/_search", - Sanbase.Elasticsearch.Query.subreddits_count(from, to) - ) - - %{"aggregations" => %{"subreddits" => %{"buckets" => buckets}}} = data - Enum.count(buckets) - end - - defp discord_channels_count(from, to) do - {:ok, data} = - Elasticsearch.post( - Cluster, - "/discord/_search", - Sanbase.Elasticsearch.Query.discord_channels_count(from, to) - ) - - %{"aggregations" => %{"channel_names" => %{"buckets" => buckets}}} = data - Enum.count(buckets) - end -end diff --git a/lib/sanbase/elasticsearch/elasticsearch_api_mock.ex b/lib/sanbase/elasticsearch/elasticsearch_api_mock.ex deleted file mode 100644 index 70169a1d3c..0000000000 --- a/lib/sanbase/elasticsearch/elasticsearch_api_mock.ex +++ /dev/null @@ -1,58 +0,0 @@ -defmodule Sanbase.ElasticsearchMock do - @behaviour Elasticsearch.API - - @impl true - def request(_config, :get, "/index1,index2,index3,index4/_stats" = url, _data, _opts) do - {:ok, - %HTTPoison.Response{ - request: %HTTPoison.Request{url: url}, - status_code: 200, - body: %{"_all" => %{"total" => %{"store" => %{"size_in_bytes" => 5_000_000}}}} - }} - end - - @impl true - def request(_config, :post, "/index1,index2,index3,index4/_search" = url, _data, _opts) do - {:ok, - %HTTPoison.Response{ - request: %HTTPoison.Request{url: url}, - status_code: 200, - body: %{"hits" => %{"total" => 1_000_000}} - }} - end - - @impl true - def request(_config, :post, "/telegram/_search" = url, _data, _opts) do - # Buckets must be an Enumerable - {:ok, - %HTTPoison.Response{ - request: %HTTPoison.Request{url: url}, - status_code: 200, - body: %{"aggregations" => %{"chat_titles" => %{"buckets" => [1, 2, 3, 4, 5]}}} - }} - end - - @impl true - def request(_config, :post, "/reddit/_search" = url, _data, _opts) do - # Buckets must be an Enumerable - {:ok, - %HTTPoison.Response{ - request: %HTTPoison.Request{url: url}, - status_code: 200, - body: %{ - "aggregations" => %{"subreddits" => %{"buckets" => [2, 4, 5, 6, 7, 8, 9, 0, 12, 2]}} - } - }} - end - - @impl true - def request(_config, :post, "/discord/_search" = url, _data, _opts) do - # Buckets must be an Enumerable - {:ok, - %HTTPoison.Response{ - request: %HTTPoison.Request{url: url}, - status_code: 200, - body: %{"aggregations" => %{"channel_names" => %{"buckets" => [1, 2, 3, 4, 5, 6]}}} - }} - end -end diff --git a/lib/sanbase/elasticsearch/query.ex b/lib/sanbase/elasticsearch/query.ex deleted file mode 100644 index 9d84697f04..0000000000 --- a/lib/sanbase/elasticsearch/query.ex +++ /dev/null @@ -1,138 +0,0 @@ -defmodule Sanbase.Elasticsearch.Query do - def telegram_channels_count(from, to) do - from_unix = DateTime.to_unix(from, :millisecond) - to_unix = DateTime.to_unix(to, :millisecond) - - ~s""" - { - "size": 0, - "aggs": { - "chat_titles": { - "terms": { - "field": "chat_title.keyword", - "size": 999999 - } - } - }, - "query": { - "bool": { - "must": [ - { - "range": { - "timestamp": { - "gte": #{from_unix}, - "lte": #{to_unix}, - "format": "epoch_millis" - } - } - } - ] - } - } - } - """ - end - - def subreddits_count(from, to) do - from_unix = DateTime.to_unix(from, :millisecond) - to_unix = DateTime.to_unix(to, :millisecond) - - ~s""" - { - "size": 0, - "aggs": { - "subreddits": { - "terms": { - "field": "subreddit_name_prefixed.keyword", - "size": 999999 - } - } - }, - "query": { - "bool": { - "must": [ - { - "range": { - "created_utc": { - "gte": #{from_unix}, - "lte": #{to_unix}, - "format": "epoch_millis" - } - } - } - ] - } - } - } - """ - end - - def discord_channels_count(from, to) do - from_unix = DateTime.to_unix(from, :millisecond) - to_unix = DateTime.to_unix(to, :millisecond) - - ~s""" - { - "size": 0, - "aggs": { - "channel_names": { - "terms": { - "field": "channel_name.keyword", - "size": 999999 - } - } - }, - "query": { - "bool": { - "must": [ - { - "range": { - "timestamp": { - "gte": #{from_unix}, - "lte": #{to_unix}, - "format": "epoch_millis" - } - } - } - ] - } - } - } - """ - end - - def documents_count_in_interval(from, to) do - from_unix = DateTime.to_unix(from, :millisecond) - to_unix = DateTime.to_unix(to, :millisecond) - - ~s""" - { - "size": 0, - "query": { - "bool": { - "should": [ - { - "range": { - "timestamp": { - "gte": #{from_unix}, - "lte": #{to_unix}, - "format": "epoch_millis" - } - } - }, - { - "range": { - "created_utc": { - "gte": #{from_unix}, - "lte": #{to_unix}, - "format": "epoch_millis" - } - } - } - ] - } - } - } - """ - end -end diff --git a/lib/sanbase/insight/post.ex b/lib/sanbase/insight/post.ex index 4e775a4c4a..709ff5da8f 100644 --- a/lib/sanbase/insight/post.ex +++ b/lib/sanbase/insight/post.ex @@ -1,7 +1,7 @@ defmodule Sanbase.Insight.Post do use Ecto.Schema - use Timex.Ecto.Timestamps + # use Timex.Ecto.Timestamps import Ecto.Changeset import Ecto.Query diff --git a/lib/sanbase/model/ico.ex b/lib/sanbase/model/ico.ex index e2bd3f6e68..ac2d4a1a15 100644 --- a/lib/sanbase/model/ico.ex +++ b/lib/sanbase/model/ico.ex @@ -13,8 +13,8 @@ defmodule Sanbase.Model.Ico do schema "icos" do belongs_to(:project, Project) - field(:start_date, Ecto.Date) - field(:end_date, Ecto.Date) + field(:start_date, :date) + field(:end_date, :date) field(:token_usd_ico_price, :decimal) field(:token_eth_ico_price, :decimal) field(:token_btc_ico_price, :decimal) @@ -112,7 +112,7 @@ defmodule Sanbase.Model.Ico do target_currency, date ) do - datetime = Sanbase.DateTimeUtils.ecto_date_to_datetime(date) + datetime = Sanbase.DateTimeUtils.date_to_datetime(date) Repo.preload(ico, ico_currencies: [:currency]).ico_currencies |> Enum.map(fn ic -> diff --git a/lib/sanbase/model/latest_btc_wallet_data.ex b/lib/sanbase/model/latest_btc_wallet_data.ex index 61b495d6fa..c7ee097842 100644 --- a/lib/sanbase/model/latest_btc_wallet_data.ex +++ b/lib/sanbase/model/latest_btc_wallet_data.ex @@ -6,7 +6,7 @@ defmodule Sanbase.Model.LatestBtcWalletData do schema "latest_btc_wallet_data" do field(:address, :string) field(:satoshi_balance, :decimal) - field(:update_time, Ecto.DateTime) + field(:update_time, :naive_datetime) end @doc false diff --git a/lib/sanbase/model/latest_coinmarketcap_data.ex b/lib/sanbase/model/latest_coinmarketcap_data.ex index 108cadbe6d..b79775210f 100644 --- a/lib/sanbase/model/latest_coinmarketcap_data.ex +++ b/lib/sanbase/model/latest_coinmarketcap_data.ex @@ -21,7 +21,7 @@ defmodule Sanbase.Model.LatestCoinmarketcapData do field(:percent_change_7d, :decimal) field(:logo_hash, :string) field(:logo_updated_at, :naive_datetime) - field(:update_time, Ecto.DateTime) + field(:update_time, :naive_datetime) end @doc false diff --git a/lib/sanbase/model/project/roi.ex b/lib/sanbase/model/project/roi.ex index 0fd23a6a26..8cb6f77e07 100644 --- a/lib/sanbase/model/project/roi.ex +++ b/lib/sanbase/model/project/roi.ex @@ -112,8 +112,8 @@ defmodule Sanbase.Model.Project.Roi do defp calc_token_usd_ico_price(_price_from, _currency_from, _ico_start_date, nil), do: nil defp calc_token_usd_ico_price(price_from, currency_from, ico_start_date, current_datetime) do - with :gt <- Ecto.DateTime.compare(current_datetime, Ecto.DateTime.from_date(ico_start_date)), - datetime <- Sanbase.DateTimeUtils.ecto_date_to_datetime(ico_start_date), + with :gt <- Date.compare(current_datetime |> DateTime.to_date(), ico_start_date), + datetime <- Sanbase.DateTimeUtils.date_to_datetime(ico_start_date), price_usd when not is_nil(price_usd) <- Sanbase.Price.Utils.fetch_last_price_before(currency_from, "USD", datetime) do price_usd = Sanbase.Math.to_float(price_usd) |> Decimal.from_float() diff --git a/lib/sanbase/repo.ex b/lib/sanbase/repo.ex index 799155d4b7..85aba74e8d 100644 --- a/lib/sanbase/repo.ex +++ b/lib/sanbase/repo.ex @@ -1,5 +1,5 @@ defmodule Sanbase.Repo do - use Ecto.Repo, otp_app: :sanbase + use Ecto.Repo, otp_app: :sanbase, adapter: Ecto.Adapters.Postgres use Scrivener, page_size: 10 require Sanbase.Utils.Config, as: Config diff --git a/lib/sanbase/utils/datetime/utils.ex b/lib/sanbase/utils/datetime/utils.ex index 10616c7bf9..6d0cf64747 100644 --- a/lib/sanbase/utils/datetime/utils.ex +++ b/lib/sanbase/utils/datetime/utils.ex @@ -62,9 +62,8 @@ defmodule Sanbase.DateTimeUtils do str_to_sec(interval) |> Integer.floor_div(3600) end - def ecto_date_to_datetime(ecto_date) do - {:ok, datetime, _} = - (Ecto.Date.to_iso8601(ecto_date) <> "T00:00:00Z") |> DateTime.from_iso8601() + def date_to_datetime(date) do + {:ok, datetime, _} = (Date.to_iso8601(date) <> "T00:00:00Z") |> DateTime.from_iso8601() datetime end diff --git a/lib/sanbase/voting/vote.ex b/lib/sanbase/voting/vote.ex index 8771b14a91..2790af3ea8 100644 --- a/lib/sanbase/voting/vote.ex +++ b/lib/sanbase/voting/vote.ex @@ -3,7 +3,8 @@ defmodule Sanbase.Vote do Module for voting for insights and timeline events. """ use Ecto.Schema - use Timex.Ecto.Timestamps + + # use Timex.Ecto.Timestamps import Ecto.Changeset diff --git a/lib/sanbase/web.ex b/lib/sanbase/web.ex index 1dc0005ef6..6e3cbb10a2 100644 --- a/lib/sanbase/web.ex +++ b/lib/sanbase/web.ex @@ -21,9 +21,6 @@ defmodule Sanbase.Application.Web do children = [ {Absinthe.Subscription, SanbaseWeb.Endpoint}, - # Start the Elasticsearch Cluster connection - Sanbase.Elasticsearch.Cluster, - # Start the graphQL in-memory cache Supervisor.child_spec( {ConCache, diff --git a/lib/sanbase_web/admin/billing/plan.ex b/lib/sanbase_web/admin/billing/plan.ex index 09507b0763..a9976db60f 100644 --- a/lib/sanbase_web/admin/billing/plan.ex +++ b/lib/sanbase_web/admin/billing/plan.ex @@ -24,7 +24,7 @@ defmodule Sanbase.ExAdmin.Billing.Plan do end end - show _plan do + show plan do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/billing/product.ex b/lib/sanbase_web/admin/billing/product.ex index e05f7b6064..bf536a67b8 100644 --- a/lib/sanbase_web/admin/billing/product.ex +++ b/lib/sanbase_web/admin/billing/product.ex @@ -4,7 +4,7 @@ defmodule Sanbase.ExAdmin.Billing.Product do register_resource Sanbase.Billing.Product do action_items(only: [:show]) - show _product do + show product do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/billing/promo_trial.ex b/lib/sanbase_web/admin/billing/promo_trial.ex index 608fae95b5..850c775545 100644 --- a/lib/sanbase_web/admin/billing/promo_trial.ex +++ b/lib/sanbase_web/admin/billing/promo_trial.ex @@ -32,7 +32,7 @@ defmodule Sanbase.ExAdmin.Billing.PromoTrial do end end - show _promo_trial do + show promo_trial do attributes_table(all: true) end diff --git a/lib/sanbase_web/admin/billing/sign_up_trial.ex b/lib/sanbase_web/admin/billing/sign_up_trial.ex index 9b3bcebb01..357d20d0da 100644 --- a/lib/sanbase_web/admin/billing/sign_up_trial.ex +++ b/lib/sanbase_web/admin/billing/sign_up_trial.ex @@ -12,7 +12,7 @@ defmodule Sanbase.ExAdmin.Billing.SignUpTrial do column(:updated_at) end - show _product do + show product do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/billing/stripe_event.ex b/lib/sanbase_web/admin/billing/stripe_event.ex index 8d543c81cc..224b05c9b9 100644 --- a/lib/sanbase_web/admin/billing/stripe_event.ex +++ b/lib/sanbase_web/admin/billing/stripe_event.ex @@ -11,7 +11,7 @@ defmodule Sanbase.ExAdmin.Billing.StripeEvent do column(:inserted_at) end - show _plan do + show plan do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/billing/subscription.ex b/lib/sanbase_web/admin/billing/subscription.ex index 8af2354562..7279afd57f 100644 --- a/lib/sanbase_web/admin/billing/subscription.ex +++ b/lib/sanbase_web/admin/billing/subscription.ex @@ -28,7 +28,7 @@ defmodule Sanbase.ExAdmin.Billing.Subscription do column(:updated_at) end - show _subscription do + show subscription do attributes_table do row(:id) row(:stripe_id) diff --git a/lib/sanbase_web/admin/chart/configuration.ex b/lib/sanbase_web/admin/chart/configuration.ex index 4c7260f33f..549912fe70 100644 --- a/lib/sanbase_web/admin/chart/configuration.ex +++ b/lib/sanbase_web/admin/chart/configuration.ex @@ -18,7 +18,7 @@ defmodule Sanbase.ExAdmin.Chart.Configuration do column(:project, link: true) end - show _configuration do + show configuration do attributes_table do row(:id) row(:title) diff --git a/lib/sanbase_web/admin/comments/notification.ex b/lib/sanbase_web/admin/comments/notification.ex index aaa7708c8c..3fd96c4ff2 100644 --- a/lib/sanbase_web/admin/comments/notification.ex +++ b/lib/sanbase_web/admin/comments/notification.ex @@ -2,7 +2,7 @@ defmodule Sanbase.ExAdmin.Comments.Notification do use ExAdmin.Register register_resource Sanbase.Comments.Notification do - show _ do + show notif do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/exchanges/market_pair_mapping.ex b/lib/sanbase_web/admin/exchanges/market_pair_mapping.ex index a2151f4fda..ea6b62b7eb 100644 --- a/lib/sanbase_web/admin/exchanges/market_pair_mapping.ex +++ b/lib/sanbase_web/admin/exchanges/market_pair_mapping.ex @@ -2,7 +2,7 @@ defmodule Sanbase.ExAdmin.Exchanges.MarketPairMapping do use ExAdmin.Register register_resource Sanbase.Exchanges.MarketPairMapping do - show _mapping do + show mapping do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/insights/comment.ex b/lib/sanbase_web/admin/insights/comment.ex index 1edf8dda09..c004f43337 100644 --- a/lib/sanbase_web/admin/insights/comment.ex +++ b/lib/sanbase_web/admin/insights/comment.ex @@ -12,7 +12,7 @@ defmodule Sanbase.ExAdmin.Insight.Comment do action_item_link("Delete Subtree (Danger)", href: "/admin2/delete_subcomment_tree/#{id}") end) - show _ do + show comment do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/insights/post.ex b/lib/sanbase_web/admin/insights/post.ex index bb087ce9cf..bf863ae5dc 100644 --- a/lib/sanbase_web/admin/insights/post.ex +++ b/lib/sanbase_web/admin/insights/post.ex @@ -18,7 +18,7 @@ defmodule Sanbase.ExAdmin.Insight.Post do column(:user, link: true) end - show _post do + show post do attributes_table do row(:id) row(:is_featured, &is_featured(&1)) diff --git a/lib/sanbase_web/admin/insights/post_comment.ex b/lib/sanbase_web/admin/insights/post_comment.ex index f4b67fceeb..f4021f8ce6 100644 --- a/lib/sanbase_web/admin/insights/post_comment.ex +++ b/lib/sanbase_web/admin/insights/post_comment.ex @@ -2,7 +2,7 @@ defmodule Sanbase.ExAdmin.Insight.PostComment do use ExAdmin.Register register_resource Sanbase.Insight.PostComment do - show _ do + show post_comment do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/model/ico.ex b/lib/sanbase_web/admin/model/ico.ex index c99eb06a1b..81f218c16a 100644 --- a/lib/sanbase_web/admin/model/ico.ex +++ b/lib/sanbase_web/admin/model/ico.ex @@ -109,13 +109,13 @@ defmodule Sanbase.ExAdmin.Model.Ico do defp set_cap_currency_default(%Ico{} = ico), do: ico defp set_start_date_default(%Ico{start_date: nil} = ico) do - Map.put(ico, :start_date, Ecto.Date.utc()) + Map.put(ico, :start_date, Date.utc_today()) end defp set_start_date_default(%Ico{} = ico), do: ico defp set_end_date_default(%Ico{end_date: nil} = ico) do - Map.put(ico, :end_date, Ecto.Date.utc()) + Map.put(ico, :end_date, Date.utc_today()) end defp set_end_date_default(%Ico{} = ico), do: ico diff --git a/lib/sanbase_web/admin/model/project_market_segment.ex b/lib/sanbase_web/admin/model/project_market_segment.ex index 734b2f8607..8243f24f94 100644 --- a/lib/sanbase_web/admin/model/project_market_segment.ex +++ b/lib/sanbase_web/admin/model/project_market_segment.ex @@ -4,7 +4,7 @@ defmodule Sanbase.ExAdmin.Model.ProjectMarketSegment do alias Sanbase.Model.{Project, MarketSegment} register_resource Sanbase.Model.Project.ProjectMarketSegment do - show _ do + show market_segment do attributes_table(all: true) end diff --git a/lib/sanbase_web/admin/notifications/notification.ex b/lib/sanbase_web/admin/notifications/notification.ex index bd55bf02e9..bfe3599269 100644 --- a/lib/sanbase_web/admin/notifications/notification.ex +++ b/lib/sanbase_web/admin/notifications/notification.ex @@ -2,7 +2,7 @@ defmodule Sanbase.ExAdmin.Notifications.Notification do use ExAdmin.Register register_resource Sanbase.Notifications.Notification do - show _notification do + show notification do attributes_table(all: true) end end diff --git a/lib/sanbase_web/admin/signals/historical_activity.ex b/lib/sanbase_web/admin/signals/historical_activity.ex index 9098170179..4a2d660cbd 100644 --- a/lib/sanbase_web/admin/signals/historical_activity.ex +++ b/lib/sanbase_web/admin/signals/historical_activity.ex @@ -11,7 +11,7 @@ defmodule Sanbase.ExAdmin.Signal.HistoricalActivity do column(:payload, &Jason.encode!(&1.payload)) end - show _historical_activity do + show historical_activity do attributes_table do row(:user) row(:user_trigger_id) diff --git a/lib/sanbase_web/admin/signals/user_trigger.ex b/lib/sanbase_web/admin/signals/user_trigger.ex index 80b2989663..687900b78f 100644 --- a/lib/sanbase_web/admin/signals/user_trigger.ex +++ b/lib/sanbase_web/admin/signals/user_trigger.ex @@ -17,7 +17,7 @@ defmodule Sanbase.ExAdmin.Signal.UserTrigger do column(:user) end - show _user_trigger do + show user_trigger do attributes_table do row(:id) row(:title, & &1.trigger.title) diff --git a/lib/sanbase_web/admin/timeline_event.ex b/lib/sanbase_web/admin/timeline_event.ex index c58f2165b5..95e1341aca 100644 --- a/lib/sanbase_web/admin/timeline_event.ex +++ b/lib/sanbase_web/admin/timeline_event.ex @@ -20,7 +20,7 @@ defmodule Sanbase.ExAdmin.TimelineEvent do actions() end - show _event do + show event do attributes_table(all: true) end end diff --git a/lib/sanbase_web/graphql/resolvers/elasticsearch_resolver.ex b/lib/sanbase_web/graphql/resolvers/elasticsearch_resolver.ex deleted file mode 100644 index 363f009fe3..0000000000 --- a/lib/sanbase_web/graphql/resolvers/elasticsearch_resolver.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule SanbaseWeb.Graphql.Resolvers.ElasticsearchResolver do - require Logger - - def stats(_root, %{from: from, to: to}, _resolution) do - {:ok, Sanbase.Elasticsearch.stats(from, to)} - rescue - error -> - Logger.error("Error getting Elasticearch stats. Reason: #{inspect(error)}") - {:error, "Error getting Elasticearch stats"} - end -end diff --git a/lib/sanbase_web/graphql/schema.ex b/lib/sanbase_web/graphql/schema.ex index d7d87a5d9d..a95cf4ce6d 100644 --- a/lib/sanbase_web/graphql/schema.ex +++ b/lib/sanbase_web/graphql/schema.ex @@ -25,6 +25,7 @@ defmodule SanbaseWeb.Graphql.Schema do import_types(Graphql.AggregationTypes) import_types(Graphql.CustomTypes.Decimal) import_types(Graphql.CustomTypes.DateTime) + import_types(Graphql.CustomTypes.Date) import_types(Graphql.CustomTypes.JSON) import_types(Graphql.CustomTypes.Interval) import_types(Absinthe.Plug.Types) diff --git a/lib/sanbase_web/graphql/schema/custom_types/date.ex b/lib/sanbase_web/graphql/schema/custom_types/date.ex new file mode 100644 index 0000000000..5c84487b91 --- /dev/null +++ b/lib/sanbase_web/graphql/schema/custom_types/date.ex @@ -0,0 +1,30 @@ +defmodule SanbaseWeb.Graphql.CustomTypes.Date do + use Absinthe.Schema.Notation + + scalar :date do + description(""" + The `Date` scalar type represents a date. The Date appears in a JSON + response as an ISO8601 formatted string, without a time component. + """) + + serialize(&Date.to_iso8601/1) + parse(&parse_date/1) + end + + @spec parse_date(Absinthe.Blueprint.Input.String.t()) :: {:ok, Date.t()} | :error + @spec parse_date(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} + defp parse_date(%Absinthe.Blueprint.Input.String{value: value}) do + case Date.from_iso8601(value) do + {:ok, date} -> {:ok, date} + _error -> :error + end + end + + defp parse_date(%Absinthe.Blueprint.Input.Null{}) do + {:ok, nil} + end + + defp parse_date(_) do + :error + end +end diff --git a/lib/sanbase_web/graphql/schema/custom_types/datetime.ex b/lib/sanbase_web/graphql/schema/custom_types/datetime.ex index bec2170577..30d7abec96 100644 --- a/lib/sanbase_web/graphql/schema/custom_types/datetime.ex +++ b/lib/sanbase_web/graphql/schema/custom_types/datetime.ex @@ -1,11 +1,6 @@ defmodule SanbaseWeb.Graphql.CustomTypes.DateTime do use Absinthe.Schema.Notation - scalar :ecto_date, name: "EctoDate" do - serialize(&Ecto.Date.to_iso8601/1) - parse(&parse_ecto_date/1) - end - scalar :datetime, name: "DateTime" do description(""" The `DateTime` scalar type represents a date and time in the UTC @@ -38,16 +33,6 @@ defmodule SanbaseWeb.Graphql.CustomTypes.DateTime do parse(&parse_naive_datetime/1) end - scalar :date do - description(""" - The `Date` scalar type represents a date. The Date appears in a JSON - response as an ISO8601 formatted string, without a time component. - """) - - serialize(&Date.to_iso8601/1) - parse(&parse_date/1) - end - scalar :time do description(""" The `Time` scalar type represents a time. The Time appears in a JSON @@ -58,23 +43,6 @@ defmodule SanbaseWeb.Graphql.CustomTypes.DateTime do parse(&parse_time/1) end - @spec parse_ecto_date(Absinthe.Blueprint.Input.String.t()) :: {:ok, Ecto.Date.type()} | :error - @spec parse_ecto_date(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} - defp parse_ecto_date(%Absinthe.Blueprint.Input.String{value: value}) do - case Ecto.Date.cast(value) do - {:ok, ecto_date} -> {:ok, ecto_date} - _error -> :error - end - end - - defp parse_ecto_date(%Absinthe.Blueprint.Input.Null{}) do - {:ok, nil} - end - - defp parse_ecto_date(_) do - :error - end - @spec parse_datetime(Absinthe.Blueprint.Input.String.t()) :: {:ok, DateTime.t()} | :error @spec parse_datetime(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} defp parse_datetime(%Absinthe.Blueprint.Input.String{value: value}) do @@ -111,23 +79,6 @@ defmodule SanbaseWeb.Graphql.CustomTypes.DateTime do :error end - @spec parse_date(Absinthe.Blueprint.Input.String.t()) :: {:ok, Date.t()} | :error - @spec parse_date(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} - defp parse_date(%Absinthe.Blueprint.Input.String{value: value}) do - case Date.from_iso8601(value) do - {:ok, date} -> {:ok, date} - _error -> :error - end - end - - defp parse_date(%Absinthe.Blueprint.Input.Null{}) do - {:ok, nil} - end - - defp parse_date(_) do - :error - end - @spec parse_time(Absinthe.Blueprint.Input.String.t()) :: {:ok, Time.t()} | :error @spec parse_time(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil} defp parse_time(%Absinthe.Blueprint.Input.String{value: value}) do diff --git a/lib/sanbase_web/graphql/schema/queries/social_data_queries.ex b/lib/sanbase_web/graphql/schema/queries/social_data_queries.ex index 600a68966e..c2ebc5f02e 100644 --- a/lib/sanbase_web/graphql/schema/queries/social_data_queries.ex +++ b/lib/sanbase_web/graphql/schema/queries/social_data_queries.ex @@ -7,14 +7,12 @@ defmodule SanbaseWeb.Graphql.Schema.SocialDataQueries do alias SanbaseWeb.Graphql.Resolvers.{ SocialDataResolver, - TwitterResolver, - ElasticsearchResolver + TwitterResolver } alias SanbaseWeb.Graphql.Complexity import_types(SanbaseWeb.Graphql.SocialDataTypes) - import_types(SanbaseWeb.Graphql.ElasticsearchTypes) object :social_data_queries do field :popular_search_terms, list_of(:popular_search_term) do @@ -354,17 +352,6 @@ defmodule SanbaseWeb.Graphql.Schema.SocialDataQueries do cache_resolve(&SocialDataResolver.news/3) end - @desc "Returns statistics for the data stored in elasticsearch" - field :elasticsearch_stats, :elasticsearch_stats do - meta(access: :free) - - arg(:from, non_null(:datetime)) - arg(:to, non_null(:datetime)) - - middleware(AccessControl) - cache_resolve(&ElasticsearchResolver.stats/3) - end - @desc """ Top social gainers/losers returns the social volume changes of all crypto projects. diff --git a/lib/sanbase_web/graphql/schema/types/elasticsearch_types.ex b/lib/sanbase_web/graphql/schema/types/elasticsearch_types.ex deleted file mode 100644 index f8fd2dd025..0000000000 --- a/lib/sanbase_web/graphql/schema/types/elasticsearch_types.ex +++ /dev/null @@ -1,12 +0,0 @@ -defmodule SanbaseWeb.Graphql.ElasticsearchTypes do - use Absinthe.Schema.Notation - - object :elasticsearch_stats do - field(:documents_count, non_null(:integer)) - field(:size_in_megabytes, non_null(:integer)) - field(:telegram_channels_count, non_null(:integer)) - field(:subreddits_count, non_null(:integer)) - field(:discord_channels_count, non_null(:integer)) - field(:average_documents_per_day, non_null(:integer)) - end -end diff --git a/lib/sanbase_web/graphql/schema/types/project_types.ex b/lib/sanbase_web/graphql/schema/types/project_types.ex index 16f42cdfc1..7aa6c9b85b 100644 --- a/lib/sanbase_web/graphql/schema/types/project_types.ex +++ b/lib/sanbase_web/graphql/schema/types/project_types.ex @@ -545,8 +545,8 @@ defmodule SanbaseWeb.Graphql.ProjectTypes do object :ico do field(:id, non_null(:id)) - field(:start_date, :ecto_date) - field(:end_date, :ecto_date) + field(:start_date, :date) + field(:end_date, :date) field(:token_usd_ico_price, :decimal) field(:token_eth_ico_price, :decimal) field(:token_btc_ico_price, :decimal) @@ -582,8 +582,8 @@ defmodule SanbaseWeb.Graphql.ProjectTypes do object :ico_with_eth_contract_info do field(:id, non_null(:id)) - field(:start_date, :ecto_date) - field(:end_date, :ecto_date) + field(:start_date, :date) + field(:end_date, :date) field(:main_contract_address, :string) field(:contract_block_number, :integer) field(:contract_abi, :string) diff --git a/mix.exs b/mix.exs index 71f2fdf5fd..06f405fbae 100644 --- a/mix.exs +++ b/mix.exs @@ -46,26 +46,31 @@ defmodule Sanbase.Mixfile do {:arc, git: "https://github.com/marinho10/arc"}, {:async_with, github: "fertapric/async_with"}, {:basic_auth, "~> 2.2"}, - {:clickhouse_ecto, git: "https://github.com/santiment/clickhouse_ecto"}, + {:clickhouse_ecto, github: "santiment/clickhouse_ecto", branch: "migrate-ecto-3"}, + {:clickhousex, + github: "ivanivanoff/clickhousex", + branch: "revert-17-revert-15-prepare_for_ecto_3", + override: true}, {:con_cache, "~> 0.13"}, {:corsica, "~> 1.0"}, {:cowboy, "~> 2.0"}, {:credo, "~> 1.0", only: [:dev, :test], runtime: false}, {:csv, "~> 2.1"}, {:dataloader, "~> 1.0.0"}, + {:db_connection, "~> 2.2", override: true}, {:decimal, "~> 1.0"}, {:dialyxir, "~> 1.0.0-rc.6", only: [:dev], runtime: false}, {:distillery, "~> 2.0", runtime: false}, {:earmark, "~> 1.2"}, {:ecto_enum, "~> 1.3"}, - {:elasticsearch, "~> 1.0"}, + {:ecto, "~> 3.0"}, + {:ecto_sql, "~> 3.0"}, {:envy, "~> 1.1.1", only: [:dev, :test]}, {:erlex, "~> 0.2.6", override: true}, - {:ex_admin, github: "santiment/ex_admin"}, + {:ex_admin, github: "IvanIvanoff/ex_admin", branch: "apply-changes"}, {:ex_aws_s3, "~> 2.0"}, {:ex_aws, "~> 2.0"}, {:ex_machina, "~> 2.2", only: [:dev, :test]}, - {:ex_queb, "~> 1.0"}, {:ex_unit_notifier, "~> 0.1", only: :test}, {:excoveralls, "~> 0.8", optional: true, only: [:dev, :test]}, {:exprof, "~> 0.2.0"}, @@ -90,13 +95,12 @@ defmodule Sanbase.Mixfile do {:mogrify, "~> 0.7.2"}, {:number, "~> 1.0"}, {:observer_cli, "~> 1.3"}, - {:phoenix_ecto, "~> 3.3"}, + {:phoenix_ecto, "~> 4.1"}, {:phoenix_live_reload, "~> 1.1", only: :dev}, {:phoenix_pubsub, "~> 1.1"}, {:phoenix, "~> 1.4.3"}, {:plug_cowboy, "~> 2.0"}, - {:poison, ">= 1.0.0"}, - {:postgrex, ">= 0.0.0"}, + {:postgrex, "~> 0.15.0", override: true}, {:prometheus_ecto, "~> 1.3"}, {:prometheus_ex, "~> 3.0", override: true}, {:prometheus_plugs, "~> 1.0"}, @@ -110,7 +114,6 @@ defmodule Sanbase.Mixfile do {:sweet_xml, "~> 0.6"}, {:temp, "~> 0.4"}, {:tesla, "~> 1.0"}, - {:timex_ecto, "~> 3.3.0"}, {:timex, "~> 3.5.0"}, {:uuid, "~> 1.1"}, {:vex, "~> 0.8.0", override: true} diff --git a/mix.lock b/mix.lock index 352c599f02..7f6fd30287 100644 --- a/mix.lock +++ b/mix.lock @@ -2,7 +2,7 @@ "absinthe": {:git, "https://github.com/absinthe-graphql/absinthe.git", "d1485f728b0fe4cea90cfbc45e92864eeb1c07dd", []}, "absinthe_metrics": {:hex, :absinthe_metrics, "1.0.0", "c4dd0444168a1d32a432cab2ced498069e58fd4b90aa9e1ec16b49557bee2cf1", [:mix], [{:absinthe, "~> 1.3", [hex: :absinthe, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: true]}], "hexpm", "c21485a8d207c78c32040b9588c254c43362fbaf7dfaa50a7c7b016f015f5643"}, "absinthe_phoenix": {:git, "https://github.com/absinthe-graphql/absinthe_phoenix.git", "1d832570ffdd031a209a9218c6fc54cde4488665", []}, - "absinthe_plug": {:git, "https://github.com/absinthe-graphql/absinthe_plug.git", "7c52e5d583252b8d44bed395f16a01b1c15fde10", []}, + "absinthe_plug": {:git, "https://github.com/absinthe-graphql/absinthe_plug.git", "625836f7c673ca65c8499ec49286d79a32ae26a7", []}, "accept": {:hex, :accept, "0.3.3", "548ebb6fb2e8b0d170e75bb6123aea6ceecb0189bb1231eeadf52eac08384a97", [:rebar3], [], "hexpm", "9df23358b4d0c62d058fb84281aae5e7a850dcc923d4907d12b938b189e20208"}, "arc": {:git, "https://github.com/marinho10/arc", "63b40c1fb8cd67d88731c6f87a5387aa746b391e", []}, "artificery": {:hex, :artificery, "0.4.2", "3ded6e29e13113af52811c72f414d1e88f711410cac1b619ab3a2666bbd7efd4", [:mix], [], "hexpm", "514586f4312ef3709a3ccbd8e55f69455add235c1729656687bb781d10d0afdb"}, @@ -10,9 +10,10 @@ "basic_auth": {:hex, :basic_auth, "2.2.4", "d8c748237870dd1df3bc5c0f1ab4f1fad6270c75472d7e62b19302ec59e92a79", [:mix], [{:plug, "~> 0.14 or ~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "a595b5f2a07e94cbde7be3dfeba24573e18655c88e74c8eb118364f856642e62"}, "brod": {:hex, :brod, "3.8.1", "74426e2d27989cd7f973599bc209c899dca8588068d27a2a37ca1b4bf8823c2a", [:make, :rebar, :rebar3], [{:kafka_protocol, "2.2.9", [hex: :kafka_protocol, repo: "hexpm", optional: false]}, {:supervisor3, "1.1.8", [hex: :supervisor3, repo: "hexpm", optional: false]}], "hexpm", "40108eba78abaecf8a3b61df3349f893d94a6cadf6eed2ed5be1f5d63b645aee"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, + "castore": {:hex, :castore, "0.1.5", "591c763a637af2cc468a72f006878584bc6c306f8d111ef8ba1d4c10e0684010", [:mix], [], "hexpm", "6db356b2bc6cc22561e051ff545c20ad064af57647e436650aa24d7d06cd941a"}, "certifi": {:git, "https://github.com/certifi/erlang-certifi", "e08b12e8993502240c25b78563993776f87ecd2a", [tag: "2.5.1"]}, - "clickhouse_ecto": {:git, "https://github.com/santiment/clickhouse_ecto", "bf8835b10bbb491664f679efe167c9514b03bfca", []}, - "clickhousex": {:hex, :clickhousex, "0.2.2", "037a1244fff6e2eb6d9f1c6f433294a59e61019cfdb11e8fd79b5360e1870a9b", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "1a3d6b3d65e1b6c9cebfb6c4bc19df074520263883badbfa83f713f60a1b2534"}, + "clickhouse_ecto": {:git, "https://github.com/santiment/clickhouse_ecto.git", "9518142275534f040edb19c61646fc3aed889040", [branch: "migrate-ecto-3"]}, + "clickhousex": {:git, "https://github.com/ivanivanoff/clickhousex.git", "1a3b25080fa755f1e5d68803e01a548c2995920f", [branch: "revert-17-revert-15-prepare_for_ecto_3"]}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "con_cache": {:hex, :con_cache, "0.14.0", "863acb90fa08017be3129074993af944cf7a4b6c3ee7c06c5cd0ed6b94fbc223", [:mix], [], "hexpm", "50887a8949377d0b707a3c6653b7610de06074751b52d0f267f52135f391aece"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, @@ -20,26 +21,26 @@ "cowboy": {:hex, :cowboy, "2.7.0", "91ed100138a764355f43316b1d23d7ff6bdb0de4ea618cb5d8677c93a7a2f115", [:rebar3], [{:cowlib, "~> 2.8.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "04fd8c6a39edc6aaa9c26123009200fc61f92a3a94f3178c527b70b767c6e605"}, "cowlib": {:hex, :cowlib, "2.8.0", "fd0ff1787db84ac415b8211573e9a30a3ebe71b5cbff7f720089972b2319c8a4", [:rebar3], [], "hexpm", "79f954a7021b302186a950a32869dbc185523d99d3e44ce430cd1f3289f41ed4"}, "crc32cer": {:git, "https://github.com/zmstone/crc32cer", "ebedd10d83856cca081715ad37dc0ac2f731e437", [tag: "0.1.3"]}, - "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, + "credo": {:hex, :credo, "1.3.1", "082e8d9268a489becf8e7aa75671a7b9088b1277cd6c1b13f40a55554b3f5126", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "0da816ed52fa520b9ea0e5d18a0d3ca269e0bd410b1174d88d8abd94be6cce3c"}, "crontab": {:hex, :crontab, "1.1.10", "dc9bb1f4299138d47bce38341f5dcbee0aa6c205e864fba7bc847f3b5cb48241", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "1347d889d1a0eda997990876b4894359e34bfbbd688acbb0ba28a2795ca40685"}, "csv": {:hex, :csv, "2.3.1", "9ce11eff5a74a07baf3787b2b19dd798724d29a9c3a492a41df39f6af686da0e", [:mix], [{:parallel_stream, "~> 1.0.4", [hex: :parallel_stream, repo: "hexpm", optional: false]}], "hexpm", "86626e1c89a4ad9a96d0d9c638f9e88c2346b89b4ba1611988594ebe72b5d5ee"}, "csvlixir": {:hex, :csvlixir, "1.0.0", "e9fd30abfca2d312390060e86bb7ec52487c813824dcccad45bb13e85ecad6b1", [:mix], [], "hexpm", "1f3a71331462ac85e962bf74d3b687b8b5e8861850e12ee02f4ef0fbdc0591f2"}, "dataloader": {:hex, :dataloader, "1.0.7", "58351b335673cf40601429bfed6c11fece6ce7ad169b2ac0f0fe83e716587391", [:mix], [{:ecto, ">= 0.0.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "12bf66478e4a5085d09dc96932d058c206ee8c219cc7691d12a40dc35c8cefaa"}, - "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm", "5f0a16a58312a610d5eb0b07506280c65f5137868ad479045f2a2dc4ced80550"}, + "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"}, "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, - "earmark": {:hex, :earmark, "1.4.4", "4821b8d05cda507189d51f2caeef370cf1e18ca5d7dfb7d31e9cafe6688106a4", [:mix], [], "hexpm", "1f93aba7340574847c0f609da787f0d79efcab51b044bb6e242cae5aca9d264d"}, - "ecto": {:hex, :ecto, "2.2.12", "ce7f619c1451daad0f59e8f01fd8e2584226171dc273e3346444446a13d93943", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm", "d5d01f3ec33e3853ac8ca80dcaf9b154a348b9eaa70009d2b9ad25c45262fdea"}, + "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, + "ecto": {:hex, :ecto, "3.4.4", "a2c881e80dc756d648197ae0d936216c0308370332c5e77a2325a10293eef845", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4bd3ad62abc3b21fb629f0f7a3dab23a192fca837d257dd08449fba7373561"}, "ecto_enum": {:hex, :ecto_enum, "1.3.2", "659f7251b6a201a236db9dceef0f713319f095a23ad1d8718efd7a3d3ef3e21b", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "7d111aef5601596f1c6da3fd1de784cb7ed7f8eca3f8af631df04f11fc8f248f"}, - "elasticsearch": {:hex, :elasticsearch, "1.0.0", "626d3fb8e7554d9c93eb18817ae2a3d22c2a4191cc903c4644b1334469b15374", [:mix], [{:httpoison, ">= 0.0.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:sigaws, "~> 0.7", [hex: :sigaws, repo: "hexpm", optional: true]}, {:vex, "~> 0.6.0", [hex: :vex, repo: "hexpm", optional: false]}], "hexpm", "9fa0b717ad57a54c28451b3eb10c5121211c29a7b33615d2bcc7e2f3c9418b2e"}, + "ecto_sql": {:hex, :ecto_sql, "3.4.3", "c552aa8a7ccff2b64024f835503b3155d8e73452c180298527fbdbcd6e79710b", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ec9e59d6fa3f8cfda9963ada371e9e6659167c2338a997bd7ea23b10b245842b"}, "envy": {:hex, :envy, "1.1.1", "0bc9bd654dec24fcdf203f7c5aa1b8f30620f12cfb28c589d5e9c38fe1b07475", [:mix], [], "hexpm", "7061eb1a47415fd757145d8dec10dc0b1e48344960265cb108f194c4252c3a89"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_admin": {:git, "https://github.com/santiment/ex_admin.git", "d12db12b3d149a77e5d035fa4e5bd9bb445f50a1", []}, - "ex_aws": {:hex, :ex_aws, "2.1.3", "26b6f036f0127548706aade4a509978fc7c26bd5334b004fba9bfe2687a525df", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "0bdbe2aed9f326922fc5a6a80417e32f0c895f4b3b2b0b9676ebf23dd16c5da4"}, + "ex_admin": {:git, "https://github.com/IvanIvanoff/ex_admin.git", "6a520b3c0c2662960801865cdfd6a2085914909a", [branch: "apply-changes"]}, + "ex_aws": {:hex, :ex_aws, "2.1.2", "a0f8443556eb527e042c749eb87347d9cd1d13688da4e5354ddee51f99272360", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "b1d24a9afa850963ff2874762316744ddcf48e1f9bad416c57b95e1c5a080f11"}, "ex_aws_s3": {:hex, :ex_aws_s3, "2.0.2", "c0258bbdfea55de4f98f0b2f0ca61fe402cc696f573815134beb1866e778f47b", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "0569f5b211b1a3b12b705fe2a9d0e237eb1360b9d76298028df2346cad13097a"}, "ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"}, - "ex_queb": {:hex, :ex_queb, "1.0.1", "833f773179fb8971b1a58b67874209f50d087024ca0771e8f9a283c9214ec4b9", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, repo: "hexpm", optional: false]}], "hexpm", "538867ed57c728f7946023a3e93d2110fed5236356b802642acb42bcd0375f83"}, + "ex_queb": {:git, "https://github.com/iwarshak/ex_queb.git", "3aab53ac21cb9b9292614abadfaeb96c10e1f74b", []}, "ex_unit_notifier": {:hex, :ex_unit_notifier, "0.1.4", "36a2dcab829f506e01bf17816590680dd1474407926d43e64c1263e627c364b8", [:mix], [], "hexpm", "fddf5054dd5fd2f809e837b749570baa5c9798e11d0163921baec49b7d5762f2"}, "exactor": {:hex, :exactor, "2.2.4", "5efb4ddeb2c48d9a1d7c9b465a6fffdd82300eb9618ece5d34c3334d5d7245b1", [:mix], [], "hexpm", "1222419f706e01bfa1095aec9acf6421367dcfab798a6f67c54cf784733cd6b5"}, "excoveralls": {:hex, :excoveralls, "0.12.3", "2142be7cb978a3ae78385487edda6d1aff0e482ffc6123877bb7270a8ffbcfe0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "568a3e616c264283f5dea5b020783ae40eef3f7ee2163f7a67cbd7b35bcadada"}, @@ -47,33 +48,36 @@ "exprof": {:hex, :exprof, "0.2.3", "8d4d657d73fc0c9ef1e30b2f9207b26ccbd2aec2baf1ca43f0b6d244c841c9f8", [:mix], [{:exprintf, "~> 0.2", [hex: :exprintf, repo: "hexpm", optional: false]}], "hexpm", "040410c672e2403908f578fb1e203a178692bbcd61b11d3745912662532b1dad"}, "extwitter": {:hex, :extwitter, "0.9.6", "27329093edced8a30d52599de3207c4e08e75c20cd1530c23ccd83ac2e88a33a", [:mix], [{:oauther, "~> 1.1", [hex: :oauther, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "b7bb01cea1e52d524be90e1311847bef9948e8a76d2118ea3eca8892840cd2da"}, "faker": {:hex, :faker, "0.13.0", "8abcb996f010ccd6c85588c89fc047f11134e04da019b70252f95431d721a3dc", [:mix], [], "hexpm", "b0016680cae6776e3d1caa34d70438acc09c11c003e80fd3d44f79ec7370be00"}, - "file_system": {:hex, :file_system, "0.2.8", "f632bd287927a1eed2b718f22af727c5aeaccc9a98d8c2bd7bff709e851dc986", [:mix], [], "hexpm", "97a3b6f8d63ef53bd0113070102db2ce05352ecf0d25390eb8d747c2bde98bca"}, + "file_system": {:hex, :file_system, "0.2.7", "e6f7f155970975789f26e77b8b8d8ab084c59844d8ecfaf58cbda31c494d14aa", [:mix], [], "hexpm", "b4cfa2d69c7f0b18fd06db222b2398abeef743a72504e6bd7df9c52f171b047f"}, "floki": {:hex, :floki, "0.26.0", "4df88977e2e357c6720e1b650f613444bfb48c5acfc6a0c646ab007d08ad13bf", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "e7b66ce7feef5518a9cd9fc7b52dd62a64028bd9cb6d6ad282a0f0fc90a4ae52"}, "gen_stage": {:hex, :gen_stage, "0.14.3", "d0c66f1c87faa301c1a85a809a3ee9097a4264b2edf7644bf5c123237ef732bf", [:mix], [], "hexpm", "8453e2289d94c3199396eb517d65d6715ef26bcae0ee83eb5ff7a84445458d76"}, "gen_state_machine": {:hex, :gen_state_machine, "2.1.0", "a38b0e53fad812d29ec149f0d354da5d1bc0d7222c3711f3a0bd5aa608b42992", [:mix], [], "hexpm", "ae367038808db25cee2f2c4b8d0531522ea587c4995eb6f96ee73410a60fa06b"}, - "gettext": {:hex, :gettext, "0.18.0", "406d6b9e0e3278162c2ae1de0a60270452c553536772167e2d701f028116f870", [:mix], [], "hexpm", "c3f850be6367ebe1a08616c2158affe4a23231c70391050bf359d5f92f66a571"}, + "gettext": {:hex, :gettext, "0.17.4", "f13088e1ec10ce01665cf25f5ff779e7df3f2dc71b37084976cf89d1aa124d5c", [:mix], [], "hexpm", "3c75b5ea8288e2ee7ea503ff9e30dfe4d07ad3c054576a6e60040e79a801e14d"}, "guardian": {:hex, :guardian, "2.1.1", "1f02b349f6ba765647cc834036a8d76fa4bd65605342fe3a031df3c99d0d411a", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "189b87ba7ce6b40d6ba029138098b96ffc4ae78f229f5b39539b9141af8bf0f8"}, "hackney": {:git, "https://github.com/benoitc/hackney.git", "e8bbfc87f2e6256bea46a50ed1bad8b4e25bb66f", []}, "hammer": {:hex, :hammer, "6.0.0", "72ec6fff10e9d63856968988a22ee04c4d6d5248071ddccfbda50aa6c455c1d7", [:mix], [{:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "d8e1ec2e534c4aae508b906759e077c3c1eb3e2b9425235d4b7bbab0b016210a"}, "html_entities": {:hex, :html_entities, "0.5.1", "1c9715058b42c35a2ab65edc5b36d0ea66dd083767bef6e3edb57870ef556549", [:mix], [], "hexpm", "30efab070904eb897ff05cd52fa61c1025d7f8ef3a9ca250bc4e6513d16c32de"}, + "html_sanitize_ex": {:git, "https://github.com/sublimecoder/html_sanitize_ex.git", "30282178751750e88418b23483be79d5d01a8047", []}, "httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"}, "idna": {:git, "https://github.com/benoitc/erlang-idna", "6cff72747821110169ecfac871b0c69e5064afff", [tag: "6.0.0"]}, "inet_cidr": {:hex, :inet_cidr, "1.0.4", "a05744ab7c221ca8e395c926c3919a821eb512e8f36547c062f62c4ca0cf3d6e", [:mix], [], "hexpm", "64a2d30189704ae41ca7dbdd587f5291db5d1dda1414e0774c29ffc81088c1bc"}, "inflex": {:hex, :inflex, "2.0.0", "db69d542b8fdb23ac667f9bc0c2395a3983fa2da6ae2efa7ab5dc541928f7a75", [:mix], [], "hexpm", "c018852409bd48b03ad96ed53594186bc074bdd1519043a0ad1fa5697aac4399"}, "influxql": {:hex, :influxql, "0.2.1", "71bfd5c0d81bf870f239baf3357bf5226b44fce16e1b9399ba1368203ca71245", [:mix], [], "hexpm", "75faf04960d6830ca0827869eaac1ba092655041c5e96deb2a588bafb601205c"}, "instream": {:hex, :instream, "0.22.0", "7eaaf0a0b9629b2cda7f2fef60c521eeab932e530aee5bc97c07d39aa0bfea8b", [:mix], [{:hackney, "~> 1.1", [hex: :hackney, repo: "hexpm", optional: false]}, {:influxql, "~> 0.2.0", [hex: :influxql, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "90eeb75b459ccf99211e1e7b06721192b25aff2bea3722017d8ee7c8fc289495"}, - "jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, "jose": {:hex, :jose, "1.10.1", "16d8e460dae7203c6d1efa3f277e25b5af8b659febfc2f2eb4bacf87f128b80a", [:mix, :rebar3], [], "hexpm", "3c7ddc8a9394b92891db7c2771da94bf819834a1a4c92e30857b7d582e2f8257"}, "kaffe": {:git, "https://github.com/santiment/kaffe.git", "2f158c678344faa17dac1c3246fb2e5bc45d7bcf", []}, "kafka_protocol": {:git, "https://github.com/qzhuyan/kafka_protocol.git", "6696c1aaabe11f963f687037149a0cfccdfd499d", [branch: "lz4-nif"]}, "libcluster": {:hex, :libcluster, "3.2.1", "b2cd5b447cde25d5897749bee6f7aaeb6c96ac379481024e9b6ba495dabeb97d", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "89f225612d135edce9def56f43bf18d575d88ac4680e3f6161283f2e55cadca4"}, - "libring": {:hex, :libring, "1.5.0", "44313eb6862f5c9168594a061e9d5f556a9819da7c6444706a9e2da533396d70", [:mix], [], "hexpm", "04e843d4fdcff49a62d8e03778d17c6cb2a03fe2d14020d3825a1761b55bd6cc"}, + "libring": {:hex, :libring, "1.4.0", "41246ba2f3fbc76b3971f6bce83119dfec1eee17e977a48d8a9cfaaf58c2a8d6", [:mix], [], "hexpm", "1feaf05ee886815ad047cad7ede17d6910710986148ae09cf73eee2989717b81"}, "lz4b": {:hex, :lz4b, "0.0.4", "9e8c8b51d3f747e814666526b5fb373758dc5eb06f1eb0e0f4a8432b867bec81", [:rebar3], [], "hexpm", "260b6d424d92c14c083d9a8cc0156f8229c172ebf875500d3139807bd9593226"}, "meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm", "d34f013c156db51ad57cc556891b9720e6a1c1df5fe2e15af999c84d6cebeb1a"}, "metrics": {:git, "https://github.com/benoitc/erlang-metrics", "c6eb4dcf29f9e907539915e2ab996f40c2ec7e8e", [tag: "1.0.1"]}, "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"}, "mimerl": {:git, "https://github.com/benoitc/mimerl", "5a1b22a8fada5b3b40438da00a6923cb87a42bbc", [tag: "1.2.0"]}, + "mint": {:hex, :mint, "1.0.0", "ca5ab33497ba2bdcc42f6cdd3927420a6159116be87c8173658e93c8746703da", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "b8943ef1e630879538dd6620bfc189d4d75fab3ad39f3fe9c50539879f7efd84"}, "mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "817dec4a7f6edf260258002f99ac8ffaf7a8f395b27bf2d13ec24018beecec8a"}, + "mochiweb": {:hex, :mochiweb, "2.20.1", "e4dbd0ed716f076366ecf62ada5755a844e1d95c781e8c77df1d4114be868cdf", [:rebar3], [], "hexpm", "d1aeee7870470d2fa9eae0b3d5ab6c33801aa2d82b10e9dade885c5c921b36aa"}, "mock": {:hex, :mock, "0.3.4", "c5862eb3b8c64237f45f586cf00c9d892ba07bb48305a43319d428ce3c2897dd", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "e6d886252f1a41f4ba06ecf2b4c8d38760b34b1c08a11c28f7397b2e03995964"}, "mockery": {:hex, :mockery, "2.3.1", "a02fd60b10ac9ed37a7a2ecf6786c1f1dd5c75d2b079a60594b089fba32dc087", [:mix], [], "hexpm", "1d0971d88ebf084e962da3f2cfee16f0ea8e04ff73a7710428500d4500b947fa"}, "mogrify": {:hex, :mogrify, "0.7.3", "1494ee739f6e90de158dec4d4edee2d854d2f2d06a522e943f996ae176bca53d", [:mix], [], "hexpm", "b3e90a87171c23efa6b5910d735dd44f3fda15ba07a57cdb89cdb8ecaf83988d"}, @@ -83,17 +87,17 @@ "observer_cli": {:hex, :observer_cli, "1.5.3", "d42e20054116c49d5242d3ff9e1913acccebe6015f449d6e312a5bc160e79a62", [:mix, :rebar3], [{:recon, "~>2.5.0", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm", "3d2de7a710b9bed4cfbdae0419d98b1985634bd8cc1f26ef9576c2eb9aa6b35e"}, "parallel_stream": {:hex, :parallel_stream, "1.0.6", "b967be2b23f0f6787fab7ed681b4c45a215a81481fb62b01a5b750fa8f30f76c", [:mix], [], "hexpm", "639b2e8749e11b87b9eb42f2ad325d161c170b39b288ac8d04c4f31f8f0823eb"}, "parse_trans": {:git, "https://github.com/uwiger/parse_trans.git", "76abb347c3c1d00fb0ccf9e4b43e22b3d2288484", [tag: "3.3.0"]}, - "phoenix": {:hex, :phoenix, "1.4.17", "1b1bd4cff7cfc87c94deaa7d60dd8c22e04368ab95499483c50640ef3bd838d8", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a8e5d7a3d76d452bb5fb86e8b7bd115f737e4f8efe202a463d4aeb4a5809611"}, - "phoenix_ecto": {:hex, :phoenix_ecto, "3.3.0", "702f6e164512853d29f9d20763493f2b3bcfcb44f118af2bc37bb95d0801b480", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "4e044e000709e7de75e82cd17dbb7ed78d398309c826ce193b4fea49bf5acb3e"}, - "phoenix_html": {:hex, :phoenix_html, "2.13.2", "f5d27c9b10ce881a60177d2b5227314fc60881e6b66b41dfe3349db6ed06cf57", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "346764ebecf5e7d318ec64db92a2aa9ef17fcb2ae0b001791cd37a0223f724ba"}, - "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.2", "38d94c30df5e2ef11000697a4fbe2b38d0fbf79239d492ff1be87bbc33bc3a84", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "a3dec3d28ddb5476c96a7c8a38ea8437923408bc88da43e5c45d97037b396280"}, + "phoenix": {:hex, :phoenix, "1.4.16", "2cbbe0c81e6601567c44cc380c33aa42a1372ac1426e3de3d93ac448a7ec4308", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "856cc1a032fa53822737413cf51aa60e750525d7ece7d1c0576d90d7c0f05c24"}, + "phoenix_ecto": {:hex, :phoenix_ecto, "4.1.0", "a044d0756d0464c5a541b4a0bf4bcaf89bffcaf92468862408290682c73ae50d", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c5e666a341ff104d0399d8f0e4ff094559b2fde13a5985d4cb5023b2c2ac558b"}, + "phoenix_html": {:hex, :phoenix_html, "2.14.2", "b8a3899a72050f3f48a36430da507dd99caf0ac2d06c77529b1646964f3d563e", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "58061c8dfd25da5df1ea0ca47c972f161beb6c875cd293917045b92ffe1bf617"}, + "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.1", "274a4b07c4adbdd7785d45a8b0bb57634d0b4f45b18d2c508b26c0344bd59b8f", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "41b4103a2fa282cfd747d377233baf213c648fdcc7928f432937676532490eee"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm", "1f13f9f0f3e769a667a6b6828d29dec37497a082d195cc52dbef401a9b69bf38"}, "plug": {:hex, :plug, "1.10.1", "c56a6d9da7042d581159bcbaef873ba9d87f15dce85420b0d287bca19f40f9bd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "b5cd52259817eb8a31f2454912ba1cff4990bca7811918878091cb2ab9e52cb8"}, - "plug_cowboy": {:hex, :plug_cowboy, "2.2.1", "fcf58aa33227a4322a050e4783ee99c63c031a2e7f9a2eb7340d55505e17f30f", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3b43de24460d87c0971887286e7a20d40462e48eb7235954681a20cee25ddeb6"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.1.2", "8b0addb5908c5238fac38e442e81b6fcd32788eaa03246b4d55d147c47c5805e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "7d722581ce865a237e14da6d946f92704101740a256bd13ec91e63c0b122fc70"}, "plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, - "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a19b61193379cdee04b5b2361bf93d1eb170cd2eec0b18042617b07e1e15fbfb"}, + "postgrex": {:hex, :postgrex, "0.15.4", "5d691c25fc79070705a2ff0e35ce0822b86a0ee3c6fdb7a4fb354623955e1aed", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "306515b9d975fcb2478dc337a1d27dc3bf8af7cd71017c333fe9db3a3d211b0a"}, "prometheus": {:hex, :prometheus, "4.3.0", "fd4648ece963904df98edc23fabfd5d1b7d791d4111259f0a4bbbad50f50d57a", [:mix, :rebar3], [], "hexpm", "1fabf28af8acd0f678101e77e6f51d9c89a2c6aa5a21cffd4d631fcda65a276f"}, "prometheus_ecto": {:hex, :prometheus_ecto, "1.4.3", "3dd4da1812b8e0dbee81ea58bb3b62ed7588f2eae0c9e97e434c46807ff82311", [:mix], [{:ecto, "~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 1.1 or ~> 2.0 or ~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: false]}], "hexpm", "8d66289f77f913b37eda81fd287340c17e61a447549deb28efc254532b2bed82"}, "prometheus_ex": {:hex, :prometheus_ex, "3.0.5", "fa58cfd983487fc5ead331e9a3e0aa622c67232b3ec71710ced122c4c453a02f", [:mix], [{:prometheus, "~> 4.0", [hex: :prometheus, repo: "hexpm", optional: false]}], "hexpm", "9fd13404a48437e044b288b41f76e64acd9735fb8b0e3809f494811dfa66d0fb"}, @@ -105,8 +109,8 @@ "remote_ip": {:hex, :remote_ip, "0.2.1", "cd27cd8ea54ecaaf3532776ff4c5e353b3804e710302e88c01eadeaaf42e7e24", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:inet_cidr, "~> 1.0", [hex: :inet_cidr, repo: "hexpm", optional: false]}, {:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "2e7ab1a461cc3cd5719f37e116a08f45c8b8493923063631b164315d6b7ee8e0"}, "rexbug": {:hex, :rexbug, "1.0.4", "b9908d95da835c7353ef051bc587662c9054fa3c0c11e96de9bad7fe18460aad", [:mix], [{:mix_test_watch, ">= 0.5.0", [hex: :mix_test_watch, repo: "hexpm", optional: true]}, {:redbug, "~> 1.2", [hex: :redbug, repo: "hexpm", optional: false]}], "hexpm", "4826565f39e617fa0eea3e916f02928b2f1d880bf5e084cb80da86a3e369390e"}, "san_exporter_ex": {:git, "https://github.com/santiment/san-exporter-ex.git", "afad951ca589fa6791c898f997e599511639c24c", []}, - "scrivener": {:hex, :scrivener, "2.3.0", "16b1d744202d47233798205447b35592d96a209241c566304f84ddef63c718b2", [:mix], [], "hexpm", "55f4e512175dd46c428acecf3306e7d2606cef886c1e4c6293d30b4499db7717"}, - "scrivener_ecto": {:hex, :scrivener_ecto, "1.2.3", "3255aee5cabfccedcb350f7e5f9f540fb72b8705a763612399264b11ae34faa9", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.11.0 or ~> 0.12.0 or ~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:scrivener, "~> 2.3", [hex: :scrivener, repo: "hexpm", optional: false]}], "hexpm", "dd8508d6e2b04229930229886bd391b46b9011077ea4b89e56a53478327a7557"}, + "scrivener": {:hex, :scrivener, "2.7.0", "fa94cdea21fad0649921d8066b1833d18d296217bfdf4a5389a2f45ee857b773", [:mix], [], "hexpm", "30da36a427f2519cf75993271fb7c5aad1759682a70f90d880a85c3d743d2c57"}, + "scrivener_ecto": {:hex, :scrivener_ecto, "2.3.0", "057f9dd3c77315f0a470263c3565353860d0294404aed611b3524c6df9044189", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:scrivener, "~> 2.4", [hex: :scrivener, repo: "hexpm", optional: false]}], "hexpm", "dfa43ca660651da63239e5d4acbfd9c57c5759bbf3a2bdc16cd70777c9bc7e0d"}, "sentry": {:hex, :sentry, "7.2.4", "b5bc90b594d40c2e653581e797a5fd2fdf994f2568f6bd66b7fa4971598be8d5", [:mix], [{:hackney, "~> 1.8 or 1.6.5", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm", "4ee4d368b5013076afcc8b73ed028bdc8ee9db84ea987e3591101e194c1fc24b"}, "snappyer": {:git, "https://github.com/zmstone/snappyer", "cd9001a9a881c50d2f116c2adbb1e620f4f8f4b6", [tag: "1.2.4"]}, "ssl_verify_fun": {:git, "https://github.com/deadtrickster/ssl_verify_fun.erl", "c5718226b0b9f3d1a38ef6ca3c3b4c75f53dda92", [tag: "1.1.4"]}, @@ -117,9 +121,8 @@ "sweet_xml": {:hex, :sweet_xml, "0.6.6", "fc3e91ec5dd7c787b6195757fbcf0abc670cee1e4172687b45183032221b66b8", [:mix], [], "hexpm", "2e1ec458f892ffa81f9f8386e3f35a1af6db7a7a37748a64478f13163a1f3573"}, "telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"}, "temp": {:hex, :temp, "0.4.7", "2c78482cc2294020a4bc0c95950b907ff386523367d4e63308a252feffbea9f2", [:mix], [], "hexpm", "6af19e7d6a85a427478be1021574d1ae2a1e1b90882586f06bde76c63cd03e0d"}, - "tesla": {:hex, :tesla, "1.3.3", "26ae98627af5c406584aa6755ab5fc96315d70d69a24dd7f8369cfcb75094a45", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2648f1c276102f9250299e0b7b57f3071c67827349d9173f34c281756a1b124c"}, + "tesla": {:hex, :tesla, "1.3.2", "deb92c5c9ce35e747a395ba413ca78593a4f75bf0e1545630ee2e3d34264021e", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7567704c4790e21bd9a961b56d0b6a988ff68cc4dacfe6b2106e258da1d5cdda"}, "timex": {:hex, :timex, "3.5.0", "b0a23167da02d0fe4f1a4e104d1f929a00d348502b52432c05de875d0b9cffa5", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "b8fd8c9fcfaef1fa9c415e0792e2e82783c7ec8a282dfceef7d48158d4cfb3e1"}, - "timex_ecto": {:hex, :timex_ecto, "3.3.0", "d5bdef09928e7a60f10a0baa47ce653f29b43d6fee87b30b236b216d0e36b98d", [:mix], [{:ecto, "~> 2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "c0584704a544090fd23b76a601f426182fd3601bfbf846fd66f75002a24a4798"}, "tzdata": {:hex, :tzdata, "0.5.22", "f2ba9105117ee0360eae2eca389783ef7db36d533899b2e84559404dbc77ebb8", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "cd66c8a1e6a9e121d1f538b01bef459334bb4029a1ffb4eeeb5e4eae0337e7b6"}, "unicode_util_compat": {:git, "https://github.com/benoitc/unicode_util_compat.git", "38d7bc105f51159e8ea3279c40121db9db1e652f", [tag: "0.3.1"]}, "uri_query": {:hex, :uri_query, "0.1.2", "ae35b83b472f3568c2c159eee3f3ccf585375d8a94fb5382db1ea3589e75c3b4", [:mix], [], "hexpm", "e3bc81816c98502c36498b9b2f239b89c71ce5eadfff7ceb2d6c0a2e6ae2ea0c"}, diff --git a/test/sanbase/billing/query_access_level_test.exs b/test/sanbase/billing/query_access_level_test.exs index e5a6be41b4..d57759f058 100644 --- a/test/sanbase/billing/query_access_level_test.exs +++ b/test/sanbase/billing/query_access_level_test.exs @@ -21,7 +21,6 @@ defmodule Sanbase.Billing.QueryAccessLevelTest do :news, :project, :historical_balance, - :elasticsearch_stats, :historical_trigger_points, :price_volume_diff, :assets_held_by_address, diff --git a/test/sanbase_web/graphql/elasticsearch/elasticsearch_stats_test.exs b/test/sanbase_web/graphql/elasticsearch/elasticsearch_stats_test.exs deleted file mode 100644 index d76d1ad3ff..0000000000 --- a/test/sanbase_web/graphql/elasticsearch/elasticsearch_stats_test.exs +++ /dev/null @@ -1,43 +0,0 @@ -defmodule SanbaseWeb.Graphql.ElasticsearchResolverTest do - use SanbaseWeb.ConnCase, async: false - - import SanbaseWeb.Graphql.TestHelpers - - test "elasticsearch successful stats", %{conn: conn} do - stats = - elasticsearch_stats_query(conn) - |> json_response(200) - - assert stats == %{ - "data" => %{ - "elasticsearchStats" => %{ - "averageDocumentsPerDay" => 33_333, - "documentsCount" => 1_000_000, - "sizeInMegabytes" => 5, - "subredditsCount" => 10, - "discordChannelsCount" => 6, - "telegramChannelsCount" => 5 - } - } - } - end - - defp elasticsearch_stats_query(conn) do - query = """ - { - elasticsearchStats( - from: "2018-09-01T00:00:00Z", - to: "2018-10-01T00:00:00Z"){ - documentsCount - averageDocumentsPerDay - telegramChannelsCount - subredditsCount - discordChannelsCount - sizeInMegabytes - } - } - """ - - conn |> post("/graphql", query_skeleton(query, "elasticsearchStats")) - end -end From 2d7402f4bc78d797396f09e98970b14e7d209330 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 21 May 2020 18:21:37 +0300 Subject: [PATCH 02/12] Use postgres adapter for ClickhouseRepo in test env. All clickhouse tests are done with mocks. The adapter is needed so a connection can be established and we do not get Repo not started error. The postgres db won't ever be queried from ClickhouseRepo --- config/test.exs | 5 +++++ lib/sanbase/application.ex | 2 +- lib/sanbase/clickhouse_repo.ex | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/test.exs b/config/test.exs index 691cbd25dd..97f337fb53 100644 --- a/config/test.exs +++ b/config/test.exs @@ -33,6 +33,11 @@ config :sanbase, Sanbase.Repo, database: "sanbase_test", pool_size: 5 +config :sanbase, Sanbase.ClickhouseRepo, + pool: Ecto.Adapters.SQL.Sandbox, + database: "sanbase_test", + pool_size: 5 + config :sanbase, Sanbase.Auth.Hmac, secret_key: "Non_empty_key_used_in_tests_only" config :sanbase, Sanbase.ExternalServices.Coinmarketcap, sync_enabled: false diff --git a/lib/sanbase/application.ex b/lib/sanbase/application.ex index 95be50c379..948415b60c 100644 --- a/lib/sanbase/application.ex +++ b/lib/sanbase/application.ex @@ -167,7 +167,7 @@ defmodule Sanbase.Application do Sanbase.Repo, # Start the Clickhouse Repo - start_in({Sanbase.ClickhouseRepo, []}, [:dev, :prod]), + start_in({Sanbase.ClickhouseRepo, []}, [:dev, :prod, :test]), # Time series Prices DB connection Sanbase.Prices.Store.child_spec(), diff --git a/lib/sanbase/clickhouse_repo.ex b/lib/sanbase/clickhouse_repo.ex index 134b7da61e..f0467ff9c2 100644 --- a/lib/sanbase/clickhouse_repo.ex +++ b/lib/sanbase/clickhouse_repo.ex @@ -1,5 +1,7 @@ defmodule Sanbase.ClickhouseRepo do - use Ecto.Repo, otp_app: :sanbase, adapter: ClickhouseEcto + # Clickhouse tests are done only through mocking the results. + @adapter if Mix.env() == :test, do: Ecto.Adapters.Postgres, else: ClickhouseEcto + use Ecto.Repo, otp_app: :sanbase, adapter: @adapter require Sanbase.Utils.Config, as: Config @@ -54,7 +56,7 @@ defmodule Sanbase.ClickhouseRepo do ordered_params = order_params(query, args) sanitized_query = sanitize_query(query) - Ecto.Adapters.SQL.query(__MODULE__, sanitized_query, ordered_params) + __MODULE__.query(sanitized_query, ordered_params) |> case do {:ok, result} -> {:ok, Enum.map(result.rows, transform_fn)} {:error, error} -> {:error, error} From 831142b30de49578caf020569ea5202feca51199 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Thu, 21 May 2020 18:22:45 +0300 Subject: [PATCH 03/12] Start reworking tests to migrate ClickhouseRepo from macros to plain functions --- .../sanbase/clickhouse/api_call_data_test.exs | 40 +++---- test/sanbase/clickhouse/gas_used_test.exs | 54 ++++----- .../erc20_assets_held_by_address_test.exs | 59 ++++------ .../eth_assets_held_by_address_test.exs | 45 +++----- .../miners_balance_test.exs | 96 ++++++---------- .../metric/clickhouse_metric_helper_test.exs | 19 ++-- .../mining_pools_distribution_test.exs | 107 ++++++------------ test/sanbase/clickhouse/top_holders_test.exs | 28 +++-- .../trending_words/trending_words_test.exs | 68 ++++++----- 9 files changed, 195 insertions(+), 321 deletions(-) diff --git a/test/sanbase/clickhouse/api_call_data_test.exs b/test/sanbase/clickhouse/api_call_data_test.exs index 0ccf3fcc55..8ce2f0b3ac 100644 --- a/test/sanbase/clickhouse/api_call_data_test.exs +++ b/test/sanbase/clickhouse/api_call_data_test.exs @@ -18,17 +18,14 @@ defmodule Sanbase.Clickhouse.ApiCallDataTest do dt2_str = "2019-01-02T00:00:00Z" dt3_str = "2019-01-03T00:00:00Z" - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!(dt1_str), 400], - [from_iso8601_to_unix!(dt2_str), 100], - [from_iso8601_to_unix!(dt3_str), 200] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!(dt1_str), 400], + [from_iso8601_to_unix!(dt2_str), 100], + [from_iso8601_to_unix!(dt3_str), 200] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = ApiCallData.api_call_history( context.user.id, @@ -44,17 +41,15 @@ defmodule Sanbase.Clickhouse.ApiCallDataTest do %{api_calls_count: 100, datetime: from_iso8601!(dt2_str)}, %{api_calls_count: 200, datetime: from_iso8601!(dt3_str)} ]} - end + end) end test "clickhouse returns empty list", context do dt1_str = "2019-01-01T00:00:00Z" dt2_str = "2019-01-03T00:00:00Z" - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, %{rows: []}} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = ApiCallData.api_call_history( context.user.id, @@ -63,19 +58,16 @@ defmodule Sanbase.Clickhouse.ApiCallDataTest do "1d" ) - assert result == - {:ok, []} - end + assert result == {:ok, []} + end) end test "clickhouse returns error", context do dt1_str = "2019-01-01T00:00:00Z" dt3_str = "2019-01-03T00:00:00Z" - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, "Something went wrong"} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "Something went wrong"}) + |> Sanbase.Mock.run_with_mocks(fn -> result = ApiCallData.api_call_history( context.user.id, @@ -86,6 +78,6 @@ defmodule Sanbase.Clickhouse.ApiCallDataTest do assert result == {:error, "Something went wrong"} - end + end) end end diff --git a/test/sanbase/clickhouse/gas_used_test.exs b/test/sanbase/clickhouse/gas_used_test.exs index bcec5b1218..e191b4cd06 100644 --- a/test/sanbase/clickhouse/gas_used_test.exs +++ b/test/sanbase/clickhouse/gas_used_test.exs @@ -16,17 +16,14 @@ defmodule Sanbase.Clickhouse.GasUsedTest do end test "when requested interval fits the values interval", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 101], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 102], - [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 103] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 101], + [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 102], + [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 103] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = GasUsed.gas_used(context.slug, context.from, context.to, context.interval) assert result == @@ -48,22 +45,19 @@ defmodule Sanbase.Clickhouse.GasUsedTest do datetime: from_iso8601!("2019-01-03T00:00:00Z") } ]} - end + end) end test "when requested interval is not full", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 101], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 102], - [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 103], - [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 104] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 101], + [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 102], + [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 103], + [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 104] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = GasUsed.gas_used(context.slug, context.from, context.to, "2d") assert result == @@ -90,19 +84,21 @@ defmodule Sanbase.Clickhouse.GasUsedTest do datetime: from_iso8601!("2019-01-04T00:00:00Z") } ]} - end + end) end test "returns empty array when query returns no rows", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = GasUsed.gas_used(context.slug, context.from, context.to, context.interval) assert result == {:ok, []} - end + end) end test "returns error when something except ethereum is requested", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = GasUsed.gas_used( "unsupported", @@ -112,6 +108,6 @@ defmodule Sanbase.Clickhouse.GasUsedTest do ) assert result == {:error, "Currently only ethereum is supported!"} - end + end) end end diff --git a/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs b/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs index 8ff2d88bec..44b4526e5a 100644 --- a/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs +++ b/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs @@ -18,28 +18,16 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.Erc20AssetsHeldByAdderssTest do end test "clickhouse returns list of results", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [ - context.p1.main_contract_address, - Sanbase.Math.ipow(10, context.p1.token_decimals) * 100 - ], - [ - context.p2.main_contract_address, - Sanbase.Math.ipow(10, context.p2.token_decimals) * 255 - ], - [context.p3.main_contract_address, 0], - [ - context.p4.main_contract_address, - Sanbase.Math.ipow(10, context.p4.token_decimals) * 1643 - ], - [context.p5.main_contract_address, 0] - ] - }} - end do + rows = [ + [context.p1.main_contract_address, Sanbase.Math.ipow(10, context.p1.token_decimals) * 100], + [context.p2.main_contract_address, Sanbase.Math.ipow(10, context.p2.token_decimals) * 255], + [context.p3.main_contract_address, 0], + [context.p4.main_contract_address, Sanbase.Math.ipow(10, context.p4.token_decimals) * 1643], + [context.p5.main_contract_address, 0] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> assert Erc20Balance.assets_held_by_address("0x123") == {:ok, [ @@ -49,29 +37,20 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.Erc20AssetsHeldByAdderssTest do %{balance: 1643, slug: context.p4.slug}, %{balance: 0.0, slug: context.p5.slug} ]} - end + end) end test "clickhouse returns no results", _context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [] - }} - end do - assert Erc20Balance.assets_held_by_address("0x123") == - {:ok, []} - end + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> + assert Erc20Balance.assets_held_by_address("0x123") == {:ok, []} + end) end test "clickhouse returns error", _context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, "Cannot execute query due to error"} - end do - assert Erc20Balance.assets_held_by_address("0x123") == - {:error, "Cannot execute query due to error"} - end + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "error"}) + |> Sanbase.Mock.run_with_mocks(fn -> + assert Erc20Balance.assets_held_by_address("0x123") == {:error, "error"} + end) end end diff --git a/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs b/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs index fb2880db20..9596e56e3f 100644 --- a/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs +++ b/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs @@ -15,43 +15,26 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.EthAssetsHeldByAdderssTest do end test "clickhouse returns list of results", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [1000 * Sanbase.Math.ipow(10, 18)] - ] - }} - end do + rows = [[1000 * Sanbase.Math.ipow(10, 18)]] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> assert EthBalance.assets_held_by_address("0x123") == - {:ok, - [ - %{balance: 1000, slug: context.project.slug} - ]} - end + {:ok, [%{balance: 1000, slug: context.project.slug}]} + end) end test "clickhouse returns no results", _context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [] - }} - end do - assert EthBalance.assets_held_by_address("0x123") == - {:ok, []} - end + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> + assert EthBalance.assets_held_by_address("0x123") == {:ok, []} + end) end test "clickhouse returns error", _context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, "Cannot execute query due to error"} - end do - assert EthBalance.assets_held_by_address("0x123") == - {:error, "Cannot execute query due to error"} - end + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "error"}) + |> Sanbase.Mock.run_with_mocks(fn -> + assert EthBalance.assets_held_by_address("0x123") == {:error, "error"} + end) end end diff --git a/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs b/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs index c3bb1e712e..06064d0150 100644 --- a/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs +++ b/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs @@ -14,91 +14,63 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.MinersBalanceTest do end test "works for intervals in days", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 100_000], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 200_000], - [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 300_000], - [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 400_000] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 100_000], + [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 200_000], + [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 300_000], + [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 400_000] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MinersBalance.historical_balance(context.slug, context.from, context.to, "1d") assert result == {:ok, [ - %{ - balance: 100_000, - datetime: from_iso8601!("2019-01-01T00:00:00Z") - }, - %{ - balance: 200_000, - datetime: from_iso8601!("2019-01-02T00:00:00Z") - }, - %{ - balance: 300_000, - datetime: from_iso8601!("2019-01-03T00:00:00Z") - }, - %{ - balance: 400_000, - datetime: from_iso8601!("2019-01-04T00:00:00Z") - } + %{balance: 100_000, datetime: ~U[2019-01-01T00:00:00Z]}, + %{balance: 200_000, datetime: ~U[2019-01-02T00:00:00Z]}, + %{balance: 300_000, datetime: ~U[2019-01-03T00:00:00Z]}, + %{balance: 400_000, datetime: ~U[2019-01-04T00:00:00Z]} ]} - end + end) end test "works for intervals in hours", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 100_000], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 200_000], - [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 300_000], - [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 400_000] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 100_000], + [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 200_000], + [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 300_000], + [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 400_000] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MinersBalance.historical_balance(context.slug, context.from, context.to, "24h") assert result == {:ok, [ - %{ - balance: 100_000, - datetime: from_iso8601!("2019-01-01T00:00:00Z") - }, - %{ - balance: 200_000, - datetime: from_iso8601!("2019-01-02T00:00:00Z") - }, - %{ - balance: 300_000, - datetime: from_iso8601!("2019-01-03T00:00:00Z") - }, - %{ - balance: 400_000, - datetime: from_iso8601!("2019-01-04T00:00:00Z") - } + %{balance: 100_000, datetime: ~U[2019-01-01T00:00:00Z]}, + %{balance: 200_000, datetime: ~U[2019-01-02T00:00:00Z]}, + %{balance: 300_000, datetime: ~U[2019-01-03T00:00:00Z]}, + %{balance: 400_000, datetime: ~U[2019-01-04T00:00:00Z]} ]} - end + end) end test "returns empty array when query returns no rows", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MinersBalance.historical_balance(context.slug, context.from, context.to, "1d") assert result == {:ok, []} - end + end) end test "returns error when something except ethereum is requested", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MinersBalance.historical_balance( "unsupported", @@ -108,6 +80,6 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.MinersBalanceTest do ) assert result == {:error, "Currently only ethereum is supported!"} - end + end) end end diff --git a/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs b/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs index e1b147a268..84abae7cdc 100644 --- a/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs +++ b/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs @@ -4,20 +4,17 @@ defmodule Sanbase.Clickhouse.Metric.HelperTest do import Mock test "metric id to name map" do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [1, "daily_active_addresses"], - [2, "nvt"] - ] - }} - end do + rows = [ + [1, "daily_active_addresses"], + [2, "nvt"] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> {:ok, map} = Sanbase.Clickhouse.MetadataHelper.metric_name_to_metric_id_map() assert {"daily_active_addresses", 1} in map assert {"nvt", 2} in map - end + end) end end diff --git a/test/sanbase/clickhouse/mining_pools_distribution_test.exs b/test/sanbase/clickhouse/mining_pools_distribution_test.exs index a525fb01e7..31a3a06c34 100644 --- a/test/sanbase/clickhouse/mining_pools_distribution_test.exs +++ b/test/sanbase/clickhouse/mining_pools_distribution_test.exs @@ -8,24 +8,21 @@ defmodule Sanbase.Clickhouse.MiningPoolsDistributionTest do setup do [ slug: "ethereum", - from: from_iso8601!("2019-01-01T00:00:00Z"), - to: from_iso8601!("2019-01-03T00:00:00Z"), + from: ~U[2019-01-01T00:00:00Z], + to: ~U[2019-01-03T00:00:00Z], interval: "1d" ] end test "when requested interval fits the values interval", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 0.10, 0.40, 0.50], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 0.20, 0.30, 0.50], - [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 0.30, 0.20, 0.50] - ] - }} - end do + rows = [ + [~U[2019-01-01T00:00:00Z] |> DateTime.to_unix(), 0.10, 0.40, 0.50], + [~U[2019-01-02T00:00:00Z] |> DateTime.to_unix(), 0.20, 0.30, 0.50], + [~U[2019-01-03T00:00:00Z] |> DateTime.to_unix(), 0.30, 0.20, 0.50] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MiningPoolsDistribution.distribution( context.slug, @@ -37,76 +34,39 @@ defmodule Sanbase.Clickhouse.MiningPoolsDistributionTest do assert result == {:ok, [ - %{ - top3: 0.10, - top10: 0.40, - other: 0.50, - datetime: from_iso8601!("2019-01-01T00:00:00Z") - }, - %{ - top3: 0.20, - top10: 0.30, - other: 0.50, - datetime: from_iso8601!("2019-01-02T00:00:00Z") - }, - %{ - top3: 0.30, - top10: 0.20, - other: 0.50, - datetime: from_iso8601!("2019-01-03T00:00:00Z") - } + %{top3: 0.10, top10: 0.40, other: 0.50, datetime: ~U[2019-01-01T00:00:00Z]}, + %{top3: 0.20, top10: 0.30, other: 0.50, datetime: ~U[2019-01-02T00:00:00Z]}, + %{top3: 0.30, top10: 0.20, other: 0.50, datetime: ~U[2019-01-03T00:00:00Z]} ]} - end + end) end test "when requested interval is not full", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 0.10, 0.40, 0.50], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 0.20, 0.30, 0.50], - [from_iso8601_to_unix!("2019-01-03T00:00:00Z"), 0.30, 0.20, 0.50], - [from_iso8601_to_unix!("2019-01-04T00:00:00Z"), 0.40, 0.10, 0.50] - ] - }} - end do + rows = [ + [~U[2019-01-01T00:00:00Z] |> DateTime.to_unix(), 0.10, 0.40, 0.50], + [~U[2019-01-02T00:00:00Z] |> DateTime.to_unix(), 0.20, 0.30, 0.50], + [~U[2019-01-03T00:00:00Z] |> DateTime.to_unix(), 0.30, 0.20, 0.50], + [~U[2019-01-04T00:00:00Z] |> DateTime.to_unix(), 0.40, 0.10, 0.50] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MiningPoolsDistribution.distribution(context.slug, context.from, context.to, "2d") assert result == {:ok, [ - %{ - top3: 0.10, - top10: 0.40, - other: 0.50, - datetime: from_iso8601!("2019-01-01T00:00:00Z") - }, - %{ - top3: 0.20, - top10: 0.30, - other: 0.50, - datetime: from_iso8601!("2019-01-02T00:00:00Z") - }, - %{ - top3: 0.30, - top10: 0.20, - other: 0.50, - datetime: from_iso8601!("2019-01-03T00:00:00Z") - }, - %{ - top3: 0.40, - top10: 0.10, - other: 0.50, - datetime: from_iso8601!("2019-01-04T00:00:00Z") - } + %{top3: 0.10, top10: 0.40, other: 0.50, datetime: ~U[2019-01-01T00:00:00Z]}, + %{top3: 0.20, top10: 0.30, other: 0.50, datetime: ~U[2019-01-02T00:00:00Z]}, + %{top3: 0.30, top10: 0.20, other: 0.50, datetime: ~U[2019-01-03T00:00:00Z]}, + %{top3: 0.40, top10: 0.10, other: 0.50, datetime: ~U[2019-01-04T00:00:00Z]} ]} - end + end) end test "returns empty array when query returns no rows", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MiningPoolsDistribution.distribution( context.slug, @@ -116,11 +76,12 @@ defmodule Sanbase.Clickhouse.MiningPoolsDistributionTest do ) assert result == {:ok, []} - end + end) end test "returns error when something except ethereum is requested", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = MiningPoolsDistribution.distribution( "unsupported", @@ -130,6 +91,6 @@ defmodule Sanbase.Clickhouse.MiningPoolsDistributionTest do ) assert result == {:error, "Currently only ethereum is supported!"} - end + end) end end diff --git a/test/sanbase/clickhouse/top_holders_test.exs b/test/sanbase/clickhouse/top_holders_test.exs index 38159e6f64..975c3d3b16 100644 --- a/test/sanbase/clickhouse/top_holders_test.exs +++ b/test/sanbase/clickhouse/top_holders_test.exs @@ -21,16 +21,13 @@ defmodule Sanbase.Clickhouse.TopHoldersTest do end test "returns data when clickhouse returns", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 7.6, 5.2, 12.8], - [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 7.1, 5.1, 12.2] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!("2019-01-01T00:00:00Z"), 7.6, 5.2, 12.8], + [from_iso8601_to_unix!("2019-01-02T00:00:00Z"), 7.1, 5.1, 12.2] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TopHolders.percent_of_total_supply( context.contract, @@ -48,20 +45,21 @@ defmodule Sanbase.Clickhouse.TopHoldersTest do in_exchanges: 7.6, outside_exchanges: 5.2, in_top_holders_total: 12.8, - datetime: from_iso8601!("2019-01-01T00:00:00Z") + datetime: ~U[2019-01-01T00:00:00Z] }, %{ in_exchanges: 7.1, outside_exchanges: 5.1, in_top_holders_total: 12.2, - datetime: from_iso8601!("2019-01-02T00:00:00Z") + datetime: ~U[2019-01-02T00:00:00Z] } ]} - end + end) end test "returns empty array when query returns no rows", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TopHolders.percent_of_total_supply( context.contract, @@ -73,6 +71,6 @@ defmodule Sanbase.Clickhouse.TopHoldersTest do ) assert result == {:ok, []} - end + end) end end diff --git a/test/sanbase/social_data/trending_words/trending_words_test.exs b/test/sanbase/social_data/trending_words/trending_words_test.exs index 8cea915eb1..5a9debec9c 100644 --- a/test/sanbase/social_data/trending_words/trending_words_test.exs +++ b/test/sanbase/social_data/trending_words/trending_words_test.exs @@ -18,11 +18,10 @@ defmodule Sanbase.SocialData.TrendingWordsTest do describe "get trending words for time interval" do test "clickhouse returns data", context do %{dt1_str: dt1_str, dt2_str: dt2_str, dt3_str: dt3_str} = context + rows = trending_words_rows(dt1_str, dt2_str, dt3_str) - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, %{rows: trending_words_rows(dt1_str, dt2_str, dt3_str)}} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_trending_words( from_iso8601!(dt1_str), @@ -47,14 +46,14 @@ defmodule Sanbase.SocialData.TrendingWordsTest do %{score: 1, word: "eth"} ] }} - end + end) end test "clickhouse returns error", context do %{dt1_str: dt1_str, dt3_str: dt3_str} = context - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> {:error, "Something went wrong"} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "error"}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_trending_words( from_iso8601!(dt1_str), @@ -63,43 +62,41 @@ defmodule Sanbase.SocialData.TrendingWordsTest do 2 ) - assert result == {:error, "Something went wrong"} - end + assert result == {:error, "error"} + end) end end describe "get currently trending words" do test "clickhouse returns data", context do %{dt1_str: dt1_str, dt2_str: dt2_str, dt3_str: dt3_str} = context + rows = trending_words_rows(dt1_str, dt2_str, dt3_str) - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, %{rows: trending_words_rows(dt1_str, dt2_str, dt3_str)}} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_currently_trending_words() assert result == {:ok, [%{score: 2, word: "xrp"}, %{score: 1, word: "eth"}]} - end + end) end test "clickhouse returns error", _context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> {:error, "Something went wrong"} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "error"}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_currently_trending_words() - assert result == {:error, "Something went wrong"} - end + assert result == {:error, "error"} + end) end end describe "get word trending history stats" do test "clickhouse returns data", context do %{dt1_str: dt1_str, dt2_str: dt2_str, dt3_str: dt3_str} = context + rows = word_trending_history_rows(dt1_str, dt2_str, dt3_str) - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, %{rows: word_trending_history_rows(dt1_str, dt2_str, dt3_str)}} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_word_trending_history( "word", @@ -115,14 +112,14 @@ defmodule Sanbase.SocialData.TrendingWordsTest do %{datetime: from_iso8601!(dt1_str), position: 10}, %{datetime: from_iso8601!(dt2_str), position: 1} ]} - end + end) end test "clickhouse returns error", context do %{dt1_str: dt1_str, dt2_str: dt2_str} = context - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> {:error, "Something went wrong"} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "error"}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_word_trending_history( "word", @@ -132,8 +129,8 @@ defmodule Sanbase.SocialData.TrendingWordsTest do 10 ) - assert result == {:error, "Something went wrong"} - end + assert result == {:error, "error"} + end) end end @@ -142,11 +139,10 @@ defmodule Sanbase.SocialData.TrendingWordsTest do %{dt1_str: dt1_str, dt2_str: dt2_str, dt3_str: dt3_str} = context project = insert(:random_project) + rows = project_trending_history_rows(dt1_str, dt2_str, dt3_str) - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, %{rows: project_trending_history_rows(dt1_str, dt2_str, dt3_str)}} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_project_trending_history( project.slug, @@ -162,15 +158,15 @@ defmodule Sanbase.SocialData.TrendingWordsTest do %{datetime: from_iso8601!(dt1_str), position: 5}, %{datetime: from_iso8601!(dt3_str), position: 10} ]} - end + end) end test "clickhouse returns error", context do %{dt1_str: dt1_str, dt2_str: dt2_str} = context project = insert(:random_project) - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> {:error, "Something went wrong"} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "error"}) + |> Sanbase.Mock.run_with_mocks(fn -> result = TrendingWords.get_project_trending_history( project.slug, @@ -180,8 +176,8 @@ defmodule Sanbase.SocialData.TrendingWordsTest do 10 ) - assert result == {:error, "Something went wrong"} - end + assert result == {:error, "error"} + end) end end From 3ea1248260e551a4d8848aa6bc1b6c9aa81640b5 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 22 May 2020 11:58:50 +0300 Subject: [PATCH 04/12] Rework tests --- config/config.exs | 3 +- lib/sanbase/billing/graphql_schema.ex | 6 +- lib/sanbase/comments/comment.ex | 6 +- lib/sanbase/comments/entity_comment.ex | 4 +- lib/sanbase/signals/evaluator/scheduler.ex | 2 +- .../graphql/middlewares/access_control.ex | 10 +- test/sanbase/statistics/statistics_test.exs | 8 +- .../graphql/clickhouse/exchanges_test.exs | 21 ++- .../historical_balances_test.exs | 142 ++++++++---------- .../dev_activity/dev_activity_api_test.exs | 16 +- .../project_api_eth_spent_over_time_test.exs | 71 +++------ .../projects/project_api_eth_spent_test.exs | 128 +++++++--------- 12 files changed, 176 insertions(+), 241 deletions(-) diff --git a/config/config.exs b/config/config.exs index 77ecc77ef7..f76c773710 100644 --- a/config/config.exs +++ b/config/config.exs @@ -51,7 +51,8 @@ config :sanbase, Sanbase.Repo, pool_size: {:system, "SANBASE_POOL_SIZE", "20"}, max_overflow: 5, # because of pgbouncer - prepare: :unnamed + prepare: :unnamed, + migration_timestamps: [type: :naive_datetime_usec] config :sanbase, Sanbase.Auth.Hmac, secret_key: {:system, "APIKEY_HMAC_SECRET_KEY", nil} diff --git a/lib/sanbase/billing/graphql_schema.ex b/lib/sanbase/billing/graphql_schema.ex index afdf9ba440..b65e1e7958 100644 --- a/lib/sanbase/billing/graphql_schema.ex +++ b/lib/sanbase/billing/graphql_schema.ex @@ -9,10 +9,8 @@ defmodule Sanbase.Billing.GraphqlSchema do require SanbaseWeb.Graphql.Schema - # @query_type Absinthe.Schema.lookup_type(SanbaseWeb.Graphql.Schema, :query) - # @fields @query_type.fields |> Map.keys() - @query_type %{fields: []} - @fields [] + @query_type Absinthe.Schema.lookup_type(SanbaseWeb.Graphql.Schema, :query) + @fields @query_type.fields |> Map.keys() @doc ~s""" Return a map of {query, product_id} key-value pairs. The key is a query that diff --git a/lib/sanbase/comments/comment.ex b/lib/sanbase/comments/comment.ex index acb116f76c..c7ad044ccc 100644 --- a/lib/sanbase/comments/comment.ex +++ b/lib/sanbase/comments/comment.ex @@ -194,7 +194,7 @@ defmodule Sanbase.Comment do defp multi_run(multi, :select_root_parent_id, %{parent_id: parent_id}) do multi - |> Ecto.Multi.run(:select_root_parent_id, fn _ -> + |> Ecto.Multi.run(:select_root_parent_id, fn _repo, _changes -> root_parent_id = from(c in __MODULE__, where: c.id == ^parent_id, select: c.root_parent_id) |> Repo.one() @@ -211,7 +211,7 @@ defmodule Sanbase.Comment do multi |> Ecto.Multi.run( :create_new_comment, - fn %{select_root_parent_id: parent_root_parent_id} -> + fn _repo, %{select_root_parent_id: parent_root_parent_id} -> # Handle all case: If the parent has a parent_root_id - inherit it # If the parent does not have it - then the parent is a top level comment # and the current parent_root_id should be se to parent_id @@ -233,7 +233,7 @@ defmodule Sanbase.Comment do multi |> Ecto.Multi.run( :update_subcomments_count, - fn %{create_new_comment: %__MODULE__{root_parent_id: root_id}} -> + fn _repo, %{create_new_comment: %__MODULE__{root_parent_id: root_id}} -> {:ok, _} = update_subcomments_counts(root_id) {:ok, "Updated all subcomment counts in the tree"} end diff --git a/lib/sanbase/comments/entity_comment.ex b/lib/sanbase/comments/entity_comment.ex index 24cf6a1902..6d07392771 100644 --- a/lib/sanbase/comments/entity_comment.ex +++ b/lib/sanbase/comments/entity_comment.ex @@ -26,10 +26,10 @@ defmodule Sanbase.Comments.EntityComment do Ecto.Multi.new() |> Ecto.Multi.run( :create_comment, - fn _changes -> Comment.create(user_id, content, parent_id) end + fn _repo, _changes -> Comment.create(user_id, content, parent_id) end ) |> Ecto.Multi.run(:link_comment_and_entity, fn - %{create_comment: comment} -> + _repo, %{create_comment: comment} -> link(entity, entity_id, comment.id) end) |> Repo.transaction() diff --git a/lib/sanbase/signals/evaluator/scheduler.ex b/lib/sanbase/signals/evaluator/scheduler.ex index bb183e7825..a53ddf802e 100644 --- a/lib/sanbase/signals/evaluator/scheduler.ex +++ b/lib/sanbase/signals/evaluator/scheduler.ex @@ -142,7 +142,7 @@ defmodule Sanbase.Signal.Scheduler do user_trigger_id: id, user_id: user_id, payload: payload, - triggered_at: max_last_triggered(last_triggered), + triggered_at: max_last_triggered(last_triggered) |> DateTime.to_naive(), data: %{user_trigger_data: identifier_kv_map} } diff --git a/lib/sanbase_web/graphql/middlewares/access_control.ex b/lib/sanbase_web/graphql/middlewares/access_control.ex index 9d42186017..998e4a4c42 100644 --- a/lib/sanbase_web/graphql/middlewares/access_control.ex +++ b/lib/sanbase_web/graphql/middlewares/access_control.ex @@ -150,6 +150,7 @@ defmodule SanbaseWeb.Graphql.Middlewares.AccessControl do middleware_args ) do if Plan.AccessChecker.is_restricted?(query) do + IO.inspect("#{inspect(query)} IS RESTRICTED????") restricted_query(resolution, middleware_args, query) else not_restricted_query(resolution, middleware_args) @@ -253,7 +254,9 @@ defmodule SanbaseWeb.Graphql.Middlewares.AccessControl do defp check_from_to_params(%Resolution{} = resolution), do: resolution defp check_from_to_both_outside(%Resolution{state: :resolved} = resolution), do: resolution - defp check_from_to_both_outside(%Resolution{arguments: %{from: from, to: to}} = resolution) do + defp check_from_to_both_outside( + %Resolution{arguments: %{from: from, to: to}, context: context} = resolution + ) do case to_param_is_after_from(from, to) do true -> resolution @@ -267,7 +270,10 @@ defmodule SanbaseWeb.Graphql.Middlewares.AccessControl do {:error, """ Both `from` and `to` parameters are outside the allowed interval - you can query with your current subscription plan. + you can query with your current subscription plan #{context[:auth][:plan] || :free}. + + `from` resolved to: #{from} + `to` resolved to: #{to} """} ) end diff --git a/test/sanbase/statistics/statistics_test.exs b/test/sanbase/statistics/statistics_test.exs index 24942a1fca..c7cce29d34 100644 --- a/test/sanbase/statistics/statistics_test.exs +++ b/test/sanbase/statistics/statistics_test.exs @@ -129,8 +129,10 @@ defmodule Sanbase.StatisticsTest do end test "active users statistics" do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> {:ok, %{rows: [3]}} end do + rows = [3] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> statistics = Sanbase.Statistics.get_all() assert {"active_users", @@ -140,7 +142,7 @@ defmodule Sanbase.StatisticsTest do "active_users_in_last_7d" => 3, "active_users_in_last_30d" => 3 }} in statistics - end + end) end test "returns the number of users, which are subscribed" do diff --git a/test/sanbase_web/graphql/clickhouse/exchanges_test.exs b/test/sanbase_web/graphql/clickhouse/exchanges_test.exs index bbe5a649f8..783065ad7b 100644 --- a/test/sanbase_web/graphql/clickhouse/exchanges_test.exs +++ b/test/sanbase_web/graphql/clickhouse/exchanges_test.exs @@ -46,17 +46,14 @@ defmodule SanbaseWeb.Graphql.ExchangesTest do end test "test fetching volume for exchange", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [from_iso8601_to_unix!("2017-05-13T00:00:00Z"), 2000, 1000], - [from_iso8601_to_unix!("2017-05-15T00:00:00Z"), 1800, 1300], - [from_iso8601_to_unix!("2017-05-18T00:00:00Z"), 1000, 1100] - ] - }} - end do + rows = [ + [from_iso8601_to_unix!("2017-05-13T00:00:00Z"), 2000, 1000], + [from_iso8601_to_unix!("2017-05-15T00:00:00Z"), 1800, 1300], + [from_iso8601_to_unix!("2017-05-18T00:00:00Z"), 1000, 1100] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = exchange_volume_query( context.exchange, @@ -88,7 +85,7 @@ defmodule SanbaseWeb.Graphql.ExchangesTest do "exchange_outflow" => 1100 } ] - end + end) end describe "#exchangeMarketPairToSlugs" do diff --git a/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs b/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs index 0bc8af70cd..a568c3b26b 100644 --- a/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs +++ b/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs @@ -1,6 +1,7 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do use SanbaseWeb.ConnCase, async: false + import Sanbase.TestHelpers import SanbaseWeb.Graphql.TestHelpers import Mock import Sanbase.DateTimeUtils, only: [from_iso8601!: 1] @@ -87,35 +88,25 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do end test "historical balances when interval is bigger than balances values interval", context do - dt1 = DateTimeUtils.from_iso8601!("2017-05-11T00:00:00Z") |> DateTime.to_unix() - dt2 = DateTimeUtils.from_iso8601!("2017-05-12T00:00:00Z") |> DateTime.to_unix() - dt3 = DateTimeUtils.from_iso8601!("2017-05-13T00:00:00Z") |> DateTime.to_unix() - dt4 = DateTimeUtils.from_iso8601!("2017-05-14T00:00:00Z") |> DateTime.to_unix() - dt5 = DateTimeUtils.from_iso8601!("2017-05-15T00:00:00Z") |> DateTime.to_unix() - dt6 = DateTimeUtils.from_iso8601!("2017-05-16T00:00:00Z") |> DateTime.to_unix() - dt7 = DateTimeUtils.from_iso8601!("2017-05-17T00:00:00Z") |> DateTime.to_unix() - dt8 = DateTimeUtils.from_iso8601!("2017-05-18T00:00:00Z") |> DateTime.to_unix() - dt9 = DateTimeUtils.from_iso8601!("2017-05-19T00:00:00Z") |> DateTime.to_unix() - dt10 = DateTimeUtils.from_iso8601!("2017-05-20T00:00:00Z") |> DateTime.to_unix() - - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [dt1, 0, 1], - [dt2, 0, 1], - [dt3, 2000 * @eth_decimals, 1], - [dt4, 1800 * @eth_decimals, 1], - [dt5, 0, 0], - [dt6, 1500 * @eth_decimals, 1], - [dt7, 1900 * @eth_decimals, 1], - [dt8, 1000 * @eth_decimals, 1], - [dt9, 0, 0], - [dt10, 0, 0] - ] - }} - end do + [dt1, dt2, dt3, dt4, dt5, dt6, dt7, dt8, dt9, dt10] = + generate_datetimes(~U[2017-05-11T00:00:00Z], "1d", 10) + |> Enum.map(&DateTime.to_unix/1) + + rows = [ + [dt1, 0, 1], + [dt2, 0, 1], + [dt3, 2000 * @eth_decimals, 1], + [dt4, 1800 * @eth_decimals, 1], + [dt5, 0, 0], + [dt6, 1500 * @eth_decimals, 1], + [dt7, 1900 * @eth_decimals, 1], + [dt8, 1000 * @eth_decimals, 1], + [dt9, 0, 0], + [dt10, 0, 0] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> selector = %{infrastructure: "ETH", slug: "ethereum"} query = @@ -145,27 +136,24 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do %{"balance" => 1000.0, "datetime" => "2017-05-19T00:00:00Z"}, %{"balance" => 1000.0, "datetime" => "2017-05-20T00:00:00Z"} ] - end + end) end test "historical balances when last interval is not full", context do - dt1 = DateTimeUtils.from_iso8601!("2017-05-13T00:00:00Z") |> DateTime.to_unix() - dt2 = DateTimeUtils.from_iso8601!("2017-05-15T00:00:00Z") |> DateTime.to_unix() - dt3 = DateTimeUtils.from_iso8601!("2017-05-17T00:00:00Z") |> DateTime.to_unix() + [dt1, dt2, dt3] = + generate_datetimes(~U[2017-05-13T00:00:00Z], "2d", 3) + |> Enum.map(&DateTime.to_unix/1) + + rows = [ + [dt1, 2000 * @eth_decimals, 1], + [dt2, 1800 * @eth_decimals, 1], + [dt3, 1400 * @eth_decimals, 1] + ] - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [dt1, 2000 * @eth_decimals, 1], - [dt2, 1800 * @eth_decimals, 1], - [dt3, 1400 * @eth_decimals, 1] - ] - }} - end do - from = from_iso8601!("2017-05-13T00:00:00Z") - to = from_iso8601!("2017-05-18T00:00:00Z") + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> + from = ~U[2017-05-13T00:00:00Z] + to = ~U[2017-05-18T00:00:00Z] selector = %{infrastructure: "ETH", slug: "ethereum"} query = historical_balances_query(selector, context.address, from, to, "2d") @@ -181,14 +169,14 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do %{"balance" => 1800.0, "datetime" => "2017-05-15T00:00:00Z"}, %{"balance" => 1400.0, "datetime" => "2017-05-17T00:00:00Z"} ] - end + end) end test "historical balances when query returns error", context do - error = "Some error description here" + error = "Something went wrong" - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> {:error, error} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, error}) + |> Sanbase.Mock.run_with_mocks(fn -> selector = %{infrastructure: "ETH", slug: "ethereum"} query = @@ -215,11 +203,12 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do "Can't fetch Historical Balances for selector: #{inspect(selector)}, Reason: #{ inspect(error) }" - end + end) end test "historical balances when query returns no rows", context do - with_mock Sanbase.ClickhouseRepo, query: fn _, _ -> {:ok, %{rows: []}} end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> selector = %{infrastructure: "ETH", slug: "ethereum"} query = @@ -237,28 +226,29 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do historical_balance = json_response(result, 200)["data"]["historicalBalance"] assert historical_balance == [] - end + end) end test "historical balances with project with contract", context do - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [~U[2017-05-11 00:00:00Z] |> DateTime.to_unix(), 0, 1], - [~U[2017-05-12 00:00:00Z] |> DateTime.to_unix(), 0, 1], - [~U[2017-05-13 00:00:00Z] |> DateTime.to_unix(), :math.pow(10, 18) * 2000, 1], - [~U[2017-05-14 00:00:00Z] |> DateTime.to_unix(), :math.pow(10, 18) * 1800, 1], - [~U[2017-05-15 00:00:00Z] |> DateTime.to_unix(), 0, 0], - [~U[2017-05-16 00:00:00Z] |> DateTime.to_unix(), :math.pow(10, 18) * 1500, 1], - [~U[2017-05-17 00:00:00Z] |> DateTime.to_unix(), :math.pow(10, 18) * 1900, 1], - [~U[2017-05-18 00:00:00Z] |> DateTime.to_unix(), :math.pow(10, 18) * 1000, 1], - [~U[2017-05-19 00:00:00Z] |> DateTime.to_unix(), 0, 0], - [~U[2017-05-20 00:00:00Z] |> DateTime.to_unix(), 0, 0] - ] - }} - end do + [dt1, dt2, dt3, dt4, dt5, dt6, dt7, dt8, dt9, dt10] = + generate_datetimes(~U[2017-05-11T00:00:00Z], "1d", 10) + |> Enum.map(&DateTime.to_unix/1) + + rows = [ + [dt1, 0, 1], + [dt2, 0, 1], + [dt3, :math.pow(10, 18) * 2000, 1], + [dt4, :math.pow(10, 18) * 1800, 1], + [dt5, 0, 0], + [dt6, :math.pow(10, 18) * 1500, 1], + [dt7, :math.pow(10, 18) * 1900, 1], + [dt8, :math.pow(10, 18) * 1000, 1], + [dt9, 0, 0], + [dt10, 0, 0] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> selector = %{infrastructure: "ETH", slug: context.project_with_contract.slug} query = @@ -289,7 +279,7 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do %{"balance" => 1000.0, "datetime" => "2017-05-19T00:00:00Z"}, %{"balance" => 1000.0, "datetime" => "2017-05-20T00:00:00Z"} ] - end + end) end test "historical balances with project without contract", context do @@ -326,10 +316,8 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do test "historical balances when clickhouse returns error", context do error = "Something bad happened" - with_mock Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, error} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, error}) + |> Sanbase.Mock.run_with_mocks(fn -> selector = %{infrastructure: "ETH", slug: context.project_with_contract.slug} query = @@ -355,7 +343,7 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do end) assert log =~ "Can't fetch Historical Balances for selector" - end + end) end defp historical_balances_query(selector, address, from, to, interval) do diff --git a/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs b/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs index fe72764185..0594d58c19 100644 --- a/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs +++ b/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs @@ -24,23 +24,15 @@ defmodule SanbaseWeb.Graphql.ProjectApiGithubTest do market_segments: [market_segment] }) - project3 = - insert(:random_project, %{ - github_organizations: [], - market_segments: [] - }) - - dt1 = "2019-01-01T00:00:00Z" |> from_iso8601!() - dt2 = "2019-01-02T00:00:00Z" |> from_iso8601!() - dt3 = "2019-01-03T00:00:00Z" |> from_iso8601!() + project3 = insert(:random_project, %{github_organizations: [], market_segments: []}) %{ project1: project1, project2: project2, project3: project3, - dt1: dt1, - dt2: dt2, - dt3: dt3, + dt1: ~U[2019-01-01T00:00:00Z], + dt2: ~U[2019-01-02T00:00:00Z], + dt3: ~U[2019-01-03T00:00:00Z], market_segment: market_segment, market_segment_without_projects: market_segment_without_projects } diff --git a/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs b/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs index 731eb14d28..c6c63ff6b3 100644 --- a/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs +++ b/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs @@ -2,6 +2,7 @@ defmodule SanbaseWeb.Graphql.ProjectApiEthSpentOverTimeTest do use SanbaseWeb.ConnCase, async: false import Mock + import Sanbase.TestHelpers import SanbaseWeb.Graphql.TestHelpers import Sanbase.Factory @@ -25,27 +26,20 @@ defmodule SanbaseWeb.Graphql.ProjectApiEthSpentOverTimeTest do end test "project eth spent over time", context do - dt1 = DateTimeUtils.from_iso8601!("2017-05-13T00:00:00Z") |> DateTime.to_unix() - dt2 = DateTimeUtils.from_iso8601!("2017-05-14T00:00:00Z") |> DateTime.to_unix() - dt3 = DateTimeUtils.from_iso8601!("2017-05-15T00:00:00Z") |> DateTime.to_unix() - dt4 = DateTimeUtils.from_iso8601!("2017-05-16T00:00:00Z") |> DateTime.to_unix() - dt5 = DateTimeUtils.from_iso8601!("2017-05-17T00:00:00Z") |> DateTime.to_unix() - dt6 = DateTimeUtils.from_iso8601!("2017-05-18T00:00:00Z") |> DateTime.to_unix() + [dt1, dt2, dt3, dt4, dt5, dt6] = + generate_datetimes(~U[2017-05-13T00:00:00Z], "1d", 6) |> Enum.map(&DateTime.to_unix/1) + + rows = [ + [dt1, -500 * @eth_decimals], + [dt2, -1500 * @eth_decimals], + [dt3, -6000 * @eth_decimals], + [dt4, 0], + [dt5, 0], + [dt6, -6500 * @eth_decimals] + ] - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [dt1, -500 * @eth_decimals], - [dt2, -1500 * @eth_decimals], - [dt3, -6000 * @eth_decimals], - [dt4, 0], - [dt5, 0], - [dt6, -6500 * @eth_decimals] - ] - }} - end do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = """ { project(id: #{context.project.id}) { @@ -68,35 +62,12 @@ defmodule SanbaseWeb.Graphql.ProjectApiEthSpentOverTimeTest do assert length(eth_spent_over_time) == 6 - assert %{ - "datetime" => "2017-05-13T00:00:00Z", - "ethSpent" => 500.0 - } in eth_spent_over_time - - assert %{ - "datetime" => "2017-05-14T00:00:00Z", - "ethSpent" => 1500.0 - } in eth_spent_over_time - - assert %{ - "datetime" => "2017-05-15T00:00:00Z", - "ethSpent" => 6000.0 - } in eth_spent_over_time - - assert %{ - "datetime" => "2017-05-16T00:00:00Z", - "ethSpent" => 0.0 - } in eth_spent_over_time - - assert %{ - "datetime" => "2017-05-17T00:00:00Z", - "ethSpent" => 0.0 - } in eth_spent_over_time - - assert %{ - "datetime" => "2017-05-18T00:00:00Z", - "ethSpent" => 6500.0 - } in eth_spent_over_time - end + assert %{"datetime" => "2017-05-13T00:00:00Z", "ethSpent" => 500.0} in eth_spent_over_time + assert %{"datetime" => "2017-05-14T00:00:00Z", "ethSpent" => 1500.0} in eth_spent_over_time + assert %{"datetime" => "2017-05-15T00:00:00Z", "ethSpent" => 6000.0} in eth_spent_over_time + assert %{"datetime" => "2017-05-16T00:00:00Z", "ethSpent" => 0.0} in eth_spent_over_time + assert %{"datetime" => "2017-05-17T00:00:00Z", "ethSpent" => 0.0} in eth_spent_over_time + assert %{"datetime" => "2017-05-18T00:00:00Z", "ethSpent" => 6500.0} in eth_spent_over_time + end) end end diff --git a/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs b/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs index 92a407863f..28e268bb36 100644 --- a/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs +++ b/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs @@ -3,6 +3,7 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do import Mock import Sanbase.Factory + import Sanbase.TestHelpers import SanbaseWeb.Graphql.TestHelpers @eth_decimals 1_000_000_000_000_000_000 @@ -14,19 +15,12 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do eth_infr = insert(:infrastructure, %{code: "ETH"}) - p = - insert(:project, %{ - name: "Santiment", - ticker: "SAN", - slug: "santiment", - infrastructure_id: eth_infr.id, - main_contract_address: "0x" <> rand_hex_str() - }) + project = insert(:random_erc20_project) project_address = p.eth_addresses |> List.first() [ - project: p, + project: project, project_address: project_address.address, dates_day_diff1: Timex.diff(datetime1, datetime3, :days) + 1, expected_sum1: 20_000, @@ -38,20 +32,17 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do end test "project total eth spent whole interval", context do - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [ - context.project_address, - 30_000 * @eth_decimals, - 10_000 * @eth_decimals, - -20_000 * @eth_decimals - ] - ] - }} - end do + rows = [ + [ + context.project_address, + 30_000 * @eth_decimals, + 10_000 * @eth_decimals, + -20_000 * @eth_decimals + ] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = """ { project(id: #{context.project.id}) { @@ -67,26 +58,23 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do trx_sum = json_response(result, 200)["data"]["project"] assert trx_sum == %{"ethSpent" => context.expected_sum1} - end + end) end test "project total eth spent part of interval", context do eth_spent = 4500 - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [ - context.project_address, - 20_000 * @eth_decimals, - 15_500 * @eth_decimals, - -4500 * @eth_decimals - ] - ] - }} - end do + rows = [ + [ + context.project_address, + 20_000 * @eth_decimals, + 15_500 * @eth_decimals, + -4500 * @eth_decimals + ] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = """ { project(id: #{context.project.id}) { @@ -102,26 +90,23 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do trx_sum = json_response(result, 200)["data"]["project"] assert trx_sum == %{"ethSpent" => eth_spent} - end + end) end test "eth spent by erc20 projects", context do eth_spent = 30_000 - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [ - context.project_address, - 100_000 * @eth_decimals, - 70_000 * @eth_decimals, - -30_000 * @eth_decimals - ] - ] - }} - end do + rows = [ + [ + context.project_address, + 100_000 * @eth_decimals, + 70_000 * @eth_decimals, + -30_000 * @eth_decimals + ] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = """ { ethSpentByErc20Projects( @@ -137,29 +122,24 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do total_eth_spent = json_response(result, 200)["data"]["ethSpentByErc20Projects"] assert total_eth_spent == eth_spent - end + end) end test "eth spent over time by erc20 projects", context do - dt1 = Timex.now() |> DateTime.to_unix() - dt2 = Timex.shift(Timex.now(), days: -1) |> DateTime.to_unix() - dt3 = Timex.shift(Timex.now(), days: -2) |> DateTime.to_unix() - dt4 = Timex.shift(Timex.now(), days: -3) |> DateTime.to_unix() - dt5 = Timex.shift(Timex.now(), days: -4) |> DateTime.to_unix() - - with_mock Sanbase.ClickhouseRepo, [:passthrough], - query: fn _, _ -> - {:ok, - %{ - rows: [ - [dt1, -16_500 * @eth_decimals], - [dt2, -5500 * @eth_decimals], - [dt3, -3500 * @eth_decimals], - [dt4, -2500 * @eth_decimals], - [dt5, -500 * @eth_decimals] - ] - }} - end do + [dt1, dt2, dt3, dt4, dt5] = + generate_datetimes(Timex.shift(Timex.now(), days: -4), "1d", 5) + |> Enum.map(&DateTime.to_unix/1) + + rows = [ + [dt1, -16_500 * @eth_decimals], + [dt2, -5500 * @eth_decimals], + [dt3, -3500 * @eth_decimals], + [dt4, -2500 * @eth_decimals], + [dt5, -500 * @eth_decimals] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = """ { ethSpentOverTimeByErc20Projects( @@ -182,7 +162,7 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do assert %{"ethSpent" => 3500.0} in total_spent assert %{"ethSpent" => 2500.0} in total_spent assert %{"ethSpent" => 500.0} in total_spent - end + end) end # Private functions From 58c5152d1fb5e84ee811beb72e63b74e415818bf Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 26 May 2020 14:56:36 +0300 Subject: [PATCH 05/12] Rework datetimes handlings --- lib/sanbase/auth/user.ex | 46 ++++++-- lib/sanbase/clickhouse/erc20_transfers.ex | 2 +- lib/sanbase/clickhouse/eth_transfers.ex | 2 +- lib/sanbase/clickhouse/github/github.ex | 2 +- lib/sanbase/comments/comment.ex | 2 + lib/sanbase/comments/entity_comment.ex | 4 +- lib/sanbase/comments/notification.ex | 4 +- lib/sanbase/insight/post.ex | 2 +- lib/sanbase/model/project/roi.ex | 8 +- lib/sanbase/timeline/cursor.ex | 4 +- lib/sanbase/timeline/timeline_event.ex | 4 +- lib/sanbase/utils/datetime/utils.ex | 8 ++ .../graphql/middlewares/access_control.ex | 1 - .../graphql/schema/custom_types/datetime.ex | 4 +- test/sanbase/auth/user_test.exs | 8 +- .../sanbase/clickhouse/api_call_data_test.exs | 1 - test/sanbase/clickhouse/gas_used_test.exs | 1 - .../erc20_assets_held_by_address_test.exs | 1 - .../eth_assets_held_by_address_test.exs | 1 - .../miners_balance_test.exs | 4 +- .../metric/clickhouse_metric_helper_test.exs | 2 - .../mining_pools_distribution_test.exs | 4 +- test/sanbase/clickhouse/top_holders_test.exs | 4 +- test/sanbase/insights/comment_test.exs | 4 +- test/sanbase/signals/scheduler_test.exs | 3 +- .../trending_words/trending_words_test.exs | 1 - .../graphql/clickhouse/exchanges_test.exs | 8 +- .../historical_balances_test.exs | 32 ++--- .../dev_activity/dev_activity_api_test.exs | 1 - .../graphql/exchanges/market_depth_test.exs | 110 ++++++++---------- .../graphql/exchanges/trades_test.exs | 82 +++++-------- test/sanbase_web/graphql/file_upload_test.exs | 2 +- .../graphql/insight/insight_api_test.exs | 6 +- .../project_api_combined_stats_test.exs | 40 ++++--- .../project_api_eth_spent_over_time_test.exs | 3 - .../projects/project_api_eth_spent_test.exs | 5 +- .../project_api_funds_raised_test.exs | 96 +++++++-------- .../timeline/timeline_event_api_test.exs | 60 +++++++--- .../graphql/user/user_api_test.exs | 23 ++-- .../user/user_eth_account_api_test.exs | 2 +- .../watchlist_historical_stats_api_test.exs | 12 +- test/support/mock.ex | 20 ---- 42 files changed, 315 insertions(+), 314 deletions(-) diff --git a/lib/sanbase/auth/user.ex b/lib/sanbase/auth/user.ex index a11296c52c..b90acfe5e1 100644 --- a/lib/sanbase/auth/user.ex +++ b/lib/sanbase/auth/user.ex @@ -101,15 +101,17 @@ defmodule Sanbase.Auth.User do timestamps() end - def generate_salt do + def generate_salt() do :crypto.strong_rand_bytes(@salt_length) |> Base.url_encode64() |> binary_part(0, @salt_length) end - def generate_email_token do + def generate_email_token() do :crypto.strong_rand_bytes(@email_token_length) |> Base.url_encode64() end def changeset(%User{} = user, attrs \\ %{}) do + attrs = Sanbase.DateTimeUtils.truncate_datetimes(attrs) + user |> cast(attrs, [ :email, @@ -189,15 +191,20 @@ defmodule Sanbase.Auth.User do def san_balance_cache_stale?(%User{san_balance_updated_at: nil}), do: true def san_balance_cache_stale?(%User{san_balance_updated_at: san_balance_updated_at}) do - Timex.diff(Timex.now(), san_balance_updated_at, :seconds) > @san_balance_cache_seconds + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + Timex.diff(naive_now, san_balance_updated_at, :seconds) > @san_balance_cache_seconds end def update_san_balance_changeset(user) do user = Repo.preload(user, :eth_accounts) san_balance = san_balance_for_eth_accounts(user) + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) user - |> change(san_balance: san_balance, san_balance_updated_at: Timex.now()) + |> change( + san_balance_updated_at: naive_now, + san_balance: san_balance + ) end @spec san_balance(%User{}) :: {:ok, float()} | {:ok, nil} | {:error, String.t()} @@ -274,7 +281,7 @@ defmodule Sanbase.Auth.User do user |> change( email_token: generate_email_token(), - email_token_generated_at: Timex.now(), + email_token_generated_at: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second), email_token_validated_at: nil, consent_id: consent ) @@ -286,44 +293,57 @@ defmodule Sanbase.Auth.User do |> changeset(%{ email_candidate: email_candidate, email_candidate_token: generate_email_token(), - email_candidate_token_generated_at: Timex.now(), + email_candidate_token_generated_at: + NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second), email_candidate_token_validated_at: nil }) |> Repo.update() end def mark_email_token_as_validated(user) do + validated_at = + (user.email_token_validated_at || Timex.now()) + |> Timex.to_naive_datetime() + |> NaiveDateTime.truncate(:second) + user |> change( - email_token_validated_at: user.email_token_validated_at || Timex.now(), + email_token_validated_at: validated_at, is_registered: true ) |> Repo.update() end def update_email_from_email_candidate(user) do + validated_at = + (user.email_candidate_token_validated_at || Timex.now()) + |> Timex.to_naive_datetime() + |> NaiveDateTime.truncate(:second) + user |> changeset(%{ email: user.email_candidate, email_candidate: nil, - email_candidate_token_validated_at: user.email_candidate_token_validated_at || Timex.now() + email_candidate_token_validated_at: validated_at }) |> Repo.update() end def email_token_valid?(user, token) do + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + cond do user.email_token != token -> false - Timex.diff(Timex.now(), user.email_token_generated_at, :minutes) > + Timex.diff(naive_now, user.email_token_generated_at, :minutes) > @login_email_valid_minutes -> false user.email_token_validated_at == nil -> true - Timex.diff(Timex.now(), user.email_token_validated_at, :minutes) > + Timex.diff(naive_now, user.email_token_validated_at, :minutes) > @login_email_valid_after_validation_minutes -> false @@ -333,18 +353,20 @@ defmodule Sanbase.Auth.User do end def email_candidate_token_valid?(user, email_candidate_token) do + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + cond do user.email_candidate_token != email_candidate_token -> false - Timex.diff(Timex.now(), user.email_candidate_token_generated_at, :minutes) > + Timex.diff(naive_now, user.email_candidate_token_generated_at, :minutes) > @login_email_valid_minutes -> false user.email_candidate_token_validated_at == nil -> true - Timex.diff(Timex.now(), user.email_candidate_token_validated_at, :minutes) > + Timex.diff(naive_now, user.email_candidate_token_validated_at, :minutes) > @login_email_valid_after_validation_minutes -> false diff --git a/lib/sanbase/clickhouse/erc20_transfers.ex b/lib/sanbase/clickhouse/erc20_transfers.ex index ba63b688b6..6cd2a727e7 100644 --- a/lib/sanbase/clickhouse/erc20_transfers.ex +++ b/lib/sanbase/clickhouse/erc20_transfers.ex @@ -22,7 +22,7 @@ defmodule Sanbase.Clickhouse.Erc20Transfers do @table "erc20_transfers" @primary_key false - @timestamps_opts updated_at: false + @timestamps_opts [updated_at: false] schema @table do field(:datetime, :utc_datetime, source: :dt) field(:contract, :string, primary_key: true) diff --git a/lib/sanbase/clickhouse/eth_transfers.ex b/lib/sanbase/clickhouse/eth_transfers.ex index 88eb87e8d8..51e4220f36 100644 --- a/lib/sanbase/clickhouse/eth_transfers.ex +++ b/lib/sanbase/clickhouse/eth_transfers.ex @@ -39,7 +39,7 @@ defmodule Sanbase.Clickhouse.EthTransfers do @eth_decimals 1_000_000_000_000_000_000 @primary_key false - @timestamps_opts updated_at: false + @timestamps_opts [updated_at: false] schema @table do field(:datetime, :utc_datetime, source: :dt) field(:from_address, :string, primary_key: true, source: :from) diff --git a/lib/sanbase/clickhouse/github/github.ex b/lib/sanbase/clickhouse/github/github.ex index 3a20f52b9a..ba7e36d563 100644 --- a/lib/sanbase/clickhouse/github/github.ex +++ b/lib/sanbase/clickhouse/github/github.ex @@ -37,7 +37,7 @@ defmodule Sanbase.Clickhouse.Github do @table "github" @primary_key false - @timestamps_opts updated_at: false + @timestamps_opts [updated_at: false] schema @table do field(:datetime, :utc_datetime, source: :dt, primary_key: true) field(:repo, :string, primary_key: true) diff --git a/lib/sanbase/comments/comment.ex b/lib/sanbase/comments/comment.ex index c7ad044ccc..195022cc0a 100644 --- a/lib/sanbase/comments/comment.ex +++ b/lib/sanbase/comments/comment.ex @@ -53,6 +53,8 @@ defmodule Sanbase.Comment do end def changeset(%__MODULE__{} = comment, attrs \\ %{}) do + attrs = Sanbase.DateTimeUtils.truncate_datetimes(attrs) + comment |> cast(attrs, [:user_id, :parent_id, :root_parent_id, :content, :edited_at]) |> validate_required([:user_id, :content]) diff --git a/lib/sanbase/comments/entity_comment.ex b/lib/sanbase/comments/entity_comment.ex index 6d07392771..58aa0a659e 100644 --- a/lib/sanbase/comments/entity_comment.ex +++ b/lib/sanbase/comments/entity_comment.ex @@ -85,11 +85,11 @@ defmodule Sanbase.Comments.EntityComment do end defp apply_cursor(query, %{type: :before, datetime: datetime}) do - from(c in query, where: c.inserted_at < ^datetime) + from(c in query, where: c.inserted_at <= ^(datetime |> DateTime.to_naive())) end defp apply_cursor(query, %{type: :after, datetime: datetime}) do - from(c in query, where: c.inserted_at >= ^datetime) + from(c in query, where: c.inserted_at >= ^(datetime |> DateTime.to_naive())) end defp apply_cursor(query, nil), do: query diff --git a/lib/sanbase/comments/notification.ex b/lib/sanbase/comments/notification.ex index 3951c64bce..ec0a8f6e42 100644 --- a/lib/sanbase/comments/notification.ex +++ b/lib/sanbase/comments/notification.ex @@ -260,7 +260,7 @@ defmodule Sanbase.Comments.Notification do where: p.post_id == ^post_comment.post.id and p.comment_id != ^post_comment.comment.id and - p.inserted_at < ^post_comment.inserted_at, + p.inserted_at <= ^post_comment.inserted_at, preload: [comment: :user] ) end @@ -270,7 +270,7 @@ defmodule Sanbase.Comments.Notification do where: t.timeline_event_id == ^timeline_event_comment.timeline_event.id and t.comment_id != ^timeline_event_comment.comment.id and - t.inserted_at < ^timeline_event_comment.inserted_at, + t.inserted_at <= ^timeline_event_comment.inserted_at, preload: [comment: :user] ) end diff --git a/lib/sanbase/insight/post.ex b/lib/sanbase/insight/post.ex index 709ff5da8f..37c0ec878c 100644 --- a/lib/sanbase/insight/post.ex +++ b/lib/sanbase/insight/post.ex @@ -61,7 +61,7 @@ defmodule Sanbase.Insight.Post do on_delete: :delete_all ) - field(:published_at, :naive_datetime) + field(:published_at, :naive_datetime_usec) timestamps() end diff --git a/lib/sanbase/model/project/roi.ex b/lib/sanbase/model/project/roi.ex index 8cb6f77e07..931fb54660 100644 --- a/lib/sanbase/model/project/roi.ex +++ b/lib/sanbase/model/project/roi.ex @@ -107,12 +107,12 @@ defmodule Sanbase.Model.Project.Roi do ) end - defp calc_token_usd_ico_price(nil, _currency_from, _ico_start_date, _current_datetime), do: nil - defp calc_token_usd_ico_price(_price_from, _currency_from, nil, _current_datetime), do: nil + defp calc_token_usd_ico_price(nil, _currency_from, _ico_start_date, _update_naive_dt), do: nil + defp calc_token_usd_ico_price(_price_from, _currency_from, nil, _update_naive_dt), do: nil defp calc_token_usd_ico_price(_price_from, _currency_from, _ico_start_date, nil), do: nil - defp calc_token_usd_ico_price(price_from, currency_from, ico_start_date, current_datetime) do - with :gt <- Date.compare(current_datetime |> DateTime.to_date(), ico_start_date), + defp calc_token_usd_ico_price(price_from, currency_from, ico_start_date, update_naive_dt) do + with :gt <- Date.compare(update_naive_dt |> NaiveDateTime.to_date(), ico_start_date), datetime <- Sanbase.DateTimeUtils.date_to_datetime(ico_start_date), price_usd when not is_nil(price_usd) <- Sanbase.Price.Utils.fetch_last_price_before(currency_from, "USD", datetime) do diff --git a/lib/sanbase/timeline/cursor.ex b/lib/sanbase/timeline/cursor.ex index 66dc74adb9..58419ca496 100644 --- a/lib/sanbase/timeline/cursor.ex +++ b/lib/sanbase/timeline/cursor.ex @@ -4,14 +4,14 @@ defmodule Sanbase.Timeline.Cursor do def filter_by_cursor(query, :before, datetime) do from( event in query, - where: event.inserted_at < ^datetime + where: event.inserted_at < ^DateTime.to_naive(datetime) ) end def filter_by_cursor(query, :after, datetime) do from( event in query, - where: event.inserted_at > ^datetime + where: event.inserted_at > ^DateTime.to_naive(datetime) ) end diff --git a/lib/sanbase/timeline/timeline_event.ex b/lib/sanbase/timeline/timeline_event.ex index de64e54ca9..b58f3c6746 100644 --- a/lib/sanbase/timeline/timeline_event.ex +++ b/lib/sanbase/timeline/timeline_event.ex @@ -32,7 +32,7 @@ defmodule Sanbase.Timeline.TimelineEvent do @max_events_returned 100 - @timestamps_opts [updated_at: false, type: :utc_datetime] + @timestamps_opts [updated_at: false] @table "timeline_events" schema @table do field(:event_type, :string) @@ -59,6 +59,8 @@ defmodule Sanbase.Timeline.TimelineEvent do def trigger_fired(), do: @trigger_fired def create_changeset(%__MODULE__{} = timeline_events, attrs \\ %{}) do + attrs = Sanbase.DateTimeUtils.truncate_datetimes(attrs) + timeline_events |> cast(attrs, [ :event_type, diff --git a/lib/sanbase/utils/datetime/utils.ex b/lib/sanbase/utils/datetime/utils.ex index 6d0cf64747..4f9b35c189 100644 --- a/lib/sanbase/utils/datetime/utils.ex +++ b/lib/sanbase/utils/datetime/utils.ex @@ -1,4 +1,12 @@ defmodule Sanbase.DateTimeUtils do + def truncate_datetimes(%{} = map, precision \\ :second) do + Enum.into(map, %{}, fn + {k, %DateTime{} = dt} -> {k, DateTime.truncate(dt, precision)} + {k, %NaiveDateTime{} = dt} -> {k, NaiveDateTime.truncate(dt, precision)} + {k, v} -> {k, v} + end) + end + def time_in_range?(%Time{} = time, %Time{} = from, %Time{} = to) do case Time.compare(from, to) do :eq -> diff --git a/lib/sanbase_web/graphql/middlewares/access_control.ex b/lib/sanbase_web/graphql/middlewares/access_control.ex index 998e4a4c42..410338e604 100644 --- a/lib/sanbase_web/graphql/middlewares/access_control.ex +++ b/lib/sanbase_web/graphql/middlewares/access_control.ex @@ -150,7 +150,6 @@ defmodule SanbaseWeb.Graphql.Middlewares.AccessControl do middleware_args ) do if Plan.AccessChecker.is_restricted?(query) do - IO.inspect("#{inspect(query)} IS RESTRICTED????") restricted_query(resolution, middleware_args, query) else not_restricted_query(resolution, middleware_args) diff --git a/lib/sanbase_web/graphql/schema/custom_types/datetime.ex b/lib/sanbase_web/graphql/schema/custom_types/datetime.ex index 30d7abec96..98e5c6a946 100644 --- a/lib/sanbase_web/graphql/schema/custom_types/datetime.ex +++ b/lib/sanbase_web/graphql/schema/custom_types/datetime.ex @@ -16,7 +16,9 @@ defmodule SanbaseWeb.Graphql.CustomTypes.DateTime do |> DateTime.to_iso8601() %DateTime{} = dt -> - DateTime.truncate(dt, :second) |> DateTime.to_iso8601() + dt + |> DateTime.truncate(:second) + |> DateTime.to_iso8601() end) parse(&parse_datetime/1) diff --git a/test/sanbase/auth/user_test.exs b/test/sanbase/auth/user_test.exs index ab9952cdb2..4c3930ff8a 100644 --- a/test/sanbase/auth/user_test.exs +++ b/test/sanbase/auth/user_test.exs @@ -39,17 +39,17 @@ defmodule Sanbase.Auth.UserTest do user = insert(:user, - san_balance: 0, eth_accounts: [%EthAccount{address: "0x000000000001"}], - privacy_policy_accepted: true + san_balance: 100, + san_balance_updated_at: ~N[2020-01-01 00:00:00] ) changeset = User.update_san_balance_changeset(user) assert changeset.changes[:san_balance] == 5.0 - # + assert Sanbase.TestUtils.datetime_close_to( - Timex.now(), + NaiveDateTime.utc_now(), changeset.changes[:san_balance_updated_at], 2, :seconds diff --git a/test/sanbase/clickhouse/api_call_data_test.exs b/test/sanbase/clickhouse/api_call_data_test.exs index 8ce2f0b3ac..740a9be6df 100644 --- a/test/sanbase/clickhouse/api_call_data_test.exs +++ b/test/sanbase/clickhouse/api_call_data_test.exs @@ -1,7 +1,6 @@ defmodule Sanbase.Clickhouse.ApiCallDataTest do use Sanbase.DataCase - import Mock import Sanbase.Factory import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1, from_iso8601!: 1] diff --git a/test/sanbase/clickhouse/gas_used_test.exs b/test/sanbase/clickhouse/gas_used_test.exs index e191b4cd06..038cabbd1a 100644 --- a/test/sanbase/clickhouse/gas_used_test.exs +++ b/test/sanbase/clickhouse/gas_used_test.exs @@ -1,6 +1,5 @@ defmodule Sanbase.Clickhouse.GasUsedTest do use Sanbase.DataCase - import Mock import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1, from_iso8601!: 1] alias Sanbase.Clickhouse.GasUsed diff --git a/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs b/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs index 44b4526e5a..41a8a4f5de 100644 --- a/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs +++ b/test/sanbase/clickhouse/historical_balance/erc20_assets_held_by_address_test.exs @@ -1,7 +1,6 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.Erc20AssetsHeldByAdderssTest do use Sanbase.DataCase - import Mock import Sanbase.Factory alias Sanbase.Clickhouse.HistoricalBalance.Erc20Balance diff --git a/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs b/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs index 9596e56e3f..e0a62bb37b 100644 --- a/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs +++ b/test/sanbase/clickhouse/historical_balance/eth_assets_held_by_address_test.exs @@ -1,7 +1,6 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.EthAssetsHeldByAdderssTest do use Sanbase.DataCase - import Mock import Sanbase.Factory alias Sanbase.Clickhouse.HistoricalBalance.EthBalance diff --git a/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs b/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs index 06064d0150..70c5b459d9 100644 --- a/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs +++ b/test/sanbase/clickhouse/historical_balance/miners_balance_test.exs @@ -1,8 +1,10 @@ defmodule Sanbase.Clickhouse.HistoricalBalance.MinersBalanceTest do use Sanbase.DataCase - import Mock + import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1, from_iso8601!: 1] + alias Sanbase.Clickhouse.HistoricalBalance.MinersBalance + require Sanbase.ClickhouseRepo setup do diff --git a/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs b/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs index 84abae7cdc..c36dec140e 100644 --- a/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs +++ b/test/sanbase/clickhouse/metric/clickhouse_metric_helper_test.exs @@ -1,8 +1,6 @@ defmodule Sanbase.Clickhouse.Metric.HelperTest do use Sanbase.DataCase - import Mock - test "metric id to name map" do rows = [ [1, "daily_active_addresses"], diff --git a/test/sanbase/clickhouse/mining_pools_distribution_test.exs b/test/sanbase/clickhouse/mining_pools_distribution_test.exs index 31a3a06c34..3cbffbe509 100644 --- a/test/sanbase/clickhouse/mining_pools_distribution_test.exs +++ b/test/sanbase/clickhouse/mining_pools_distribution_test.exs @@ -1,8 +1,8 @@ defmodule Sanbase.Clickhouse.MiningPoolsDistributionTest do use Sanbase.DataCase - import Mock - import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1, from_iso8601!: 1] + alias Sanbase.Clickhouse.MiningPoolsDistribution + require Sanbase.ClickhouseRepo setup do diff --git a/test/sanbase/clickhouse/top_holders_test.exs b/test/sanbase/clickhouse/top_holders_test.exs index 975c3d3b16..541341eba1 100644 --- a/test/sanbase/clickhouse/top_holders_test.exs +++ b/test/sanbase/clickhouse/top_holders_test.exs @@ -1,9 +1,11 @@ defmodule Sanbase.Clickhouse.TopHoldersTest do use Sanbase.DataCase - import Mock + import Sanbase.Factory import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1, from_iso8601!: 1] + alias Sanbase.Clickhouse.TopHolders + require Sanbase.ClickhouseRepo setup do diff --git a/test/sanbase/insights/comment_test.exs b/test/sanbase/insights/comment_test.exs index bb1c9f0e9b..f887cc214b 100644 --- a/test/sanbase/insights/comment_test.exs +++ b/test/sanbase/insights/comment_test.exs @@ -43,11 +43,11 @@ defmodule Sanbase.Insight.CommentTest do {:ok, comment} = EntityComment.create_and_link(@entity_type, post.id, post.user_id, nil, content) - naive_dt_before_update = NaiveDateTime.utc_now() + naive_dt_before_update = Timex.shift(NaiveDateTime.utc_now(), seconds: -1) {:ok, updated_comment} = Comment.update(comment.id, comment.user_id, updated_content) - naive_dt_after_update = NaiveDateTime.utc_now() + naive_dt_after_update = Timex.shift(NaiveDateTime.utc_now(), seconds: 1) assert comment.edited_at == nil assert comment.content == content diff --git a/test/sanbase/signals/scheduler_test.exs b/test/sanbase/signals/scheduler_test.exs index a283bcb47d..6c3e3ba156 100644 --- a/test/sanbase/signals/scheduler_test.exs +++ b/test/sanbase/signals/scheduler_test.exs @@ -46,8 +46,7 @@ defmodule Sanbase.Signal.SchedulerTest do project: project, price_usd: 62, user: user, - mock_fun: mock_fun, - mock_chart: [%{image: %{url: "somelink"}}] + mock_fun: mock_fun ] end diff --git a/test/sanbase/social_data/trending_words/trending_words_test.exs b/test/sanbase/social_data/trending_words/trending_words_test.exs index 5a9debec9c..6b2c8120f3 100644 --- a/test/sanbase/social_data/trending_words/trending_words_test.exs +++ b/test/sanbase/social_data/trending_words/trending_words_test.exs @@ -1,7 +1,6 @@ defmodule Sanbase.SocialData.TrendingWordsTest do use Sanbase.DataCase - import Mock import Sanbase.Factory import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1, from_iso8601!: 1] diff --git a/test/sanbase_web/graphql/clickhouse/exchanges_test.exs b/test/sanbase_web/graphql/clickhouse/exchanges_test.exs index 783065ad7b..31e94c09d6 100644 --- a/test/sanbase_web/graphql/clickhouse/exchanges_test.exs +++ b/test/sanbase_web/graphql/clickhouse/exchanges_test.exs @@ -1,10 +1,8 @@ defmodule SanbaseWeb.Graphql.ExchangesTest do use SanbaseWeb.ConnCase, async: false - import Mock import Sanbase.Factory import SanbaseWeb.Graphql.TestHelpers - import Sanbase.DateTimeUtils, only: [from_iso8601_to_unix!: 1] setup do infr = insert(:infrastructure, %{code: "ETH"}) @@ -47,9 +45,9 @@ defmodule SanbaseWeb.Graphql.ExchangesTest do test "test fetching volume for exchange", context do rows = [ - [from_iso8601_to_unix!("2017-05-13T00:00:00Z"), 2000, 1000], - [from_iso8601_to_unix!("2017-05-15T00:00:00Z"), 1800, 1300], - [from_iso8601_to_unix!("2017-05-18T00:00:00Z"), 1000, 1100] + [~U[2017-05-13T00:00:00Z] |> DateTime.to_unix(), 2000, 1000], + [~U[2017-05-15T00:00:00Z] |> DateTime.to_unix(), 1800, 1300], + [~U[2017-05-18T00:00:00Z] |> DateTime.to_unix(), 1000, 1100] ] Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) diff --git a/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs b/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs index a568c3b26b..a953af0d69 100644 --- a/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs +++ b/test/sanbase_web/graphql/clickhouse/historical_balance/historical_balances_test.exs @@ -3,13 +3,9 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do import Sanbase.TestHelpers import SanbaseWeb.Graphql.TestHelpers - import Mock - import Sanbase.DateTimeUtils, only: [from_iso8601!: 1] import ExUnit.CaptureLog import Sanbase.Factory - alias Sanbase.DateTimeUtils - require Sanbase.ClickhouseRepo @eth_decimals 1_000_000_000_000_000_000 @@ -29,8 +25,8 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do project_with_contract: project_with_contract, project_without_contract: project_without_contract, address: "0x321321321", - from: from_iso8601!("2017-05-11T00:00:00Z"), - to: from_iso8601!("2017-05-20T00:00:00Z"), + from: ~U[2017-05-11T00:00:00Z], + to: ~U[2017-05-20T00:00:00Z], interval: "1d" ] end @@ -54,19 +50,15 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do dt3 = ~U[2019-01-03 00:00:00Z] dt4 = ~U[2019-01-04 00:00:00Z] - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [dt1 |> DateTime.to_unix(), :math.pow(10, 18) * 2000, 1], - [dt2 |> DateTime.to_unix(), 0, 0], - [dt3 |> DateTime.to_unix(), 0, 0], - [dt4 |> DateTime.to_unix(), :math.pow(10, 18) * 1800, 1] - ] - }} - end - ) do + rows = [ + [dt1 |> DateTime.to_unix(), :math.pow(10, 18) * 2000, 1], + [dt2 |> DateTime.to_unix(), 0, 0], + [dt3 |> DateTime.to_unix(), 0, 0], + [dt4 |> DateTime.to_unix(), :math.pow(10, 18) * 1800, 1] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> from = dt1 to = dt4 @@ -84,7 +76,7 @@ defmodule SanbaseWeb.Graphql.Clickhouse.HistoricalBalancesTest do historical_balance = result["data"]["historicalBalance"] assert length(historical_balance) == 4 end - end + end) end test "historical balances when interval is bigger than balances values interval", context do diff --git a/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs b/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs index 0594d58c19..ff6e015fb0 100644 --- a/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs +++ b/test/sanbase_web/graphql/dev_activity/dev_activity_api_test.exs @@ -4,7 +4,6 @@ defmodule SanbaseWeb.Graphql.ProjectApiGithubTest do import Mock import Sanbase.Factory import SanbaseWeb.Graphql.TestHelpers - import Sanbase.DateTimeUtils, only: [from_iso8601!: 1] alias Sanbase.Model.Project alias Sanbase.Clickhouse.Github diff --git a/test/sanbase_web/graphql/exchanges/market_depth_test.exs b/test/sanbase_web/graphql/exchanges/market_depth_test.exs index 9d5fb1bccb..9a1774b828 100644 --- a/test/sanbase_web/graphql/exchanges/market_depth_test.exs +++ b/test/sanbase_web/graphql/exchanges/market_depth_test.exs @@ -1,34 +1,24 @@ defmodule SanbaseWeb.Graphql.Exchanges.MarketDepthTest do use SanbaseWeb.ConnCase, async: false - import Mock import SanbaseWeb.Graphql.TestHelpers import ExUnit.CaptureLog test "#last_market_depth", context do - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [result_row()] - }} - end - ) do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows()}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = last_market_depth_query() result = execute_query(context.conn, query, "lastExchangeMarketDepth") - assert hd(result) == expected_exchange_market_depth() - end + assert List.first(result) == expected_exchange_market_depth() + end) end test "#last_market_depth with error from clickhouse", context do error = "error description" - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, error} - end - ) do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, error}) + |> Sanbase.Mock.run_with_mocks(fn -> query = last_market_depth_query() log = @@ -40,7 +30,7 @@ defmodule SanbaseWeb.Graphql.Exchanges.MarketDepthTest do ~s(Can't fetch Last exchange market depth for exchange and ticker_pair: "Kraken" and "ZEC/BTC", Reason: #{ inspect(error) }) - end + end) end defp expected_exchange_market_depth() do @@ -75,49 +65,51 @@ defmodule SanbaseWeb.Graphql.Exchanges.MarketDepthTest do """ end - defp result_row() do + defp rows() do [ - 1_571_417_428, - "Kraken", - "ZEC/BTC", - 0.00455979, - 0.0012996121796948, - 0.28495291, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - 0.00455005, - 0.7868672411467281, - 173.00153222999998, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil + [ + 1_571_417_428, + "Kraken", + "ZEC/BTC", + 0.00455979, + 0.0012996121796948, + 0.28495291, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + 0.00455005, + 0.7868672411467281, + 173.00153222999998, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil, + nil + ] ] end end diff --git a/test/sanbase_web/graphql/exchanges/trades_test.exs b/test/sanbase_web/graphql/exchanges/trades_test.exs index b67c5fef91..520020276b 100644 --- a/test/sanbase_web/graphql/exchanges/trades_test.exs +++ b/test/sanbase_web/graphql/exchanges/trades_test.exs @@ -1,36 +1,28 @@ defmodule SanbaseWeb.Graphql.Exchanges.TradesTest do use SanbaseWeb.ConnCase, async: false - import Mock import SanbaseWeb.Graphql.TestHelpers import ExUnit.CaptureLog test "#last_exchange_trades", context do - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [1_569_704_025, "Kraken", "ETH/EUR", "buy", 2.11604737, 159.63, 337.7846416731] - ] - }} - end - ) do + rows = [ + [1_569_704_025, "Kraken", "ETH/EUR", "buy", 2.11604737, 159.63, 337.7846416731] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = last_trades_query() result = execute_query(context.conn, query, "lastExchangeTrades") assert hd(result) == expected_exchange_trade() - end + end) end test "#last_exchange_trades with error from clickhouse", context do error = "error description" - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, error} - end - ) do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, error}) + |> Sanbase.Mock.run_with_mocks(fn -> query = last_trades_query() log = @@ -42,35 +34,28 @@ defmodule SanbaseWeb.Graphql.Exchanges.TradesTest do ~s(Can't fetch Last exchange trades for exchange and ticker_pair: "Kraken" and "ETH/EUR", Reason: #{ inspect(error) }) - end + end) end test "#exchange_trades", context do - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [1_569_704_025, "Kraken", "ETH/EUR", "buy", 2.11604737, 159.63, 337.7846416731] - ] - }} - end - ) do + rows = [ + [1_569_704_025, "Kraken", "ETH/EUR", "buy", 2.11604737, 159.63, 337.7846416731] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = trades_query() result = execute_query(context.conn, query, "exchangeTrades") assert hd(result) == expected_exchange_trade() - end + end) end test "#exchange_trades with error from clickhouse", context do error = "error description" - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, error} - end - ) do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, error}) + |> Sanbase.Mock.run_with_mocks(fn -> query = trades_query() log = @@ -82,35 +67,28 @@ defmodule SanbaseWeb.Graphql.Exchanges.TradesTest do ~s(Can't fetch Exchange trades for exchange and ticker_pair: "Kraken" and "ETH/EUR", Reason: #{ inspect(error) }) - end + end) end test "#aggregated exchange_trades", context do - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:ok, - %{ - rows: [ - [1_569_704_025, 2.11604737, 159.63, 337.7846416731, "buy"] - ] - }} - end - ) do + rows = [ + [1_569_704_025, 2.11604737, 159.63, 337.7846416731, "buy"] + ] + + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: rows}}) + |> Sanbase.Mock.run_with_mocks(fn -> query = aggregated_trades_query() result = execute_query(context.conn, query, "exchangeTrades") assert hd(result) == expected_exchange_trade() - end + end) end test "#aggregated exchange_trades with error from clickhouse", context do error = "error description" - with_mock(Sanbase.ClickhouseRepo, - query: fn _, _ -> - {:error, error} - end - ) do + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, error}) + |> Sanbase.Mock.run_with_mocks(fn -> query = aggregated_trades_query() log = @@ -122,7 +100,7 @@ defmodule SanbaseWeb.Graphql.Exchanges.TradesTest do ~s(Can't fetch Aggregated exchange trades for exchange and ticker_pair: "Kraken" and "ETH/EUR", Reason: #{ inspect(error) }) - end + end) end defp expected_exchange_trade() do diff --git a/test/sanbase_web/graphql/file_upload_test.exs b/test/sanbase_web/graphql/file_upload_test.exs index 6952769a84..f0a7dd9b97 100644 --- a/test/sanbase_web/graphql/file_upload_test.exs +++ b/test/sanbase_web/graphql/file_upload_test.exs @@ -12,7 +12,7 @@ defmodule SanbaseWeb.Graphql.FileUploadTest do %User{ salt: User.generate_salt(), san_balance: Decimal.mult(Decimal.new(10), Sanbase.SantimentContract.decimals_expanded()), - san_balance_updated_at: Timex.now(), + san_balance_updated_at: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second), privacy_policy_accepted: true } |> Repo.insert!() diff --git a/test/sanbase_web/graphql/insight/insight_api_test.exs b/test/sanbase_web/graphql/insight/insight_api_test.exs index 209b792ec0..fc345a66b3 100644 --- a/test/sanbase_web/graphql/insight/insight_api_test.exs +++ b/test/sanbase_web/graphql/insight/insight_api_test.exs @@ -664,7 +664,8 @@ defmodule SanbaseWeb.Graphql.InsightApiTest do insert(:post, user: user, ready_state: Post.published(), - updated_at: Timex.shift(Timex.now(), seconds: -1) + updated_at: + Timex.shift(NaiveDateTime.utc_now(), seconds: -1) |> NaiveDateTime.truncate(:second) ) mutation = """ @@ -687,8 +688,9 @@ defmodule SanbaseWeb.Graphql.InsightApiTest do updated_at = Sanbase.DateTimeUtils.from_iso8601!(result["data"]["updateInsight"]["updatedAt"]) + |> DateTime.to_naive() - assert DateTime.compare(updated_at, post.updated_at) == :gt + assert NaiveDateTime.compare(updated_at, post.updated_at) == :gt end test "can update tags for published insight", %{conn: conn, user: user} do diff --git a/test/sanbase_web/graphql/projects/project_api_combined_stats_test.exs b/test/sanbase_web/graphql/projects/project_api_combined_stats_test.exs index 72b43d5e85..4912d7e534 100644 --- a/test/sanbase_web/graphql/projects/project_api_combined_stats_test.exs +++ b/test/sanbase_web/graphql/projects/project_api_combined_stats_test.exs @@ -34,37 +34,47 @@ defmodule SanbaseWeb.Graphql.ProjectApiCombinedStatsTest do fn -> result = get_history_stats(conn, from, to, slugs) - assert result == %{ - "data" => %{ - "projectsListHistoryStats" => [ - %{"datetime" => "2017-05-13T00:00:00Z", "marketcap" => 545, "volume" => 220}, - %{"datetime" => "2017-05-14T00:00:00Z", "marketcap" => 2000, "volume" => 1400}, - %{"datetime" => "2017-05-15T00:00:00Z", "marketcap" => 2600, "volume" => 1600} - ] + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: data}}) + |> Sanbase.Mock.run_with_mocks(fn -> + assert result == %{ + "data" => %{ + "projectsListHistoryStats" => [ + %{"datetime" => "2017-05-13T00:00:00Z", "marketcap" => 545, "volume" => 220}, + %{ + "datetime" => "2017-05-14T00:00:00Z", + "marketcap" => 2000, + "volume" => 1400 + }, + %{ + "datetime" => "2017-05-15T00:00:00Z", + "marketcap" => 2600, + "volume" => 1600 + } + ] + } } - } + end) end - |> Sanbase.Mock.with_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: data}}) end test "the database returns no data", context do %{conn: conn, from: from, to: to, slugs: slugs} = context - fn -> + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = get_history_stats(conn, from, to, slugs) assert result == %{"data" => %{"projectsListHistoryStats" => []}} - end - |> Sanbase.Mock.with_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: []}}) + end) end test "the database returns an error", context do %{conn: conn, from: from, to: to, slugs: slugs} = context - fn -> + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "Database error"}) + |> Sanbase.Mock.run_with_mocks(fn -> %{"errors" => [error]} = get_history_stats(conn, from, to, slugs) assert error["message"] =~ "Cannot get combined history stats for a list of slugs." - end - |> Sanbase.Mock.with_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "Database error"}) + end) end defp get_history_stats(conn, from, to, slugs) do diff --git a/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs b/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs index c6c63ff6b3..d4a196b1ef 100644 --- a/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs +++ b/test/sanbase_web/graphql/projects/project_api_eth_spent_over_time_test.exs @@ -1,13 +1,10 @@ defmodule SanbaseWeb.Graphql.ProjectApiEthSpentOverTimeTest do use SanbaseWeb.ConnCase, async: false - import Mock import Sanbase.TestHelpers import SanbaseWeb.Graphql.TestHelpers import Sanbase.Factory - alias Sanbase.DateTimeUtils - @eth_decimals 1_000_000_000_000_000_000 setup do diff --git a/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs b/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs index 28e268bb36..f243da1e5b 100644 --- a/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs +++ b/test/sanbase_web/graphql/projects/project_api_eth_spent_test.exs @@ -1,7 +1,6 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do use SanbaseWeb.ConnCase, async: false - import Mock import Sanbase.Factory import Sanbase.TestHelpers import SanbaseWeb.Graphql.TestHelpers @@ -15,9 +14,9 @@ defmodule SanbaseWeb.Graphql.ProjecApiEthSpentTest do eth_infr = insert(:infrastructure, %{code: "ETH"}) - project = insert(:random_erc20_project) + project = insert(:random_erc20_project, infrastructure: eth_infr) - project_address = p.eth_addresses |> List.first() + project_address = project.eth_addresses |> List.first() [ project: project, diff --git a/test/sanbase_web/graphql/projects/project_api_funds_raised_test.exs b/test/sanbase_web/graphql/projects/project_api_funds_raised_test.exs index 935c5c2fc4..bb1f9cdb08 100644 --- a/test/sanbase_web/graphql/projects/project_api_funds_raised_test.exs +++ b/test/sanbase_web/graphql/projects/project_api_funds_raised_test.exs @@ -40,49 +40,45 @@ defmodule SanbaseWeb.Graphql.ProjectApiFundsRaisedTest do test "fetch project funds raised", context do %{conn: conn, project: project} = context - expected_result = %{ - "name" => project.name, - "fundsRaisedBtcIcoEndPrice" => 72.5, - "fundsRaisedEthIcoEndPrice" => 390.0, - "fundsRaisedUsdIcoEndPrice" => 1950.0, - "icos" => [ - %{ - "endDate" => "2017-08-19", - "fundsRaisedBtcIcoEndPrice" => 32.5, - "fundsRaisedEthIcoEndPrice" => 190.0, - "fundsRaisedUsdIcoEndPrice" => 950.0 - }, - %{ - "endDate" => "2017-10-17", - "fundsRaisedEthIcoEndPrice" => 200.0, - "fundsRaisedUsdIcoEndPrice" => 1.0e3, - "fundsRaisedBtcIcoEndPrice" => 40.0 - } - ] - } - - fn -> + Sanbase.Mock.prepare_mock(Sanbase.Price, :last_record_before, fn slug, datetime -> + if DateTime.compare(datetime, context.datetime) == :lt do + case slug do + "bitcoin" -> {:ok, %{price_usd: 2, price_btc: 0.1, marketcap: 100, volume: 100}} + "test" -> {:ok, %{price_usd: 4, price_btc: 0.05, marketcap: 100, volume: 100}} + "ethereum" -> {:ok, %{price_usd: 5, price_btc: 0.2, marketcap: nil, volume: nil}} + end + else + case slug do + "bitcoin" -> {:ok, %{price_usd: 5, price_btc: 0.2, marketcap: 100, volume: 100}} + "test" -> {:ok, %{price_usd: 4, price_btc: 0.03, marketcap: 100, volume: 100}} + "ethereum" -> {:ok, %{price_usd: 10, price_btc: 0.8, marketcap: 100, volume: 100}} + end + end + end) + |> Sanbase.Mock.run_with_mocks(fn -> result = get_funds_raised(conn, project) |> get_in(["data", "projectBySlug"]) - assert result == expected_result - end - |> Sanbase.Mock.with_mock2( - {Sanbase.Price, :last_record_before, - fn slug, datetime -> - if DateTime.compare(datetime, context.datetime) == :lt do - case slug do - "bitcoin" -> {:ok, %{price_usd: 2, price_btc: 0.1, marketcap: 100, volume: 100}} - "test" -> {:ok, %{price_usd: 4, price_btc: 0.05, marketcap: 100, volume: 100}} - "ethereum" -> {:ok, %{price_usd: 5, price_btc: 0.2, marketcap: nil, volume: nil}} - end - else - case slug do - "bitcoin" -> {:ok, %{price_usd: 5, price_btc: 0.2, marketcap: 100, volume: 100}} - "test" -> {:ok, %{price_usd: 4, price_btc: 0.03, marketcap: 100, volume: 100}} - "ethereum" -> {:ok, %{price_usd: 10, price_btc: 0.8, marketcap: 100, volume: 100}} - end - end - end} - ) + + assert result == %{ + "name" => project.name, + "fundsRaisedBtcIcoEndPrice" => 72.5, + "fundsRaisedEthIcoEndPrice" => 390.0, + "fundsRaisedUsdIcoEndPrice" => 1950.0, + "icos" => [ + %{ + "endDate" => "2017-08-19", + "fundsRaisedBtcIcoEndPrice" => 32.5, + "fundsRaisedEthIcoEndPrice" => 190.0, + "fundsRaisedUsdIcoEndPrice" => 950.0 + }, + %{ + "endDate" => "2017-10-17", + "fundsRaisedEthIcoEndPrice" => 200.0, + "fundsRaisedUsdIcoEndPrice" => 1.0e3, + "fundsRaisedBtcIcoEndPrice" => 40.0 + } + ] + } + end) end test "no ico does not break query", context do @@ -92,15 +88,13 @@ defmodule SanbaseWeb.Graphql.ProjectApiFundsRaisedTest do get_funds_raised(conn, project) |> get_in(["data", "projectBySlug"]) - expected_result = %{ - "name" => project.name, - "fundsRaisedUsdIcoEndPrice" => nil, - "fundsRaisedEthIcoEndPrice" => nil, - "fundsRaisedBtcIcoEndPrice" => nil, - "icos" => [] - } - - assert result == expected_result + assert result == %{ + "name" => project.name, + "fundsRaisedUsdIcoEndPrice" => nil, + "fundsRaisedEthIcoEndPrice" => nil, + "fundsRaisedBtcIcoEndPrice" => nil, + "icos" => [] + } end # Private functions diff --git a/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs b/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs index b61ad7a361..40dfd0519b 100644 --- a/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs +++ b/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs @@ -98,8 +98,10 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do assert result |> hd() |> Map.get("events") |> hd() |> Map.get("data") == nil assert result |> hd() |> Map.get("cursor") == %{ - "after" => DateTime.to_iso8601(DateTime.truncate(event3.inserted_at, :second)), - "before" => DateTime.to_iso8601(DateTime.truncate(event1.inserted_at, :second)) + "after" => + DateTime.to_iso8601(event3.inserted_at |> DateTime.from_naive!("Etc/UTC")), + "before" => + DateTime.to_iso8601(event1.inserted_at |> DateTime.from_naive!("Etc/UTC")) } end @@ -502,29 +504,43 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do {trigger1, trigger2, trigger3} = create_trigger(context) - insight_event = - insert(:timeline_event, - post: post, - user: context.user, - event_type: TimelineEvent.publish_insight_type() - ) - generic_setting_trigger_event = %{ user_trigger: nil, user: context.user, event_type: TimelineEvent.trigger_fired(), payload: %{"default" => "some signal payload"}, - data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}} + data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}}, + inserted_at: NaiveDateTime.utc_now() } + insight_event = + insert(:timeline_event, + post: post, + user: context.user, + event_type: TimelineEvent.publish_insight_type(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -4) + ) + trigger1_event = - insert(:timeline_event, %{generic_setting_trigger_event | user_trigger: trigger1}) + insert(:timeline_event, %{ + generic_setting_trigger_event + | user_trigger: trigger1, + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -3) + }) trigger2_event = - insert(:timeline_event, %{generic_setting_trigger_event | user_trigger: trigger2}) + insert(:timeline_event, %{ + generic_setting_trigger_event + | user_trigger: trigger2, + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -2) + }) trigger3_event = - insert(:timeline_event, %{generic_setting_trigger_event | user_trigger: trigger3}) + insert(:timeline_event, %{ + generic_setting_trigger_event + | user_trigger: trigger3, + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -1) + }) create_test_events(context) @@ -668,28 +684,32 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do insert(:post, user: user_to_follow, state: Post.approved_state(), - ready_state: Post.published() + ready_state: Post.published(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -10) ) post2 = insert(:post, user: san_author2, state: Post.approved_state(), - ready_state: Post.published() + ready_state: Post.published(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -9) ) post3 = insert(:post, user: san_author2, state: Post.approved_state(), - ready_state: Post.published() + ready_state: Post.published(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -8) ) event_with_0_votes_and_1_comments_by_followed = insert(:timeline_event, post: post1, user: user_to_follow, - event_type: TimelineEvent.publish_insight_type() + event_type: TimelineEvent.publish_insight_type(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -7) ) EntityComment.create_and_link( @@ -704,7 +724,8 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do insert(:timeline_event, post: post2, user: san_author2, - event_type: TimelineEvent.publish_insight_type() + event_type: TimelineEvent.publish_insight_type(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -6) ) Sanbase.Vote.create(%{ @@ -716,7 +737,8 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do insert(:timeline_event, post: post3, user: san_author2, - event_type: TimelineEvent.publish_insight_type() + event_type: TimelineEvent.publish_insight_type(), + inserted_at: Timex.shift(NaiveDateTime.utc_now(), seconds: -5) ) %{ diff --git a/test/sanbase_web/graphql/user/user_api_test.exs b/test/sanbase_web/graphql/user/user_api_test.exs index b7f3f4177f..0f54e50064 100644 --- a/test/sanbase_web/graphql/user/user_api_test.exs +++ b/test/sanbase_web/graphql/user/user_api_test.exs @@ -236,11 +236,12 @@ defmodule SanbaseWeb.Graphql.UserApiTest do |> Repo.insert!() |> User.update_email_candidate("example+foo@santiment.net") + generated_at = + Timex.shift(NaiveDateTime.utc_now(), days: -2) |> NaiveDateTime.truncate(:second) + user = user - |> Ecto.Changeset.change( - email_candidate_token_generated_at: Timex.shift(Timex.now(), days: -2) - ) + |> Ecto.Changeset.change(email_candidate_token_generated_at: generated_at) |> Repo.update!() query = """ @@ -414,9 +415,11 @@ defmodule SanbaseWeb.Graphql.UserApiTest do |> Repo.insert!() |> User.update_email_token() + generated_at = Timex.shift(Timex.now(), days: -2) |> NaiveDateTime.truncate(:second) + user = user - |> Ecto.Changeset.change(email_token_generated_at: Timex.shift(Timex.now(), days: -2)) + |> Ecto.Changeset.change(email_token_generated_at: generated_at) |> Repo.update!() query = """ @@ -447,11 +450,13 @@ defmodule SanbaseWeb.Graphql.UserApiTest do |> Repo.insert!() |> User.update_email_token() + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + user = user |> Ecto.Changeset.change( - email_token_generated_at: Timex.now(), - email_token_validated_at: Timex.now() + email_token_generated_at: naive_now, + email_token_validated_at: naive_now ) |> Repo.update!() @@ -488,11 +493,13 @@ defmodule SanbaseWeb.Graphql.UserApiTest do |> Repo.insert!() |> User.update_email_token() + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + user = user |> Ecto.Changeset.change( - email_token_generated_at: Timex.now(), - email_token_validated_at: Timex.shift(Timex.now(), minutes: -20) + email_token_generated_at: naive_now, + email_token_validated_at: Timex.shift(naive_now, minutes: -20) ) |> Repo.update!() diff --git a/test/sanbase_web/graphql/user/user_eth_account_api_test.exs b/test/sanbase_web/graphql/user/user_eth_account_api_test.exs index 37df57d1f6..442ae4bcd9 100644 --- a/test/sanbase_web/graphql/user/user_eth_account_api_test.exs +++ b/test/sanbase_web/graphql/user/user_eth_account_api_test.exs @@ -87,7 +87,7 @@ defmodule SanbaseWeb.Graphql.UserEthAccountApiTest do result = add_eth_address(context.conn, @address) %{"errors" => [error]} = result assert error["message"] == "Could not add an ethereum address." - end) =~ ~s/[address: {"has already been taken", []}]/ + end) =~ ~s/[address: {"has already been taken"/ end # Helper functions diff --git a/test/sanbase_web/graphql/watchlist/watchlist_historical_stats_api_test.exs b/test/sanbase_web/graphql/watchlist/watchlist_historical_stats_api_test.exs index 6d938c6833..5b0357ac19 100644 --- a/test/sanbase_web/graphql/watchlist/watchlist_historical_stats_api_test.exs +++ b/test/sanbase_web/graphql/watchlist/watchlist_historical_stats_api_test.exs @@ -81,11 +81,11 @@ defmodule SanbaseWeb.Graphql.WatchlistHistoricalStatsApiTest do } } - fn -> + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: data}}) + |> Sanbase.Mock.run_with_mocks(fn -> result = get_watchlist_historical_stats(conn, from, to, watchlist) assert result == expected_result - end - |> Sanbase.Mock.with_mock2(&Sanbase.ClickhouseRepo.query/2, {:ok, %{rows: data}}) + end) end test "empty watchlist", context do @@ -100,11 +100,11 @@ defmodule SanbaseWeb.Graphql.WatchlistHistoricalStatsApiTest do test "the database returns an errors", context do %{conn: conn, from: from, to: to, watchlist: watchlist} = context - fn -> + Sanbase.Mock.prepare_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "Clickhouse error"}) + |> Sanbase.Mock.run_with_mocks(fn -> %{"errors" => [error]} = get_watchlist_historical_stats(conn, from, to, watchlist) assert error["message"] =~ "Can't fetch historical stats for a watchlist." - end - |> Sanbase.Mock.with_mock2(&Sanbase.ClickhouseRepo.query/2, {:error, "Clickhouse error"}) + end) end defp get_watchlist_historical_stats(conn, from, to, watchlist) do diff --git a/test/support/mock.ex b/test/support/mock.ex index 46bc418ecf..37729a49ba 100644 --- a/test/support/mock.ex +++ b/test/support/mock.ex @@ -43,26 +43,6 @@ defmodule Sanbase.Mock do end end - def with_mock2(assert_fun, {module, fun_name, fun_body}) do - with_mock(module, [{fun_name, fun_body}], do: assert_fun.()) - end - - for arity <- 0..16 do - @arity arity - - def with_mock2(assert_fun, captured_fun, data) - when is_function(captured_fun, unquote(arity)) do - {:name, name} = Function.info(captured_fun, :name) - {:module, module} = Function.info(captured_fun, :module) - - fun = fn unquote_splicing(Macro.generate_arguments(@arity, __MODULE__)) -> - data - end - - with_mock(module, [{name, fun}], do: assert_fun.()) - end - end - def init(), do: MapSet.new() def prepare_mock(state \\ MapSet.new(), module, fun_name, fun_body, opts \\ []) From e4e6bb64eca00c168c4056b78eed7d315c09b151 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 26 May 2020 16:03:51 +0300 Subject: [PATCH 06/12] Remove start_in for ClickhouseRepo --- lib/sanbase/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sanbase/application.ex b/lib/sanbase/application.ex index 948415b60c..6d4a96b4cb 100644 --- a/lib/sanbase/application.ex +++ b/lib/sanbase/application.ex @@ -167,7 +167,7 @@ defmodule Sanbase.Application do Sanbase.Repo, # Start the Clickhouse Repo - start_in({Sanbase.ClickhouseRepo, []}, [:dev, :prod, :test]), + Sanbase.ClickhouseRepo, # Time series Prices DB connection Sanbase.Prices.Store.child_spec(), From bd762a9497c72acf32549e9783cb02b788c06cac Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 26 May 2020 17:23:28 +0300 Subject: [PATCH 07/12] Use clickhousex master branch --- lib/sanbase/application.ex | 2 -- lib/sanbase/user_lists/watchlist_function.ex | 8 ++++++-- lib/sanbase_web/admin/auth/user.ex | 16 ++++++---------- .../graphql/resolvers/user/user_resolver.ex | 2 +- mix.exs | 7 ++----- mix.lock | 6 +++--- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/sanbase/application.ex b/lib/sanbase/application.ex index 6d4a96b4cb..a13279e108 100644 --- a/lib/sanbase/application.ex +++ b/lib/sanbase/application.ex @@ -1,8 +1,6 @@ defmodule Sanbase.Application do use Application - import Sanbase.ApplicationUtils - require Logger require Sanbase.Utils.Config, as: Config diff --git a/lib/sanbase/user_lists/watchlist_function.ex b/lib/sanbase/user_lists/watchlist_function.ex index cf71416a79..2f82f2fcb5 100644 --- a/lib/sanbase/user_lists/watchlist_function.ex +++ b/lib/sanbase/user_lists/watchlist_function.ex @@ -1,11 +1,11 @@ defmodule Sanbase.WatchlistFunction do - use Vex.Struct + use Ecto.Type defstruct name: "empty", args: [] alias Sanbase.Model.Project - @behaviour Ecto.Type + @impl Ecto.Type def type, do: :map def evaluate(%__MODULE__{name: "market_segment", args: args}) do @@ -50,10 +50,12 @@ defmodule Sanbase.WatchlistFunction do def empty(), do: %__MODULE__{name: "empty", args: []} + @impl Ecto.Type def cast(function) when is_binary(function) do parse(function) end + @impl Ecto.Type def cast(%__MODULE__{} = function), do: {:ok, function} def cast(%{} = function) do @@ -67,6 +69,7 @@ defmodule Sanbase.WatchlistFunction do def cast(_), do: :error + @impl Ecto.Type def load(function) when is_map(function) do function = for {key, val} <- function do @@ -76,6 +79,7 @@ defmodule Sanbase.WatchlistFunction do {:ok, struct!(__MODULE__, function)} end + @impl Ecto.Type def dump(%__MODULE__{} = function), do: {:ok, Map.from_struct(function)} def dump(_), do: :error diff --git a/lib/sanbase_web/admin/auth/user.ex b/lib/sanbase_web/admin/auth/user.ex index 9b0c725afb..97f2b63052 100644 --- a/lib/sanbase_web/admin/auth/user.ex +++ b/lib/sanbase_web/admin/auth/user.ex @@ -4,8 +4,6 @@ defmodule Sanbase.ExAdmin.Auth.User do alias Sanbase.Auth.EthAccount alias Sanbase.Insight.Post - @environment Mix.env() - register_resource Sanbase.Auth.User do controller do before_filter(:assign_all_user_insights_to_anonymous, only: [:destroy]) @@ -19,14 +17,12 @@ defmodule Sanbase.ExAdmin.Auth.User do column(:id, link: true) column(:address) - unless @environment == :dev do - column("San balance", fn eth_account -> - case EthAccount.san_balance(eth_account) do - nil -> "" - san_balance -> san_balance |> Decimal.to_string() - end - end) - end + column("San balance", fn eth_account -> + case EthAccount.san_balance(eth_account) do + nil -> "" + san_balance -> san_balance + end + end) end end end diff --git a/lib/sanbase_web/graphql/resolvers/user/user_resolver.ex b/lib/sanbase_web/graphql/resolvers/user/user_resolver.ex index bd63fc5488..953a8aa492 100644 --- a/lib/sanbase_web/graphql/resolvers/user/user_resolver.ex +++ b/lib/sanbase_web/graphql/resolvers/user/user_resolver.ex @@ -268,7 +268,7 @@ defmodule SanbaseWeb.Graphql.Resolvers.UserResolver do is_registered: true }) ) - |> Multi.run(:add_eth_account, fn %{add_user: %User{id: id}} -> + |> Multi.run(:add_eth_account, fn _repo, %{add_user: %User{id: id}} -> eth_account = EthAccount.changeset(%EthAccount{}, %{user_id: id, address: address}) |> Repo.insert() diff --git a/mix.exs b/mix.exs index 06f405fbae..2c1f0b9bca 100644 --- a/mix.exs +++ b/mix.exs @@ -47,10 +47,7 @@ defmodule Sanbase.Mixfile do {:async_with, github: "fertapric/async_with"}, {:basic_auth, "~> 2.2"}, {:clickhouse_ecto, github: "santiment/clickhouse_ecto", branch: "migrate-ecto-3"}, - {:clickhousex, - github: "ivanivanoff/clickhousex", - branch: "revert-17-revert-15-prepare_for_ecto_3", - override: true}, + {:clickhousex, github: "ivanivanoff/clickhousex", override: true}, {:con_cache, "~> 0.13"}, {:corsica, "~> 1.0"}, {:cowboy, "~> 2.0"}, @@ -62,7 +59,7 @@ defmodule Sanbase.Mixfile do {:dialyxir, "~> 1.0.0-rc.6", only: [:dev], runtime: false}, {:distillery, "~> 2.0", runtime: false}, {:earmark, "~> 1.2"}, - {:ecto_enum, "~> 1.3"}, + {:ecto_enum, "~> 1.4"}, {:ecto, "~> 3.0"}, {:ecto_sql, "~> 3.0"}, {:envy, "~> 1.1.1", only: [:dev, :test]}, diff --git a/mix.lock b/mix.lock index 7f6fd30287..b38f37d56d 100644 --- a/mix.lock +++ b/mix.lock @@ -13,7 +13,7 @@ "castore": {:hex, :castore, "0.1.5", "591c763a637af2cc468a72f006878584bc6c306f8d111ef8ba1d4c10e0684010", [:mix], [], "hexpm", "6db356b2bc6cc22561e051ff545c20ad064af57647e436650aa24d7d06cd941a"}, "certifi": {:git, "https://github.com/certifi/erlang-certifi", "e08b12e8993502240c25b78563993776f87ecd2a", [tag: "2.5.1"]}, "clickhouse_ecto": {:git, "https://github.com/santiment/clickhouse_ecto.git", "9518142275534f040edb19c61646fc3aed889040", [branch: "migrate-ecto-3"]}, - "clickhousex": {:git, "https://github.com/ivanivanoff/clickhousex.git", "1a3b25080fa755f1e5d68803e01a548c2995920f", [branch: "revert-17-revert-15-prepare_for_ecto_3"]}, + "clickhousex": {:git, "https://github.com/ivanivanoff/clickhousex.git", "d138f85c53a102059af1a682fc8dc4aabdf10b66", []}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "con_cache": {:hex, :con_cache, "0.14.0", "863acb90fa08017be3129074993af944cf7a4b6c3ee7c06c5cd0ed6b94fbc223", [:mix], [], "hexpm", "50887a8949377d0b707a3c6653b7610de06074751b52d0f267f52135f391aece"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, @@ -32,8 +32,8 @@ "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, "ecto": {:hex, :ecto, "3.4.4", "a2c881e80dc756d648197ae0d936216c0308370332c5e77a2325a10293eef845", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4bd3ad62abc3b21fb629f0f7a3dab23a192fca837d257dd08449fba7373561"}, - "ecto_enum": {:hex, :ecto_enum, "1.3.2", "659f7251b6a201a236db9dceef0f713319f095a23ad1d8718efd7a3d3ef3e21b", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "7d111aef5601596f1c6da3fd1de784cb7ed7f8eca3f8af631df04f11fc8f248f"}, - "ecto_sql": {:hex, :ecto_sql, "3.4.3", "c552aa8a7ccff2b64024f835503b3155d8e73452c180298527fbdbcd6e79710b", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ec9e59d6fa3f8cfda9963ada371e9e6659167c2338a997bd7ea23b10b245842b"}, + "ecto_enum": {:hex, :ecto_enum, "1.4.0", "d14b00e04b974afc69c251632d1e49594d899067ee2b376277efd8233027aec8", [:mix], [{:ecto, ">= 3.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "> 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "8fb55c087181c2b15eee406519dc22578fa60dd82c088be376d0010172764ee4"}, + "ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"}, "envy": {:hex, :envy, "1.1.1", "0bc9bd654dec24fcdf203f7c5aa1b8f30620f12cfb28c589d5e9c38fe1b07475", [:mix], [], "hexpm", "7061eb1a47415fd757145d8dec10dc0b1e48344960265cb108f194c4252c3a89"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_admin": {:git, "https://github.com/IvanIvanoff/ex_admin.git", "6a520b3c0c2662960801865cdfd6a2085914909a", [branch: "apply-changes"]}, From bd2a0551331c1b667406fffdb67d3da4b80b7991 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 27 May 2020 14:15:58 +0300 Subject: [PATCH 08/12] Address Ecto 3 migraiton issues - Add comments to functions - Add --skip-if-loaded flag to test alias - Make insights datetimes all :naive_datetime - Fix wrong @impl in MetricAdapter --- lib/sanbase/auth/user.ex | 2 -- lib/sanbase/clickhouse_repo.ex | 10 ++++++++++ lib/sanbase/insight/post.ex | 13 +++++++++---- lib/sanbase/social_data/metric_adapter.ex | 17 ++++++++--------- lib/sanbase/voting/vote.ex | 2 -- mix.exs | 2 +- test/sanbase/signals/validation_test.exs | 6 ++---- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/sanbase/auth/user.ex b/lib/sanbase/auth/user.ex index b90acfe5e1..eb3c1ad10b 100644 --- a/lib/sanbase/auth/user.ex +++ b/lib/sanbase/auth/user.ex @@ -1,8 +1,6 @@ defmodule Sanbase.Auth.User do use Ecto.Schema - # use Timex.Ecto.Timestamps - import Ecto.Changeset import Ecto.Query diff --git a/lib/sanbase/clickhouse_repo.ex b/lib/sanbase/clickhouse_repo.ex index f0467ff9c2..eca298af58 100644 --- a/lib/sanbase/clickhouse_repo.ex +++ b/lib/sanbase/clickhouse_repo.ex @@ -82,12 +82,22 @@ defmodule Sanbase.ClickhouseRepo do end end + @doc ~s""" + Replace positional params denoted as `?1`, `?2`, etc. with just `?` as they + are not supported by ClickHouse. A complex regex is used as such character + sequences can apear inside strings in which case they should not be removed. + """ def sanitize_query(query) do query |> IO.iodata_to_binary() |> String.replace(~r/(\?([0-9]+))(?=(?:[^\\"']|[\\"'][^\\"']*[\\"'])*$)/, "?") end + @doc ~s""" + Add artificial support for positional paramters. Extract all occurences of `?1`, + `?2`, etc. in the query and reorder and duplicate the params so every param + in the list appears in order as if every positional param is just `?` + """ def order_params(query, params) do sanitised = Regex.replace(~r/(([^\\]|^))["'].*?[^\\]['"]/, IO.iodata_to_binary(query), "\\g{1}") diff --git a/lib/sanbase/insight/post.ex b/lib/sanbase/insight/post.ex index 37c0ec878c..e7285f45da 100644 --- a/lib/sanbase/insight/post.ex +++ b/lib/sanbase/insight/post.ex @@ -1,8 +1,6 @@ defmodule Sanbase.Insight.Post do use Ecto.Schema - # use Timex.Ecto.Timestamps - import Ecto.Changeset import Ecto.Query import Sanbase.Utils.ErrorHandling, only: [changeset_errors_to_str: 1] @@ -61,7 +59,7 @@ defmodule Sanbase.Insight.Post do on_delete: :delete_all ) - field(:published_at, :naive_datetime_usec) + field(:published_at, :naive_datetime) timestamps() end @@ -71,6 +69,8 @@ defmodule Sanbase.Insight.Post do end def create_changeset(%Post{} = post, attrs) do + attrs = Sanbase.DateTimeUtils.truncate_datetimes(attrs) + post |> cast(attrs, [ :title, @@ -90,6 +90,8 @@ defmodule Sanbase.Insight.Post do end def update_changeset(%Post{} = post, attrs) do + attrs = Sanbase.DateTimeUtils.truncate_datetimes(attrs) + preloads = if(attrs[:tags], do: [:tags], else: []) ++ if attrs[:metrics], do: [:metrics], else: [] @@ -114,9 +116,12 @@ defmodule Sanbase.Insight.Post do end def publish_changeset(%Post{} = post, attrs) do + attrs = Sanbase.DateTimeUtils.truncate_datetimes(attrs) + naive_now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + post |> cast(attrs, [:ready_state, :published_at]) - |> change(published_at: NaiveDateTime.utc_now()) + |> change(published_at: naive_now) end def awaiting_approval_state(), do: @awaiting_approval diff --git a/lib/sanbase/social_data/metric_adapter.ex b/lib/sanbase/social_data/metric_adapter.ex index be7045a1eb..7bf28c46ca 100644 --- a/lib/sanbase/social_data/metric_adapter.ex +++ b/lib/sanbase/social_data/metric_adapter.ex @@ -137,15 +137,6 @@ defmodule Sanbase.SocialData.MetricAdapter do @impl Sanbase.Metric.Behaviour def available_aggregations(), do: @aggregations - @impl Sanbase.Metric.Behaviour - def available_social_slugs() do - # Providing a 2 element tuple `{any, integer}` will use that second element - # as TTL for the cache key - Sanbase.Cache.get_or_store({:social_metrics_available_slugs, 1800}, fn -> - Sanbase.SocialData.SocialVolume.social_volume_projects() - end) - end - @impl Sanbase.Metric.Behaviour def available_slugs(), do: {:ok, Project.List.projects_slugs(preload?: false)} @@ -241,4 +232,12 @@ defmodule Sanbase.SocialData.MetricAdapter do defp metric_to_source("social_volume_" <> source), do: source defp metric_to_source("social_dominance_" <> source), do: source defp metric_to_source("community_messages_count_" <> source), do: source + + defp available_social_slugs() do + # Providing a 2 element tuple `{any, integer}` will use that second element + # as TTL for the cache key + Sanbase.Cache.get_or_store({:social_metrics_available_slugs, 1800}, fn -> + Sanbase.SocialData.SocialVolume.social_volume_projects() + end) + end end diff --git a/lib/sanbase/voting/vote.ex b/lib/sanbase/voting/vote.ex index 2790af3ea8..f14d83c2f4 100644 --- a/lib/sanbase/voting/vote.ex +++ b/lib/sanbase/voting/vote.ex @@ -4,8 +4,6 @@ defmodule Sanbase.Vote do """ use Ecto.Schema - # use Timex.Ecto.Timestamps - import Ecto.Changeset alias Sanbase.Repo diff --git a/mix.exs b/mix.exs index 2c1f0b9bca..ae8608b555 100644 --- a/mix.exs +++ b/mix.exs @@ -141,7 +141,7 @@ defmodule Sanbase.Mixfile do test: [ "load_dotenv", "ecto.create -r Sanbase.Repo --quiet", - "ecto.load -r Sanbase.Repo", + "ecto.load -r Sanbase.Repo --skip-if-loaded", "test" ], diff --git a/test/sanbase/signals/validation_test.exs b/test/sanbase/signals/validation_test.exs index 2c31527abf..341eaf8d3e 100644 --- a/test/sanbase/signals/validation_test.exs +++ b/test/sanbase/signals/validation_test.exs @@ -478,10 +478,8 @@ defmodule Sanbase.Signal.ValidationTest do alias Sanbase.Model.Project test "with binary slug, which is a project, returns :ok" do - project = Sanbase.Factory.insert(%Project{name: "santiment", slug: "santiment"}) - project_slug = %{slug: "santiment"} - - assert Validation.valid_slug?(project_slug) == :ok + project = Sanbase.Factory.insert(:project, %{name: "santiment", slug: "santiment"}) + assert Validation.valid_slug?(%{slug: project.slug}) == :ok end test "with binary slug, but not a project, returns :error" do From 22e66b39e50c9097e5ba7bd8f9c5f718d565424d Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 27 May 2020 15:03:16 +0300 Subject: [PATCH 09/12] Timeline cursor uses >= and <=. Add tests for cursor --- lib/sanbase/timeline/cursor.ex | 4 +- test/sanbase/signals/validation_test.exs | 2 - .../timeline/timeline_event_api_test.exs | 116 +++++++++++++----- 3 files changed, 89 insertions(+), 33 deletions(-) diff --git a/lib/sanbase/timeline/cursor.ex b/lib/sanbase/timeline/cursor.ex index 58419ca496..9554ca5a24 100644 --- a/lib/sanbase/timeline/cursor.ex +++ b/lib/sanbase/timeline/cursor.ex @@ -4,14 +4,14 @@ defmodule Sanbase.Timeline.Cursor do def filter_by_cursor(query, :before, datetime) do from( event in query, - where: event.inserted_at < ^DateTime.to_naive(datetime) + where: event.inserted_at <= ^datetime ) end def filter_by_cursor(query, :after, datetime) do from( event in query, - where: event.inserted_at > ^DateTime.to_naive(datetime) + where: event.inserted_at >= ^datetime ) end diff --git a/test/sanbase/signals/validation_test.exs b/test/sanbase/signals/validation_test.exs index 341eaf8d3e..7ef1fd650e 100644 --- a/test/sanbase/signals/validation_test.exs +++ b/test/sanbase/signals/validation_test.exs @@ -475,8 +475,6 @@ defmodule Sanbase.Signal.ValidationTest do end describe "#valid_slug?" do - alias Sanbase.Model.Project - test "with binary slug, which is a project, returns :ok" do project = Sanbase.Factory.insert(:project, %{name: "santiment", slug: "santiment"}) assert Validation.valid_slug?(%{slug: project.slug}) == :ok diff --git a/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs b/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs index 40dfd0519b..4bf163ea7c 100644 --- a/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs +++ b/test/sanbase_web/graphql/timeline/timeline_event_api_test.exs @@ -90,7 +90,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do event_type: TimelineEvent.create_public_trigger_type() ) - result = timeline_events_query(conn, "limit: 5") + result = get_timeline_events(conn, "limit: 5") # Watchlist updates are ignored now assert result |> hd() |> Map.get("events") |> length() == 2 @@ -143,7 +143,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do event_type: TimelineEvent.create_public_trigger_type() ) - result = timeline_events_query(conn, "limit: 5") + result = get_timeline_events(conn, "limit: 5") assert result |> hd() |> Map.get("events") |> length() == 0 end @@ -152,7 +152,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do {_timeline_event, user_trigger} = create_timeline_event(context.user) trigger_fired_event = - timeline_events_query(context.conn, "limit: 5") + get_timeline_events(context.conn, "limit: 5") |> hd() |> Map.get("events") |> hd() @@ -193,7 +193,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}} ) - assert timeline_events_query(context.conn, "limit: 5") + assert get_timeline_events(context.conn, "limit: 5") |> hd() |> Map.get("events") |> length() == 1 @@ -222,7 +222,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}} ) - assert timeline_events_query(context.conn, "limit: 5") + assert get_timeline_events(context.conn, "limit: 5") |> hd() |> Map.get("events") |> length() == 1 @@ -252,7 +252,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}} ) - assert timeline_events_query(context.conn, "limit: 5") |> hd() |> Map.get("events") == [] + assert get_timeline_events(context.conn, "limit: 5") |> hd() |> Map.get("events") == [] end test "trigger fired event from private trigger from followed user is not fetched", context do @@ -278,7 +278,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}} ) - assert timeline_events_query(context.conn, "limit: 5") |> hd() |> Map.get("events") == [] + assert get_timeline_events(context.conn, "limit: 5") |> hd() |> Map.get("events") == [] end describe "timeline events for not logged in user" do @@ -299,7 +299,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do event_type: TimelineEvent.publish_insight_type() ) - result = timeline_events_query(build_conn(), "limit: 5") + result = get_timeline_events(build_conn(), "limit: 5") assert result |> hd() |> Map.get("events") |> length() == 1 end @@ -327,7 +327,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do data: %{"user_trigger_data" => %{"default" => %{"value" => 15}}} ) - result = timeline_events_query(build_conn(), "limit: 5") + result = get_timeline_events(build_conn(), "limit: 5") assert result |> hd() |> Map.get("events") == [] end @@ -368,7 +368,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do describe "order timeline events" do test "by datetime by default", context do events = create_test_events(context) - result = timeline_events_query(context.conn, "limit: 3") + result = get_timeline_events(context.conn, "limit: 3") assert event_ids(result) == [ events.event_with_0_votes_and_0_comments_by_sanfam.id, @@ -383,7 +383,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do {:ok, _user_list} = UserList.create_user_list(context.user, %{name: "My Test List", is_public: true}) - result = timeline_events_query(context.conn, "limit: 4, orderBy: VOTES") + result = get_timeline_events(context.conn, "limit: 4, orderBy: VOTES") assert event_ids(result) == [ events.event_with_1_votes_and_0_comments_by_sanfam.id, @@ -395,7 +395,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do test "by number of comments, by datetime", context do events = create_test_events(context) - result = timeline_events_query(context.conn, "limit: 3, orderBy: COMMENTS") + result = get_timeline_events(context.conn, "limit: 3, orderBy: COMMENTS") assert event_ids(result) == [ events.event_with_0_votes_and_1_comments_by_followed.id, @@ -407,7 +407,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do test "by author name, by datetime", context do events = create_test_events(context) - result = timeline_events_query(context.conn, "limit: 3, orderBy: AUTHOR") + result = get_timeline_events(context.conn, "limit: 3, orderBy: AUTHOR") assert event_ids(result) == [ events.event_with_0_votes_and_1_comments_by_followed.id, @@ -424,7 +424,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do {:ok, _user_list} = UserList.create_user_list(context.user, %{name: "My Test List", is_public: true}) - result = timeline_events_query(context.conn, "filterBy: {author: ALL}, limit: 4") + result = get_timeline_events(context.conn, "filterBy: {author: ALL}, limit: 4") assert event_ids(result) == [ events.event_with_0_votes_and_0_comments_by_sanfam.id, @@ -435,7 +435,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do test "by san family", context do events = create_test_events(context) - result = timeline_events_query(context.conn, "filterBy: {author: SANFAM}, limit: 3") + result = get_timeline_events(context.conn, "filterBy: {author: SANFAM}, limit: 3") assert event_ids(result) == [ events.event_with_0_votes_and_0_comments_by_sanfam.id, @@ -445,7 +445,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do test "by followed users", context do events = create_test_events(context) - result = timeline_events_query(context.conn, "filterBy: {author: FOLLOWED}, limit: 3") + result = get_timeline_events(context.conn, "filterBy: {author: FOLLOWED}, limit: 3") assert event_ids(result) == [ events.event_with_0_votes_and_1_comments_by_followed.id @@ -465,7 +465,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do event_type: TimelineEvent.update_watchlist_type() ) - result = timeline_events_query(context.conn, "filterBy: {author: OWN}, limit: 3") + result = get_timeline_events(context.conn, "filterBy: {author: OWN}, limit: 3") # watchlist events are ignored now assert event_ids(result) == [] end @@ -487,7 +487,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do create_test_events(context) result = - timeline_events_query( + get_timeline_events( context.conn, "filterBy: {author: ALL, watchlists: [#{user_list.id}]}, limit: 3" ) @@ -545,7 +545,7 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do create_test_events(context) result = - timeline_events_query( + get_timeline_events( context.conn, "filterBy: {author: ALL, assets: [#{context.project.id}]}, limit: 5" ) @@ -559,9 +559,72 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do end end - defp timeline_events_query(conn, args_str) do - query = - ~s| + describe "cursor filtered events" do + test "cursor before", context do + events = create_test_events(context) + now = DateTime.utc_now() + + args_str = "cursor: " <> map_to_input_object_str(%{type: :before, datetime: now}) + + events1 = + get_timeline_events( + context.conn, + args_str + ) + |> hd() + |> Map.get("events") + + assert length(events1) == length(events |> Map.keys()) + + args_str = + "cursor: " <> + map_to_input_object_str(%{type: :before, datetime: Timex.shift(now, seconds: -60)}) + + events2 = + get_timeline_events( + context.conn, + args_str + ) + |> hd() + |> Map.get("events") + + assert length(events2) == 0 + end + + test "cursor after", context do + events = create_test_events(context) + now = DateTime.utc_now() + + args_str = "cursor: " <> map_to_input_object_str(%{type: :after, datetime: now}) + + events1 = + get_timeline_events( + context.conn, + args_str + ) + |> hd() + |> Map.get("events") + + assert length(events1) == 0 + + args_str = + "cursor: " <> + map_to_input_object_str(%{type: :after, datetime: Timex.shift(now, seconds: -60)}) + + events2 = + get_timeline_events( + context.conn, + args_str + ) + |> hd() + |> Map.get("events") + + assert length(events2) == length(events |> Map.keys()) + end + end + + defp get_timeline_events(conn, args_str) do + query = ~s| { timelineEvents(#{args_str}) { cursor { @@ -597,7 +660,8 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do } } }| - |> format_interpolated_json() + + # |> format_interpolated_json() result = conn @@ -836,10 +900,4 @@ defmodule SanbaseWeb.Graphql.TimelineEventApiTest do |> Map.get("events") |> Enum.map(&String.to_integer(&1["id"])) end - - defp format_interpolated_json(string) do - string - |> String.replace(~r|\"|, ~S|\\"|) - |> String.replace(~r|'|, ~S|"|) - end end From 852cd86551d4544e16e60b4af0d8398ea6b80191 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 27 May 2020 18:23:39 +0300 Subject: [PATCH 10/12] Use ex_admin master branch --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index ae8608b555..10315bea7f 100644 --- a/mix.exs +++ b/mix.exs @@ -64,7 +64,7 @@ defmodule Sanbase.Mixfile do {:ecto_sql, "~> 3.0"}, {:envy, "~> 1.1.1", only: [:dev, :test]}, {:erlex, "~> 0.2.6", override: true}, - {:ex_admin, github: "IvanIvanoff/ex_admin", branch: "apply-changes"}, + {:ex_admin, github: "IvanIvanoff/ex_admin"}, {:ex_aws_s3, "~> 2.0"}, {:ex_aws, "~> 2.0"}, {:ex_machina, "~> 2.2", only: [:dev, :test]}, diff --git a/mix.lock b/mix.lock index b38f37d56d..8310e8ad5b 100644 --- a/mix.lock +++ b/mix.lock @@ -36,7 +36,7 @@ "ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"}, "envy": {:hex, :envy, "1.1.1", "0bc9bd654dec24fcdf203f7c5aa1b8f30620f12cfb28c589d5e9c38fe1b07475", [:mix], [], "hexpm", "7061eb1a47415fd757145d8dec10dc0b1e48344960265cb108f194c4252c3a89"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_admin": {:git, "https://github.com/IvanIvanoff/ex_admin.git", "6a520b3c0c2662960801865cdfd6a2085914909a", [branch: "apply-changes"]}, + "ex_admin": {:git, "https://github.com/IvanIvanoff/ex_admin.git", "8d72877557c6bf6e23899a355105f0ff8ccb5485", []}, "ex_aws": {:hex, :ex_aws, "2.1.2", "a0f8443556eb527e042c749eb87347d9cd1d13688da4e5354ddee51f99272360", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "b1d24a9afa850963ff2874762316744ddcf48e1f9bad416c57b95e1c5a080f11"}, "ex_aws_s3": {:hex, :ex_aws_s3, "2.0.2", "c0258bbdfea55de4f98f0b2f0ca61fe402cc696f573815134beb1866e778f47b", [:mix], [{:ex_aws, "~> 2.0", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:sweet_xml, ">= 0.0.0", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "0569f5b211b1a3b12b705fe2a9d0e237eb1360b9d76298028df2346cad13097a"}, "ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"}, From 7025d13ba3caba10642c11919c9a564da6b46131 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 27 May 2020 18:25:14 +0300 Subject: [PATCH 11/12] Fix user ex_admin page pattern mismatches --- lib/sanbase_web/admin/auth/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sanbase_web/admin/auth/user.ex b/lib/sanbase_web/admin/auth/user.ex index 97f2b63052..be77dd90cd 100644 --- a/lib/sanbase_web/admin/auth/user.ex +++ b/lib/sanbase_web/admin/auth/user.ex @@ -19,8 +19,8 @@ defmodule Sanbase.ExAdmin.Auth.User do column("San balance", fn eth_account -> case EthAccount.san_balance(eth_account) do - nil -> "" - san_balance -> san_balance + :error -> "" + san_balance -> san_balance || "" end end) end From 2ea18ed7768052361784866ed19efb9db550228f Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Fri, 29 May 2020 17:29:38 +0300 Subject: [PATCH 12/12] Update clickhousex to properly authenticate on chproxy 1.13 --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index 8310e8ad5b..b11b53968b 100644 --- a/mix.lock +++ b/mix.lock @@ -13,7 +13,7 @@ "castore": {:hex, :castore, "0.1.5", "591c763a637af2cc468a72f006878584bc6c306f8d111ef8ba1d4c10e0684010", [:mix], [], "hexpm", "6db356b2bc6cc22561e051ff545c20ad064af57647e436650aa24d7d06cd941a"}, "certifi": {:git, "https://github.com/certifi/erlang-certifi", "e08b12e8993502240c25b78563993776f87ecd2a", [tag: "2.5.1"]}, "clickhouse_ecto": {:git, "https://github.com/santiment/clickhouse_ecto.git", "9518142275534f040edb19c61646fc3aed889040", [branch: "migrate-ecto-3"]}, - "clickhousex": {:git, "https://github.com/ivanivanoff/clickhousex.git", "d138f85c53a102059af1a682fc8dc4aabdf10b66", []}, + "clickhousex": {:git, "https://github.com/ivanivanoff/clickhousex.git", "00fcfffae6c2326d3ed66afdd8bc1522464b8255", []}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "con_cache": {:hex, :con_cache, "0.14.0", "863acb90fa08017be3129074993af944cf7a4b6c3ee7c06c5cd0ed6b94fbc223", [:mix], [], "hexpm", "50887a8949377d0b707a3c6653b7610de06074751b52d0f267f52135f391aece"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},