Skip to content

Commit

Permalink
fix: fix in-flight exit deleted bug and add tests (#1714)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgebal authored Sep 3, 2020
1 parent fd1beac commit f302553
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "priv/cabbage"]
path = priv/cabbage
url = https://github.com/omgnetwork/specs.git
branch = master
branch = master
16 changes: 8 additions & 8 deletions apps/omg_eth/test/omg_eth/root_chain/abi_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -506,25 +506,25 @@ defmodule OMG.Eth.RootChain.AbiTest do
test "if in flight exit deleted can be decoded" do
in_flight_exit_deleted_log = %{
:event_signature => "InFlightExitDeleted(uint160)",
"address" => "0x92ce4d7773c57d96210c46a07b89acf725057f21",
"blockHash" => "0xcafbc4b710c5fab8f3d719f65053637407231ecde31a859f1709e3478a2eda54",
"blockNumber" => "0x14a",
"address" => "0x89afce326e7da55647d22e24336c6a2816c99f6b",
"blockHash" => "0xa27ed6299f3d74954e2c32629a5d807743627f8e57f83c8cbeaa4351da73f597",
"blockNumber" => "0x3e8",
"data" => "0x",
"logIndex" => "0x2",
"logIndex" => "0x0",
"removed" => false,
"topics" => [
"0x1991c4c350498b0cc937c6a08bc5bdecf2e4fdd9d918052a880f102e43dbe45c",
"0x000000000000000000000000003fd275046f2823936fd97c1e3c8b225464d7f1"
"0x00000000000000000000000000d1d291fd21f1899f4c9d621f65dd1e0aa2355d"
],
"transactionHash" => "0xbe310ade41278c5607620311b79363aa520ac46c7ba754bf3027d501c5a95f40",
"transactionIndex" => "0x0"
}

