Beispiel #1
0
 def start(self):
     super(TestApp, self).start()
     log.debug("adding test accounts")
     # high balance account
     self.services.accounts.add_account(Account.new("", tester.keys[0]), store=False)
     # low balance account
     self.services.accounts.add_account(Account.new("", tester.keys[1]), store=False)
     # locked account
     locked_account = Account.new("", tester.keys[2])
     locked_account.lock()
     self.services.accounts.add_account(locked_account, store=False)
     assert set(acct.address for acct in self.services.accounts) == set(tester.accounts[:3])
Beispiel #2
0
 def start(self):
     super(TestApp, self).start()
     log.debug('adding test accounts')
     # high balance account
     self.services.accounts.add_account(Account.new('', tester.keys[0]), store=False)
     # low balance account
     self.services.accounts.add_account(Account.new('', tester.keys[1]), store=False)
     # locked account
     locked_account = Account.new('', tester.keys[2])
     locked_account.lock()
     self.services.accounts.add_account(locked_account, store=False)
     assert set(acct.address for acct in self.services.accounts) == set(tester.accounts[:3])
Beispiel #3
0
 def start(self):
     super(EdgeChainApp, self).start()
     log.debug('adding test accounts')
     self.services.accounts.add_account(Account.new('ADMIN',
                                                    tester.keys[0]),
                                        store=False)
     self.services.accounts.add_account(Account.new('MES', tester.keys[1]),
                                        store=False)
     self.services.accounts.add_account(Account.new('REQUESTER1',
                                                    tester.keys[2]),
                                        store=False)
     self.services.accounts.add_account(Account.new('REQUESTER2',
                                                    tester.keys[3]),
                                        store=False)
Beispiel #4
0
 def start(self):
     super(TestApp, self).start()
     log.debug('adding test accounts')
     # high balance account
     self.services.accounts.add_account(Account.new('', tester.keys[0]), store=False)
     # low balance account
     self.services.accounts.add_account(Account.new('', tester.keys[1]), store=False)
     # locked account
     locked_account = Account.new('', tester.keys[2])
     locked_account.lock()
     self.services.accounts.add_account(locked_account, store=False)
     self.privkey = None
     assert set(acct.address for acct in self.services.accounts) == set(tester.accounts[:3])
     test_transport = TestTransport(call_func=self.rpc_request)
     self.client = JSONRPCClient(transport=test_transport)
Beispiel #5
0
def rundummy(ctx, num_validators, node_num, seed):

    # reduce key derivation iterations
    PBKDF2_CONSTANTS['c'] = 100

    config = ctx.obj['config']

    # create bootstrap node priv_key and enode
    bootstrap_node_privkey = mk_privkey('%d:udp:%d' % (seed, 0))
    bootstrap_node_pubkey = privtopub_raw(bootstrap_node_privkey)
    assert len(bootstrap_node_pubkey) == 64,  len(bootstrap_node_pubkey)
    base_port = 29870
    host = b'0.0.0.0'

    bootstrap_node = host_port_pubkey_to_uri(host, base_port, bootstrap_node_pubkey)
    config['discovery']['bootstrap_nodes'] = [bootstrap_node]

    # create this node priv_key
    config['node']['privkey_hex'] = mk_privkey('%d:udp:%d' % (seed, node_num)).encode('hex')

    # create validator addresses
    validators = [privtoaddr(mk_privkey('%d:account:%d' % (seed, i)))
                  for i in range(num_validators)]
    config['hdc']['validators'] = validators

    # create this node account
    account = Account.new(password='', key=mk_privkey('%d:account:%d' % (seed, node_num)))

    # set ports based on node
    config['discovery']['listen_port'] = base_port + node_num
    config['p2p']['listen_port'] = base_port + node_num
    config['p2p']['min_peers'] = 2
    config['jsonrpc']['listen_port'] += node_num

    _start_app(account, config)
