Beispiel #1
0
def test_nettingchannel_settle_timeout_inrange(private_keys,
                                               tester_channelmanager,
                                               tester_chain):
    """ The netting channel constructor must enforce that settle timeout is in
    the valid range.

    Also asserts that the constants.py and the netting channel contract values
    are synched.
    """
    pkey0 = private_keys[0]
    pkey1 = private_keys[1]
    pkey2 = private_keys[2]

    with pytest.raises(TransactionFailed):
        small_settle_timeout = NETTINGCHANNEL_SETTLE_TIMEOUT_MIN - 1
        tester_channelmanager.newChannel(
            privatekey_to_address(pkey1),
            small_settle_timeout,
            sender=pkey0,
        )

    with pytest.raises(TransactionFailed):
        big_settle_timeout = NETTINGCHANNEL_SETTLE_TIMEOUT_MAX + 1
        tester_channelmanager.newChannel(
            privatekey_to_address(pkey1),
            big_settle_timeout,
            sender=pkey0,
        )

    minimum_settle_timeout = NETTINGCHANNEL_SETTLE_TIMEOUT_MIN
    netting_channel_address0_hex = tester_channelmanager.newChannel(
        privatekey_to_address(pkey1),
        minimum_settle_timeout,
        sender=pkey0,
    )
    max_settle_timeout = NETTINGCHANNEL_SETTLE_TIMEOUT_MAX
    netting_channel_address1_hex = tester_channelmanager.newChannel(
        privatekey_to_address(pkey2),
        max_settle_timeout,
        sender=pkey0,
    )

    netting_channel = tester.ABIContract(
        tester_chain, CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
        netting_channel_address0_hex)
    # pylint: disable=no-member
    assert netting_channel.settleTimeout(
        sender=pkey0) == minimum_settle_timeout
    netting_channel2 = tester.ABIContract(
        tester_chain, CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
        netting_channel_address1_hex)
    assert netting_channel2.settleTimeout(sender=pkey0) == max_settle_timeout
Beispiel #2
0
    def __init__(self,
                 jsonrpc_client,
                 manager_address,
                 startgas=GAS_LIMIT,
                 gasprice=GAS_PRICE,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):
        # pylint: disable=too-many-arguments

        if not isaddress(manager_address):
            raise ValueError('manager_address must be a valid address')

        result = jsonrpc_client.call(
            'eth_getCode',
            address_encoder(manager_address),
            'latest',
        )

        if result == '0x':
            raise AddressWithoutCode(
                'Channel manager address {} does not contain code'.format(
                    address_encoder(manager_address), ))

        proxy = jsonrpc_client.new_abi_contract(
            CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER),
            address_encoder(manager_address),
        )

        self.address = manager_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
Beispiel #3
0
    def __init__(
            self,
            jsonrpc_client,
            discovery_address,
            startgas,
            gasprice,
            poll_timeout=DEFAULT_POLL_TIMEOUT):

        if not isaddress(discovery_address):
            raise ValueError('discovery_address must be a valid address')

        check_address_has_code(jsonrpc_client, discovery_address, 'Discovery')

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_ENDPOINT_REGISTRY),
            address_encoder(discovery_address),
        )

        self.address = discovery_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
        self.not_found_address = '0x' + '0' * 40
    def __init__(
            self,
            jsonrpc_client,
            registry_address,
            startgas,
            gasprice,
            poll_timeout=DEFAULT_POLL_TIMEOUT):
        # pylint: disable=too-many-arguments

        if not isaddress(registry_address):
            raise ValueError('registry_address must be a valid address')

        check_address_has_code(jsonrpc_client, registry_address, 'Registry')

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY),
            address_encoder(registry_address),
        )

        self.address = registry_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout

        self.address_to_channelmanager = dict()
        self.token_to_channelmanager = dict()
