Ejemplo n.º 1
0
def _tester_services(deploy_key, private_keys, tester_blockgas_limit):
    # calling the fixture directly because we don't want to force all
    # blockchain_services to instantiate a state
    tester = tester_state(
        deploy_key,
        private_keys,
        tester_blockgas_limit,
    )

    tester_registry_address = tester_deploy_contract(
        tester,
        deploy_key,
        contract_name='Registry',
        contract_file='Registry.sol',
    )

    deploy_blockchain = BlockChainServiceTesterMock(
        deploy_key,
        tester,
        tester_registry_address,
    )

    blockchain_services = list()
    for privkey in private_keys:
        blockchain = BlockChainServiceTesterMock(
            privkey,
            tester,
            tester_registry_address,
        )
        blockchain_services.append(blockchain)

    return BlockchainServices(deploy_blockchain, blockchain_services)
Ejemplo n.º 2
0
def _tester_services(deploy_key, private_keys, tester_blockgas_limit):
    # calling the fixture directly because we don't want to force all
    # blockchain_services to instantiate a state
    tester = tester_state(
        deploy_key,
        private_keys,
        tester_blockgas_limit,
    )

    tester_registry_address = tester_deploy_contract(
        tester,
        deploy_key,
        contract_name='Registry',
        contract_file='Registry.sol',
    )

    deploy_blockchain = BlockChainServiceTesterMock(
        deploy_key,
        tester,
        tester_registry_address,
    )

    blockchain_services = list()
    for privkey in private_keys:
        blockchain = BlockChainServiceTesterMock(
            privkey,
            tester,
            tester_registry_address,
        )
        blockchain_services.append(blockchain)

    return BlockchainServices(deploy_blockchain, blockchain_services)
Ejemplo n.º 3
0
def deploy_and_open_channel_alloc(deployment_key):
    """ Compiles, deploys and dumps a minimal raiden smart contract environment for use in a
    genesis block. This will:
        - deploy the raiden Registry contract stack
        - deploy a token contract
        - open a channel for the TEST_ACCOUNT address
        - deploy the EndpointRegistry/discovery contract
        - register a known value for the TEST_ACCOUNT address
        - dump the complete state in a genesis['alloc'] compatible format
        - return the state dump and the contract addresses
    """
    deployment_key_bin = deployment_key.decode('hex')
    state = tester_state(deployment_key_bin, [deployment_key_bin], 6 * 10**6)

    registry_address = tester_deploy_contract(
        state,
        deployment_key_bin,
        'Registry',
        get_contract_path('Registry.sol'),
    )

    discovery_address = tester_deploy_contract(
        state,
        deployment_key_bin,
        'EndpointRegistry',
        get_contract_path('EndpointRegistry.sol'),
    )

    client = BlockChainServiceTesterMock(
        deployment_key_bin,
        state,
    )

    registry = client.registry(registry_address)

    token_address = client.deploy_and_register_token(
        registry,
        'HumanStandardToken',
        get_contract_path('HumanStandardToken.sol'),
        constructor_parameters=(100, 'smoketesttoken', 2, 'RST'))

    manager = registry.manager_by_token(token_address)

    assert manager.private_key == deployment_key_bin
    our_address = TEST_ACCOUNT['address']

    channel_address = manager.new_netting_channel(
        our_address.decode('hex'), TEST_PARTNER_ADDRESS.decode('hex'), 50)

    client.token(token_address).approve(channel_address, TEST_DEPOSIT_AMOUNT)
    channel = NettingChannelTesterMock(state, deployment_key_bin,
                                       channel_address)
    channel.deposit(TEST_DEPOSIT_AMOUNT)

    discovery = client.discovery(discovery_address)
    discovery.proxy.registerEndpoint(TEST_ENDPOINT)

    contracts = dict(
        registry_address=registry_address,
        token_address=token_address,
        discovery_address=discovery_address,
        channel_address=channel_address,
    )
    for k, v in contracts.iteritems():
        contracts[k] = hexlify(v)

    alloc = dict()
    # preserve all accounts and contracts
    for address in state.block.state.to_dict().keys():
        address = hexlify(address)
        alloc[address] = state.block.account_to_dict(address)

    for account, content in alloc.iteritems():
        alloc[account]['storage'] = fix_tester_storage(content['storage'])

    return dict(
        alloc=alloc,
        contracts=contracts,
    )
Ejemplo n.º 4
0
def deploy_and_open_channel_alloc(deployment_key):
    """ Compiles, deploys and dumps a minimal raiden smart contract environment for use in a
    genesis block. This will:
        - deploy the raiden Registry contract stack
        - deploy a token contract
        - open a channel for the TEST_ACCOUNT address
        - deploy the EndpointRegistry/discovery contract
        - register a known value for the TEST_ACCOUNT address
        - dump the complete state in a genesis['alloc'] compatible format
        - return the state dump and the contract addresses
    """
    deployment_key_bin = unhexlify(deployment_key)
    state = create_tester_chain(
        deployment_key_bin,
        [deployment_key_bin],
        6 * 10 ** 6
    )

    registry_address = tester_deploy_contract(
        state,
        deployment_key_bin,
        'Registry',
        get_contract_path('Registry.sol'),
    )

    discovery_address = tester_deploy_contract(
        state,
        deployment_key_bin,
        'EndpointRegistry',
        get_contract_path('EndpointRegistry.sol'),
    )

    client = BlockChainServiceTesterMock(
        deployment_key_bin,
        state,
    )

    registry = client.registry(registry_address)

    token_address = client.deploy_and_register_token(
        registry,
        'HumanStandardToken',
        get_contract_path('HumanStandardToken.sol'),
        constructor_parameters=(100, 'smoketesttoken', 2, 'RST')
    )

    manager = registry.manager_by_token(token_address)
    assert manager.private_key == deployment_key_bin

    channel_address = manager.new_netting_channel(
        unhexlify(TEST_PARTNER_ADDRESS),
        50
    )

    client.token(token_address).approve(channel_address, TEST_DEPOSIT_AMOUNT)
    channel = NettingChannelTesterMock(
        state,
        deployment_key_bin,
        channel_address
    )
    channel.deposit(TEST_DEPOSIT_AMOUNT)

    discovery = client.discovery(discovery_address)
    discovery.proxy.registerEndpoint(TEST_ENDPOINT)

    contracts = dict(
        registry_address=address_encoder(registry_address),
        token_address=address_encoder(token_address),
        discovery_address=address_encoder(discovery_address),
        channel_address=address_encoder(channel_address),
    )

    alloc = dict()
    # preserve all accounts and contracts
    for address in state.head_state.to_dict().keys():
        alloc[address] = state.head_state.account_to_dict(address)

    for account, content in alloc.items():
        alloc[account]['storage'] = fix_tester_storage(content['storage'])

    return dict(
        alloc=alloc,
        contracts=contracts,
    )