-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEzklAppUnitTests.swift
More file actions
107 lines (91 loc) · 4.26 KB
/
EzklAppUnitTests.swift
File metadata and controls
107 lines (91 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import XCTest
import EzklPackage
@testable import EzklApp
final class EzklAppUnitTests: XCTestCase {
var witnessOutput: Data = Data()
var vkData: Data = Data()
var proofOutput: Data = Data()
// Test 1: Test genWitness with valid input
func testGenWitnessWithValidInput() async throws {
// Set up the file paths (assuming correct test files are available in the bundle)
guard let inputPath = Bundle.main.path(forResource: "input", ofType: "json"),
let compiledCircuitPath = Bundle.main.path(forResource: "network", ofType: "ezkl") else {
XCTFail("Required files not found in the bundle")
return
}
// Read the file contents as Data and Strings
let inputData = try Data(contentsOf: URL(fileURLWithPath: inputPath))
let compiledCircuitData = try Data(contentsOf: URL(fileURLWithPath: compiledCircuitPath))
// Run the function with the file contents as arguments
do {
witnessOutput = try genWitness(compiledCircuit: compiledCircuitData, input: inputData)
XCTAssertFalse(witnessOutput.isEmpty, "Witness should be generated")
} catch {
XCTFail("genWitness failed with error: \(error)")
}
}
// Runs prove with valid witness
func proveWithValidWitness() throws {
// Ensure the witness output is available
guard !witnessOutput.isEmpty else {
XCTFail("Witness output is not available from the previous step")
return
}
// Set up the file paths
guard let compiledCircuitPath = Bundle.main.path(forResource: "network", ofType: "ezkl"),
let srsPath = Bundle.main.path(forResource: "kzg", ofType: "srs") else {
XCTFail("Required files not found in the bundle")
return
}
// Read the file contents as Data
let compiledCircuitData = try Data(contentsOf: URL(fileURLWithPath: compiledCircuitPath))
let srsData = try Data(contentsOf: URL(fileURLWithPath: srsPath))
// Generate the VK
do {
vkData = try genVk(compiledCircuit: compiledCircuitData, srs: srsData, compressSelectors: true)
} catch {
XCTFail("prove failed with error: \(error)")
}
guard let pkData = try? genPk(vk: vkData, compiledCircuit: compiledCircuitData, srs: srsData) else {
XCTFail("prove failed: failed to generate the Pk")
return
}
// Run the function with the witness output and file contents
do {
proofOutput = try prove(witness: witnessOutput, pk: pkData, compiledCircuit: compiledCircuitData, srs: srsData)
XCTAssertFalse(proofOutput.isEmpty, "Proof should be generated")
} catch {
XCTFail("prove failed with error: \(error)")
}
}
// Runs verify with valid proof
func verifyWithValidProof() throws {
// Ensure the proof output is available
guard !proofOutput.isEmpty else {
XCTFail("Proof output is not available from the previous step")
return
}
// Set up the file paths
guard let settingsPath = Bundle.main.path(forResource: "settings", ofType: "json"),
let srsPath = Bundle.main.path(forResource: "kzg", ofType: "srs") else {
XCTFail("Required files not found in the bundle")
return
}
// Read the file contents as Data and Strings
let settingsJson = try Data(contentsOf: URL(fileURLWithPath: settingsPath))
let srsData = try Data(contentsOf: URL(fileURLWithPath: srsPath))
// Run the function with the proof output and file contents
do {
let verificationResult = try verify(proof: proofOutput, vk: vkData, settings: settingsJson, srs: srsData)
XCTAssertTrue(verificationResult, "Proof should be verified successfully")
} catch {
XCTFail("verify failed with error: \(error)")
}
}
// End-to-end test that chains all steps together
func testEndToEndProcess() async throws {
try await testGenWitnessWithValidInput()
try proveWithValidWitness()
try verifyWithValidProof()
}
}