Beispiel #5
0
    def __init__(self,
                 jsonrpc_client,
                 discovery_address,
                 startgas,
                 gasprice,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):

        if not isaddress(discovery_address):
            raise ValueError('discovery_address must be a valid address')

        result = jsonrpc_client.call(
            'eth_getCode',
            address_encoder(discovery_address),
            'latest',
        )

        if result == '0x':
            raise AddressWithoutCode(
                'Discovery address {} does not contain code'.format(
                    address_encoder(discovery_address), ))

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_ENDPOINT_REGISTRY),
            address_encoder(discovery_address),
        )

        self.address = discovery_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
Beispiel #6
0
    def __init__(self,
                 jsonrpc_client,
                 registry_address,
                 startgas,
                 gasprice,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):
        # pylint: disable=too-many-arguments

        if not isaddress(registry_address):
            raise ValueError('registry_address must be a valid address')

        check_address_has_code(jsonrpc_client, registry_address)

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY),
            address_encoder(registry_address),
        )

        self.address = registry_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout

        self.address_to_channelmanager = dict()
        self.token_to_channelmanager = dict()
Beispiel #7
0
    def __init__(self,
                 jsonrpc_client,
                 discovery_address,
                 startgas=GAS_LIMIT,
                 gasprice=GAS_PRICE,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):

        result = jsonrpc_client.call(
            'eth_getCode',
            address_encoder(discovery_address),
            'latest',
        )

        if result == '0x':
            raise AddressWithoutCode(
                'Discovery address {} does not contain code'.format(
                    address_encoder(discovery_address), ))

        proxy = jsonrpc_client.new_abi_contract(
            CONTRACT_MANAGER.get_abi(CONTRACT_ENDPOINT_REGISTRY),
            address_encoder(discovery_address),
        )

        self.address = discovery_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
Beispiel #8
0
def new_nettingcontract(our_key, partner_key, tester_state, log_listener,
                        channelmanager, settle_timeout):

    if settle_timeout < NETTINGCHANNEL_SETTLE_TIMEOUT_MIN:
        raise ValueError('settle_timeout must be larger-or-equal to {}'.format(
            NETTINGCHANNEL_SETTLE_TIMEOUT_MIN
        ))

    netting_channel_address0_hex = channelmanager.newChannel(
        privatekey_to_address(partner_key),
        settle_timeout,
        sender=our_key,
    )
    tester_state.mine(number_of_blocks=1)

    nettingchannel_translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL)
    )

    nettingchannel = tester.ABIContract(
        tester_state,
        nettingchannel_translator,
        netting_channel_address0_hex,
        log_listener=log_listener,
        default_key=INVALID_KEY,
    )

    return nettingchannel
    def __init__(
        self,
        jsonrpc_client,
        registry_address,
        poll_timeout=DEFAULT_POLL_TIMEOUT,
    ):
        # pylint: disable=too-many-arguments

        if not isaddress(registry_address):
            raise InvalidAddress(
                'Expected binary address format for token network registry')

        check_address_has_code(jsonrpc_client, registry_address,
                               CONTRACT_TOKEN_NETWORK_REGISTRY)

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_TOKEN_NETWORK_REGISTRY),
            address_encoder(registry_address),
        )
        CONTRACT_MANAGER.check_contract_version(
            proxy.functions.contract_version().call(),
            CONTRACT_TOKEN_NETWORK_REGISTRY)

        self.address = registry_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.poll_timeout = poll_timeout
        self.node_address = privatekey_to_address(self.client.privkey)

        self.address_to_tokennetwork = dict()
        self.token_to_tokennetwork = dict()
Beispiel #10
0
    def __init__(self,
                 jsonrpc_client,
                 token_address,
                 startgas=GAS_LIMIT,
                 gasprice=GAS_PRICE,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):

        if not isaddress(token_address):
            raise ValueError('token_address must be a valid address')

        result = jsonrpc_client.call(
            'eth_getCode',
            address_encoder(token_address),
            'latest',
        )

        if result == '0x':
            raise AddressWithoutCode(
                'Token address {} does not contain code'.format(
                    address_encoder(token_address), ))

        proxy = jsonrpc_client.new_abi_contract(
            CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN),
            address_encoder(token_address),
        )

        self.address = token_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
