Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow zero gas prices in create_transaction() #42

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ledgereth/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ def create_transaction(
"gas_price is incompatible with max_priority_fee_per_gas and max_fee_per_gas"
)

# we need a gas price for a valid transaction
if gas_price is None and max_fee_per_gas is None:
raise ValueError("gas_price or max_fee_per_gas must be provided")

# Create a serializable tx object
if max_fee_per_gas:
tx = Type2Transaction(
Expand Down
27 changes: 27 additions & 0 deletions tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,33 @@ def test_rinkeby_send(yield_dongle):
assert sender == Account.recover_transaction(signed.rawTransaction)


def test_zero_gas_price(yield_dongle):
"""Test a transaction with a 0 gas price"""
chain_id = 80001
destination = "0xf0155486a14539f784739be1c02e93f28eb8e960"

with yield_dongle() as dongle:
sender = get_accounts(dongle=dongle, count=1)[0].address

signed = create_transaction(
destination=destination,
amount=int(10e17),
gas=int(1e6),
gas_price=int(1e9),
data="",
nonce=2023,
chain_id=chain_id,
dongle=dongle,
)

print("signed:", signed)

assert signed.v in [(chain_id * 2 + 35) + x for x in (0, 1)]
assert signed.r
assert signed.s
assert sender == Account.recover_transaction(signed.rawTransaction)


def test_eip2930_send(yield_dongle):
"""Test a type 1 (EIP-2930) transaction"""
chain_id = 137
Expand Down
Loading