2023-08-02 07:00:07 +09:30
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <common/wireaddr.h>
|
|
|
|
#include <common/bigsize.h>
|
|
|
|
#include <common/channel_id.h>
|
|
|
|
#include <common/setup.h>
|
|
|
|
#include <common/utils.h>
|
|
|
|
#include <common/node_id.h>
|
|
|
|
#include <ccan/read_write_all/read_write_all.h>
|
2024-03-20 10:59:28 +10:30
|
|
|
#include <wire/onion_wiregen.h>
|
2023-08-02 07:00:07 +09:30
|
|
|
|
2024-04-08 15:50:12 +01:00
|
|
|
#include "../flow.c"
|
2023-08-02 07:00:07 +09:30
|
|
|
#include "../mcf.c"
|
|
|
|
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
2024-07-17 18:35:11 +09:30
|
|
|
/* Generated stub for sciddir_or_pubkey_from_node_id */
|
|
|
|
bool sciddir_or_pubkey_from_node_id(struct sciddir_or_pubkey *sciddpk UNNEEDED,
|
|
|
|
const struct node_id *node_id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "sciddir_or_pubkey_from_node_id called!\n"); abort(); }
|
2023-08-02 07:00:07 +09:30
|
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
bool dual;
|
|
|
|
u32 part;
|
|
|
|
int chandir;
|
|
|
|
u32 chanidx;
|
|
|
|
|
|
|
|
common_setup(argv[0]);
|
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
for (int j = 0; j < 32; j++) {
|
|
|
|
for (int k = 0; k < 32; k++) {
|
|
|
|
struct arc a, a2;
|
|
|
|
|
|
|
|
a.idx = (1U << i) | (1U << j) | (1U << k);
|
|
|
|
arc_to_parts(a, &chanidx, &chandir, &part, &dual);
|
|
|
|
a2 = arc_from_parts(chanidx, chandir, part, dual);
|
|
|
|
assert(a.idx == a2.idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test all chanidx */
|
|
|
|
for (int i = 0; i < (1U << ARC_CHANIDX_BITS); i++) {
|
|
|
|
struct arc a = arc_from_parts(i, chandir, part, dual);
|
|
|
|
|
|
|
|
arc_to_parts(a, &chanidx, NULL, NULL, NULL);
|
|
|
|
assert(chanidx == i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test both chandir */
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
struct arc a = arc_from_parts(chanidx, i, part, dual);
|
|
|
|
|
|
|
|
arc_to_parts(a, NULL, &chandir, NULL, NULL);
|
|
|
|
assert(chandir == i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test all parts */
|
|
|
|
for (int i = 0; i < CHANNEL_PARTS; i++) {
|
|
|
|
struct arc a = arc_from_parts(chanidx, chandir, i, dual);
|
|
|
|
|
|
|
|
arc_to_parts(a, NULL, NULL, &part, NULL);
|
|
|
|
assert(part == i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test both dual */
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
struct arc a = arc_from_parts(chanidx, chandir, part, i);
|
|
|
|
|
|
|
|
arc_to_parts(a, NULL, NULL, NULL, &dual);
|
|
|
|
assert(dual == i);
|
|
|
|
|
|
|
|
assert(arc_is_dual(a) == dual);
|
|
|
|
|
|
|
|
a = arc_dual(a);
|
|
|
|
arc_to_parts(a, NULL, NULL, NULL, &dual);
|
|
|
|
assert(dual == !i);
|
|
|
|
assert(arc_is_dual(a) == dual);
|
|
|
|
}
|
|
|
|
|
|
|
|
common_shutdown();
|
|
|
|
}
|
|
|
|
|