From a84d7b5241458276d9a2e7608b000372e94fe0c9 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 22 Dec 2023 19:45:17 -0700 Subject: [PATCH] add example ffi test --- codex_storage_proofs.nim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/codex_storage_proofs.nim b/codex_storage_proofs.nim index fbfa78b..2a4d5d2 100644 --- a/codex_storage_proofs.nim +++ b/codex_storage_proofs.nim @@ -1,7 +1,6 @@ import std/os import std/strutils -import std/sha1 import std/macros const @@ -23,14 +22,23 @@ static: include codex_proofs_ffi -proc unsafeBufferPath*(path: var string): Buffer = +template unsafeBufferPath*(path: var string): Buffer = assert path.len() > 0 - Buffer(data: cast[ptr uint8](path.cstring), len: path.len().uint) + Buffer(data: cast[ptr uint8](path.cstring), + len: path.len().uint) + +template unsafeBufferFromFile*(path: string): Buffer = + assert path.len() > 0 + let entireFile = readFile(path) + + Buffer(data: cast[ptr uint8](entireFile.cstring), + len: entireFile.len().uint) when isMainModule: var r1cs_path = "src/circuit_tests/artifacts/storer-test.r1cs" wasm_path = "src/circuit_tests/artifacts/storer-test_js/storer-test.wasm" + let r1cs_buff = unsafeBufferPath(r1cs_path) wasm_buff = unsafeBufferPath(wasm_path) @@ -40,3 +48,8 @@ when isMainModule: echo "storage_ctx: ", storage_ctx.repr assert storage_ctx != nil + let + mpack_arg_path = "test/proof_test.mpack" + proofArgs = unsafeBufferFromFile(mpack_arg_path) + echo "proofArgs:size: ", proofArgs.len + # prove_mpack_ext()