Refactor asserts for merkle proofs to byte_size checks
MODIFY
apps/omg/test/omg/block_test.exs
apps/omg/test/omg/block_test.exs
@@ -172,19 +172,23 @@ defmodule OMG.BlockTest do
end
describe "inclusion_proof/2" do
+ # The tests below checks merkle proof normally tested via speaking to the contract
+ # (integration tests) against a fixed binary. The motivation for having such
+ # test is a quick test of whether the merkle proving didn't change.
@tag fixtures: [:stable_alice]
test "calculates the inclusion proof when a list of transactions is given", %{
stable_alice: alice
} do
+ # odd number of transactions, just in case
tx_1 = TestHelper.create_encoded([{1, 0, 0, alice}], eth(), [{alice, 7}])
tx_2 = TestHelper.create_encoded([{1, 1, 0, alice}], eth(), [{alice, 2}])
+ tx_3 = TestHelper.create_encoded([{1, 0, 1, alice}], eth(), [{alice, 2}])
- encoded_proof =
- [tx_1, tx_2]
- |> Block.inclusion_proof(1)
- |> Base.encode16(case: :lower)
+ proof = Block.inclusion_proof([tx_1, tx_2, tx_3], 1)
- assert "491b9e07c4997c976c38a91f" <> _ = encoded_proof
+ assert "491b9e07c4997c976c38a91f" <> _ = Base.encode16(proof, case: :lower)
+ assert is_binary(proof)
+ assert byte_size(proof) == 32 * 16
end
@tag fixtures: [:stable_alice]
@@ -193,22 +197,30 @@ defmodule OMG.BlockTest do
} do
tx_1 = TestHelper.create_encoded([{1, 0, 0, alice}], eth(), [{alice, 7}])
tx_2 = TestHelper.create_encoded([{1, 1, 0, alice}], eth(), [{alice, 2}])
+ proof = Block.inclusion_proof(%Block{transactions: [tx_1, tx_2]}, 1)
+
+ assert is_binary(proof)
+ assert byte_size(proof) == 32 * 16
+ end
+
+ @tag fixtures: [:stable_alice]
+ test "calculating a proof via a block or a list of transactions return the same result", %{
+ stable_alice: alice
+ } do
+ tx_1 = TestHelper.create_encoded([{1, 0, 0, alice}], eth(), [{alice, 7}])
+ tx_2 = TestHelper.create_encoded([{1, 1, 0, alice}], eth(), [{alice, 2}])
- encoded_proof =
- %Block{transactions: [tx_1, tx_2]}
- |> Block.inclusion_proof(1)
- |> Base.encode16(case: :lower)
+ block_proof = Block.inclusion_proof(%Block{transactions: [tx_1, tx_2]}, 1)
+ transactions_proof = Block.inclusion_proof([tx_1, tx_2], 1)
- assert "491b9e07c4997c976c38a91f" <> _ = encoded_proof
+ assert block_proof == transactions_proof
end
test "calculates the inclusion proof when an empty list is given" do
- encoded_proof =
- []
- |> Block.inclusion_proof(1)
- |> Base.encode16(case: :lower)
+ proof = Block.inclusion_proof([], 1)
- assert "290decd9548b62a8d60345a9" <> _ = encoded_proof
+ assert is_binary(proof)
+ assert byte_size(proof) == 32 * 16
end
test "raises an error when an invalid input is given (map)" do
@@ -217,29 +229,8 @@ defmodule OMG.BlockTest do
end
end
- @tag fixtures: [:stable_alice, :stable_bob]
- test "Block merkle proof smoke test", %{
- stable_alice: alice
- } do
- # this checks merkle proof normally tested via speaking to the contract (integration tests) against
- # a fixed binary. The motivation for having such test is a quick test of whether the merkle proving didn't change
-
- # odd number of transactions, just in case
- tx_1 = TestHelper.create_encoded([{1, 0, 0, alice}], eth(), [{alice, 7}])
- tx_2 = TestHelper.create_encoded([{1, 1, 0, alice}], eth(), [{alice, 2}])
- tx_3 = TestHelper.create_encoded([{1, 0, 1, alice}], eth(), [{alice, 2}])
-
- txs = [tx_1, tx_2, tx_3]
- assert Block.inclusion_proof(txs, 1) == Block.inclusion_proof(%Block{transactions: txs}, 1)
-
- assert %Block{transactions: [tx_1, tx_2, tx_3]}
- |> Block.inclusion_proof(2)
- |> Base.encode16(case: :lower) ==
- "290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563c62f5e8b8c8303e7845c0e8ea800fc1bae9ccb7782b6f3c870c2d48fdddf5bb4890740a8eb06ce9be422cb8da5cdafc2b58c0a5e24036c578de2a433c828ff7d3b8ec09e026fdc305365dfc94e189a81b38c7597b3d941c279f042e8206e0bd8ecd50eee38e386bd62be9bedb990706951b65fe053bd9d8a521af753d139e2dadefff6d330bb5403f63b14f33b578274160de3a50df4efecf0e0db73bcdd3da5617bdd11f7c0a11f49db22f629387a12da7596f9d1704d7465177c63d88ec7d7292c23a9aa1d8bea7e2435e555a4a60e379a5a35f3f452bae60121073fb6eeade1cea92ed99acdcb045a6726b2f87107e8a61620a232cf4d7d5b5766b3952e107ad66c0a68c72cb89e4fb4303841966e4062a76ab97451e3b9fb526a5ceb7f82e026cc5a4aed3c22a58cbd3d2ac754c9352c5436f638042dca99034e836365163d04cffd8b46a874edf5cfae63077de85f849a660426697b06a829c70dd1409cad676aa337a485e4728a0b240d92b3ef7b3c372d06d189322bfd5f61f1e7203ea2fca4a49658f9fab7aa63289c91b7c7b6c832a6d0e69334ff5b0a3483d09dab4ebfd9cd7bca2505f7bef59cc1c12ecc708fff26ae4af19abe852afe9e20c8622def10d13dd169f550f578bda343d9717a138562e0093b380a1120789d53cf10"
- end
-
@tag fixtures: [:alice]
- test "Block merkle proof smoke test for deposit transactions",
+ test "calculates a block merkle proof for deposit transactions",
%{alice: alice} do
tx = TestHelper.create_encoded([], eth(), [{alice, 7}])
proof = Block.inclusion_proof(%Block{transactions: [tx]}, 0)

MODIFY
apps/omg/test/omg/merkle_test.exs
apps/omg/test/omg/merkle_test.exs
@@ -27,18 +27,11 @@ defmodule OMG.MerkleTest do
# return the same result
values = ["abc", "def", "ghi"]
- proof_1 =
- values
- |> Merkle.create_tx_proof(1)
- |> Base.encode16(case: :lower)
-
- proof_2 =
- values
- |> Merkle.create_tx_proof(2)
- |> Base.encode16(case: :lower)
+ proof_1 = Merkle.create_tx_proof(values, 1)
+ proof_2 = Merkle.create_tx_proof(values, 2)
- assert "6162639621ddbb2d2631190" <> _ = proof_1
assert proof_1 != proof_2
+ assert "6162639621ddbb2d2631190" <> _ = Base.encode16(proof_1, case: :lower)
end
end

Refactor asserts for merkle proofs to byte_size checks