Beispiel #6
0
 def create_account_helper(self, password):
     # reduces key derivation iterations to speed up creation
     PBKDF2_CONSTANTS['c'] = 1
     wallet_path = os.path.join(self.keystore_dir, 'wallet.json')
     account = Account.new(password, path=wallet_path)
     with open(account.path, 'w') as f:
         f.write(account.dump())
     return account
def private_to_account(ctx, privatekey, password):
    # privatekey is provided in the console, so it's expected to be hexadecimal
    privatekey = safe_address_decode(privatekey)

    # cast the values to bytes because it is the expected type in the Crypto library
    password = bytes(password)
    privkey = bytes(privatekey)

    account = Account.new(password, key=privkey)
    print account.dump()
Beispiel #8
0
 def test_pyethapp(self):
     from pyethapp.accounts import Account
     from ethereum_utils import AccountUtils
     AccountUtils.patch_ethereum_tools_keys()
     password = "******"
     uuid = None
     account = Account.new(password, uuid=uuid)
     # restore iterations
     address = account.address.hex()
     self.assertIsNotNone(account)
     self.assertIsNotNone(address)
 def new_account(self, password):
     """
     Creates an account on the disk and returns it.
     """
     # lazy loading
     from pyethapp.accounts import Account
     account = Account.new(password, uuid=None)
     account.path = os.path.join(
         self.app.services.accounts.keystore_dir,
         account.address.hex())
     self.app.services.accounts.add_account(account)
     return account
Beispiel #10
0
def start_app(config, accounts):

    # create app
    app = HPCApp(config)

    # development mode
    if False:
        gevent.get_hub().SYSTEM_ERROR = BaseException

    if config['test_privkeys']:
        # init accounts first, as we need (and set by copy) the coinbase early FIXME
        genesis_config = dict(alloc=dict())
        for privkey in config['test_privkeys']:
            assert len(privkey) == 32
            address = privtoaddr(privkey)
            account = Account.new(password='', key=privkey)
            accounts.append(account)
            # add to genesis alloc
            genesis_config['alloc'][address] = {'wei': config['test_privkeys_endowment']}

        if config['test_privkeys'] and config['eth'].get('genesis_hash'):
            del config['eth']['genesis_hash']

        konfig.update_config_from_genesis_json(config, genesis_config)

    # dump config
    pyethapp_app.dump_config(config)

    if AccountsService in services:
        AccountsService.register_with_app(app)

    # add account
    for account in accounts:
        app.services.accounts.add_account(account, store=False)

    if config['hdc']['validators']:
        assert app.services.accounts.coinbase in config['hdc']['validators']

    # register services
    for service in services:
        assert issubclass(service, BaseService)
        if service.name not in app.config['deactivated_services'] + [AccountsService.name]:
            assert service.name not in app.services
            service.register_with_app(app)
            assert hasattr(app.services, service.name)

    # start app
    log.info('starting')
    app.start()
    for cb in config['post_app_start_callbacks']:
        cb(app)
    return app
Beispiel #11
0
 def test_pyethapp(self):
     from pyethapp.accounts import Account
     from ethereum.tools.keys import PBKDF2_CONSTANTS
     # backup iterations
     iterations_backup = PBKDF2_CONSTANTS['c']
     # speeds up the test
     PBKDF2_CONSTANTS['c'] = 100
     password = "******"
     uuid = None
     account = Account.new(password, uuid=uuid)
     # restore iterations
     PBKDF2_CONSTANTS['c'] = iterations_backup
     address = account.address.encode('hex')
     self.assertIsNotNone(account)
     self.assertIsNotNone(address)
Beispiel #12
0
def _configure_node_network(config, num_validators, node_num, seed):
    assert node_num < num_validators

    # reduce key derivation iterations
    PBKDF2_CONSTANTS["c"] = 100

    # create this node priv_key
    config["node"]["privkey_hex"] = mk_privkey("%d:udp:%d" % (seed, node_num)).encode("hex")

    # create validator addresses
    validators = [privtoaddr(mk_privkey("%d:account:%d" % (seed, i))) for i in range(num_validators)]
    config["hdc"]["validators"] = validators

    # create this node account
    account = Account.new(password="", key=mk_privkey("%d:account:%d" % (seed, node_num)))
    assert account.address in validators
    return config, account
