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

Commit adce623

Browse files
committed
Use apply_message for call() in tester
1 parent 66d88fe commit adce623

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

ethereum/tools/tester.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ethereum.consensus_strategy import get_consensus_strategy
66
from ethereum.config import config_homestead, config_tangerine, config_spurious, config_metropolis, default_config, Env
77
from ethereum.pow.ethpow import Miner
8-
from ethereum.messages import apply_transaction
8+
from ethereum.messages import apply_transaction, apply_message
99
from ethereum.common import verify_execution_results, mk_block_from_prevstate, set_execution_results
1010
from ethereum.meta import make_head_candidate
1111
from ethereum.abi import ContractTranslator
@@ -136,15 +136,11 @@ def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, g
136136
return output
137137

138138
def call(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, gasprice=GASPRICE):
139-
state = self.state
140-
self.state = self.state.ephemeral_clone()
141-
try:
142-
output = self.tx(sender, to, value, data, startgas, gasprice)
143-
self.state = state
144-
return output
145-
except Exception as e:
146-
self.state = state
147-
raise e
139+
sender_addr = privtoaddr(sender)
140+
result = apply_message(self.state.ephemeral_clone(), sender=sender_addr, to=to, value=value, data=data, gas=startgas)
141+
if result is None:
142+
raise TransactionFailed()
143+
return result
148144

149145
class Chain(object):
150146
def __init__(self, alloc=base_alloc, env=None, genesis=None):
@@ -176,14 +172,11 @@ def tx(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, g
176172
return output
177173

178174
def call(self, sender=k0, to=b'\x00' * 20, value=0, data=b'', startgas=STARTGAS, gasprice=GASPRICE):
179-
snapshot = self.snapshot()
180-
try:
181-
output = self.tx(sender, to, value, data, startgas, gasprice)
182-
self.revert(snapshot)
183-
return output
184-
except Exception as e:
185-
self.revert(snapshot)
186-
raise e
175+
sender_addr = privtoaddr(sender)
176+
result = apply_message(self.head_state.ephemeral_clone(), sender=sender_addr, to=to, value=value, data=data, gas=startgas)
177+
if result is None:
178+
raise TransactionFailed()
179+
return result
187180

188181
def contract(self, sourcecode, args=[], sender=k0, value=0, language='evm', startgas=STARTGAS, gasprice=GASPRICE):
189182
if language == 'evm':

0 commit comments

Comments
 (0)