Beispiel #11
0
    def __init__(self,
                 jsonrpc_client,
                 registry_address,
                 startgas=GAS_LIMIT,
                 gasprice=GAS_PRICE,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):
        # pylint: disable=too-many-arguments

        result = jsonrpc_client.call(
            'eth_getCode',
            address_encoder(registry_address),
            'latest',
        )

        if result == '0x':
            raise ValueError(
                'Registry address {} does not contain code'.format(
                    address_encoder(registry_address), ))

        proxy = jsonrpc_client.new_abi_contract(
            CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY),
            address_encoder(registry_address),
        )

        self.address = registry_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
Beispiel #12
0
    def __init__(self,
                 jsonrpc_client,
                 channel_address,
                 startgas=GAS_LIMIT,
                 gasprice=GAS_PRICE,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):
        # pylint: disable=too-many-arguments

        result = jsonrpc_client.call(
            'eth_getCode',
            address_encoder(channel_address),
            'latest',
        )

        if result == '0x':
            raise AddressWithoutCode(
                'Netting channel address {} does not contain code'.format(
                    address_encoder(channel_address), ))

        proxy = jsonrpc_client.new_abi_contract(
            CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
            address_encoder(channel_address),
        )

        self.address = channel_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout

        # check we are a participant of the given channel
        self.node_address = privatekey_to_address(self.client.privkey)
        self.detail(self.node_address)
Beispiel #13
0
    def __init__(self,
                 jsonrpc_client,
                 manager_address,
                 startgas,
                 gasprice,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):
        # pylint: disable=too-many-arguments

        if not isaddress(manager_address):
            raise ValueError('manager_address must be a valid address')

        check_address_has_code(jsonrpc_client, manager_address,
                               'Channel Manager')

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER),
            address_encoder(manager_address),
        )

        self.address = manager_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
Beispiel #14
0
    def __init__(
        self,
        jsonrpc_client,
        manager_address,
        poll_timeout=DEFAULT_POLL_TIMEOUT,
    ):
        # pylint: disable=too-many-arguments

        if not isaddress(manager_address):
            raise InvalidAddress(
                'Expected binary address format for token nework')

        check_address_has_code(jsonrpc_client, manager_address,
                               'Channel Manager')

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_TOKEN_NETWORK),
            address_encoder(manager_address),
        )

        CONTRACT_MANAGER.check_contract_version(
            proxy.functions.contract_version().call(), CONTRACT_TOKEN_NETWORK)

        self.address = manager_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.node_address = privatekey_to_address(self.client.privkey)
        self.poll_timeout = poll_timeout
        # Prevents concurrent deposit, withdraw, close, or settle operations on the same channel
        self.channel_operations_lock = dict()
        self.open_channel_transactions = dict()
Beispiel #15
0
def create_registryproxy(tester_chain, tester_registry_address, log_listener):
    translator = tester.ContractTranslator(CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY))
    tester_chain.head_state.log_listeners.append(log_listener)
    registry_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_registry_address,
    )
    return registry_abi
def create_registryproxy(tester_chain, tester_registry_address, log_listener):
    translator = tester.ContractTranslator(CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY))
    tester_chain.head_state.log_listeners.append(log_listener)
    registry_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_registry_address,
    )
    return registry_abi
Beispiel #17
0
def create_registryproxy(tester_state, tester_registry_address, log_listener):
    translator = tester.ContractTranslator(CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY))
    registry_abi = tester.ABIContract(
        tester_state,
        translator,
        tester_registry_address,
        log_listener=log_listener,
        default_key=INVALID_KEY,
    )
    return registry_abi
Beispiel #18
0
def create_tokenproxy(tester_chain, tester_token_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN))
    tester_chain.head_state.log_listeners.append(log_listener)
    token_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_token_address,
    )
    return token_abi
Beispiel #19
0
def create_nettingchannel_proxy(tester_chain, tester_nettingchannel_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL)
    )
    tester_chain.head_state.log_listeners.append(log_listener)
    netting_channel_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_nettingchannel_address,
    )
    return netting_channel_abi
def create_nettingchannel_proxy(tester_chain, tester_nettingchannel_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL)
    )
    tester_chain.head_state.log_listeners.append(log_listener)
    netting_channel_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_nettingchannel_address,
    )
    return netting_channel_abi