assert Abi.decode_log(in_flight_exit_deleted_log) == %{
eth_height: 330,
eth_height: 1000,
event_signature: "InFlightExitDeleted(uint160)",
exit_id: 1_423_280_346_484_099_708_949_144_162_169_101_241_792_387_057,
log_index: 2,
exit_id: 4_679_199_003_952_701_118_642_806_135_853_996_264_334_177_629,
log_index: 0,
root_chain_txhash:
<<190, 49, 10, 222, 65, 39, 140, 86, 7, 98, 3, 17, 183, 147, 99, 170, 82, 10, 196, 108, 123, 167, 84,
191, 48, 39, 213, 1, 197, 169, 95, 64>>
Expand Down
2 changes: 1 addition & 1 deletion apps/omg_watcher/lib/omg_watcher/exit_processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule OMG.Watcher.ExitProcessor do
def delete_in_flight_exits([]), do: {:ok, []}

def delete_in_flight_exits(in_flight_exit_deleted_events) do
GenServer.call(__MODULE__, {:in_flight_exits_deleted, in_flight_exit_deleted_events}, @timeout)
GenServer.call(__MODULE__, {:delete_in_flight_exits, in_flight_exit_deleted_events}, @timeout)
end

@doc """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
[name: :exit_started, enrich: true],
[name: :in_flight_exit_input_piggybacked, enrich: false],
[name: :in_flight_exit_output_piggybacked, enrich: false],
[name: :in_flight_exit_started, enrich: true]
[name: :in_flight_exit_started, enrich: true],
[name: :in_flight_exit_deleted, enrich: false]
]}
)

Expand Down Expand Up @@ -70,6 +71,11 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
event_fetcher_name: event_fetcher_name
} do
assert event_fetcher_name |> :sys.get_state() |> Map.get(:events) == [
[
signature: "InFlightExitDeleted(uint160)",
name: :in_flight_exit_deleted,
enrich: false
],
[
signature: "InFlightExitStarted(address,bytes32)",
name: :in_flight_exit_started,
Expand Down Expand Up @@ -107,6 +113,7 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
"InFlightExitOutputPiggybacked(address,bytes32,uint16)",
"InFlightExitInputPiggybacked(address,bytes32,uint16)",
"ExitStarted(address,uint160)",
"InFlightExitDeleted(uint160)",
"DepositCreated(address,uint256,address,uint256)"
])
end
Expand Down Expand Up @@ -225,7 +232,8 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
EthereumEventAggregatorTest.deposit_created_log(from_block + 1),
EthereumEventAggregatorTest.exit_started_log(to_block),
EthereumEventAggregatorTest.in_flight_exit_output_piggybacked_log(from_block),
EthereumEventAggregatorTest.in_flight_exit_input_piggybacked_log(to_block)
EthereumEventAggregatorTest.in_flight_exit_input_piggybacked_log(to_block),
EthereumEventAggregatorTest.in_flight_exit_deleted_log(from_block)
]}
end

Expand Down Expand Up @@ -255,6 +263,8 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do

in_flight_exit_output_piggybacked_log = from_block |> in_flight_exit_output_piggybacked_log() |> Abi.decode_log()
in_flight_exit_input_piggybacked_log = to_block |> in_flight_exit_input_piggybacked_log() |> Abi.decode_log()

exit_deleted = from_block |> in_flight_exit_deleted_log() |> Abi.decode_log()
# now we're asserting that the API returns the correct events based on the range
assert EthereumEventAggregator.exit_started(event_fetcher_name, from_block, to_block) == {:ok, [exit_started_log]}

Expand All @@ -264,10 +274,14 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
assert EthereumEventAggregator.deposit_created(event_fetcher_name, from_block, to_block) ==
{:ok, [deposit_created, deposit_created_2]}

assert EthereumEventAggregator.in_flight_exit_deleted(event_fetcher_name, from_block, to_block) ==
{:ok, [exit_deleted]}

# and now we're asserting that the API calls actually stored the events above
# also that the events were stored at the right blknum key
assert Enum.sort(:ets.tab2list(table)) ==
Enum.sort([
{from_block, get_signature_from_event(events, :in_flight_exit_deleted), [exit_deleted]},
{from_block, get_signature_from_event(events, :deposit_created), [deposit_created]},
{from_block, get_signature_from_event(events, :in_flight_exit_output_piggybacked),
[in_flight_exit_output_piggybacked_log]},
Expand All @@ -279,12 +293,14 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
{from_block + 1, get_signature_from_event(events, :in_flight_exit_started), []},
{from_block + 1, get_signature_from_event(events, :in_flight_exit_input_piggybacked), []},
{from_block + 1, get_signature_from_event(events, :exit_started), []},
{from_block + 1, get_signature_from_event(events, :in_flight_exit_deleted), []},
{to_block, get_signature_from_event(events, :deposit_created), []},
{to_block, get_signature_from_event(events, :in_flight_exit_output_piggybacked), []},
{to_block, get_signature_from_event(events, :exit_started), [exit_started_log]},
{to_block, get_signature_from_event(events, :in_flight_exit_input_piggybacked),
[in_flight_exit_input_piggybacked_log]},
{to_block, get_signature_from_event(events, :in_flight_exit_started), []}
{to_block, get_signature_from_event(events, :in_flight_exit_started), []},
{to_block, get_signature_from_event(events, :in_flight_exit_deleted), []}
])
end

Expand Down Expand Up @@ -337,6 +353,7 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do

assert Enum.sort(:ets.tab2list(table)) ==
Enum.sort([
{from_block, get_signature_from_event(events, :in_flight_exit_deleted), []},
{from_block, get_signature_from_event(events, :deposit_created), [deposit_created]},
{to_block, get_signature_from_event(events, :exit_started), [exit_started_log]},
{from_block, get_signature_from_event(events, :in_flight_exit_output_piggybacked),
Expand Down Expand Up @@ -529,6 +546,24 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do
}
end

def in_flight_exit_deleted_log(block_number) do
%{
:event_signature => "InFlightExitDeleted(uint160)",
"address" => "0x92ce4d7773c57d96210c46a07b89acf725057f21",
"blockHash" => "0xcafbc4b710c5fab8f3d719f65053637407231ecde31a859f1709e3478a2eda54",
"blockNumber" => "0x" <> Integer.to_string(block_number, 16),
"data" => "0x",
"logIndex" => "0x2",
"removed" => false,
"topics" => [
"0x1991c4c350498b0cc937c6a08bc5bdecf2e4fdd9d918052a880f102e43dbe45c",
"0x000000000000000000000000003fd275046f2823936fd97c1e3c8b225464d7f1"
],
"transactionHash" => "0xbe310ade41278c5607620311b79363aa520ac46c7ba754bf3027d501c5a95f40",
"transactionIndex" => "0x0"
}
end

def start_standard_exit_log() do
"0x70e014620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000001d1e4e4ea00000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000005df85b01c0f6f501f39408858124b3b880c68b360fd319cc61da27545e9a940000000000000000000000000000000000000000880de0b6b3a764000080a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200f39a869f62e75cf5f0bf914688a6b289caf2049435d8e68c5c5e6d05e44913f34ed5c02d6d48c8932486c99d3ad999e5d8949dc3be3b3058cc2979690c3e3a621c792b14bf66f82af36f00f5fba7014fa0c1e2ff3c7c273bfe523c1acf67dc3f5fa080a686a5a0d05c3d4822fd54d632dc9cc04b1616046eba2ce499eb9af79f5eb949690a0404abf4cebafc7cfffa382191b7dd9e7df778581e6fb78efab35fd364c9d5dadad4569b6dd47f7feabafa3571f842434425548335ac6e690dd07168d8bc5b77979c1a6702334f529f5783f79e942fd2cd03f6e55ac2cf496e849fde9c446fab46a8d27db1e3100f275a777d385b44e3cbc045cabac9da36cae040ad516082324c96127cf29f4535eb5b7ebacfe2a1d6d3aab8ec0483d32079a859ff70f9215970a8beebb1c164c474e82438174c8eeb6fbc8cb4594b88c9448f1d40b09beaecac5b45db6e41434a122b695c5a85862d8eae40b3268f6f37e414337be38eba7ab5bbf303d01f4b7ae07fd73edc2f3be05e43948a34418a3272509c43c2811a821e5c982ba51874ac7dc9dd79a80cc2f05f6f664c9dbb2e454435137da06ce44de45532a56a3a7007a2d0c6b435f726f95104bfa6e707046fc154bae91898d03a1a0ac6f9b45e471646e2555ac79e3fe87eb1781e26f20500240c379274fe91096e60d1545a8045571fdab9b530d0d6e7e8746e78bf9f20f4e86f06"
end
Expand Down

0 comments on commit f302553

Please sign in to comment.