From 8daf9b2577e47b9bf448023093214e512845c654 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 7 Nov 2019 19:16:01 +0100 Subject: [PATCH] pytest: Add a test for `createonion` --- tests/test_pay.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_pay.py b/tests/test_pay.py index 8a5517893..91be945c7 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -2441,3 +2441,36 @@ def test_shadow_routing(node_factory): assert total_amount.millisatoshis < (n_payments * amount) * (1 + 0.01) # FIXME: Test cltv delta too ? + + +def test_createonion_rpc(node_factory): + l1 = node_factory.get_node() + + hops = [{ + "type": "legacy", + "pubkey": "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619", + "payload": "0000000000000000000000000000000000000000" + }, { + "pubkey": "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c", + "payload": "0101010101010101000000000000000100000001" + }, { + "pubkey": "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007", + "payload": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" + }, { + "pubkey": "032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991", + "payload": "0303030303030303000000000000000300000003" + }, { + "type": "legacy", + "pubkey": "02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145", + "payload": "0404040404040404000000000000000400000004" + }] + + res = l1.rpc.createonion(hops=hops, assocdata="BB" * 32) + assert(len(res['onion']) == 2 * 1366) + assert(len(res['shared_secrets']) == len(hops)) + + res = l1.rpc.createonion(hops=hops, assocdata="42" * 32, + session_key="41" * 32) + # The trailer is generated using the filler and can be ued as a + # checksum. This trailer is from the test-vector in the specs. + assert(res['onion'].endswith('be89e4701eb870f8ed64fafa446c78df3ea'))