Beispiel #21
0
def create_tokenproxy(tester_state, tester_token_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN))
    token_abi = tester.ABIContract(
        tester_state,
        translator,
        tester_token_address,
        log_listener=log_listener,
        default_key=INVALID_KEY,
    )
    return token_abi
Beispiel #22
0
def create_channelmanager_proxy(tester_chain, tester_channelmanager_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER)
    )
    channel_manager_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_channelmanager_address,
    )
    tester_chain.head_state.log_listeners.append(log_listener)
    return channel_manager_abi
Beispiel #23
0
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_chain,
            CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN), address)
def create_tokenproxy(tester_chain, tester_token_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN)
    )
    tester_chain.head_state.log_listeners.append(log_listener)
    token_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_token_address,
    )
    return token_abi
def create_channelmanager_proxy(tester_chain, tester_channelmanager_address, log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER)
    )
    channel_manager_abi = tester.ABIContract(
        tester_chain,
        translator,
        tester_channelmanager_address,
    )
    tester_chain.head_state.log_listeners.append(log_listener)
    return channel_manager_abi
Beispiel #26
0
def create_channelmanager_proxy(tester_state, tester_channelmanager_address,
                                log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER))
    channel_manager_abi = tester.ABIContract(
        tester_state,
        translator,
        tester_channelmanager_address,
        log_listener=log_listener,
        default_key=INVALID_KEY,
    )
    return channel_manager_abi
Beispiel #27
0
def create_nettingchannel_proxy(tester_state, tester_nettingchannel_address,
                                log_listener):
    translator = tester.ContractTranslator(
        CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL))
    netting_channel_abi = tester.ABIContract(
        tester_state,
        translator,
        tester_nettingchannel_address,
        log_listener=log_listener,
        default_key=INVALID_KEY,
    )
    return netting_channel_abi
Beispiel #28
0
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_chain, CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER),
            address)
        self.participant_filter = defaultdict(list)
        self.address_filter = defaultdict(list)
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_chain,
            CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN),
            address
        )
Beispiel #30
0
    def __init__(self, tester_state, private_key, address):
        if len(tester_state.block.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_state = tester_state
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_state,
            CONTRACT_MANAGER.get_abi(CONTRACT_ENDPOINT_REGISTRY),
            address,
            default_key=private_key,
        )
Beispiel #31
0
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.registry_proxy = tester.ABIContract(
            self.tester_chain, CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY),
            self.address)
        self.tokenadded_filters = list()

        self.address_to_channelmanager = dict()
        self.token_to_channelmanager = dict()
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_chain,
            CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER),
            address
        )
        self.participant_filter = defaultdict(list)
        self.address_filter = defaultdict(list)
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.registry_proxy = tester.ABIContract(
            self.tester_chain,
            CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY),
            self.address
        )
        self.tokenadded_filters = list()

        self.address_to_channelmanager = dict()
        self.token_to_channelmanager = dict()
Beispiel #34
0
    def __init__(self,
                 jsonrpc_client,
                 channel_address,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):

        self.address = channel_address
        self.client = jsonrpc_client
        self.poll_timeout = poll_timeout

        self.client = jsonrpc_client
        self.node_address = privatekey_to_address(self.client.privkey)
        self.proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
            address_encoder(channel_address),
        )

        # check we are a participant of the given channel
        self.detail()
        self._check_exists()
Beispiel #35
0
    def __init__(self,
                 jsonrpc_client,
                 token_address,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):

        if not isaddress(token_address):
            raise ValueError('token_address must be a valid address')

        check_address_has_code(jsonrpc_client, token_address, 'Token')

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN),
            address_encoder(token_address),
        )

        self.address = token_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.poll_timeout = poll_timeout
Beispiel #36
0
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_chain, CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
            address)

        self.newbalance_filters = list()
        self.secretrevealed_filters = list()
        self.channelclose_filters = list()
        self.channelsettle_filters = list()

        # check we are a participant of the channel
        self.detail()
