@@ -7,42 +7,65 @@ defmodule EthClientTest do
7
7
@ bin "../contracts/src/bin/Storage.bin"
8
8
@ abi "../contracts/src/bin/Storage.abi"
9
9
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
14
14
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
16
18
assert contract == EthClient.Context . contract ( )
17
19
end
20
+ end
18
21
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
24
25
{ :ok , tx_ans } = EthClient . invoke ( "store(uint256)" , [ 3 ] , 0 )
25
26
assert tx_ans != nil
26
27
end
27
28
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
31
39
32
- contract = EthClient . deploy ( bin , abi )
40
+ describe "call/2" do
41
+ @ tag bin: @ bin , abi: @ abi
42
+ test "[SUCCESS] Call" do
33
43
{ :ok , res } = EthClient . call ( "retrieve()" , [ ] )
34
44
assert res == "0x0000000000000000000000000000000000000000000000000000000000000000"
35
45
{ :ok , res } = EthClient . call ( "test_function()" , [ ] )
36
46
assert res == "0x0000000000000000000000000000000000000000000000000000000000000001"
37
47
end
38
48
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
42
53
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
44
59
60
+ describe "balance/1" do
61
+ @ tag bin: @ bin , abi: @ abi
62
+ test "[SUCCESS] Balance" , % { contract: contract } do
45
63
assert 0.0 == EthClient . get_balance ( contract . address )
46
64
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
47
70
end
48
71
end
0 commit comments