Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 4a73f8a

Browse files
committed
Added last_gas_used function to tester
1 parent c396a35 commit 4a73f8a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ethereum/tools/tester.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, g
148148
self.last_sender = sender
149149
return o
150150

151-
def contract(self, sourcecode, args=[], sender=k0, value=0, language='evm', startgas=STARTGAS, gasprice=GASPRICE):
151+
def last_gas_used(self, with_tx=False):
152+
if len(self.head_state.receipts) == 1:
153+
diff = self.head_state.receipts[-1].gas_used
154+
else:
155+
diff = self.head_state.receipts[-1].gas_used - self.head_state.receipts[-2].gas_used
156+
return diff - (not with_tx) * self.last_tx.intrinsic_gas_used
157+
158+
def contract(self, sourcecode, args=[], sender=k0, value=0, language=None, l=None, startgas=STARTGAS, gasprice=GASPRICE):
159+
assert not (l and language)
160+
language = l or language
152161
if language == 'evm':
153162
assert len(args) == 0
154163
return self.tx(sender=sender, to=b'', value=value, data=sourcecode, startgas=startgas, gasprice=gasprice)

0 commit comments

Comments
 (0)