Beispiel #37
0
    def __init__(self,
                 jsonrpc_client,
                 channel_address,
                 poll_timeout=DEFAULT_POLL_TIMEOUT):

        self.address = channel_address
        self.client = jsonrpc_client
        self.poll_timeout = poll_timeout
        # Prevents concurrent deposit, close, or settle operations on the same channel
        self.channel_operations_lock = RLock()
        self.client = jsonrpc_client
        self.node_address = privatekey_to_address(self.client.privkey)
        self.proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
            address_encoder(channel_address),
        )

        # check we are a participant of the given channel
        self.detail()
        self._check_exists()
    def __init__(self, tester_chain, private_key, address):
        if len(tester_chain.head_state.get_code(address)) == 0:
            raise Exception('Contract code empty')

        self.address = address
        self.tester_chain = tester_chain
        self.private_key = private_key

        self.proxy = tester.ABIContract(
            tester_chain,
            CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL),
            address
        )

        self.newbalance_filters = list()
        self.secretrevealed_filters = list()
        self.channelclose_filters = list()
        self.channelsettle_filters = list()

        # check we are a participant of the channel
        self.detail()
    def __init__(
            self,
            jsonrpc_client,
            token_address,
            startgas,
            gasprice,
            poll_timeout=DEFAULT_POLL_TIMEOUT):

        if not isaddress(token_address):
            raise ValueError('token_address must be a valid address')

        check_address_has_code(jsonrpc_client, token_address, 'Token')

        proxy = jsonrpc_client.new_contract_proxy(
            CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN),
            address_encoder(token_address),
        )

        self.address = token_address
        self.proxy = proxy
        self.client = jsonrpc_client
        self.startgas = startgas
        self.gasprice = gasprice
        self.poll_timeout = poll_timeout
def test_blockchain(
        blockchain_backend,  # required to start the geth backend pylint: disable=unused-argument
        blockchain_rpc_ports,
        private_keys,
        poll_timeout):
    # pylint: disable=too-many-locals

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

    privatekey = private_keys[0]
    address = privatekey_to_address(privatekey)
    total_token = 100

    host = '127.0.0.1'
    jsonrpc_client = JSONRPCClient(
        host,
        blockchain_rpc_ports[0],
        privatekey,
    )

    humantoken_path = get_contract_path('HumanStandardToken.sol')
    humantoken_contracts = compile_file(humantoken_path, libraries=dict())
    token_proxy = jsonrpc_client.deploy_solidity_contract(
        address,
        'HumanStandardToken',
        humantoken_contracts,
        list(),
        (total_token, 'raiden', 2, 'Rd'),
        contract_path=humantoken_path,
        gasprice=GAS_PRICE,
        timeout=poll_timeout,
    )

    registry_path = get_contract_path('Registry.sol')
    registry_contracts = compile_file(registry_path)
    registry_proxy = jsonrpc_client.deploy_solidity_contract(
        address,
        'Registry',
        registry_contracts,
        list(),
        tuple(),
        contract_path=registry_path,
        gasprice=GAS_PRICE,
        timeout=poll_timeout,
    )

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert not log_list

    assert token_proxy.call('balanceOf', address) == total_token
    transaction_hash = registry_proxy.transact(
        'addToken',
        token_proxy.contract_address,
        gasprice=denoms.wei,
    )
    jsonrpc_client.poll(unhexlify(transaction_hash), timeout=poll_timeout)

    assert len(registry_proxy.call('tokenAddresses')) == 1

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 1

    channel_manager_address_encoded = registry_proxy.call(
        'channelManagerByToken',
        token_proxy.contract_address,
    )
    channel_manager_address = normalize_address(channel_manager_address_encoded)

    log = log_list[0]
    log_topics = [
        topic_decoder(topic)
        for topic in log['topics']  # pylint: disable=invalid-sequence-index
    ]
    log_data = log['data']  # pylint: disable=invalid-sequence-index
    event = registry_proxy.translator.decode_event(
        log_topics,
        unhexlify(log_data[2:]),
    )

    assert channel_manager_address == normalize_address(event['channel_manager_address'])
    assert token_proxy.contract_address == normalize_address(event['token_address'])

    channel_manager_proxy = jsonrpc_client.new_contract_proxy(
        CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER),
        channel_manager_address,
    )

    transaction_hash = channel_manager_proxy.transact(
        'newChannel',
        addresses[1],
        10,
        gasprice=denoms.wei,
    )
    jsonrpc_client.poll(unhexlify(transaction_hash), timeout=poll_timeout)

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 2
Beispiel #41
0
def registry_abi():
    return CONTRACT_MANAGER.get_abi(CONTRACT_REGISTRY)
