From 477e566649b7abeee12d0fd47815f3669e5927d5 Mon Sep 17 00:00:00 2001 From: hswick Date: Fri, 28 Sep 2018 19:39:18 -0500 Subject: [PATCH] Changed get_changes to get_filter_changes, filter now returns ok --- lib/exw3.ex | 10 +++++----- test/exw3_test.exs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/exw3.ex b/lib/exw3.ex index ad6bf03..cc9db13 100644 --- a/lib/exw3.ex +++ b/lib/exw3.ex @@ -461,11 +461,11 @@ defmodule ExW3 do ) end - @spec get_changes(binary(), integer()) :: {:ok, []} - def get_changes(filter_id, seconds \\ 0) do + @spec get_filter_changes(binary(), integer()) :: {:ok, []} + def get_filter_changes(filter_id, seconds \\ 0) do GenServer.call( ContractManager, - {:get_changes, {filter_id, seconds}} + {:get_filter_changes, {filter_id, seconds}} ) end @@ -788,10 +788,10 @@ defmodule ExW3 do filter_id = ExW3.new_filter(payload) - {:reply, filter_id, Map.put(state, :filters, Map.put(state[:filters], filter_id, %{contract_name: contract_name, event_name: event_name}))} + {:reply, {:ok, filter_id}, Map.put(state, :filters, Map.put(state[:filters], filter_id, %{contract_name: contract_name, event_name: event_name}))} end - def handle_call({:get_changes, {filter_id, seconds}}, _from, state) do + def handle_call({:get_filter_changes, {filter_id, seconds}}, _from, state) do :timer.sleep(1000 * seconds) diff --git a/test/exw3_test.exs b/test/exw3_test.exs index 2f5b3e5..2cc1c95 100644 --- a/test/exw3_test.exs +++ b/test/exw3_test.exs @@ -202,7 +202,7 @@ defmodule EXW3Test do # Test non indexed events - filter_id = ExW3.Contract.filter(:EventTester, "Simple") + {:ok, filter_id} = ExW3.Contract.filter(:EventTester, "Simple") {:ok, _tx_hash} = ExW3.Contract.send( @@ -212,7 +212,7 @@ defmodule EXW3Test do %{from: Enum.at(context[:accounts], 0), gas: 30_000} ) - {:ok, change_logs} = ExW3.Contract.get_changes(filter_id) + {:ok, change_logs} = ExW3.Contract.get_filter_changes(filter_id) event_log = Enum.at(change_logs, 0) @@ -227,7 +227,7 @@ defmodule EXW3Test do # Test indexed events - indexed_filter_id = ExW3.Contract.filter(:EventTester, "SimpleIndex") + {:ok, indexed_filter_id} = ExW3.Contract.filter(:EventTester, "SimpleIndex") {:ok, _tx_hash} = ExW3.Contract.send( @@ -237,7 +237,7 @@ defmodule EXW3Test do %{from: Enum.at(context[:accounts], 0), gas: 30_000} ) - {:ok, change_logs} = ExW3.Contract.get_changes(indexed_filter_id) + {:ok, change_logs} = ExW3.Contract.get_filter_changes(indexed_filter_id) event_log = Enum.at(change_logs, 0) @@ -251,7 +251,7 @@ defmodule EXW3Test do # Test Indexing Indexed Events - indexed_filter_id = + {:ok, indexed_filter_id} = ExW3.Contract.filter( :EventTester, "SimpleIndex", @@ -270,7 +270,7 @@ defmodule EXW3Test do %{from: Enum.at(context[:accounts], 0), gas: 30_000} ) - {:ok, change_logs} = ExW3.Contract.get_changes(indexed_filter_id) + {:ok, change_logs} = ExW3.Contract.get_filter_changes(indexed_filter_id) event_log = Enum.at(change_logs, 0) assert event_log |> is_map @@ -284,7 +284,7 @@ defmodule EXW3Test do # Tests filter with map params - indexed_filter_id = + {:ok, indexed_filter_id} = ExW3.Contract.filter( :EventTester, "SimpleIndex", @@ -302,7 +302,7 @@ defmodule EXW3Test do ) # Demonstrating the delay capability - {:ok, change_logs} = ExW3.Contract.get_changes(indexed_filter_id, 1) + {:ok, change_logs} = ExW3.Contract.get_filter_changes(indexed_filter_id, 1) event_log = Enum.at(change_logs, 0) assert event_log |> is_map