4
0
Fork 0

Created failing test case for using topics for indexed events

indexed
hswick 7 years ago
parent 6810583771
commit 586a8b416c
  1. 17
      lib/exw3.ex
  2. 34
      test/exw3_test.exs

@ -649,7 +649,7 @@ defmodule ExW3 do
arg_count = Enum.count(arguments)
input_types_count = Enum.count(input_types)
if input_types_count != arg_count do
raise "Number of provided arguments to constructor is incorrect. Was given #{arg_count} args, was looking for #{input_types_count}."
raise "Number of provided arguments to constructor is incorrect. Was given #{arg_count} args, looking for #{input_types_count}."
end
bin <> (ExW3.encode_data(types_signature, arguments) |> Base.encode16(case: :lower))
@ -731,6 +731,13 @@ defmodule ExW3 do
# Calls
defp filter_topics_helper(event_signature, event_data, topic_types) do
if event_data[:topics] do
else
[event_signature]
end
end
def handle_call({:filter, {contract_name, event_name, other_pid, event_data}}, _from, state) do
contract_info = state[contract_name]
@ -739,7 +746,13 @@ defmodule ExW3 do
raise "EventListener process not alive. Call ExW3.EventListener.start_link before using ExW3.Contract.subscribe"
end
payload = Map.merge(%{address: contract_info[:address], topics: [contract_info[:event_names][event_name]]}, event_data)
event_signature = contract_info[:event_names][event_name]
topic_types = contract_info[:events][event_signature]
IO.inspect topic_types
topics = filter_topics_helper(event_signature, event_data, topic_types)
payload = Map.merge(%{address: contract_info[:address], topics: topics}, event_data)
filter_id = ExW3.new_filter(payload)
event_attributes = contract_info[:events][contract_info[:event_names][event_name]]

@ -233,7 +233,7 @@ defmodule EXW3Test do
ExW3.uninstall_filter(filter_id)
# # Test indexed events
# Test indexed events
{:ok, agent} = Agent.start_link(fn -> [] end)
@ -263,6 +263,38 @@ defmodule EXW3Test do
assert ExW3.bytes_to_string(Map.get(log_data, "data")) == "Hello, World!"
assert Map.get(log_data, "otherNum") == 42
ExW3.uninstall_filter(indexed_filter_id)
# Test Indexing Indexed Events
{:ok, agent} = Agent.start_link(fn -> [] end)
indexed_filter_id = ExW3.Contract.filter(:EventTester, "SimpleIndex", self(), %{topics: [46, "Hello, World!"]})
{:ok, _tx_hash} =
ExW3.Contract.send(
:EventTester,
:simpleIndex,
["Hello, World!"],
%{from: Enum.at(context[:accounts], 0), gas: 30_000}
)
receive do
{:event, {_filter_id, data}} ->
Agent.update(agent, fn list -> [data | list] end)
after 3_000 ->
raise "Never received event"
end
state = Agent.get(agent, fn list -> list end)
event_log = Enum.at(state, 0)
assert event_log |> is_map
log_data = Map.get(event_log, "data")
assert log_data |> is_map
assert Map.get(log_data, "num") == 46
assert ExW3.bytes_to_string(Map.get(log_data, "data")) == "Hello, World!"
assert Map.get(log_data, "otherNum") == 42
ExW3.uninstall_filter(indexed_filter_id)
end
test "starts a Contract GenServer for Complex contract", context do

Loading…
Cancel
Save