Beispiel #42
0
def token_abi():
    return CONTRACT_MANAGER.get_abi(CONTRACT_HUMAN_STANDARD_TOKEN)
Beispiel #43
0
def channel_manager_abi():
    return CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER)
Beispiel #44
0
def test_blockchain(
        blockchain_type,
        blockchain_backend,  # required to start the geth backend
        blockchain_rpc_ports,
        private_keys,
        poll_timeout):
    # pylint: disable=too-many-locals

    # this test is for interaction with a blockchain using json-rpc, so it
    # doesnt make sense to execute it against tester
    if blockchain_type not in ('geth', ):
        return

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

    privatekey = private_keys[0]
    address = privatekey_to_address(privatekey)
    total_token = 100

    jsonrpc_client = JSONRPCClient(
        port=blockchain_rpc_ports[0],
        privkey=privatekey,
        print_communication=False,
    )
    patch_send_transaction(jsonrpc_client)
    patch_send_message(jsonrpc_client)

    humantoken_path = get_contract_path('HumanStandardToken.sol')
    humantoken_contracts = compile_file(humantoken_path, libraries=dict())
    token_proxy = jsonrpc_client.deploy_solidity_contract(
        address,
        'HumanStandardToken',
        humantoken_contracts,
        dict(),
        (total_token, 'raiden', 2, 'Rd'),
        contract_path=humantoken_path,
        gasprice=default_gasprice,
        timeout=poll_timeout,
    )

    registry_path = get_contract_path('Registry.sol')
    registry_contracts = compile_file(registry_path)
    registry_proxy = jsonrpc_client.deploy_solidity_contract(
        address,
        'Registry',
        registry_contracts,
        dict(),
        tuple(),
        contract_path=registry_path,
        gasprice=default_gasprice,
        timeout=poll_timeout,
    )

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 0

    # pylint: disable=no-member

    assert token_proxy.balanceOf(address) == total_token
    transaction_hash = registry_proxy.addToken.transact(
        token_proxy.address,
        gasprice=denoms.wei,
    )
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=poll_timeout)

    assert len(registry_proxy.tokenAddresses.call()) == 1

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 1

    channel_manager_address_encoded = registry_proxy.channelManagerByToken.call(
        token_proxy.address, )
    channel_manager_address = channel_manager_address_encoded.decode('hex')

    log = log_list[0]
    log_topics = [
        decode_topic(topic) for topic in log['topics']  # pylint: disable=invalid-sequence-index
    ]
    log_data = log['data']
    event = registry_proxy.translator.decode_event(
        log_topics,
        log_data[2:].decode('hex'),
    )

    assert channel_manager_address == event['channel_manager_address'].decode(
        'hex')
    assert token_proxy.address == event['token_address'].decode('hex')

    channel_manager_proxy = jsonrpc_client.new_contract_proxy(
        CONTRACT_MANAGER.get_abi(CONTRACT_CHANNEL_MANAGER),
        channel_manager_address,
    )

    transaction_hash = channel_manager_proxy.newChannel.transact(
        addresses[1],
        10,
        gasprice=denoms.wei,
    )
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=poll_timeout)

    log_list = jsonrpc_client.call(
        'eth_getLogs',
        {
            'fromBlock': '0x0',
            'toBlock': 'latest',
            'topics': [],
        },
    )
    assert len(log_list) == 2
Beispiel #45
0
def netting_channel_abi():
    return CONTRACT_MANAGER.get_abi(CONTRACT_NETTING_CHANNEL)