cleans up testbackendfactory

This commit is contained in:
Ben 2024-08-22 16:00:18 +02:00
parent 571d01c82d
commit 497b86ed8c
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
1 changed files with 5 additions and 54 deletions

View File

@ -1,6 +1,4 @@
import os
import std/strutils
import ../../asynctest
import pkg/chronos
@ -17,10 +15,6 @@ type
argR1csFile: string
argWasmFile: string
argZKeyFile: string
argUrl: string
argFilepath: string
argZipFile: string
argOutputDir: string
method initializeCircomBackend*(
self: BackendUtilsMock,
@ -37,29 +31,6 @@ method initializeCircomBackend*(
vkpPtr: ptr VerifyingKey = key.addr
return CircomCompat(vkp: vkpPtr)
method downloadFile*(
self: BackendUtilsMock,
url: string,
filepath: string
): ?!void =
self.argUrl = url
self.argFilepath = filepath
success()
method unzipFile*(
self: BackendUtilsMock,
zipFile: string,
outputDir: string): ?!void =
self.argZipFile = zipFile
self.argOutputDir = outputDir
try:
writeFile(outputDir / "proof_main.r1cs", "r1cs_file")
writeFile(outputDir / "proof_main.wasm", "wasm_file")
writeFile(outputDir / "proof_main.zkey", "zkey_file")
except Exception as exc:
return failure(exc.msg)
success()
suite "Test BackendFactory":
let
utilsMock = BackendUtilsMock()
@ -83,18 +54,13 @@ suite "Test BackendFactory":
circomWasm: InputFile("tests/circuits/fixtures/proof_main.wasm"),
circomZkey: InputFile("tests/circuits/fixtures/proof_main.zkey")
)
ceremonyHash = string.none
backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet
backend = (await initializeBackend(config, utilsMock)).tryGet
check:
backend.vkp != nil
utilsMock.argR1csFile == $config.circomR1cs
utilsMock.argWasmFile == $config.circomWasm
utilsMock.argZKeyFile == $config.circomZkey
isEmptyOrWhitespace(utilsMock.argUrl)
isEmptyOrWhitespace(utilsMock.argFilepath)
isEmptyOrWhitespace(utilsMock.argZipFile)
isEmptyOrWhitespace(utilsMock.argOutputDir)
test "Should create backend from local files":
let
@ -109,24 +75,16 @@ suite "Test BackendFactory":
# will be picked up as local files:
circuitDir: OutDir("tests/circuits/fixtures")
)
ceremonyHash = string.none
backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet
backend = (await initializeBackend(config, utilsMock)).tryGet
check:
backend.vkp != nil
utilsMock.argR1csFile == config.circuitDir / "proof_main.r1cs"
utilsMock.argWasmFile == config.circuitDir / "proof_main.wasm"
utilsMock.argZKeyFile == config.circuitDir / "proof_main.zkey"
isEmptyOrWhitespace(utilsMock.argUrl)
isEmptyOrWhitespace(utilsMock.argFilepath)
isEmptyOrWhitespace(utilsMock.argZipFile)
isEmptyOrWhitespace(utilsMock.argOutputDir)
test "Should download and unzip ceremony file if not available":
test "Should suggest usage of downloader tool when files not available":
let
ceremonyHash = some "12345"
expectedZip = circuitDir / "circuit.zip"
expectedUrl = "https://circuit.codex.storage/proving-key/" & !ceremonyHash
config = CodexConf(
cmd: StartUpCmd.persistence,
nat: ValidIpAddress.init("127.0.0.1"),
@ -136,14 +94,7 @@ suite "Test BackendFactory":
circuitDir: OutDir(circuitDir)
)
backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet
backendResult = (await initializeBackend(config, utilsMock))
check:
backend.vkp != nil
utilsMock.argR1csFile == config.circuitDir / "proof_main.r1cs"
utilsMock.argWasmFile == config.circuitDir / "proof_main.wasm"
utilsMock.argZKeyFile == config.circuitDir / "proof_main.zkey"
utilsMock.argUrl == expectedUrl
utilsMock.argFilepath == expectedZip
utilsMock.argZipFile == expectedZip
utilsMock.argOutputDir == circuitDir
backendResult.isErr