1
+ import dataclasses
2
+ import logging
1
3
from unittest .mock import patch
2
4
3
5
import pytest
14
16
from raiden .network .pathfinding import (
15
17
PFSInfo ,
16
18
check_pfs_for_production ,
19
+ check_pfs_transport_configuration ,
17
20
configure_pfs_or_exit ,
18
21
session ,
19
22
)
@@ -51,6 +54,7 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
51
54
"version" : "0.0.1" ,
52
55
"payment_address" : to_checksum_address (privatekey_to_address (private_keys [0 ])),
53
56
"matrix_server" : "http://matrix.example.com" ,
57
+ "matrix_room_id" : "!room-id:matrix.example.com" ,
54
58
}
55
59
56
60
response = mocked_json_response (response_data = json_data )
@@ -64,7 +68,6 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
64
68
node_network_id = chain_id ,
65
69
token_network_registry_address = token_network_registry_address_test_default ,
66
70
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
67
- matrix_servers = ["http://matrix.example.com" ],
68
71
)
69
72
70
73
# With private routing configure_pfs should raise assertion
@@ -76,7 +79,6 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
76
79
node_network_id = chain_id ,
77
80
token_network_registry_address = token_network_registry_address_test_default ,
78
81
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
79
- matrix_servers = ["http://matrix.example.com" ],
80
82
)
81
83
82
84
# Asking for auto address
@@ -90,7 +92,6 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
90
92
node_network_id = chain_id ,
91
93
token_network_registry_address = token_network_registry_address_test_default ,
92
94
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
93
- matrix_servers = ["matrix.example.com" ],
94
95
)
95
96
assert config .url in urls
96
97
assert is_canonical_address (config .payment_address )
@@ -105,7 +106,6 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
105
106
node_network_id = chain_id ,
106
107
token_network_registry_address = token_network_registry_address_test_default ,
107
108
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
108
- matrix_servers = ["matrix.example.com" ],
109
109
)
110
110
assert config .url == given_address
111
111
assert is_same_address (config .payment_address , json_data ["payment_address" ])
@@ -123,7 +123,6 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
123
123
node_network_id = chain_id ,
124
124
token_network_registry_address = token_network_registry_address_test_default ,
125
125
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
126
- matrix_servers = ["http://matrix.example.com" ],
127
126
)
128
127
129
128
# Addresses of token network registries of pfs and client conflict, should exit the client
@@ -139,7 +138,6 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
139
138
to_canonical_address ("0x2222222222222222222222222222222222222221" )
140
139
),
141
140
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
142
- matrix_servers = ["http://matrix.example.com" ],
143
141
)
144
142
145
143
# ChainIDs of pfs and client conflict, should exit the client
@@ -153,22 +151,59 @@ def test_configure_pfs(service_registry_address, private_keys, web3, contract_ma
153
151
node_network_id = ChainID (chain_id + 1 ),
154
152
token_network_registry_address = token_network_registry_address_test_default ,
155
153
pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
156
- matrix_servers = ["http://matrix.example.com" ],
157
154
)
158
155
159
- # Wrong matrix server
160
- response = mocked_json_response (response_data = json_data )
161
- with pytest .raises (RaidenError , match = "matrix server" ):
162
- with patch .object (session , "get" , return_value = response ):
163
- configure_pfs_or_exit (
164
- pfs_url = "http://foo" ,
165
- routing_mode = RoutingMode .PFS ,
166
- service_registry = service_registry ,
167
- node_network_id = ChainID (chain_id ),
168
- token_network_registry_address = token_network_registry_address_test_default ,
169
- pathfinding_max_fee = DEFAULT_PATHFINDING_MAX_FEE ,
170
- matrix_servers = ["matrix.doesnotexist.com" ],
171
- )
156
+
157
+ def test_check_pfs_transport_configuration (chain_id , private_keys , caplog ):
158
+ matrix_server_url = "http://matrix.example.com"
159
+ matrix_room_id = "!room-id:matrix.example.com"
160
+ pfs_info = PFSInfo (
161
+ url = "http://foo" ,
162
+ price = TokenAmount (0 ),
163
+ chain_id = chain_id ,
164
+ token_network_registry_address = token_network_registry_address_test_default ,
165
+ payment_address = to_canonical_address ("0x2222222222222222222222222222222222222221" ),
166
+ message = "" ,
167
+ operator = "" ,
168
+ version = "" ,
169
+ user_deposit_address = privatekey_to_address (private_keys [1 ]),
170
+ confirmed_block_number = BlockNumber (10 ),
171
+ matrix_server = matrix_server_url ,
172
+ matrix_room_id = matrix_room_id ,
173
+ )
174
+
175
+ # Room id mismatch, must raise
176
+ with pytest .raises (RaidenError ):
177
+ check_pfs_transport_configuration (
178
+ pfs_info = pfs_info ,
179
+ pfs_was_autoselected = True ,
180
+ transport_pfs_broadcast_room_id = "!this-is-not-the-room-youre-looking-for:example.com" ,
181
+ matrix_server_url = matrix_server_url ,
182
+ matrix_server_was_autoselected = True ,
183
+ )
184
+
185
+ # Room ids match, must not raise
186
+ check_pfs_transport_configuration (
187
+ pfs_info = pfs_info ,
188
+ pfs_was_autoselected = True ,
189
+ transport_pfs_broadcast_room_id = matrix_room_id ,
190
+ matrix_server_url = matrix_server_url ,
191
+ matrix_server_was_autoselected = True ,
192
+ )
193
+
194
+ # With the matrix_room_id missing from the PFS response the check can't be performed
195
+ pfs_info_no_room_id = dataclasses .replace (pfs_info , matrix_room_id = None )
196
+ with caplog .at_level (logging .WARNING ):
197
+ check_pfs_transport_configuration (
198
+ pfs_info = pfs_info_no_room_id ,
199
+ pfs_was_autoselected = True ,
200
+ transport_pfs_broadcast_room_id = "!not-this-again:matrix.org" ,
201
+ matrix_server_url = matrix_server_url ,
202
+ matrix_server_was_autoselected = True ,
203
+ )
204
+ assert "Can't check PFS transport configuration" in (
205
+ record .msg ["event" ] for record in caplog .records
206
+ )
172
207
173
208
174
209
def test_check_pfs_for_production (
@@ -195,6 +230,7 @@ def test_check_pfs_for_production(
195
230
user_deposit_address = privatekey_to_address (private_keys [1 ]),
196
231
confirmed_block_number = BlockNumber (10 ),
197
232
matrix_server = "http://matrix.example.com" ,
233
+ matrix_room_id = "!room-id:matrix.example.com" ,
198
234
)
199
235
with pytest .raises (RaidenError ):
200
236
check_pfs_for_production (service_registry = service_registry , pfs_info = pfs_info )
@@ -212,6 +248,7 @@ def test_check_pfs_for_production(
212
248
user_deposit_address = privatekey_to_address (private_keys [1 ]),
213
249
confirmed_block_number = BlockNumber (10 ),
214
250
matrix_server = "http://matrix.example.com" ,
251
+ matrix_room_id = "!room-id:matrix.example.com" ,
215
252
)
216
253
with pytest .raises (RaidenError ):
217
254
check_pfs_for_production (service_registry = service_registry , pfs_info = pfs_info )
0 commit comments