11import std/ tempfiles
2+ import std/ appdirs
3+ import std/ paths
24import codex/ conf
35import codex/ utils/ fileutils
46import ../ asynctest
@@ -10,51 +12,90 @@ import ../examples
1012asyncchecksuite " Command line interface" :
1113 let key = " 4242424242424242424242424242424242424242424242424242424242424242"
1214
15+ var tmpDataDir: string
16+ setup:
17+ # Ensure the key file is created with safe permissions
18+ tmpDataDir = createTempDir (prefix = " testcli_" , suffix = " " , dir = $ getTempDir ())
19+
20+ teardown:
21+ # Remove the temporary data directory after tests
22+ discard removeDir (tmpDataDir)
23+
1324 proc startCodex (args: seq [string ]): Future [CodexProcess ] {.async .} =
14- return await CodexProcess .startNode (args, false , " cli-test-node" )
25+ var args = args
26+ if not args.anyIt (it.contains (" --data-dir" )):
27+ args.add (" --data-dir=" & tmpDataDir)
28+
29+ return await CodexProcess .startNode (args, debug = false , " cli-test-node" )
1530
1631 test " complains when persistence is enabled without ethereum account" :
1732 let node = await startCodex (@ [" persistence" ])
33+
34+ defer :
35+ await node.stop ()
36+
1837 await node.waitUntilOutput (" Persistence enabled, but no Ethereum account was set" )
19- await node.stop ()
2038
2139 test " complains when ethereum private key file has wrong permissions" :
2240 let unsafeKeyFile = genTempPath (" " , " " )
2341 discard unsafeKeyFile.writeFile (key, 0o 666 )
2442 let node = await startCodex (@ [" persistence" , " --eth-private-key=" & unsafeKeyFile])
43+
44+ defer :
45+ await node.stop ()
46+ discard removeFile (unsafeKeyFile)
47+
2548 await node.waitUntilOutput (
2649 " Ethereum private key file does not have safe file permissions"
2750 )
28- await node.stop ()
29- discard removeFile (unsafeKeyFile)
3051
31- let
32- marketplaceArg = " --marketplace-address=" & $ EthAddress .example
33- expectedDownloadInstruction =
34- " Proving circuit files are not found. Please run the following to download them:"
52+ let expectedDownloadInstruction =
53+ " Proving circuit files are not found. Please run the following to download them:"
3554
3655 test " suggests downloading of circuit files when persistence is enabled without accessible r1cs file" :
37- let node = await startCodex (@ [" persistence" , " prover" , marketplaceArg])
56+ let node = await startCodex (
57+ @ [
58+ " persistence" ,
59+ " prover" ,
60+ " --marketplace-address=" & $ EthAddress .example,
61+ " --prover-backend=nimgroth16" ,
62+ ]
63+ )
64+
65+ defer :
66+ await node.stop ()
67+
3868 await node.waitUntilOutput (expectedDownloadInstruction)
39- await node.stop ()
4069
41- test " suggests downloading of circuit files when persistence is enabled without accessible wasm file" :
70+ test " suggests downloading of circuit files when persistence is enabled without accessible zkey file" :
4271 let node = await startCodex (
4372 @ [
44- " persistence" , " prover" , marketplaceArg,
73+ " persistence" ,
74+ " prover" ,
75+ " --marketplace-address=" & $ EthAddress .example,
76+ " --prover-backend=nimgroth16" ,
4577 " --circom-r1cs=tests/circuits/fixtures/proof_main.r1cs" ,
4678 ]
4779 )
80+
81+ defer :
82+ await node.stop ()
83+
4884 await node.waitUntilOutput (expectedDownloadInstruction)
49- await node.stop ()
5085
51- test " suggests downloading of circuit files when persistence is enabled without accessible zkey file" :
86+ test " suggests downloading of circuit files when persistence is enabled without accessible graph file" :
5287 let node = await startCodex (
5388 @ [
54- " persistence" , " prover" , marketplaceArg,
89+ " persistence" ,
90+ " prover" ,
91+ " --marketplace-address=" & $ EthAddress .example,
92+ " --prover-backend=nimgroth16" ,
5593 " --circom-r1cs=tests/circuits/fixtures/proof_main.r1cs" ,
56- " --circom-wasm =tests/circuits/fixtures/proof_main.wasm " ,
94+ " --circom-zkey =tests/circuits/fixtures/proof_main.zkey " ,
5795 ]
5896 )
97+
98+ defer :
99+ await node.stop ()
100+
59101 await node.waitUntilOutput (expectedDownloadInstruction)
60- await node.stop ()
0 commit comments