From 7935c8949c1de74a934a16075b8bb6686aeb46dc Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 22 Dec 2023 19:51:25 -0700 Subject: [PATCH] updates --- .gitignore | 1 + codex_storage_proofs.nim | 26 +++----------------------- test/config.nims | 1 + test/tffi.nim | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 test/config.nims create mode 100644 test/tffi.nim diff --git a/.gitignore b/.gitignore index 5958c14..f84d256 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ out.log src/circuit_tests/artifacts/* !src/circuit_tests/artifacts/.keep codex_storage_proofs +test/tffi diff --git a/codex_storage_proofs.nim b/codex_storage_proofs.nim index 5660e96..139ec5a 100644 --- a/codex_storage_proofs.nim +++ b/codex_storage_proofs.nim @@ -22,6 +22,9 @@ static: include codex_proofs_ffi +proc len*(buff: Buffer): int = + buff.len.int + template unsafeBufferPath*(path: var string): Buffer = assert path.len() > 0 Buffer(data: cast[ptr uint8](path.cstring), @@ -33,26 +36,3 @@ template unsafeBufferFromFile*(path: string): Buffer = 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) - - let storage_ctx = init_storage_proofs(r1cs_buff, wasm_buff, nil) - - echo "storage_ctx: ", storage_ctx.repr - assert storage_ctx != nil - - var - mpack_arg_path = "test/proof_test.mpack" - proofBuff = unsafeBufferFromFile(mpack_arg_path) - echo "proofArgs:size: ", proofBuff.len - let res = prove_mpack_ext(storage_ctx, addr proofBuff) - - echo "result: ", res.repr - diff --git a/test/config.nims b/test/config.nims new file mode 100644 index 0000000..28cc8e2 --- /dev/null +++ b/test/config.nims @@ -0,0 +1 @@ +--path:"../" \ No newline at end of file diff --git a/test/tffi.nim b/test/tffi.nim new file mode 100644 index 0000000..3ff7e74 --- /dev/null +++ b/test/tffi.nim @@ -0,0 +1,27 @@ + +import unittest2 +import codex_storage_proofs + +suite "storage proofs ffi": + test "basic ffi circuit": + 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) + + let storage_ctx = init_storage_proofs(r1cs_buff, wasm_buff, nil) + + echo "storage_ctx: ", storage_ctx.repr + check storage_ctx != nil + + var + mpack_arg_path = "test/proof_test.mpack" + proofBuff = unsafeBufferFromFile(mpack_arg_path) + echo "proofArgs:size: ", proofBuff.len() + let res = prove_mpack_ext(storage_ctx, addr proofBuff) + + echo "result: ", res.repr + check res != nil