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

update estimate_gas interface everywhere #298

Merged
merged 2 commits into from
Sep 26, 2024
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,10 @@ value from the evm.

<a id="api-estimate_gas"></a>

#### `EthereumTester.estimate_gas(transaction)`
#### `EthereumTester.estimate_gas(transaction, block_number='latest')`

Executes the provided `transaction` object, measuring and returning the gas
Executes the provided `transaction` object at the evm state from the block
denoted by the `block_number` parameter, measuring and returning the gas
consumption.

<a id="api-fee_history"></a>
Expand Down
2 changes: 1 addition & 1 deletion eth_tester/backends/mock/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def send_signed_transaction(self, signed_transaction):
transaction = dissoc(signed_transaction, "r", "s", "v")
return self.send_transaction(transaction)

def estimate_gas(self, transaction):
def estimate_gas(self, transaction, block_number="latest"):
raise NotImplementedError("Must be implemented by subclasses")

def call(self, transaction, block_number="latest"):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/298.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing ``block_number`` arg to ``MockBackend`` ``estimate_gas`` and test.
1 change: 1 addition & 0 deletions newsfragments/298.docs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing ``block_number`` arg to ``estimate_gas`` documentation.
16 changes: 16 additions & 0 deletions tests/core/test_mock_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,25 @@ def eth_tester():
return EthereumTester(backend=backend)


@pytest.fixture
def test_transaction():
return {
"from": "0x" + "1" * 40,
"to": "0x" + "2" * 40,
"gas": 21000,
"value": 1000000000000000000,
"data": "0x1234",
"nonce": 0,
}


class TestMockBackendDirect(BaseTestBackendDirect):
supports_evm_execution = False

@pytest.mark.skip(reason="receipt status not supported in MockBackend")
def test_get_transaction_receipt_byzantium(self, eth_tester, test_transaction):
pass

def test_estimate_gas_raises_not_implemented(self, eth_tester, test_transaction):
with pytest.raises(NotImplementedError):
eth_tester.estimate_gas(test_transaction, block_number="pending")