From 3c146f92e441303d8dc01d1419625073e4d3f2f3 Mon Sep 17 00:00:00 2001 From: Amanda Date: Wed, 21 Nov 2018 13:18:03 -0200 Subject: [PATCH] Add test to MetadataUpdater's GenServer Co-Authored-By: w-sanches <1727723+w-sanches@users.noreply.github.com> --- .../indexer/token/metadata_updater_test.exs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/apps/indexer/test/indexer/token/metadata_updater_test.exs b/apps/indexer/test/indexer/token/metadata_updater_test.exs index f1caa67e20..e72097f2b4 100644 --- a/apps/indexer/test/indexer/token/metadata_updater_test.exs +++ b/apps/indexer/test/indexer/token/metadata_updater_test.exs @@ -8,6 +8,52 @@ defmodule Indexer.Token.MetadataUpdaterTest do alias Indexer.Token.MetadataUpdater setup :verify_on_exit! + setup :set_mox_global + + test "updates tokens metadata on start" do + insert(:token, name: nil, symbol: nil, decimals: 10, cataloged: true) + + expect( + EthereumJSONRPC.Mox, + :json_rpc, + 1, + fn [%{id: "decimals"}, %{id: "name"}, %{id: "symbol"}, %{id: "totalSupply"}], _opts -> + {:ok, + [ + %{ + id: "decimals", + result: "0x0000000000000000000000000000000000000000000000000000000000000012" + }, + %{ + id: "name", + result: + "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000642616e636f720000000000000000000000000000000000000000000000000000" + }, + %{ + id: "symbol", + result: + "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003424e540000000000000000000000000000000000000000000000000000000000" + }, + %{ + id: "totalSupply", + result: "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000" + } + ]} + end + ) + + pid = start_supervised!({MetadataUpdater, %{update_interval: 0}}) + + wait_for_results(fn -> + updated = Repo.one!(from(t in Token, where: t.cataloged == true and not is_nil(t.name), limit: 1)) + + assert updated.name != nil + assert updated.symbol != nil + end) + + # Terminates the process so it finishes all Ecto processes. + GenServer.stop(pid) + end describe "update_metadata/1" do test "updates the metadata for a list of tokens" do