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

Function test_forward

tests/test_pay.py:1154–1216  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1152
1153
1154def test_forward(node_factory, bitcoind):
1155 # Connect 1 -> 2 -> 3.
1156 l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
1157
1158 # If they're at different block heights we can get spurious errors.
1159 sync_blockheight(bitcoind, [l1, l2, l3])
1160
1161 chanid1 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id']
1162 chanid2 = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['short_channel_id']
1163 assert only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['short_channel_id'] == chanid1
1164 assert only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id'] == chanid2
1165
1166 inv = l3.rpc.invoice(100000000, 'testpayment1', 'desc')
1167 rhash = inv['payment_hash']
1168 assert only_one(l3.rpc.listinvoices('testpayment1')['invoices'])['status'] == 'unpaid'
1169
1170 # Fee for node2 is 10 millionths, plus 1.
1171 amt = 100000000
1172 fee = amt * 10 // 1000000 + 1
1173
1174 baseroute = [{'amount_msat': amt + fee,
1175 'id': l2.info['id'],
1176 'delay': 12,
1177 'channel': chanid1},
1178 {'amount_msat': amt,
1179 'id': l3.info['id'],
1180 'delay': 6,
1181 'channel': chanid2}]
1182
1183 # Unknown other peer
1184 route = copy.deepcopy(baseroute)
1185 route[1]['id'] = '031a8dc444e41bb989653a4501e11175a488a57439b0c4947704fd6e3de5dca607'
1186 l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
1187 with pytest.raises(RpcError):
1188 l1.rpc.waitsendpay(rhash)
1189
1190 # Delay too short (we always add one internally anyway, so subtract 2 here).
1191 route = copy.deepcopy(baseroute)
1192 route[0]['delay'] = 8
1193 l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
1194 with pytest.raises(RpcError):
1195 l1.rpc.waitsendpay(rhash)
1196
1197 # Final delay too short
1198 route = copy.deepcopy(baseroute)
1199 route[1]['delay'] = 3
1200 l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
1201 with pytest.raises(RpcError):
1202 l1.rpc.waitsendpay(rhash)
1203
1204 # This one works
1205 route = copy.deepcopy(baseroute)
1206 l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
1207 l1.rpc.waitsendpay(rhash)
1208 wait_for(lambda: only_one(l1.rpc.listpeerchannels()['channels'])['htlcs'] == [])
1209
1210 # Check that invoice payment and fee are tracked appropriately
1211 l1.rpc.bkpr_dumpincomecsv('koinly', 'koinly.csv')

Callers

nothing calls this directly

Calls 10

sync_blockheightFunction · 0.90
only_oneFunction · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
joinMethod · 0.80
invoiceMethod · 0.45
listinvoicesMethod · 0.45

Tested by

no test coverage detected