(node_factory)
| 1049 | |
| 1050 | |
| 1051 | def test_payment_fronting(node_factory): |
| 1052 | # Nodes will not front for offers if they don't have an advertized address, so allow localhost. |
| 1053 | l1, l2 = node_factory.get_nodes(2, opts={'dev-allow-localhost': None}) |
| 1054 | l3, l4 = node_factory.get_nodes(2, opts=[{'payment-fronting-node': l1.info['id'], |
| 1055 | 'dev-allow-localhost': None}, |
| 1056 | {'payment-fronting-node': [l1.info['id'], l2.info['id']], |
| 1057 | 'dev-allow-localhost': None}]) |
| 1058 | |
| 1059 | assert l3.rpc.listconfigs('payment-fronting-node') == {'configs': {'payment-fronting-node': {'sources': ['cmdline'], 'values_str': [l1.info['id']]}}} |
| 1060 | assert l4.rpc.listconfigs('payment-fronting-node') == {'configs': {'payment-fronting-node': {'sources': ['cmdline', 'cmdline'], 'values_str': [l1.info['id'], l2.info['id']]}}} |
| 1061 | |
| 1062 | # l1 <----> l3 |
| 1063 | # \ |
| 1064 | # \-----> l4 <----> l2 |
| 1065 | node_factory.join_nodes([l1, l3], wait_for_announce=True) |
| 1066 | node_factory.join_nodes([l1, l4], wait_for_announce=True) |
| 1067 | node_factory.join_nodes([l2, l4], wait_for_announce=True) |
| 1068 | |
| 1069 | l3inv = l3.rpc.invoice(1000, 'l3inv', 'l3inv')['bolt11'] |
| 1070 | assert only_one(only_one(l3.rpc.decode(l3inv)['routes']))['pubkey'] == l1.info['id'] |
| 1071 | |
| 1072 | l4inv = l4.rpc.invoice(1000, 'l4inv', 'l4inv')['bolt11'] |
| 1073 | assert [only_one(r)['pubkey'] for r in l4.rpc.decode(l4inv)['routes']] == [l1.info['id'], l2.info['id']] |
| 1074 | |
| 1075 | l1.rpc.xpay(l3inv) |
| 1076 | l1.rpc.xpay(l4inv) |
| 1077 | |
| 1078 | # Now test offers. |
| 1079 | l3offer = l3.rpc.offer(1000, 'l3offer', 'l3offer')['bolt12'] |
| 1080 | assert only_one(l3.rpc.decode(l3offer)['offer_paths'])['first_node_id'] == l1.info['id'] |
| 1081 | |
| 1082 | l4offer = l4.rpc.offer(1000, 'l4offer', 'l4offer')['bolt12'] |
| 1083 | assert [r['first_node_id'] for r in l4.rpc.decode(l4offer)['offer_paths']] == [l1.info['id'], l2.info['id']] |
| 1084 | |
| 1085 | l3invb12 = l1.rpc.fetchinvoice(l3offer)['invoice'] |
| 1086 | l4invb12 = l1.rpc.fetchinvoice(l4offer)['invoice'] |
| 1087 | |
| 1088 | assert only_one(l3.rpc.decode(l3invb12)['invoice_paths'])['first_node_id'] == l1.info['id'] |
| 1089 | # Given multiple, it will pick one. |
| 1090 | assert only_one(l3.rpc.decode(l4invb12)['invoice_paths'])['first_node_id'] in (l1.info['id'], l2.info['id']) |
| 1091 | |
| 1092 | l1.rpc.xpay(l3invb12) |
| 1093 | l1.rpc.xpay(l4invb12) |
| 1094 | |
| 1095 | # Balance so l3 can pay ->l1->l4. |
| 1096 | l3inv2 = l3.rpc.invoice(10000000, 'l3inv2', 'l3inv2')['bolt11'] |
| 1097 | l1.rpc.xpay(l3inv2) |
| 1098 | |
| 1099 | # When l3 creates an invoice request, it will also use the fronting nodes. |
| 1100 | l3invreq = l3.rpc.invoicerequest(amount=1000, description='l3invreq')['bolt12'] |
| 1101 | assert only_one(l3.rpc.decode(l3invreq)['invreq_paths'])['first_node_id'] == l1.info['id'] |
| 1102 | l4.rpc.sendinvoice(invreq=l3invreq, label='l3invreq') |
| 1103 | |
| 1104 | # We can explicitly override offers: make it use a specific node |
| 1105 | l4offer_front2 = l4.rpc.offer(1000, 'l4offer', 'l4offer', fronting_nodes=[l2.info['id']])['bolt12'] |
| 1106 | assert [r['first_node_id'] for r in l4.rpc.decode(l4offer_front2)['offer_paths']] == [l2.info['id']] |
| 1107 | |
| 1108 | # ... or make it not front at all |
nothing calls this directly
no test coverage detected