| 3374 | |
| 3375 | |
| 3376 | def test_createonion_limits(node_factory): |
| 3377 | l1, = node_factory.get_nodes(1) |
| 3378 | hops = [{ |
| 3379 | # privkey: 41bfd2660762506c9933ade59f1debf7e6495b10c14a92dbcd2d623da2507d3d |
| 3380 | "pubkey": "0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518", |
| 3381 | "payload": bytes([227] + [0] * 227).hex(), |
| 3382 | }, { |
| 3383 | "pubkey": "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c", |
| 3384 | "payload": bytes([227] + [0] * 227).hex(), |
| 3385 | }, { |
| 3386 | "pubkey": "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007", |
| 3387 | "payload": bytes([227] + [0] * 227).hex(), |
| 3388 | }, { |
| 3389 | "pubkey": "032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991", |
| 3390 | "payload": bytes([227] + [0] * 227).hex(), |
| 3391 | }, { |
| 3392 | "pubkey": "02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145", |
| 3393 | "payload": bytes([227] + [0] * 227).hex(), |
| 3394 | }] |
| 3395 | |
| 3396 | # This should success since it's right at the edge |
| 3397 | l1.rpc.createonion(hops=hops, assocdata="BB" * 32) |
| 3398 | |
| 3399 | # This one should fail however |
| 3400 | with pytest.raises(RpcError, match=r'Payloads exceed maximum onion packet size.'): |
| 3401 | hops[0]['payload'] = bytes([228] + [0] * 228).hex() |
| 3402 | l1.rpc.createonion(hops=hops, assocdata="BB" * 32) |
| 3403 | |
| 3404 | # But with a larger onion, it will work! |
| 3405 | oniontool = os.path.join(os.path.dirname(__file__), "..", "devtools", "onion") |
| 3406 | onion = l1.rpc.createonion(hops=hops, assocdata="BB" * 32, onion_size=1301)['onion'] |
| 3407 | |
| 3408 | # Oniontool wants a filename :( |
| 3409 | onionfile = os.path.join(l1.daemon.lightning_dir, 'onion') |
| 3410 | with open(onionfile, "w") as f: |
| 3411 | f.write(onion) |
| 3412 | |
| 3413 | subprocess.check_output( |
| 3414 | [oniontool, '--assoc-data', "BB" * 32, |
| 3415 | 'decode', onionfile, "41bfd2660762506c9933ade59f1debf7e6495b10c14a92dbcd2d623da2507d3d"] |
| 3416 | ) |
| 3417 | |
| 3418 | |
| 3419 | def test_sendpay_msatoshi_arg(node_factory): |