def __init__(self, chain_state: ChainState, channel_state: NettingChannelState): self.secret = random_secret() self.secrethash = SecretHash(sha3(self.secret)) self.lock_expiration = get_initial_lock_expiration( chain_state.block_number, channel_state.reveal_timeout) self.payment_identifier = PaymentID(create_default_identifier()) self.message_identifier = MessageID( message_identifier_from_prng(chain_state.pseudo_random_generator))
def test_init_with_usable_routes(): channel1 = factories.make_channel( our_balance=UNIT_TRANSFER_AMOUNT, token_address=UNIT_TOKEN_ADDRESS, token_network_identifier=UNIT_TOKEN_NETWORK_ADDRESS, ) channel_map = {channel1.identifier: channel1} available_routes = [factories.route_from_channel(channel1)] pseudo_random_generator = random.Random() init_state_change = ActionInitInitiator( factories.UNIT_TRANSFER_DESCRIPTION, available_routes, ) block_number = 1 transition = initiator_manager.state_transition( None, init_state_change, channel_map, pseudo_random_generator, block_number, ) assert isinstance(transition.new_state, InitiatorPaymentState) assert transition.events, 'we have a valid route, the mediated transfer event must be emitted' payment_state = transition.new_state assert payment_state.initiator.transfer_description == factories.UNIT_TRANSFER_DESCRIPTION mediated_transfers = [ e for e in transition.events if isinstance(e, SendLockedTransfer) ] assert len(mediated_transfers ) == 1, 'mediated_transfer should /not/ split the transfer' send_mediated_transfer = mediated_transfers[0] transfer = send_mediated_transfer.transfer expiration = initiator.get_initial_lock_expiration(block_number, channel1.reveal_timeout) assert transfer.balance_proof.token_network_identifier == channel1.token_network_identifier assert transfer.lock.amount == factories.UNIT_TRANSFER_DESCRIPTION.amount assert transfer.lock.expiration == expiration assert transfer.lock.secrethash == factories.UNIT_TRANSFER_DESCRIPTION.secrethash assert send_mediated_transfer.recipient == channel1.partner_state.address
def test_init_with_usable_routes(): channel1 = factories.make_channel( our_balance=UNIT_TRANSFER_AMOUNT, token_address=UNIT_TOKEN_ADDRESS, token_network_identifier=UNIT_TOKEN_NETWORK_ADDRESS, ) channel_map = {channel1.identifier: channel1} available_routes = [factories.route_from_channel(channel1)] pseudo_random_generator = random.Random() init_state_change = ActionInitInitiator( factories.UNIT_TRANSFER_DESCRIPTION, available_routes, ) block_number = 1 transition = initiator_manager.state_transition( None, init_state_change, channel_map, pseudo_random_generator, block_number, ) assert isinstance(transition.new_state, InitiatorPaymentState) assert transition.events, 'we have a valid route, the mediated transfer event must be emitted' payment_state = transition.new_state assert payment_state.initiator.transfer_description == factories.UNIT_TRANSFER_DESCRIPTION mediated_transfers = [e for e in transition.events if isinstance(e, SendLockedTransfer)] assert len(mediated_transfers) == 1, 'mediated_transfer should /not/ split the transfer' send_mediated_transfer = mediated_transfers[0] transfer = send_mediated_transfer.transfer expiration = initiator.get_initial_lock_expiration(block_number, channel1.reveal_timeout) assert transfer.balance_proof.token_network_identifier == channel1.token_network_identifier assert transfer.lock.amount == factories.UNIT_TRANSFER_DESCRIPTION.amount assert transfer.lock.expiration == expiration assert transfer.lock.secrethash == factories.UNIT_TRANSFER_DESCRIPTION.secrethash assert send_mediated_transfer.recipient == channel1.partner_state.address