Skip to content

Commit ecb88c2

Browse files
authored
Refactor whitespace and improve test clarity in generate-proof.test.ts (#92)
- Removed unnecessary whitespace for cleaner code formatting. - Updated transaction receipt retrieval methods for contract deployments to use waitForTransactionReceipt. - Enhanced logging for better visibility during test execution. - Ensured consistent formatting and readability throughout the test file.
1 parent 4a17bb5 commit ecb88c2

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

solidity-example/js/generate-proof.test.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,42 +51,42 @@ process.on('uncaughtException', (error) => {
5151
});
5252

5353
describe("Noir Solidity Example with Ethereum Integration", () => {
54-
54+
5555
before(async () => {
5656
console.log("Starting Anvil...");
57-
57+
5858
// Start Anvil with higher gas limits
5959
anvilProcess = spawn('anvil', [
60-
'--port', '8545',
60+
'--port', '8545',
6161
'--host', '0.0.0.0',
6262
'--gas-limit', '50000000',
6363
'--code-size-limit', '50000000',
6464
'--disable-default-create2-deployer'
6565
], {
6666
stdio: ['ignore', 'pipe', 'pipe']
6767
});
68-
68+
6969
// Wait for Anvil to start with timeout
7070
await new Promise((resolve, reject) => {
7171
const timeout = setTimeout(() => {
7272
reject(new Error('Anvil startup timeout'));
7373
}, 15000);
74-
74+
7575
anvilProcess!.stdout!.on('data', (data) => {
7676
if (data.toString().includes('Listening on')) {
7777
clearTimeout(timeout);
7878
resolve(void 0);
7979
}
8080
});
81-
81+
8282
anvilProcess!.stderr!.on('data', (data) => {
8383
console.error('Anvil error:', data.toString());
8484
});
8585
});
86-
86+
8787
// Wait longer for Anvil to be fully ready
8888
await new Promise(resolve => setTimeout(resolve, 3000));
89-
89+
9090
// Setup viem clients
9191
account = privateKeyToAccount(PRIVATE_KEY);
9292

@@ -100,32 +100,32 @@ describe("Noir Solidity Example with Ethereum Integration", () => {
100100
chain: foundry,
101101
transport: http('http://127.0.0.1:8545')
102102
});
103-
103+
104104
console.log("Anvil started successfully");
105105
});
106-
106+
107107
after(async () => {
108108
console.log("Cleaning up...");
109-
109+
110110
if (anvilProcess) {
111111
console.log("Stopping Anvil...");
112-
112+
113113
try {
114114
// Send SIGTERM first for graceful shutdown
115115
anvilProcess.kill('SIGTERM');
116-
116+
117117
// Wait for process to exit gracefully
118118
await new Promise((resolve) => {
119119
const cleanup = () => {
120120
console.log("Anvil stopped");
121121
anvilProcess = null;
122122
resolve(void 0);
123123
};
124-
124+
125125
// Listen for exit events
126126
anvilProcess!.on('exit', cleanup);
127127
anvilProcess!.on('close', cleanup);
128-
128+
129129
// Force kill after 2 seconds if it doesn't exit gracefully
130130
setTimeout(() => {
131131
if (anvilProcess && !anvilProcess.killed) {
@@ -144,49 +144,49 @@ describe("Noir Solidity Example with Ethereum Integration", () => {
144144
anvilProcess = null;
145145
}
146146
}
147-
147+
148148
// Force exit after cleanup to prevent hanging
149149
console.log("Tests completed, forcing exit...");
150150
setTimeout(() => {
151151
process.exit(0);
152152
}, 100);
153153
});
154-
154+
155155
test("should deploy contracts", async () => {
156156
console.log("Deploying Verifier contract...");
157-
157+
158158
// Deploy Verifier
159159
const verifierHash = await walletClient.deployContract({
160160
abi: VerifierArtifact.abi,
161161
bytecode: VerifierArtifact.bytecode.object as `0x${string}`,
162162
args: [],
163163
});
164-
165-
const verifierReceipt = await publicClient.getTransactionReceipt({ hash: verifierHash });
164+
165+
const verifierReceipt = await publicClient.waitForTransactionReceipt({ hash: verifierHash });
166166
verifierAddress = verifierReceipt.contractAddress!;
167167
console.log(`Verifier deployed at: ${verifierAddress}`);
168-
168+
169169
console.log("Deploying Starter contract...");
170-
170+
171171
// Deploy Starter with Verifier address
172172
const starterHash = await walletClient.deployContract({
173173
abi: StarterArtifact.abi,
174174
bytecode: StarterArtifact.bytecode.object as `0x${string}`,
175175
args: [verifierAddress],
176176
});
177-
178-
const starterReceipt = await publicClient.getTransactionReceipt({ hash: starterHash });
177+
178+
const starterReceipt = await publicClient.waitForTransactionReceipt({ hash: starterHash });
179179
starterAddress = starterReceipt.contractAddress!;
180180
console.log(`Starter deployed at: ${starterAddress}`);
181-
181+
182182
// Verify deployment
183183
assert.ok(verifierAddress, "Verifier should be deployed");
184184
assert.ok(starterAddress, "Starter should be deployed");
185185
});
186186

187187
test("should submit proof transaction to blockchain and verify", async () => {
188188
assert.ok(starterAddress, "Starter contract must be deployed first");
189-
189+
190190
console.log("Generating proof...");
191191
const noir = new Noir(circuit as any);
192192
const honk = new UltraHonkBackend(circuit.bytecode, { threads: 1 });
@@ -195,53 +195,53 @@ describe("Noir Solidity Example with Ethereum Integration", () => {
195195
const inputs = { x: 3, y: 3 };
196196
const { witness } = await noir.execute(inputs);
197197
const { proof, publicInputs } = await honk.generateProof(witness, { keccak: true });
198-
198+
199199
console.log("Proof generated successfully");
200200
console.log(`Public inputs: ${publicInputs}`);
201-
201+
202202
// Check initial verified count
203203
const initialCount = await publicClient.readContract({
204204
address: starterAddress,
205205
abi: StarterArtifact.abi,
206206
functionName: 'getVerifiedCount',
207207
});
208208
console.log(`Initial verified count: ${initialCount}`);
209-
209+
210210
// Format public inputs as bytes32 array
211211
const formattedPublicInputs = publicInputs.map((input: string) => {
212212
// Convert to hex string and pad to 32 bytes
213213
const hex = BigInt(input).toString(16).padStart(64, '0');
214214
return `0x${hex}` as `0x${string}`;
215215
});
216-
216+
217217
console.log("Submitting proof verification transaction...");
218-
218+
219219
// Submit verification transaction
220220
const hash = await walletClient.writeContract({
221221
address: starterAddress,
222222
abi: StarterArtifact.abi,
223223
functionName: 'verifyEqual',
224224
args: [`0x${Buffer.from(proof).toString('hex')}` as `0x${string}`, formattedPublicInputs],
225225
});
226-
226+
227227
console.log(`Transaction hash: ${hash}`);
228-
228+
229229
// Wait for transaction confirmation
230230
const receipt = await publicClient.waitForTransactionReceipt({ hash });
231231
console.log(`Transaction confirmed in block: ${receipt.blockNumber}`);
232-
232+
233233
// Verify transaction was successful
234234
assert.equal(receipt.status, 'success', "Transaction should be successful");
235-
235+
236236
// Check that verified count increased
237237
const finalCount = await publicClient.readContract({
238238
address: starterAddress,
239239
abi: StarterArtifact.abi,
240240
functionName: 'getVerifiedCount',
241241
});
242242
console.log(`Final verified count: ${finalCount}`);
243-
243+
244244
assert.equal(finalCount, initialCount + 1n, "Verified count should increase by 1");
245245
});
246-
246+
247247
});

0 commit comments

Comments
 (0)