Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[55] Add ABI tests #75

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions eth_client/test/abi_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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
# Context.set_chain_id(4)
# Context.set_rpc_host("")
contract = EthClient.deploy(@bin, @abi)
:ok
end

describe "get/1" do
test "[SUCCESS] Get an ABI by an abi path", %{} do
result = ABI.get(@abi)

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

test "[SUCCESS] Get an ABI by an ABI address" do
address = Context.user_account().address

{code, _response} = ABI.get(address)

assert :ok == code
jpcenteno marked this conversation as resolved.
Show resolved Hide resolved
end

test "[FAILURE] Get an ABI by an invalid ABI address" do
address = '0x0'

assert_raise MatchError, fn ->
ABI.get(address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a ticket to change this function in order to return an {:error, :invalid_address} or something like that.

end
end
end
end