import pytest
from ethereum import blocks
from ethereum.db import DB
from ethereum.config import Env
from pyethapp.utils import merge_dict
from pyethapp.utils import update_config_from_genesis_json
import pyethapp.config as konfig
from pyethapp.profiles import PROFILES


def check_genesis(profile):
    config = dict(eth=dict())

    # Set config values based on profile selection
    merge_dict(config, PROFILES[profile])

    # Load genesis config
    update_config_from_genesis_json(config, config['eth']['genesis'])

    konfig.update_config_with_defaults(config, {'eth': {'block': blocks.default_config}})

    print config['eth'].keys()
    bc = config['eth']['block']
    print bc.keys()
    env = Env(DB(), bc)

    genesis = blocks.genesis(env)
    print 'genesis.hash', genesis.hash.encode('hex')
    print 'expected', config['eth']['genesis_hash']
    assert genesis.hash == config['eth']['genesis_hash'].decode('hex')


@pytest.mark.xfail  # FIXME
def test_olympic():
    check_genesis('olympic')


def test_frontier():
    check_genesis('frontier')


if __name__ == '__main__':
    test_genesis()

from pprint import pprint
import pytest
from ethereum import blocks
from ethereum.db import DB
from ethereum.config import Env
from pyethapp.utils import merge_dict
from pyethapp.utils import update_config_from_genesis_json
import pyethapp.config as konfig
from pyethapp.profiles import PROFILES


@pytest.mark.parametrize('profile', PROFILES.keys())
def test_profile(profile):
    config = dict(eth=dict())

    konfig.update_config_with_defaults(config, {'eth': {'block': blocks.default_config}})

    # Set config values based on profile selection
    merge_dict(config, PROFILES[profile])

    # Load genesis config
    update_config_from_genesis_json(config, config['eth']['genesis'])

    bc = config['eth']['block']
    pprint(bc)
    env = Env(DB(), bc)

    genesis = blocks.genesis(env)
    assert genesis.hash.encode('hex') == config['eth']['genesis_hash']

Fix & cleanup profile genesis tests
Fix & cleanup profile genesis tests