Beispiel #13
0
 def new_account_helper(password, security_ratio=None):
     """
     Helper method for creating an account in memory.
     Returns the created account.
     security_ratio is a ratio of the default PBKDF2 iterations.
     Ranging from 1 to 100 means 100% of the iterations.
     """
     # TODO: perform validation on security_ratio (within allowed range)
     if security_ratio:
         default_iterations = PBKDF2_CONSTANTS["c"]
         new_iterations = int((default_iterations * security_ratio) / 100)
         PBKDF2_CONSTANTS["c"] = new_iterations
     uuid = None
     account = Account.new(password, uuid=uuid)
     # reverts to previous iterations
     if security_ratio:
         PBKDF2_CONSTANTS["c"] = default_iterations
     return account
Beispiel #14
0
def _configure_node_network(config, num_validators, node_num, seed):
    assert node_num < num_validators

    # reduce key derivation iterations
    PBKDF2_CONSTANTS['c'] = 100

    # create this node priv_key
    config['node']['privkey_hex'] = mk_privkey('%d:udp:%d' % (seed, node_num)).encode('hex')

    # create validator addresses
    validators = [privtoaddr(mk_privkey('%d:account:%d' % (seed, i)))
                  for i in range(num_validators)]
    config['hdc']['validators'] = validators

    # create this node account
    account = Account.new(password='', key=mk_privkey('%d:account:%d' % (seed, node_num)))
    assert account.address in validators
    return config, account
Beispiel #15
0
    def __init__(self, privkey, validators, simenv=None):
        self.config = copy.deepcopy(hdc_service.ChainService.default_config)
        self.config['db'] = dict(path='_db')
        self.config['data_dir'] = tempfile.mkdtemp()
        self.config['hdc']['validators'] = validators

        self.simenv = simenv
        self.services = self.Services()
        self.services.db = EphemDB()
        self.services.accounts = AccountsService(self)
        self.services.peermanager = PeerManagerMock(self)
        account = Account.new(password='', key=privkey)
        self.services.accounts.add_account(account, store=False)
        if simenv:
            self.services.chainservice = SimChainService(self, simenv=simenv)
        else:
            self.services.chainservice = hdc_service.ChainService(self)
        self.isactive = True
Beispiel #16
0
def _configure_node_network(config, num_validators, node_num, seed):
    assert node_num < num_validators

    # reduce key derivation iterations
    PBKDF2_CONSTANTS['c'] = 100

    # create this node priv_key
    config['node']['privkey_hex'] = mk_privkey('%d:udp:%d' % (seed, node_num)).encode('hex')

    # create validator addresses
    validators = [privtoaddr(mk_privkey('%d:account:%d' % (seed, i)))
                  for i in range(num_validators)]
    config['hdc']['validators'] = validators

    # create this node account
    account = Account.new(password='', key=mk_privkey('%d:account:%d' % (seed, node_num)))
    assert account.address in validators
    return config, account
Beispiel #17
0
    def __init__(self, privkey, validators, simenv=None):
        self.config = copy.deepcopy(hdc_service.ChainService.default_config)
        self.config['db'] = dict(path='_db')
        self.config['data_dir'] = tempfile.mkdtemp()
        self.config['hdc']['validators'] = validators

        initial_alloc = dict((a, dict(wei=2 ** 200)) for a in validators)
        self.config['eth']['block']['GENESIS_INITIAL_ALLOC'] = initial_alloc

        self.simenv = simenv
        self.services = self.Services()
        self.services.db = EphemDB()
        self.services.accounts = AccountsService(self)
        self.services.peermanager = PeerManagerMock(self)
        account = Account.new(password='', key=privkey)
        self.services.accounts.add_account(account, store=False)
        if simenv:
            self.services.chainservice = SimChainService(self, simenv=simenv)
        else:
            self.services.chainservice = hdc_service.ChainService(self)
        self.isactive = True
