We don't need SHA verification or Merkle dags in our transport bundle. Content stores can handle both bundle and term verification and hashing.
61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include "../include/arboricx.h"
|
|
|
|
static uint8_t *read_file(const char *path, size_t *out_len) {
|
|
FILE *f = fopen(path, "rb");
|
|
if (!f) return NULL;
|
|
fseek(f, 0, SEEK_END);
|
|
*out_len = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
uint8_t *buf = malloc(*out_len);
|
|
fread(buf, 1, *out_len, f);
|
|
fclose(f);
|
|
return buf;
|
|
}
|
|
|
|
int test_bundle(arb_ctx_t *ctx, const char *path, const char *name, int expect_val) {
|
|
size_t bundle_len;
|
|
uint8_t *bundle = read_file(path, &bundle_len);
|
|
if (!bundle) { printf("bundle not found: %s\n", path); return 1; }
|
|
|
|
uint32_t term = arb_load_bundle(ctx, bundle, bundle_len, name);
|
|
if (term == 0) {
|
|
printf("load_bundle failed for %s\n", path);
|
|
free(bundle);
|
|
return 1;
|
|
}
|
|
|
|
uint32_t result = arb_reduce(ctx, term, 1000000000ULL);
|
|
|
|
int b;
|
|
if (!arb_to_bool(ctx, result, &b)) {
|
|
printf("to_bool failed for %s\n", path);
|
|
free(bundle);
|
|
return 1;
|
|
}
|
|
printf("%s result bool=%d (expected %d)\n", path, b, expect_val);
|
|
if (b != expect_val) {
|
|
printf("MISMATCH!\n");
|
|
free(bundle);
|
|
return 1;
|
|
}
|
|
|
|
free(bundle);
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
arb_ctx_t *ctx = arboricx_init();
|
|
if (!ctx) { printf("init failed\n"); return 1; }
|
|
|
|
if (test_bundle(ctx, "../../test/fixtures/true.arboricx", "true", 1) != 0) return 1;
|
|
if (test_bundle(ctx, "../../test/fixtures/false.arboricx", "false", 0) != 0) return 1;
|
|
|
|
arboricx_free(ctx);
|
|
printf("All bool tests passed.\n");
|
|
return 0;
|
|
}
|