Skip to content
This repository has been archived by the owner on Aug 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #223 from gsalgado/develop
Browse files Browse the repository at this point in the history
Fix last issue in console_service.py
  • Loading branch information
Jan Xie authored Jun 8, 2017
2 parents 587d6b0 + feb2746 commit ba0da2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions pyethapp/console_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from IPython.lib.inputhook import inputhook_manager, stdin_ready
from devp2p.service import BaseService
from ethereum.exceptions import InvalidTransaction
from ethereum.pow.consensus import initialize
from ethereum.slogging import getLogger
from ethereum.messages import apply_transaction
from ethereum.state import State
Expand Down Expand Up @@ -213,18 +214,25 @@ def call(this, to, value=0, data='', sender=None,
assert block.prevhash == this.chain.head_hash
# rebuild block state before finalization
test_state = this.chain.mk_poststate_of_blockhash(block.prevhash)
initialize(test_state, block)
for tx in block.transactions:
success, _ = apply_transaction(test_state, tx)
assert success

# Need this because otherwise the Transaction.network_id
# @property returns 0, which causes the tx to fail validation.
class MockedTx(Transaction):
network_id = None

# apply transaction
nonce = test_state.get_nonce(sender)
tx = Transaction(nonce, gasprice, startgas, to, value, data)
tx = MockedTx(nonce, gasprice, startgas, to, value, data)
tx.sender = sender

try:
success, output = apply_transaction(test_state, tx)
except InvalidTransaction:
except InvalidTransaction as e:
log.debug("error applying tx in Eth.call", exc=e)
success = False

assert block.state_root == state_root_before
Expand Down
6 changes: 3 additions & 3 deletions pyethapp/tests/test_console_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ethereum.pow.ethpow import mine
import ethereum.tools.keys
import ethereum.config
from ethereum.slogging import get_logger
from ethereum.slogging import get_logger, configure_logging
from ethereum.state import State
from pyethapp.accounts import Account, AccountsService, mk_random_privkey
from pyethapp.app import EthApp
Expand All @@ -20,7 +20,7 @@
# reduce key derivation iterations
ethereum.tools.keys.PBKDF2_CONSTANTS['c'] = 100


configure_logging(':trace')
log = get_logger('test.console_service')


Expand Down Expand Up @@ -194,7 +194,7 @@ def test_console_name_reg_contract(test_app):
test_app.mine_next_block()

creates = chain.head.transactions[0].creates
state_dict = State(chain.head.state_root, chain.env).to_dict()
state_dict = chain.state.to_dict()
code = state_dict[creates.encode('hex')]['code']
assert len(code) > 2
assert code != '0x'
Expand Down

0 comments on commit ba0da2f

Please sign in to comment.