Beispiel #18
0
    def __init__(self, privkey, validators, simenv=None):
        self.config = copy.deepcopy(hdc_service.ChainService.default_config)
        self.config["db"] = dict(path="_db")
        self.config["data_dir"] = tempfile.mkdtemp()
        self.config["hdc"]["validators"] = validators

        initial_alloc = dict((a, dict(wei=2 ** 200)) for a in validators)
        self.config["eth"]["block"]["GENESIS_INITIAL_ALLOC"] = initial_alloc

        self.simenv = simenv
        self.services = self.Services()
        self.services.db = EphemDB()
        self.services.accounts = AccountsService(self)
        self.services.peermanager = PeerManagerMock(self)
        account = Account.new(password="", key=privkey)
        self.services.accounts.add_account(account, store=False)
        if simenv:
            self.services.chainservice = SimChainService(self, simenv=simenv)
        else:
            self.services.chainservice = hdc_service.ChainService(self)
        self.isactive = True
Beispiel #19
0
def runlocal(ctx, num_validators, node_num, seed):

    assert node_num < num_validators

    # reduce key derivation iterations
    PBKDF2_CONSTANTS['c'] = 100

    config = ctx.obj['config']

    # create this node priv_key
    config['node']['privkey_hex'] = mk_privkey('%d:udp:%d' % (seed, node_num)).encode('hex')

    # create validator addresses
    validators = [privtoaddr(mk_privkey('%d:account:%d' % (seed, i)))
                  for i in range(num_validators)]
    config['hdc']['validators'] = validators

    # create this node account
    account = Account.new(password='', key=mk_privkey('%d:account:%d' % (seed, node_num)))
    assert account.address in validators

    config['p2p']['min_peers'] = 2

    _start_app(account, config, validators)
def account(privkey, password, uuid):
    return Account.new(password, privkey, uuid)
 def __init__(self, privkey):
     self.services = self.Services()
     self.services.db = EphemDB()
     self.services.accounts = AccountsService(self)
     account = Account.new(password='', key=privkey)
     self.services.accounts.add_account(account, store=False)
Beispiel #22
0
def create_hydrachain_cluster(private_keys, hydrachain_private_keys, p2p_base_port, base_datadir):
    """ Initializes a hydrachain network used for testing. """
    # pylint: disable=too-many-locals
    from hydrachain.app import services, start_app, HPCApp
    import pyethapp.config as konfig

    def privkey_to_uri(private_key):
        host = b'0.0.0.0'
        pubkey = privtopub(private_key)
        return host_port_pubkey_to_uri(host, p2p_base_port, pubkey)

    account_addresses = [
        privtoaddr(priv)
        for priv in private_keys
    ]

    alloc = {
        encode_hex(address): {
            'balance': DEFAULT_BALANCE,
        }
        for address in account_addresses
    }

    genesis = {
        'nonce': '0x00006d6f7264656e',
        'difficulty': '0x20000',
        'mixhash': '0x00000000000000000000000000000000000000647572616c65787365646c6578',
        'coinbase': '0x0000000000000000000000000000000000000000',
        'timestamp': '0x00',
        'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
        'extraData': '0x',
        'gasLimit': GAS_LIMIT_HEX,
        'alloc': alloc,
    }

    bootstrap_nodes = [
        privkey_to_uri(hydrachain_private_keys[0]),
    ]

    validators_addresses = [
        privtoaddr(private_key)
        for private_key in hydrachain_private_keys
    ]

    all_apps = []
    for number, private_key in enumerate(hydrachain_private_keys):
        config = konfig.get_default_config(services + [HPCApp])
        config = update_config_from_genesis_json(config, genesis)

        datadir = os.path.join(base_datadir, str(number))
        konfig.setup_data_dir(datadir)

        account = Account.new(
            password='',
            key=private_key,
        )

        config['data_dir'] = datadir
        config['hdc']['validators'] = validators_addresses
        config['node']['privkey_hex'] = encode_hex(private_key)
        config['jsonrpc']['listen_port'] += number
        config['client_version_string'] = 'NODE{}'.format(number)

        # setting to 0 so that the CALLCODE opcode works at the start of the
        # network
        config['eth']['block']['HOMESTEAD_FORK_BLKNUM'] = 0

        config['discovery']['bootstrap_nodes'] = bootstrap_nodes
        config['discovery']['listen_port'] = p2p_base_port + number

        config['p2p']['listen_port'] = p2p_base_port + number
        config['p2p']['min_peers'] = min(10, len(hydrachain_private_keys) - 1)
        config['p2p']['max_peers'] = len(hydrachain_private_keys) * 2

        # only one of the nodes should have the Console service running
        if number != 0 and Console.name not in config['deactivated_services']:
            config['deactivated_services'].append(Console.name)

        hydrachain_app = start_app(config, accounts=[account])
        all_apps.append(hydrachain_app)

    hydrachain_wait(private_keys, len(hydrachain_private_keys) - 1)

    return all_apps
