/* Eduardo: testing route_map. * */ #include "config.h" #include #include #include #include #include #include #include #include #include #include #include #include #define RENEPAY_UNITTEST #include "../flow.c" #include "../route.c" /* AUTOGENERATED MOCKS START */ /* 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(); } /* AUTOGENERATED MOCKS END */ static void destroy_route( struct route *route, struct route_map * map) { printf("calling %s with %s\n", __func__, fmt_routekey(tmpctx,&route->key)); route_map_del(map, route); } static void valgrind_ok1(void) { const char seed[] = "seed"; struct sha256 hash; sha256(&hash,seed,sizeof(seed)); tal_t *this_ctx = tal(tmpctx,tal_t); struct route_map *map = tal(this_ctx, struct route_map); route_map_init(map); { tal_t *local_ctx = tal(this_ctx,tal_t); struct routekey key; struct route *r1 = new_route(local_ctx, 1, 1, hash, AMOUNT_MSAT(0), AMOUNT_MSAT(0)); struct route *r2 = new_route(local_ctx, 2, 3, hash, AMOUNT_MSAT(0), AMOUNT_MSAT(0)); printf("key1 = %s\n", fmt_routekey(local_ctx,&r1->key)); printf("key1 = %s\n", fmt_routekey(local_ctx,&r2->key)); printf("key hash 1 = %zu\n", routekey_hash(&r1->key)); printf("key hash 2 = %zu\n", routekey_hash(&r2->key)); route_map_add(map,r1); tal_add_destructor2(r1, destroy_route, map); route_map_add(map,r2); tal_add_destructor2(r2, destroy_route, map); key = routekey(&hash,1,1); struct route *q1 = route_map_get(map, &key); key = routekey(&hash,2,3); struct route *q2 = route_map_get(map, &key); assert(routekey_hash(&q1->key)==routekey_hash(&r1->key)); assert(routekey_hash(&q2->key)==routekey_hash(&r2->key)); tal_free(local_ctx); } tal_free(this_ctx); } int main(int argc, char *argv[]) { common_setup(argv[0]); valgrind_ok1(); common_shutdown(); }