From aed1192832408ed85f0a21fdfe1be33085b6c55a Mon Sep 17 00:00:00 2001 From: Estefi Date: Fri, 27 May 2022 16:12:52 -0300 Subject: [PATCH 1/6] Add ABI tests --- eth_client/test/abi_test.exs | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 eth_client/test/abi_test.exs diff --git a/eth_client/test/abi_test.exs b/eth_client/test/abi_test.exs new file mode 100644 index 0000000..b97a964 --- /dev/null +++ b/eth_client/test/abi_test.exs @@ -0,0 +1,94 @@ +defmodule EthClientTest.ABI do + use ExUnit.Case + doctest EthClient + alias EthClient.ABI + alias EthClient.Context + + @bin "../contracts/src/bin/Storage.bin" + @abi "../contracts/src/bin/Storage.abi" + + # setup_all do + # EthClient.deploy(@bin, @abi) + # :ok + # end + + describe "get/1" do + @tag bin: @bin, abi: @abi + test "[SUCCESS] Get an ABI by an abi path", %{} do + abi_path = @abi + result = ABI.get(abi_path) + + assert {:ok, + [ + %{ + "inputs" => [], + "name" => "retrieve", + "outputs" => [ + %{"internalType" => "uint256", "name" => "", "type" => "uint256"} + ], + "stateMutability" => "view", + "type" => "function" + }, + %{ + "inputs" => [ + %{"internalType" => "uint256", "name" => "num", "type" => "uint256"} + ], + "name" => "store", + "outputs" => [], + "stateMutability" => "nonpayable", + "type" => "function" + }, + %{ + "inputs" => [], + "name" => "test_function", + "outputs" => [ + %{"internalType" => "uint256", "name" => "", "type" => "uint256"} + ], + "stateMutability" => "pure", + "type" => "function" + } + ]} == result + end + + @tag bin: @bin, abi: @abi + test "[SUCCESS] Get an ABI by an ABI address" do + + contract = Context.contract() + address = contract.address + + result = ABI.get(address) + + assert {:ok, + [ + %{ + "inputs" => [], + "name" => "retrieve", + "outputs" => [ + %{"internalType" => "uint256", "name" => "", "type" => "uint256"} + ], + "stateMutability" => "view", + "type" => "function" + }, + %{ + "inputs" => [ + %{"internalType" => "uint256", "name" => "num", "type" => "uint256"} + ], + "name" => "store", + "outputs" => [], + "stateMutability" => "nonpayable", + "type" => "function" + }, + %{ + "inputs" => [], + "name" => "test_function", + "outputs" => [ + %{"internalType" => "uint256", "name" => "", "type" => "uint256"} + ], + "stateMutability" => "pure", + "type" => "function" + } + ]} == result + end + end + +end From b7cc3e4ef5201354c8c3e1896fcf6c19a5bf82e8 Mon Sep 17 00:00:00 2001 From: Estefi Date: Wed, 1 Jun 2022 17:29:09 -0300 Subject: [PATCH 2/6] wip: abi tests --- eth_client/test/abi_test.exs | 56 ++++++++++++------------------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/eth_client/test/abi_test.exs b/eth_client/test/abi_test.exs index b97a964..5d3ef4b 100644 --- a/eth_client/test/abi_test.exs +++ b/eth_client/test/abi_test.exs @@ -7,10 +7,12 @@ defmodule EthClientTest.ABI do @bin "../contracts/src/bin/Storage.bin" @abi "../contracts/src/bin/Storage.abi" - # setup_all do - # EthClient.deploy(@bin, @abi) - # :ok - # end + setup_all do + # Context.set_chain_id(4) + # Context.set_rpc_host("") + contract = EthClient.deploy(@bin, @abi) + :ok + end describe "get/1" do @tag bin: @bin, abi: @abi @@ -53,41 +55,21 @@ defmodule EthClientTest.ABI do @tag bin: @bin, abi: @abi test "[SUCCESS] Get an ABI by an ABI address" do - contract = Context.contract() - address = contract.address + address = Context.user_account().address - result = ABI.get(address) + {code, _response} = ABI.get(address) - assert {:ok, - [ - %{ - "inputs" => [], - "name" => "retrieve", - "outputs" => [ - %{"internalType" => "uint256", "name" => "", "type" => "uint256"} - ], - "stateMutability" => "view", - "type" => "function" - }, - %{ - "inputs" => [ - %{"internalType" => "uint256", "name" => "num", "type" => "uint256"} - ], - "name" => "store", - "outputs" => [], - "stateMutability" => "nonpayable", - "type" => "function" - }, - %{ - "inputs" => [], - "name" => "test_function", - "outputs" => [ - %{"internalType" => "uint256", "name" => "", "type" => "uint256"} - ], - "stateMutability" => "pure", - "type" => "function" - } - ]} == result + assert :ok == code + end + + @tag bin: @bin, abi: @abi + test "[FAILURE] Get an ABI by an invalid ABI address" do + + address = '0x0' + + assert_raise MatchError, fn -> + ABI.get(address) + end end end From 708491739e41350252d106b879d6e43d6a2357e6 Mon Sep 17 00:00:00 2001 From: Estefi Date: Thu, 2 Jun 2022 10:31:57 -0300 Subject: [PATCH 3/6] ran mix format --- eth_client/test/abi_test.exs | 61 +++++++++++++++++------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/eth_client/test/abi_test.exs b/eth_client/test/abi_test.exs index 5d3ef4b..959df08 100644 --- a/eth_client/test/abi_test.exs +++ b/eth_client/test/abi_test.exs @@ -21,40 +21,39 @@ defmodule EthClientTest.ABI do result = ABI.get(abi_path) assert {:ok, - [ - %{ - "inputs" => [], - "name" => "retrieve", - "outputs" => [ - %{"internalType" => "uint256", "name" => "", "type" => "uint256"} - ], - "stateMutability" => "view", - "type" => "function" - }, - %{ - "inputs" => [ - %{"internalType" => "uint256", "name" => "num", "type" => "uint256"} - ], - "name" => "store", - "outputs" => [], - "stateMutability" => "nonpayable", - "type" => "function" - }, - %{ - "inputs" => [], - "name" => "test_function", - "outputs" => [ - %{"internalType" => "uint256", "name" => "", "type" => "uint256"} - ], - "stateMutability" => "pure", - "type" => "function" - } - ]} == result + [ + %{ + "inputs" => [], + "name" => "retrieve", + "outputs" => [ + %{"internalType" => "uint256", "name" => "", "type" => "uint256"} + ], + "stateMutability" => "view", + "type" => "function" + }, + %{ + "inputs" => [ + %{"internalType" => "uint256", "name" => "num", "type" => "uint256"} + ], + "name" => "store", + "outputs" => [], + "stateMutability" => "nonpayable", + "type" => "function" + }, + %{ + "inputs" => [], + "name" => "test_function", + "outputs" => [ + %{"internalType" => "uint256", "name" => "", "type" => "uint256"} + ], + "stateMutability" => "pure", + "type" => "function" + } + ]} == result end @tag bin: @bin, abi: @abi test "[SUCCESS] Get an ABI by an ABI address" do - address = Context.user_account().address {code, _response} = ABI.get(address) @@ -64,7 +63,6 @@ defmodule EthClientTest.ABI do @tag bin: @bin, abi: @abi test "[FAILURE] Get an ABI by an invalid ABI address" do - address = '0x0' assert_raise MatchError, fn -> @@ -72,5 +70,4 @@ defmodule EthClientTest.ABI do end end end - end From 4dbe0f7f95bee740adaf433d4666dca956775008 Mon Sep 17 00:00:00 2001 From: Estefi Date: Thu, 2 Jun 2022 15:56:13 -0300 Subject: [PATCH 4/6] removed unnecesary configuration --- eth_client/test/abi_test.exs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/eth_client/test/abi_test.exs b/eth_client/test/abi_test.exs index 959df08..a374389 100644 --- a/eth_client/test/abi_test.exs +++ b/eth_client/test/abi_test.exs @@ -15,10 +15,8 @@ defmodule EthClientTest.ABI do end describe "get/1" do - @tag bin: @bin, abi: @abi test "[SUCCESS] Get an ABI by an abi path", %{} do - abi_path = @abi - result = ABI.get(abi_path) + result = ABI.get(@abi) assert {:ok, [ @@ -52,7 +50,6 @@ defmodule EthClientTest.ABI do ]} == result end - @tag bin: @bin, abi: @abi test "[SUCCESS] Get an ABI by an ABI address" do address = Context.user_account().address @@ -61,7 +58,6 @@ defmodule EthClientTest.ABI do assert :ok == code end - @tag bin: @bin, abi: @abi test "[FAILURE] Get an ABI by an invalid ABI address" do address = '0x0' From cb71b58be233d497fdc19db8ab8543a22d72aae9 Mon Sep 17 00:00:00 2001 From: Estefi Date: Thu, 9 Jun 2022 11:35:59 -0300 Subject: [PATCH 5/6] Enhance assertion --- eth_client/test/abi_test.exs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/eth_client/test/abi_test.exs b/eth_client/test/abi_test.exs index a374389..5ce6113 100644 --- a/eth_client/test/abi_test.exs +++ b/eth_client/test/abi_test.exs @@ -53,9 +53,7 @@ defmodule EthClientTest.ABI do test "[SUCCESS] Get an ABI by an ABI address" do address = Context.user_account().address - {code, _response} = ABI.get(address) - - assert :ok == code + assert {:ok, _response} = ABI.get(address) end test "[FAILURE] Get an ABI by an invalid ABI address" do From 51ff3c747ff4b9cbf1a0cac16dae3fad615c9f26 Mon Sep 17 00:00:00 2001 From: Estefi Date: Wed, 15 Jun 2022 18:01:52 -0300 Subject: [PATCH 6/6] run tests synchronously --- .github/workflows/elixir_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/elixir_ci.yml b/.github/workflows/elixir_ci.yml index 9105350..93ce0d0 100644 --- a/.github/workflows/elixir_ci.yml +++ b/.github/workflows/elixir_ci.yml @@ -75,7 +75,7 @@ jobs: run: | source .envrc cd eth_client/ - mix test + mix test --seed 0 - name: Code Coverage run: | source .envrc