-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathethers_test.exs
743 lines (619 loc) · 23.7 KB
/
ethers_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
defmodule Ethers.Contract.Test.HelloWorldContract do
@moduledoc false
use Ethers.Contract, abi_file: "tmp/hello_world_abi.json"
end
defmodule Ethers.Contract.Test.HelloWorldWithDefaultAddressContract do
@moduledoc false
use Ethers.Contract,
abi_file: "tmp/hello_world_abi.json",
default_address: "0x1000bf6a479f320ead074411a4b0e7944ea8c9c1"
end
defmodule EthersTest do
use ExUnit.Case
doctest Ethers
import Ethers.TestHelpers
alias Ethers.Contract.Test.HelloWorldContract
alias Ethers.Contract.Test.HelloWorldWithDefaultAddressContract
alias Ethers.ExecutionError
@from "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
@to "0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc"
@from_private_key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
describe "current_gas_price" do
test "returns the correct gas price" do
assert {:ok, gas_price} = Ethers.current_gas_price()
assert is_integer(gas_price)
end
end
describe "max_priority_fee_per_gas" do
test "returns the correct max priority fee per gas" do
assert {:ok, max_priority_fee_per_gas} = Ethers.max_priority_fee_per_gas()
assert is_integer(max_priority_fee_per_gas)
end
test "bang version returns unwrapped value" do
assert is_integer(Ethers.max_priority_fee_per_gas!())
end
end
describe "current_block_number" do
test "returns the current block number" do
assert {:ok, n} = Ethers.current_block_number()
assert n >= 0
end
test "can override the rpc options" do
assert {:ok, 1001} ==
Ethers.current_block_number(
rpc_client: Ethers.TestRPCModule,
rpc_opts: [block: "0x3E9"]
)
end
end
describe "get_balance" do
test "returns correct balance for account" do
assert {:ok, 0} == Ethers.get_balance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
assert {:ok, 10_000_000_000_000_000_000_000} ==
Ethers.get_balance("0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc")
end
test "bang version returns unwrapped value" do
assert 10_000_000_000_000_000_000_000 ==
Ethers.get_balance!("0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc")
end
test "bang version raises on error" do
assert_raise ExecutionError, fn ->
Ethers.get_balance!("invalid account")
end
end
test "works with binary accounts" do
bin = Ethers.Utils.hex_decode!("0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc")
assert {:ok, 10_000_000_000_000_000_000_000} == Ethers.get_balance(bin)
end
test "returns error with invalid account" do
assert {:error, :invalid_account} == Ethers.get_balance("invalid account")
end
end
describe "get_transaction_count" do
@address "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f"
test "returns the correct transaction count" do
assert {:ok, c} = Ethers.get_transaction_count(@address)
assert is_integer(c)
assert c >= 0
Ethers.send_transaction!(%{
from: @address,
to: "0xaadA6BF26964aF9D7eEd9e03E53415D37aA96045",
value: 1000
})
|> wait_for_transaction!()
assert {:ok, c + 1} == Ethers.get_transaction_count(@address)
end
end
describe "get_transaction" do
test "returns correct transaction by tx_hash" do
{:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: @to,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
checksum_to_addr = Ethers.Utils.to_checksum_address(@to)
assert {:ok,
%Ethers.Transaction.Signed{
payload: %Ethers.Transaction.Eip1559{
to: ^checksum_to_addr
},
metadata: %Ethers.Transaction.Metadata{
block_hash: "0x" <> _,
block_number: block_number,
transaction_index: 0
}
}} = Ethers.get_transaction(tx_hash)
assert is_integer(block_number) and block_number >= 0
end
test "bang version returns unwrapped value" do
{:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: @to,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
assert %Ethers.Transaction.Signed{
payload: %Ethers.Transaction.Eip1559{
to: checksum_to_addr
}
} = Ethers.get_transaction!(tx_hash)
assert checksum_to_addr == Ethers.Utils.to_checksum_address(@to)
end
test "bang version raises on error" do
assert_raise ExecutionError, fn ->
Ethers.get_transaction!("invalid tx_hash")
end
end
test "works in batch requests" do
{:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: @to,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
assert {:ok,
[
ok: %Ethers.Transaction.Signed{
payload: %Ethers.Transaction.Eip1559{}
}
]} =
Ethers.batch([
{:get_transaction, tx_hash}
])
end
test "returns error by non-existent tx_hash" do
assert {:error, :transaction_not_found} =
Ethers.get_transaction(
"0x5194596d703a53f65dcb1d7df60fcfa1f7d904ad3145887677a6ab68a425d8d3"
)
end
test "returns error by invalid tx_hash" do
assert {:error, _err} = Ethers.get_transaction("invalid tx_hash")
end
end
describe "get_transaction_receipt" do
test "returns correct transaction receipt by tx_hash" do
{:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: @to,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
downcased_to_addr = String.downcase(@to)
assert {:ok,
%{
"transactionHash" => ^tx_hash,
"from" => @from,
"to" => ^downcased_to_addr
}} = Ethers.get_transaction_receipt(tx_hash)
end
test "bang version returns unwrapped value" do
{:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: @to,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
receipt = Ethers.get_transaction_receipt!(tx_hash)
assert receipt["transactionHash"] == tx_hash
assert receipt["from"] == @from
assert receipt["to"] == String.downcase(@to)
end
test "bang version raises on error" do
assert_raise ExecutionError, fn ->
Ethers.get_transaction_receipt!("invalid tx_hash")
end
end
test "returns error by non-existent tx_hash" do
assert {:error, :transaction_receipt_not_found} =
Ethers.get_transaction_receipt(
"0x5194596d703a53f65dcb1d7df60fcfa1f7d904ad3145887677a6ab68a425d8d3"
)
end
test "returns error by invalid tx_hash" do
assert {:error, _err} = Ethers.get_transaction_receipt("invalid tx_hash")
end
end
describe "contract deployment" do
test "can deploy a contract given a module which has the binary" do
contract_address = deploy(HelloWorldContract, from: @from)
assert HelloWorldContract.say_hello() |> Ethers.call!(to: contract_address) ==
"Hello World!"
end
test "can deploy a contract given the contract binary" do
bin = HelloWorldContract.__contract_binary__()
contract_address = deploy(bin, from: @from)
assert HelloWorldContract.say_hello() |> Ethers.call!(to: contract_address) ==
"Hello World!"
end
test "can deploy a contract given the contract binary prefixed with 0x" do
bin = HelloWorldContract.__contract_binary__()
contract_address = deploy("0x" <> bin, from: @from)
assert HelloWorldContract.say_hello() |> Ethers.call!(to: contract_address) ==
"Hello World!"
end
test "returns error if the module does not include the binary" do
assert_raise UndefinedFunctionError, fn ->
assert {:error, :binary_not_found} = Ethers.deploy(NotFoundContract, from: @from)
end
assert {:error, :binary_not_found} =
Ethers.deploy(Ethers.Contracts.ERC20, from: @from)
end
test "getting the deployed address of a non existing (not yet validated) transaction" do
tx_hash = "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060"
assert {:error, :transaction_not_found} = Ethers.deployed_address(tx_hash)
end
test "getting the deployed address of a non contract creation transaction" do
contract_address = deploy(HelloWorldContract, from: @from)
{:ok, tx_hash} =
HelloWorldContract.set_hello("Bye")
|> Ethers.send_transaction(to: contract_address, from: @from)
wait_for_transaction!(tx_hash)
assert {:error, :no_contract_address} = Ethers.deployed_address(tx_hash)
assert HelloWorldContract.say_hello() |> Ethers.call!(to: contract_address) ==
"Bye"
end
end
describe "get_logs/2" do
test "returns error when request fails" do
assert {:error, %{reason: :nxdomain}} =
Ethers.get_logs(%{topics: [], selector: nil},
rpc_opts: [url: "http://non.exists"]
)
end
test "with bang function, raises error when request fails" do
assert_raise Mint.TransportError, "non-existing domain", fn ->
Ethers.get_logs!(%{topics: [], selector: nil},
rpc_opts: [url: "http://non.exists"]
)
end
end
end
describe "default address" do
test "is included in the function calls when has default address" do
assert %Ethers.TxData{
base_module: HelloWorldWithDefaultAddressContract,
data: "0xef5fb05b",
selector: %ABI.FunctionSelector{
function: "sayHello",
method_id: <<239, 95, 176, 91>>,
type: :function,
inputs_indexed: nil,
state_mutability: :view,
input_names: [],
types: [],
returns: [:string],
return_names: [""]
},
default_address: "0x1000bf6a479f320ead074411a4b0e7944ea8c9c1"
} == HelloWorldWithDefaultAddressContract.say_hello()
assert %{data: "0xef5fb05b", to: "0x1000bf6a479f320ead074411a4b0e7944ea8c9c1"} ==
HelloWorldWithDefaultAddressContract.say_hello()
|> Ethers.TxData.to_map([])
end
test "is not included in the function calls when does not have default address" do
assert %Ethers.TxData{
base_module: HelloWorldContract,
data: "0xef5fb05b",
selector: %ABI.FunctionSelector{
function: "sayHello",
method_id: <<239, 95, 176, 91>>,
type: :function,
inputs_indexed: nil,
state_mutability: :view,
input_names: [],
types: [],
returns: [:string],
return_names: [""]
},
default_address: nil
} == HelloWorldContract.say_hello()
end
test "is included in event filters when has default address" do
assert %Ethers.EventFilter{
topics: [
"0xbe6cf5e99b344c66895d6304d442b2f51b6359ee51ac581db2255de9373e24b8"
],
selector: %ABI.FunctionSelector{
function: "HelloSet",
method_id:
Ethers.Utils.hex_decode!(
"0xbe6cf5e99b344c66895d6304d442b2f51b6359ee51ac581db2255de9373e24b8"
),
type: :event,
inputs_indexed: [false],
state_mutability: nil,
input_names: ["message"],
types: [:string],
returns: []
},
default_address: "0x1000bf6a479f320ead074411a4b0e7944ea8c9c1"
} == HelloWorldWithDefaultAddressContract.EventFilters.hello_set()
assert %{
topics: ["0xbe6cf5e99b344c66895d6304d442b2f51b6359ee51ac581db2255de9373e24b8"],
address: "0x1000bf6a479f320ead074411a4b0e7944ea8c9c1"
} ==
HelloWorldWithDefaultAddressContract.EventFilters.hello_set()
|> Ethers.EventFilter.to_map([])
end
test "is not included in event filters when does not have default address" do
assert %Ethers.EventFilter{
topics: [
"0xbe6cf5e99b344c66895d6304d442b2f51b6359ee51ac581db2255de9373e24b8"
],
selector: %ABI.FunctionSelector{
function: "HelloSet",
method_id:
Ethers.Utils.hex_decode!(
"0xbe6cf5e99b344c66895d6304d442b2f51b6359ee51ac581db2255de9373e24b8"
),
type: :event,
inputs_indexed: [false],
state_mutability: nil,
input_names: ["message"],
types: [:string],
returns: []
},
default_address: nil
} == HelloWorldContract.EventFilters.hello_set()
end
end
describe "batch/2" do
test "Can batch multiple requests" do
address = deploy(HelloWorldContract, from: @from)
HelloWorldContract.set_hello("Hello Batch!")
|> Ethers.send_transaction!(to: address, from: @from)
|> wait_for_transaction!()
assert {:ok, results} =
Ethers.batch([
{:call, HelloWorldContract.say_hello(), to: address},
{:send, HelloWorldContract.set_hello("hi"), from: @from, to: address},
:net_version,
{:estimate_gas, HelloWorldContract.say_hello(), to: address},
{:get_logs, HelloWorldContract.EventFilters.hello_set(), address: address},
:current_block_number,
:current_gas_price,
{:eth_call, [%{}, "latest"]}
])
assert [
ok: "Hello Batch!",
ok: "0x" <> _hash,
ok: <<_net_version::binary>>,
ok: gas_estimate,
ok: [%Ethers.Event{}],
ok: block_number,
ok: gas_price,
ok: "0x"
] = results
assert is_integer(gas_estimate)
assert is_integer(block_number)
assert is_integer(gas_price)
end
test "returns error for invalid action" do
assert {:error, :no_to_address} = Ethers.batch([{:call, HelloWorldContract.say_hello()}])
end
end
describe "batch!/2" do
test "returns the correct result" do
address = deploy(HelloWorldContract, from: @from)
assert [ok: "Hello World!", ok: _] =
Ethers.batch!([
{:call, HelloWorldContract.say_hello(), to: address},
:current_block_number
])
assert_raise ExecutionError, "Unexpected error: no_to_address", fn ->
Ethers.batch!([{:call, HelloWorldContract.say_hello()}])
end
end
end
describe "deploy/2" do
test "accepts signer and signer_opts" do
assert {:error, :no_private_key} =
Ethers.deploy(HelloWorldContract, from: @from, signer: Ethers.Signer.Local)
end
end
describe "send_transaction/2" do
test "accepts signer and signer_opts" do
assert {:error, :no_private_key} =
HelloWorldContract.set_hello("hello")
|> Ethers.send_transaction(
from: @from,
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
signer: Ethers.Signer.Local
)
end
test "signs and sends an eip1559 transaction using a signer" do
address = deploy(HelloWorldContract, from: @from)
assert {:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: address,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
assert {:ok, "hello local signer"} =
Ethers.call(HelloWorldContract.say_hello(), to: address)
end
test "signs and sends a legacy transaction using a signer" do
address = deploy(HelloWorldContract, from: @from)
{:ok, tx_hash} =
HelloWorldContract.set_hello("hello local signer")
|> Ethers.send_transaction(
from: @from,
to: address,
type: Ethers.Transaction.Legacy,
signer: Ethers.Signer.Local,
signer_opts: [
private_key: @from_private_key
]
)
wait_for_transaction!(tx_hash)
assert {:ok, %Ethers.Transaction.Signed{payload: %Ethers.Transaction.Legacy{}}} =
Ethers.get_transaction(tx_hash)
assert {:ok, "hello local signer"} =
Ethers.call(HelloWorldContract.say_hello(), to: address)
end
test "converts all integer params and overrides to hex" do
assert {:ok, _tx_hash} =
Ethers.send_transaction(
%{value: 1000},
rpc_client: Ethers.TestRPCModule,
from: @from,
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
rpc_opts: [send_params_to_pid: self()]
)
assert_receive %{
from: @from,
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
value: "0x3E8",
type: "0x2"
}
end
end
describe "sign_transaction/2" do
test "returns the signed eip1559 transaction and is valid" do
address = deploy(HelloWorldContract, from: @from)
assert {:ok, "0x02" <> _ = signed} =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction(
from: @from,
to: address,
signer: Ethers.Signer.JsonRPC,
type: Ethers.Transaction.Eip1559
)
assert {:ok, tx_hash} = Ethers.send_transaction(signed)
wait_for_transaction!(tx_hash)
assert {:ok, "hi signed"} = Ethers.call(HelloWorldContract.say_hello(), to: address)
end
test "returns the signed legacy transaction and is valid" do
address = deploy(HelloWorldContract, from: @from)
assert {:ok, signed} =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction(
from: @from,
to: address,
signer: Ethers.Signer.JsonRPC,
type: Ethers.Transaction.Legacy
)
refute String.starts_with?(signed, "0x02")
assert {:ok, tx_hash} = Ethers.rpc_client().eth_send_raw_transaction(signed)
wait_for_transaction!(tx_hash)
assert {:ok, "hi signed"} = Ethers.call(HelloWorldContract.say_hello(), to: address)
end
test "uses Signer.JsonRPC as default signer" do
address = deploy(HelloWorldContract, from: @from)
assert {:ok, signed} =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction(from: @from, to: address)
assert {:ok, tx_hash} = Ethers.rpc_client().eth_send_raw_transaction(signed)
wait_for_transaction!(tx_hash)
assert {:ok, "hi signed"} = Ethers.call(HelloWorldContract.say_hello(), to: address)
end
test "requires from address" do
assert {:error, :no_from_address} =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction(
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
signer: Ethers.Signer.JsonRPC
)
end
test "requires signer" do
assert {:error, :no_signer} =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction(
from: @from,
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
signer: nil
)
end
end
describe "sign_transaction!/2" do
test "returns signed transaction" do
signed =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction!(
from: @from,
gas: 10_000,
max_fee_per_gas: 123_123_123,
chain_id: 31_337,
nonce: 100,
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
signer: Ethers.Signer.JsonRPC
)
assert String.starts_with?(signed, "0x02")
end
test "returns signed transaction with custom max_priority_fee_per_gas" do
signed =
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction!(
from: @from,
gas: 10_000,
max_fee_per_gas: 123_123_123,
max_priority_fee_per_gas: 2_000_000_000,
chain_id: 31_337,
nonce: 100,
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
signer: Ethers.Signer.JsonRPC
)
assert String.starts_with?(signed, "0x02")
end
test "raises in case of error" do
assert_raise Ethers.ExecutionError, "Unexpected error: no_from_address", fn ->
HelloWorldContract.set_hello("hi signed")
|> Ethers.sign_transaction!(
to: "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
signer: Ethers.Signer.JsonRPC
)
end
end
end
describe "call/2" do
test "works without selector (raw call)" do
address = deploy(HelloWorldContract, from: @from)
tx_data = HelloWorldContract.say_hello()
assert {:ok,
"0x000000000000000000000000000000000000000000000000000000000000002000000000000" <>
"0000000000000000000000000000000000000000000000000000c48656c6c6f20576f726c642100" <>
"00000000000000000000000000000000000000"} =
Ethers.call(%{data: tx_data.data}, to: address)
end
end
describe "deprecated send/2 and send!/2 still work" do
test "send/2 still works" do
address = deploy(HelloWorldContract, from: @from)
{:ok, tx_hash} =
HelloWorldContract.set_hello("hi send")
|> Ethers.send(to: address, from: @from)
wait_for_transaction!(tx_hash)
assert {:ok, "hi send"} = Ethers.call(HelloWorldContract.say_hello(), to: address)
end
test "send!/2 still works" do
address = deploy(HelloWorldContract, from: @from)
tx_hash =
HelloWorldContract.set_hello("hi send!")
|> Ethers.send!(to: address, from: @from)
wait_for_transaction!(tx_hash)
assert {:ok, "hi send!"} = Ethers.call(HelloWorldContract.say_hello(), to: address)
end
end
describe "chain_id" do
test "returns the chain id" do
assert {:ok, chain_id} = Ethers.chain_id()
# Anvil's default chain id
assert chain_id == 31_337
end
test "bang version returns unwrapped value" do
assert Ethers.chain_id!() == 31_337
end
end
end