MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_getroute_routes

Function check_getroute_routes

tests/test_askrene.py:2187–2239  ·  view source on GitHub ↗

Check that routes are as expected in result. This is similar to check_getroute_paths but it compares all fields inside the routes and not just the path.

(
    node,
    source,
    destination,
    amount_msat,
    routes,
    layers=[],
    maxfee_msat=1000,
    final_cltv=99,
)

Source from the content-addressed store, hash-verified

2185
2186
2187def check_getroute_routes(
2188 node,
2189 source,
2190 destination,
2191 amount_msat,
2192 routes,
2193 layers=[],
2194 maxfee_msat=1000,
2195 final_cltv=99,
2196):
2197 """Check that routes are as expected in result. This is similar to
2198 check_getroute_paths but it compares all fields inside the routes and not
2199 just the path."""
2200
2201 def check_route_as_expected(routes, expected_routes):
2202 """Make sure all fields in paths are match those in routes"""
2203
2204 def dict_subset_eq(a, b):
2205 """Is every key in B is the same in A?"""
2206 return all(a.get(key) == b[key] for key in b if key != "path")
2207
2208 for r in expected_routes:
2209 found = False
2210 for i, candidate in enumerate(routes):
2211 pathlen = len(r["path"])
2212 if len(candidate["path"]) != pathlen:
2213 continue
2214 if dict_subset_eq(candidate, r) and all(
2215 dict_subset_eq(candidate["path"][i], r["path"][i])
2216 for i in range(pathlen)
2217 ):
2218 del routes[i]
2219 found = True
2220 break
2221
2222 if not found:
2223 raise ValueError(
2224 "Could not find route {} in routes {}".format(r, routes)
2225 )
2226
2227 if routes != []:
2228 raise ValueError("Did not expect paths {}".format(routes))
2229
2230 getroutes = node.rpc.getroutes(
2231 source=source,
2232 destination=destination,
2233 amount_msat=amount_msat,
2234 layers=layers,
2235 maxfee_msat=maxfee_msat,
2236 final_cltv=final_cltv,
2237 )
2238 assert getroutes["probability_ppm"] <= 1000000
2239 check_route_as_expected(getroutes["routes"], routes)
2240
2241
2242def test_includefees(node_factory):

Callers 1

test_includefeesFunction · 0.85

Calls 2

check_route_as_expectedFunction · 0.85
getroutesMethod · 0.80

Tested by

no test coverage detected