Beispiel #23
0
def private_to_account(ctx, privatekey, password):
    account = Account.new(password.encode('ascii'),
                          key=privatekey.encode('ascii'))
    print account.dump()
def account(privkey, password, uuid):
    return Account.new(password, privkey, uuid)
Beispiel #25
0
def account_file():
    account = Account.new('', key="1" * 64)
    print account.dump()
Beispiel #26
0
 def __init__(self, privkey):
     self.services = self.Services()
     self.services.db = EphemDB()
     self.services.accounts = AccountsService(self)
     account = Account.new(password='', key=privkey)
     self.services.accounts.add_account(account, store=False)
Beispiel #27
0
def account_file():
    account = Account.new('', key="1" * 64)
    print account.dump()
Beispiel #28
0
 def add_accounts(self, user_id, locked=False):
     account = Account.new(user_id)
     if locked:
         account.lock()
     self.services.accounts.add_account(account, store=False)
Beispiel #29
0
def hydrachain_create_blockchain(private_keys, hydrachain_private_keys,
                                 p2p_base_port, base_datadir):
    """ Initializes a hydrachain network used for testing. """
    # pylint: disable=too-many-locals
    from hydrachain.app import services, start_app, HPCApp
    import pyethapp.config as konfig

    def privkey_to_uri(private_key):
        host = b'0.0.0.0'
        pubkey = privtopub(private_key)
        return host_port_pubkey_to_uri(host, p2p_base_port, pubkey)

    account_addresses = [
        privatekey_to_address(priv)
        for priv in private_keys
    ]

    alloc = {
        encode_hex(address): {
            'balance': DEFAULT_BALANCE_BIN,
        }
        for address in account_addresses
    }

    genesis = {
        'nonce': '0x00006d6f7264656e',
        'difficulty': '0x20000',
        'mixhash': '0x00000000000000000000000000000000000000647572616c65787365646c6578',
        'coinbase': '0x0000000000000000000000000000000000000000',
        'timestamp': '0x00',
        'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
        'extraData': '0x',
        'gasLimit': GAS_LIMIT_HEX,
        'alloc': alloc,
    }

    bootstrap_nodes = [
        privkey_to_uri(hydrachain_private_keys[0]),
    ]

    validators_addresses = [
        privatekey_to_address(private_key)
        for private_key in hydrachain_private_keys
    ]

    all_apps = []
    for number, private_key in enumerate(hydrachain_private_keys):
        config = konfig.get_default_config(services + [HPCApp])
        config = update_config_from_genesis_json(config, genesis)

        datadir = os.path.join(base_datadir, str(number))
        konfig.setup_data_dir(datadir)

        account = Account.new(
            password='',
            key=private_key,
        )

        config['data_dir'] = datadir
        config['hdc']['validators'] = validators_addresses
        config['node']['privkey_hex'] = encode_hex(private_key)
        config['jsonrpc']['listen_port'] += number
        config['client_version_string'] = 'NODE{}'.format(number)

        # setting to 0 so that the CALLCODE opcode works at the start of the
        # network
        config['eth']['block']['HOMESTEAD_FORK_BLKNUM'] = 0

        config['discovery']['bootstrap_nodes'] = bootstrap_nodes
        config['discovery']['listen_port'] = p2p_base_port + number

        config['p2p']['listen_port'] = p2p_base_port + number
        config['p2p']['min_peers'] = min(10, len(hydrachain_private_keys) - 1)
        config['p2p']['max_peers'] = len(hydrachain_private_keys) * 2

        # only one of the nodes should have the Console service running
        if number != 0 and Console.name not in config['deactivated_services']:
            config['deactivated_services'].append(Console.name)

        hydrachain_app = start_app(config, accounts=[account])
        all_apps.append(hydrachain_app)

    hydrachain_wait(private_keys, len(hydrachain_private_keys) - 1)

    return all_apps
