Skip to content

Commit ca1f429

Browse files
committed
bindings: fix gate vector unit test notation
1 parent ce58b3f commit ca1f429

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/bindings/crypto/bindings/gate-vector-napi.unit-test.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import type { Field, Gate, Wire } from './kimchi-types.js';
66
const require = createRequire(import.meta.url);
77

88
function loadNative() {
9+
const slug = `${process.platform}-${process.arch}`;
910
const candidates = [
10-
'../../compiled/_node_bindings/plonk_napi.node',
11+
`../../../../../native/${slug}/plonk_napi.node`,
1112
'../../compiled/node_bindings/plonk_napi.node',
13+
'../../compiled/_node_bindings/plonk_napi.node',
1214
];
1315
for (const path of candidates) {
1416
try {
@@ -23,6 +25,21 @@ function loadNative() {
2325

2426
const native: any = loadNative();
2527

28+
const gateVectorCreate =
29+
native.caml_pasta_fp_plonk_gate_vector_create ?? native.camlPastaFpPlonkGateVectorCreate;
30+
const gateVectorLen =
31+
native.caml_pasta_fp_plonk_gate_vector_len ?? native.camlPastaFpPlonkGateVectorLen;
32+
const gateVectorAdd =
33+
native.caml_pasta_fp_plonk_gate_vector_add ?? native.camlPastaFpPlonkGateVectorAdd;
34+
const gateVectorGet =
35+
native.caml_pasta_fp_plonk_gate_vector_get ?? native.camlPastaFpPlonkGateVectorGet;
36+
const gateVectorWrap =
37+
native.caml_pasta_fp_plonk_gate_vector_wrap ?? native.camlPastaFpPlonkGateVectorWrap;
38+
const gateVectorDigest =
39+
native.caml_pasta_fp_plonk_gate_vector_digest ?? native.camlPastaFpPlonkGateVectorDigest;
40+
const circuitSerialize =
41+
native.caml_pasta_fp_plonk_circuit_serialize ?? native.camlPastaFpPlonkCircuitSerialize;
42+
2643
const { fp } = napiConversionCore(native);
2744

2845
const zeroField: Field = [0, 0n];
@@ -44,24 +61,24 @@ const sampleGate: Gate = [
4461
[0, zeroField, zeroField, zeroField, zeroField, zeroField, zeroField, zeroField],
4562
];
4663

47-
const vector = native.camlPastaFpPlonkGateVectorCreate();
48-
expect(native.camlPastaFpPlonkGateVectorLen(vector)).toBe(0);
64+
const vector = gateVectorCreate();
65+
expect(gateVectorLen(vector)).toBe(0);
4966

50-
native.camlPastaFpPlonkGateVectorAdd(vector, fp.gateToRust(sampleGate));
51-
expect(native.camlPastaFpPlonkGateVectorLen(vector)).toBe(1);
67+
gateVectorAdd(vector, fp.gateToRust(sampleGate));
68+
expect(gateVectorLen(vector)).toBe(1);
5269

53-
const gate0 = native.camlPastaFpPlonkGateVectorGet(vector, 0);
70+
const gate0 = gateVectorGet(vector, 0);
5471
expect(gate0.typ).toBe(sampleGate[1]);
5572

5673
const rustTarget = fp.wireToRust(mlWire(0, 0));
5774
const rustHead = fp.wireToRust(mlWire(1, 2));
58-
native.camlPastaFpPlonkGateVectorWrap(vector, rustTarget, rustHead);
59-
const wrapped = native.camlPastaFpPlonkGateVectorGet(vector, 0);
75+
gateVectorWrap(vector, rustTarget, rustHead);
76+
const wrapped = gateVectorGet(vector, 0);
6077
expect(wrapped.wires.w0).toEqual({ row: 1, col: 2 });
6178

62-
native.camlPastaFpPlonkGateVectorDigest(0, vector);
63-
native.camlPastaFpPlonkCircuitSerialize(0, vector);
79+
gateVectorDigest(0, vector);
80+
circuitSerialize(0, vector);
6481

65-
console.log('{}', native.camlPastaFpPlonkGateVectorDigest(0, vector));
82+
console.log('{}', gateVectorDigest(0, vector));
6683

6784
console.log('gate vector napi bindings (fp) are working ✔️');

0 commit comments

Comments
 (0)