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

Function test_pay_fakenet

tests/test_xpay.py:24–144  ·  view source on GitHub ↗
(node_factory)

Source from the content-addressed store, hash-verified

22
23
24def test_pay_fakenet(node_factory):
25 hash1 = sha256(bytes.fromhex('00' + '00' * 31)).hexdigest()
26 hash2 = sha256(bytes.fromhex('01' + '00' * 31)).hexdigest()
27 failhash = '00' * 32
28
29 # Create gossip map of channels from l2 (aka nodemap[0])
30 gsfile, nodemap = generate_gossip_store([GenChannel(0, 1, capacity_sats=100_000),
31 GenChannel(1, 2, capacity_sats=100_000),
32 GenChannel(2, 3, capacity_sats=200_000)],
33 nodemap={0: '033845802d25b4e074ccfd7cd8b339a41dc75bf9978a034800444b51d42b07799a'})
34
35 # l2 will warn l1 about its invalid gossip: ignore.
36 l1, l2 = node_factory.line_graph(2,
37 opts=[{'gossip_store_file': gsfile.name,
38 'subdaemon': 'channeld:../tests/plugins/channeld_fakenet',
39 'allow_warning': True}, {}])
40
41 # l1 needs to know l2's shaseed for the channel so it can make revocations
42 hsmfile = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, "hsm_secret")
43 # Needs peer node id and channel dbid (1, it's the first channel), prints out:
44 # "shaseed: xxxxxxx\n"
45 shaseed = subprocess.check_output(["tools/lightning-hsmtool", "dumpcommitments", l1.info['id'], "1", "0", hsmfile]).decode('utf-8').strip().partition(": ")[2]
46 l1.rpc.dev_peer_shachain(l2.info['id'], shaseed)
47
48 # Failure from final (unknown payment hash)
49 l1.rpc.sendpay(route=[{'id': l2.info['id'],
50 'channel': first_scid(l1, l2),
51 'delay': 18 + 6,
52 'amount_msat': 1000001},
53 {'id': nodemap[1],
54 'channel': '0x1x0',
55 'delay': 18,
56 'amount_msat': 100000}],
57 payment_hash=failhash)
58
59 with pytest.raises(RpcError, match="WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS") as err:
60 l1.rpc.waitsendpay(payment_hash=failhash, timeout=TIMEOUT)
61
62 assert err.value.error['data']['erring_node'] == nodemap[1]
63
64 # Success from final (known payment hash)
65 l1.rpc.sendpay(route=[{'id': l2.info['id'],
66 'channel': first_scid(l1, l2),
67 'delay': 18 + 6,
68 'amount_msat': 1000001},
69 {'id': nodemap[1],
70 'channel': '0x1x0',
71 'delay': 18,
72 'amount_msat': 100000}],
73 payment_hash=hash1)
74 l1.rpc.waitsendpay(payment_hash=hash1, timeout=TIMEOUT)
75
76 # Failure from node 2 (unknown scid)
77 l1.rpc.sendpay(route=[{'id': l2.info['id'],
78 'channel': first_scid(l1, l2),
79 'delay': 18 + 6 + 6,
80 'amount_msat': 1000002},
81 {'id': nodemap[1],

Callers

nothing calls this directly

Calls 9

generate_gossip_storeFunction · 0.90
GenChannelClass · 0.90
first_scidFunction · 0.90
line_graphMethod · 0.80
joinMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
sha256Class · 0.50
decodeMethod · 0.45

Tested by

no test coverage detected