-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathtest_default_account_api.py
46 lines (32 loc) · 1.11 KB
/
test_default_account_api.py
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
import pytest
@pytest.fixture(autouse=True)
def wait_for_first_block(w3, wait_for_block):
wait_for_block(w3)
def test_uses_default_account_when_set(w3, wait_for_transaction):
current_default = w3.eth.default_account
w3.eth.default_account = None
assert w3.eth.default_account is None
w3.eth.default_account = w3.eth.accounts[3]
assert w3.eth.default_account == w3.eth.accounts[3]
txn_hash = w3.eth.send_transaction(
{
"to": w3.eth.accounts[3],
"value": 1234,
}
)
wait_for_transaction(w3, txn_hash)
txn = w3.eth.get_transaction(txn_hash)
assert txn["from"] == w3.eth.accounts[3]
w3.eth.default_account = current_default
def test_uses_given_from_address_when_provided(w3, wait_for_transaction):
w3.eth.default_account = w3.eth.accounts[3]
txn_hash = w3.eth.send_transaction(
{
"from": w3.eth.accounts[5],
"to": w3.eth.accounts[1],
"value": 1234,
}
)
wait_for_transaction(w3, txn_hash)
txn = w3.eth.get_transaction(txn_hash)
assert txn["from"] == w3.eth.accounts[5]