This commit is contained in:
Jaremy Creechley 2023-12-22 19:51:25 -07:00
parent 9a3259b8a7
commit 7935c8949c
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
4 changed files with 32 additions and 23 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ out.log
src/circuit_tests/artifacts/* src/circuit_tests/artifacts/*
!src/circuit_tests/artifacts/.keep !src/circuit_tests/artifacts/.keep
codex_storage_proofs codex_storage_proofs
test/tffi

View File

@ -22,6 +22,9 @@ static:
include codex_proofs_ffi include codex_proofs_ffi
proc len*(buff: Buffer): int =
buff.len.int
template unsafeBufferPath*(path: var string): Buffer = template unsafeBufferPath*(path: var string): Buffer =
assert path.len() > 0 assert path.len() > 0
Buffer(data: cast[ptr uint8](path.cstring), Buffer(data: cast[ptr uint8](path.cstring),
@ -33,26 +36,3 @@ template unsafeBufferFromFile*(path: string): Buffer =
Buffer(data: cast[ptr uint8](entireFile.cstring), Buffer(data: cast[ptr uint8](entireFile.cstring),
len: entireFile.len().uint) 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

1
test/config.nims Normal file
View File

@ -0,0 +1 @@
--path:"../"

27
test/tffi.nim Normal file
View File

@ -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