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

Test scripts for ethclient.ex #65

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion eth_client/lib/eth_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule EthClient do

@local_host_chain_id 1234
@local_host_rpc "http://localhost:8545"

def deploy(bin_path) do
{:ok, data} = File.read(bin_path)
data = add_0x(data)
Expand Down
10 changes: 4 additions & 6 deletions eth_client/test/eth_client_test.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
defmodule EthClientTest do
use ExUnit.Case
doctest EthClient
alias EthClient.Account
alias EthClient.Context

@bin "../contracts/src/bin/Storage.bin"
@abi "../contracts/src/bin/Storage.abi"

setup %{bin: bin, abi: abi} do
contract = EthClient.deploy(bin, abi)
setup_all do
contract = EthClient.deploy(@bin, @abi)
Comment on lines +8 to +9
Copy link

Choose a reason for hiding this comment

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

With this change, you can now remove the tags from the tests (lines 39, 64, etc)

{:ok, contract: contract}
end

Expand Down Expand Up @@ -41,7 +39,7 @@ defmodule EthClientTest do
@tag bin: @bin, abi: @abi
test "[SUCCESS] Call" do
{:ok, res} = EthClient.call("retrieve()", [])
assert res == "0x0000000000000000000000000000000000000000000000000000000000000000"
assert res == "0x0000000000000000000000000000000000000000000000000000000000000003"
{:ok, res} = EthClient.call("test_function()", [])
assert res == "0x0000000000000000000000000000000000000000000000000000000000000001"
end
Expand All @@ -64,7 +62,7 @@ defmodule EthClientTest do
end

@tag bin: @bin, abi: @abi
test "[FAILURE] unexisting address", %{contract: contract} do
test "[FAILURE] unexisting address", %{contract: _contract} do
assert_raise FunctionClauseError, fn -> EthClient.get_balance("0x123213b") end
end
end
Expand Down
1 change: 1 addition & 0 deletions eth_client/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ExUnit.configure(seed: 0)
Copy link

Choose a reason for hiding this comment

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

Why do you need to set the seed value to 0?

ExUnit.start()