mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-28 10:13:10 +00:00
refactor: simplify error handling in suggestDownloadTool and enhance test setup for CLI
This commit is contained in:
parent
a38e41da5c
commit
f8f745692c
@ -71,9 +71,7 @@ proc getZkeyFile*(config: CodexConf): ?!string =
|
||||
|
||||
proc suggestDownloadTool(config: CodexConf) =
|
||||
without address =? config.marketplaceAddress:
|
||||
raise (ref Defect)(
|
||||
msg: "Proving backend initializing while marketplace address not set."
|
||||
)
|
||||
raiseAssert("Proving backend initializing while marketplace address not set.")
|
||||
|
||||
let
|
||||
tokens = ["cirdl", "\"" & $config.circuitDir & "\"", config.ethProvider, $address]
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import std/tempfiles
|
||||
import std/appdirs
|
||||
import std/paths
|
||||
import codex/conf
|
||||
import codex/utils/fileutils
|
||||
import ../../asynctest
|
||||
@ -10,51 +12,90 @@ import ../../examples
|
||||
asyncchecksuite "Command line interface":
|
||||
let key = "4242424242424242424242424242424242424242424242424242424242424242"
|
||||
|
||||
var tmpDataDir: string
|
||||
setup:
|
||||
# Ensure the key file is created with safe permissions
|
||||
tmpDataDir = createTempDir(prefix = "testcli_", suffix = "", dir = $getTempDir())
|
||||
|
||||
teardown:
|
||||
# Remove the temporary data directory after tests
|
||||
discard removeDir(tmpDataDir)
|
||||
|
||||
proc startCodex(args: seq[string]): Future[CodexProcess] {.async.} =
|
||||
return await CodexProcess.startNode(args, false, "cli-test-node")
|
||||
var args = args
|
||||
if not args.anyIt(it.contains("--data-dir")):
|
||||
args.add("--data-dir=" & tmpDataDir)
|
||||
|
||||
return await CodexProcess.startNode(args, debug = false, "cli-test-node")
|
||||
|
||||
test "complains when persistence is enabled without ethereum account":
|
||||
let node = await startCodex(@["persistence"])
|
||||
|
||||
defer:
|
||||
await node.stop()
|
||||
|
||||
await node.waitUntilOutput("Persistence enabled, but no Ethereum account was set")
|
||||
await node.stop()
|
||||
|
||||
test "complains when ethereum private key file has wrong permissions":
|
||||
let unsafeKeyFile = genTempPath("", "")
|
||||
discard unsafeKeyFile.writeFile(key, 0o666)
|
||||
let node = await startCodex(@["persistence", "--eth-private-key=" & unsafeKeyFile])
|
||||
|
||||
defer:
|
||||
await node.stop()
|
||||
discard removeFile(unsafeKeyFile)
|
||||
|
||||
await node.waitUntilOutput(
|
||||
"Ethereum private key file does not have safe file permissions"
|
||||
)
|
||||
await node.stop()
|
||||
discard removeFile(unsafeKeyFile)
|
||||
|
||||
let
|
||||
marketplaceArg = "--marketplace-address=" & $EthAddress.example
|
||||
expectedDownloadInstruction =
|
||||
"Proving circuit files are not found. Please run the following to download them:"
|
||||
let expectedDownloadInstruction =
|
||||
"Proving circuit files are not found. Please run the following to download them:"
|
||||
|
||||
test "suggests downloading of circuit files when persistence is enabled without accessible r1cs file":
|
||||
let node = await startCodex(@["persistence", "prover", marketplaceArg])
|
||||
await node.waitUntilOutput(expectedDownloadInstruction)
|
||||
await node.stop()
|
||||
|
||||
test "suggests downloading of circuit files when persistence is enabled without accessible wasm file":
|
||||
let node = await startCodex(
|
||||
@[
|
||||
"persistence", "prover", marketplaceArg,
|
||||
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
||||
"persistence",
|
||||
"prover",
|
||||
"--marketplace-address=" & $EthAddress.example,
|
||||
"--prover-backend=nimgroth16",
|
||||
]
|
||||
)
|
||||
|
||||
defer:
|
||||
await node.stop()
|
||||
|
||||
await node.waitUntilOutput(expectedDownloadInstruction)
|
||||
await node.stop()
|
||||
|
||||
test "suggests downloading of circuit files when persistence is enabled without accessible zkey file":
|
||||
let node = await startCodex(
|
||||
@[
|
||||
"persistence", "prover", marketplaceArg,
|
||||
"persistence",
|
||||
"prover",
|
||||
"--marketplace-address=" & $EthAddress.example,
|
||||
"--prover-backend=nimgroth16",
|
||||
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
||||
"--circom-wasm=tests/circuits/fixtures/proof_main.wasm",
|
||||
]
|
||||
)
|
||||
|
||||
defer:
|
||||
await node.stop()
|
||||
|
||||
await node.waitUntilOutput(expectedDownloadInstruction)
|
||||
|
||||
test "suggests downloading of circuit files when persistence is enabled without accessible graph file":
|
||||
let node = await startCodex(
|
||||
@[
|
||||
"persistence",
|
||||
"prover",
|
||||
"--marketplace-address=" & $EthAddress.example,
|
||||
"--prover-backend=nimgroth16",
|
||||
"--circom-r1cs=tests/circuits/fixtures/proof_main.r1cs",
|
||||
"--circom-zkey=tests/circuits/fixtures/proof_main.zkey",
|
||||
]
|
||||
)
|
||||
|
||||
defer:
|
||||
await node.stop()
|
||||
|
||||
await node.waitUntilOutput(expectedDownloadInstruction)
|
||||
await node.stop()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user