forked from ledgerwatch/automated-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_templates.py
43 lines (36 loc) · 1.33 KB
/
transaction_templates.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
import os
contracts_path = os.environ.get("MOCKS_DIR", f"{os.path.dirname(__file__)}/Contracts")
class TransactionTemplates:
@staticmethod
def base_template(web3, address, private_key):
return {
"nonce": web3.eth.get_transaction_count(
web3.eth.account.from_key(private_key).address
),
"to": address,
"value": web3.toWei(0.02, "ether"),
"gas": 21000,
"chainId": web3.eth.chain_id,
}
@staticmethod
def legacy_transaction(web3, address, private_key):
legacy_transaction = TransactionTemplates.base_template(
web3, address, private_key
).copy()
legacy_transaction.update(
{
"gasPrice": web3.eth.gas_price,
}
)
return legacy_transaction
@staticmethod
def eip1559_transaction(web3, address, private_key):
eip1559_transaction = TransactionTemplates.base_template(
web3, address, private_key
).copy()
max_priority_fee = web3.eth.max_priority_fee
max_fee_per_gas = max_priority_fee + web3.eth.get_block("latest").baseFeePerGas
eip1559_transaction.update(
{"maxFeePerGas": max_fee_per_gas, "maxPriorityFeePerGas": max_priority_fee}
)
return eip1559_transaction