def test_pfs_send_capacity_updates_on_deposit_and_withdraw( raiden_network: List[App], token_addresses: List[TokenAddress]) -> None: # We need to test if PFSCapacityUpdates and PFSFeeUpdates are being # sent after a deposit and withdraw. # Therefore, we create two Raiden nodes app0 and app1. # The nodes open a channel but do not deposit # a pfs matrix room is mocked to see what is sent to it app0, app1 = raiden_network transport0 = app0.raiden.transport pfs_room_name = make_room_alias(transport0.chain_id, PATH_FINDING_BROADCASTING_ROOM) pfs_room = transport0._broadcast_rooms.get(pfs_room_name) # need to assert for mypy that pfs_room is not None assert isinstance(pfs_room, Room) pfs_room.send_text = MagicMock(spec=pfs_room.send_text) api0 = RaidenAPI(app0.raiden) api0.channel_open( token_address=token_addresses[0], registry_address=app0.raiden.default_registry.address, partner_address=app1.raiden.address, ) # the room should not have been called at channel opening assert pfs_room.send_text.call_count == 0 api0.set_total_channel_deposit( token_address=token_addresses[0], registry_address=app0.raiden.default_registry.address, partner_address=app1.raiden.address, total_deposit=TokenAmount(10), ) # now we expect the room to be called the 1st time with a PFSCapacityUpdate # and a PFSFeeUpdate after the deposit assert "PFSCapacityUpdate" in str(pfs_room.send_text.call_args_list[0]) assert "PFSFeeUpdate" in str(pfs_room.send_text.call_args_list[0]) api0.set_total_channel_withdraw( token_address=token_addresses[0], registry_address=app0.raiden.default_registry.address, partner_address=app1.raiden.address, total_withdraw=WithdrawAmount(5), ) # now we expect the room to be called the 2nd time with a PFSCapacityUpdate # after the withdraw assert "PFSCapacityUpdate" in str(pfs_room.send_text.call_args_list[1]) assert "PFSFeeUpdate" in str(pfs_room.send_text.call_args_list[1])
def test_pfs_send_capacity_updates_on_deposit_and_withdraw( raiden_network: List[App], token_addresses: List[TokenAddress]) -> None: """ We need to test if PFSCapacityUpdates and PFSFeeUpdates are being sent after a deposit and withdraw. The nodes open a channel but do not deposit. After deposit and withdraw it is checked that the correct messages are sent. """ app0, app1, app2 = raiden_network api0 = RaidenAPI(app0.raiden) api0.channel_open( token_address=token_addresses[0], registry_address=app0.raiden.default_registry.address, partner_address=app1.raiden.address, ) wait_all_apps(raiden_network) # There should be no messages sent at channel opening assert len(get_messages(app0)) == 0 assert len(get_messages(app1)) == 0 assert len(get_messages(app2)) == 0 api0.set_total_channel_deposit( token_address=token_addresses[0], registry_address=app0.raiden.default_registry.address, partner_address=app1.raiden.address, total_deposit=TokenAmount(10), ) wait_all_apps(raiden_network) # We expect a PFSCapacityUpdate and a PFSFeeUpdate after the deposit messages0 = get_messages(app0) assert len(messages0) == 2 assert len([x for x in messages0 if isinstance(x, PFSCapacityUpdate)]) == 1 assert len([x for x in messages0 if isinstance(x, PFSFeeUpdate)]) == 1 # We expect the same messages for the target messages1 = get_messages(app1) assert len(messages1) == 2 assert len([x for x in messages1 if isinstance(x, PFSCapacityUpdate)]) == 1 assert len([x for x in messages1 if isinstance(x, PFSFeeUpdate)]) == 1 # Unrelated node should not send updates assert len(get_messages(app2)) == 0 api0.set_total_channel_withdraw( token_address=token_addresses[0], registry_address=app0.raiden.default_registry.address, partner_address=app1.raiden.address, total_withdraw=WithdrawAmount(5), ) wait_all_apps(raiden_network) # We expect a PFSCapacityUpdate and a PFSFeeUpdate after the withdraw messages0 = get_messages(app0) assert len(messages0) == 4 assert len([x for x in messages0 if isinstance(x, PFSCapacityUpdate)]) == 2 assert len([x for x in messages0 if isinstance(x, PFSFeeUpdate)]) == 2 # We expect the same messages for the target messages1 = get_messages(app1) assert len(messages1) == 4 assert len([x for x in messages1 if isinstance(x, PFSCapacityUpdate)]) == 2 assert len([x for x in messages1 if isinstance(x, PFSFeeUpdate)]) == 2 # Unrelated node should not send updates assert len(get_messages(app2)) == 0