common/test: fix up name of test file to match latest version.

Otherwise it's skipped!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-01-12 14:24:38 +10:30
parent e9eb5f493b
commit 8e630e7c53

View File

@@ -44,6 +44,18 @@ bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id U
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
#if 0
/* Updated each time, as we pretend to be Alice, Bob, Carol */
static struct secret mykey;
static void test_ecdh(const struct pubkey *point, struct secret *ss)
{
if (secp256k1_ecdh(secp256k1_ctx, ss->data, &point->pubkey,
mykey.data, NULL, NULL) != 1)
abort();
}
#endif
static bool json_to_tok(const char *buffer, const jsmntok_t *tok,
const jsmntok_t **tokp)
{
@@ -64,6 +76,9 @@ int main(int argc, char *argv[])
struct short_channel_id initscid;
struct sphinx_path *sp;
struct secret session_key, *path_secrets;
u32 final_cltv;
struct amount_msat initial_amount, final_amount;
u32 path_fee_base_msat, path_fee_proportional_millionths, path_cltv_delta;
common_setup(argv[0]);
@@ -74,7 +89,7 @@ int main(int argc, char *argv[])
json = grab_file(tmpctx,
path_join(tmpctx,
dir ? dir : "../bolts",
"bolt04/onion-route-blinding-test.json"));
"bolt04/blinded-payment-onion-test.json"));
if (!json) {
printf("test file not found, skipping\n");
goto out;
@@ -87,9 +102,20 @@ int main(int argc, char *argv[])
bpath = tal(tmpctx, struct blinded_path);
assert(json_scan(tmpctx, json, toks, "{generate:{session_key:%,associated_data:%,blinded_route:{introduction_node_id:%,blinding:%,hops:%}}}",
assert(json_scan(tmpctx, json, toks,
"{generate:{session_key:%,"
"associated_data:%,"
"final_amount_msat:%,"
"final_cltv:%,"
"blinded_payinfo:{fee_base_msat:%,fee_proportional_millionths:%,cltv_expiry_delta:%},"
"blinded_route:{introduction_node_id:%,blinding:%,hops:%}}}",
JSON_SCAN(json_to_secret, &session_key),
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &associated_data),
JSON_SCAN(json_to_msat, &final_amount),
JSON_SCAN(json_to_u32, &final_cltv),
JSON_SCAN(json_to_u32, &path_fee_base_msat),
JSON_SCAN(json_to_u32, &path_fee_proportional_millionths),
JSON_SCAN(json_to_u32, &path_cltv_delta),
JSON_SCAN(json_to_pubkey, &bpath->first_node_id),
JSON_SCAN(json_to_pubkey, &bpath->blinding),
JSON_SCAN(json_to_tok, &hops_tok)) == NULL);
@@ -105,19 +131,28 @@ int main(int argc, char *argv[])
&bpath->path[i]->encrypted_recipient_data)) == NULL);
}
/* FIXME: These amounts / scid should be in test vectors! */
onionhops = blinded_onion_hops(tmpctx, AMOUNT_MSAT(200), 700, AMOUNT_MSAT(200), bpath);
assert(mk_short_channel_id(&initscid, 0, 0, 10));
assert(json_scan(tmpctx, json, toks, "{generate:{full_route:{hops:%}}}",
JSON_SCAN(json_to_tok, &hops_tok)) == NULL);
/* Prepend Alice: poor thing doesn't speak blinding! */
/* We have to read scid from first hop contents, since it's made up */
assert(json_scan(tmpctx, json, hops_tok + 1, "{tlvs:{outgoing_channel_id:%}}",
JSON_SCAN(json_to_short_channel_id, &initscid)) == NULL);
initial_amount = final_amount;
assert(amount_msat_add_fee(&initial_amount,
path_fee_base_msat, path_fee_proportional_millionths));
/* FIXME: Test vector actually claims total_amount_msat is 150000msat! */
struct amount_msat total_amount;
assert(amount_msat_add(&total_amount, final_amount, AMOUNT_MSAT(50000)));
onionhops = blinded_onion_hops(tmpctx, final_amount, final_cltv, total_amount, bpath);
/* Prepend Alice: poor thing doesn't speak blinding! (But doesn't charge fees!) */
tal_resize(&onionhops, tal_count(onionhops) + 1);
memmove(onionhops + 1, onionhops,
(tal_count(onionhops) - 1) * sizeof(*onionhops));
onionhops[0] = onion_nonfinal_hop(onionhops, &initscid,
AMOUNT_MSAT(500), 1000);
assert(json_scan(tmpctx, json, toks, "{generate:{full_route:{hops:%}}}",
JSON_SCAN(json_to_tok, &hops_tok)) == NULL);
initial_amount, final_cltv + path_cltv_delta);
ids = tal_arr(tmpctx, struct pubkey, hops_tok->size);
json_for_each_arr(i, t, hops_tok) {
@@ -134,7 +169,7 @@ int main(int argc, char *argv[])
/* Now, create onion! */
sp = sphinx_path_new_with_key(tmpctx, associated_data, &session_key);
for (i = 0; i < tal_count(ids); i++)
sphinx_add_hop(sp, &ids[i], onionhops[i]);
sphinx_add_hop_has_length(sp, &ids[i], onionhops[i]);
onion = serialize_onionpacket(tmpctx,
create_onionpacket(tmpctx, sp, ROUTING_INFO_SIZE,
@@ -147,6 +182,49 @@ int main(int argc, char *argv[])
onion, tal_bytelen(onion)));
/* FIXME: unwrap and test! */
#if 0
struct onionpacket *op;
struct pubkey *blinding;
assert(json_scan(tmpctx, json, toks, "{decrypt:{hops:%}}",
JSON_SCAN(json_to_tok, &hops_tok)) == NULL);
op = parse_onionpacket(tmpctx, expected_onion, tal_bytelen(expected_onion), NULL);
blinding = NULL;
json_for_each_arr(i, t, hops_tok) {
struct route_step *rs;
struct secret ss;
const u8 *serialized;
assert(json_scan(tmpctx, json, t, "{node_privkey:%,onion:%}",
JSON_SCAN(json_to_secret, &mykey),
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &expected_onion))
== NULL);
serialized = serialize_onionpacket(tmpctx, op);
assert(memeq(expected_onion, tal_bytelen(expected_onion),
serialized, tal_bytelen(serialized)));
if (blinding) {
assert(unblind_onion(blinding, test_ecdh,
&op->ephemeralkey, &ss));
} else {
test_ecdh(&op->ephemeralkey, &ss);
}
rs = process_onionpacket(tmpctx, op, &ss, associated_data,
tal_bytelen(associated_data), true);
assert(memeq(rs->raw_payload, tal_bytelen(rs->raw_payload),
onionhops[i], tal_bytelen(onionhops[i])));
if (rs->nextcase == ONION_FORWARD)
op = rs->next;
else
op = NULL;
blinding = tal(tmpctx, struct pubkey);
/* Alice doesn't have a blinding! */
if (json_scan(tmpctx, json, t, "{next_blinding:%}",
JSON_SCAN(json_to_pubkey, blinding)) != NULL)
blinding = NULL;
}
assert(!op);
#endif
out:
common_shutdown();