Repository: ethereum/eth-tester (language: python)

Issue:
Add `block_identifier` param to `estimate_gas`
* Version: 0.4.0-beta.1

### What was wrong?
`estimate_gas` can take both a transaction and a block_identifier, but eth_tester only allows transactions in the `estimate_gas` method. It would be nice to test that the block_identifier is working as expected in web3py.

See comment [here](https://github.com/ethereum/web3.py/pull/1595#issuecomment-594240415)

### How can it be fixed?
I haven't looked too closely, but it should be straightforward to add another param. 





Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 72c42e05..f1f98747 100644
--- a/README.md
+++ b/README.md
@@ -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>
diff --git a/newsfragments/298.bugfix.rst b/newsfragments/298.bugfix.rst
new file mode 100644
index 00000000..a494ca94
--- /dev/null
+++ b/newsfragments/298.bugfix.rst
@@ -0,0 +1,1 @@
+Add missing ``block_number`` arg to ``MockBackend`` ``estimate_gas`` and test.
diff --git a/newsfragments/298.docs.rst b/newsfragments/298.docs.rst
new file mode 100644
index 00000000..6b54c9d9
--- /dev/null
+++ b/newsfragments/298.docs.rst
@@ -0,0 +1,1 @@
+Add missing ``block_number`` arg to ``estimate_gas`` documentation.


Test patch:
diff --git a/eth_tester/backends/mock/main.py b/eth_tester/backends/mock/main.py
index 5a386519..d9a2ec0b 100644
--- a/eth_tester/backends/mock/main.py
+++ b/eth_tester/backends/mock/main.py
@@ -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"):
diff --git a/tests/core/test_mock_backend.py b/tests/core/test_mock_backend.py
index 0f9d3419..a7a64b44 100644
--- a/tests/core/test_mock_backend.py
+++ b/tests/core/test_mock_backend.py
@@ -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")