Beispiel #30
0
def hydrachain_network(private_keys, base_port, base_datadir):
    """ Initializes a hydrachain network used for testing. """
    # pylint: disable=too-many-locals
    from hydrachain.app import services, start_app, HPCApp
    import pyethapp.config as konfig

    gevent.get_hub().SYSTEM_ERROR = BaseException
    PBKDF2_CONSTANTS['c'] = 100
    quantity = len(private_keys)

    def privkey_to_uri(private_key):
        host = b'0.0.0.0'
        pubkey = privtopub(private_key)
        return host_port_pubkey_to_uri(host, base_port, pubkey)

    addresses = [
        privtoaddr(priv)
        for priv in private_keys
    ]

    bootstrap_nodes = [
        privkey_to_uri(private_keys[0]),
    ]

    validator_keys = [
        mk_privkey('raidenvalidator:{}'.format(position))
        for position in range(quantity)
    ]

    validator_addresses = [
        privtoaddr(validator_keys[position])
        for position in range(quantity)
    ]

    alloc = {
        addr.encode('hex'): {
            'balance': '1606938044258990275541962092341162602522202993782792835301376',
        }
        for addr in addresses
    }

    genesis = {
        'nonce': '0x00006d6f7264656e',
        'difficulty': '0x20000',
        'mixhash': '0x00000000000000000000000000000000000000647572616c65787365646c6578',
        'coinbase': '0x0000000000000000000000000000000000000000',
        'timestamp': '0x00',
        'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
        'extraData': '0x',
        'gasLimit': '0x5FEFD8',
        'alloc': alloc,
    }

    all_apps = []
    for number in range(quantity):
        port = base_port + number

        config = konfig.get_default_config(services + [HPCApp])

        # del config['eth']['genesis_hash']
        config = update_config_from_genesis_json(config, genesis)

        datadir = os.path.join(base_datadir, str(number))
        konfig.setup_data_dir(datadir)

        account = Account.new(
            password='',
            key=validator_keys[number],
        )

        config['data_dir'] = datadir
        config['node']['privkey_hex'] = private_keys[number].encode('hex')
        config['hdc']['validators'] = validator_addresses
        config['jsonrpc']['listen_port'] += number
        config['client_version_string'] = 'NODE{}'.format(number)

        # setting to 0 so that the CALLCODE opcode works at the start of the
        # network
        config['eth']['block']['HOMESTEAD_FORK_BLKNUM'] = 0

        config['discovery']['bootstrap_nodes'] = bootstrap_nodes
        config['discovery']['listen_port'] = port

        config['p2p']['listen_port'] = port
        config['p2p']['min_peers'] = min(10, quantity - 1)
        config['p2p']['max_peers'] = quantity * 2

        # only one of the nodes should have the Console service running
        if number != 0:
            config['deactivated_services'].append(Console.name)

        hydrachain_app = start_app(config, accounts=[account])
        all_apps.append(hydrachain_app)

    return all_apps