def test_receive_hashlocktransfer_unknown(raiden_network): app0 = raiden_network[0] # pylint: disable=unbalanced-tuple-unpacking token_manager0 = app0.raiden.managers_by_token_address.values()[0] other_key = PrivateKey(HASH2, ctx=GLOBAL_CTX, raw=True) other_address = privatekey_to_address(other_key.private_key) amount = 10 lock = Lock(amount, 1, HASH) refund_transfer = RefundTransfer(identifier=1, nonce=1, token=token_manager0.token_address, transferred_amount=amount, recipient=app0.raiden.address, locksroot=HASH, lock=lock) sign_and_send(refund_transfer, other_key, other_address, app0) transfer_timeout = TransferTimeout(HASH, HASH) sign_and_send(transfer_timeout, other_key, other_address, app0) secret = Secret(1, HASH, token_manager0.token_address) sign_and_send(secret, other_key, other_address, app0) secret_request = SecretRequest(1, HASH, 1) sign_and_send(secret_request, other_key, other_address, app0) reveal_secret = RevealSecret(HASH) sign_and_send(reveal_secret, other_key, other_address, app0) # Whenever processing of ConfirmTransfer is implemented test it here # too by removing the expectation of an exception with pytest.raises(KeyError): confirm_transfer = ConfirmTransfer(HASH) sign_and_send(confirm_transfer, other_key, other_address, app0)
def create_timeouttransfer_for(self, transfer): """ Return a TransferTimeout for `transfer`. """ lock = transfer.lock if not self.our_state.balance_proof.is_pending(lock.hashlock): raise ValueError('Unknow hashlock') return TransferTimeout( transfer.hash, lock.hashlock, )
def create_timeouttransfer_for(self, transfer): """ Return a TransferTimeout for `transfer`. """ lock = transfer.lock if lock.hashlock not in self.our_state.locked: raise ValueError('Unknow hashlock') return TransferTimeout( transfer.hash, lock.hashlock, )
def test_transfer_timeout(iterations=ITERATIONS): echo = HASH hashlock = HASH msg = TransferTimeout(echo, hashlock) msg.sign(PRIVKEY, ADDRESS) run_timeit('TransferTimeout', msg, iterations=iterations)
def send_transfer_and_wait(self, recipient, transfer, path, timeout): """ Send `transfer` to `recipient` and wait for the response. Args: recipient (address): The address of the node that will receive the message. transfer: The transfer message. path: The current path that is being tried. timeout: How long should we wait for a response from `recipient`. Returns: TransferTimeout: If the other end didn't respond """ self.event = AsyncResult() self.raiden.send(recipient, transfer) # The event is set either when a relevant message is received or we # reach the timeout. # # The relevant messages are: CancelTransfer, TransferTimeout, # SecretRequest, or Secret msg = self.event.wait(timeout) # Timed out if msg is None: log.error( 'TIMEOUT [{}]! recipient={} didnt respond path={}'.format( timeout, pex(recipient), lpex(path), )) transfer_timeout = TransferTimeout( echo=transfer.hash, hashlock=transfer.lock.hashlock, ) self.raiden.sign(transfer_timeout) return transfer_timeout log.debug( 'HAVE EVENT {} {}'.format(self, msg), node=pex(self.raiden.address), ) if isinstance(msg, CancelTransfer): assert msg.lock.hashlock == transfer.lock.hashlock assert msg.lock.amount == transfer.lock.amount assert msg.recipient == transfer.sender == self.raiden.address channel = self.assetmanager.channels[msg.sender] channel.register_transfer(msg) return msg elif isinstance(msg, TransferTimeout): assert msg.echo == transfer.hash return msg # send back StaleHashLock, we need new hashlock elif isinstance(msg, Secret): # done exit assert msg.hashlock == self.hashlock # channel = self.assetmanager.channels[msg.recipient] # channel.claim_locked(msg.secret) # fixme this is also done by assetmanager return msg elif isinstance(msg, SecretRequest): # reveal secret log.info('SECRETREQUEST RECEIVED {}'.format(msg)) assert msg.sender == self.target return msg raise NotImplementedError()