Skip to content

Commit 386a90f

Browse files
committed
Add further tests
1 parent 4148ead commit 386a90f

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

eth_client/test/eth_client_test.exs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,65 @@ defmodule EthClientTest do
77
@bin "../contracts/src/bin/Storage.bin"
88
@abi "../contracts/src/bin/Storage.abi"
99

10-
describe "Ethereum war tooling functions" do
11-
test "Deploy" do
12-
bin = @bin
13-
abi = @abi
10+
setup %{bin: bin, abi: abi} do
11+
contract = EthClient.deploy(bin, abi)
12+
{:ok, contract: contract}
13+
end
1414

15-
contract = EthClient.deploy(bin, abi)
15+
describe "deploy/2" do
16+
@tag bin: @bin, abi: @abi
17+
test "[SUCCESS] Succesful deploy", %{contract: contract} do
1618
assert contract == EthClient.Context.contract()
1719
end
20+
end
1821

19-
test "Invoke" do
20-
bin = @bin
21-
abi = @abi
22-
23-
contract = EthClient.deploy(bin, abi)
22+
describe "invoke/3" do
23+
@tag bin: @bin, abi: @abi
24+
test "[SUCCESS] invokes a function it returns the transaction hash" do
2425
{:ok, tx_ans} = EthClient.invoke("store(uint256)", [3], 0)
2526
assert tx_ans != nil
2627
end
2728

28-
test "Call" do
29-
bin = @bin
30-
abi = @abi
29+
@tag bin: @bin, abi: @abi
30+
test "[FAILURE] invokes a function with incorrect amount of params" do
31+
assert_raise UndefinedFunctionError, fn -> EthClient.invoke("store(uint256)", []) end
32+
end
33+
34+
@tag bin: @bin, abi: @abi
35+
test "[FAILURE] invokes a contract function with incorrect params" do
36+
assert_raise FunctionClauseError, fn -> EthClient.invoke("store(uint256)", [], 0) end
37+
end
38+
end
3139

32-
contract = EthClient.deploy(bin, abi)
40+
describe "call/2" do
41+
@tag bin: @bin, abi: @abi
42+
test "[SUCCESS] Call" do
3343
{:ok, res} = EthClient.call("retrieve()", [])
3444
assert res == "0x0000000000000000000000000000000000000000000000000000000000000000"
3545
{:ok, res} = EthClient.call("test_function()", [])
3646
assert res == "0x0000000000000000000000000000000000000000000000000000000000000001"
3747
end
3848

39-
test "Balance" do
40-
bin = @bin
41-
abi = @abi
49+
@tag bin: @bin, abi: @abi
50+
test "[FAILURE] calls a function with incorrect amount of params" do
51+
assert_raise UndefinedFunctionError, fn -> EthClient.call("retrieve()") end
52+
end
4253

43-
contract = EthClient.deploy(bin, abi)
54+
@tag bin: @bin, abi: @abi
55+
test "[FAILURE] calls a contract function with incorrect params" do
56+
assert_raise FunctionClauseError, fn -> EthClient.call("retrieve()", [12]) end
57+
end
58+
end
4459

60+
describe "balance/1" do
61+
@tag bin: @bin, abi: @abi
62+
test "[SUCCESS] Balance", %{contract: contract} do
4563
assert 0.0 == EthClient.get_balance(contract.address)
4664
end
65+
66+
@tag bin: @bin, abi: @abi
67+
test "[FAILURE] unexisting address", %{contract: contract} do
68+
assert_raise FunctionClauseError, fn -> EthClient.get_balance("0x123213b") end
69+
end
4770
end
4871
end

0 commit comments

Comments
 (0)