-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathend_to_end.test.ts
69 lines (62 loc) · 2.1 KB
/
end_to_end.test.ts
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
import { Votes, VotesProgram, VotesProof } from './example_packed_uint_circuit';
import {
TextInput,
TextInputProgram,
TextInputProof,
} from './example_packed_string_circuit';
import { Character } from 'o1js';
describe('End to End Votes Test', () => {
const init = [0n, 0n];
const initVotes = Votes.fromBigInts(init);
let initProof: VotesProof;
beforeAll(async () => {
await VotesProgram.compile();
initProof = (await VotesProgram.init(initVotes)).proof;
initProof.verify();
});
describe('Incrementing votes', () => {
it('Increments the 0th index', async () => {
const unpackedVotes = [1n, 0n];
const proofVotes = Votes.fromBigInts(unpackedVotes);
const proof = (await VotesProgram.incrementIndex0(proofVotes, initProof))
.proof;
proof.verify();
proofVotes.packed.assertEquals(proof.publicInput.packed);
});
// Temporarily skipping, the proof does not verify, but the behavior does not match #toThrow
it.skip('throws when verifying an invalid proof', async () => {
const unpackedVotes = [1n, 0n];
const proofVotes = Votes.fromBigInts(unpackedVotes);
const proof = (await VotesProgram.incrementIndex1(proofVotes, initProof))
.proof;
expect(() => {
proof.verify();
}).toThrow();
});
});
});
describe('End to End Text Input Test', () => {
const init = 'Mina Protocol';
const initTextInput = TextInput.fromString(init);
let initProof: TextInputProof;
beforeAll(async () => {
await TextInputProgram.compile();
initProof = (await TextInputProgram.init(initTextInput)).proof;
initProof.verify();
});
describe('Adding Input', () => {
it('adds input', async () => {
let unpackedTextInput = 'Zina Protocol';
let proofTextInput = TextInput.fromString(unpackedTextInput);
const p1 = (
await TextInputProgram.changeFirstLetter(
proofTextInput,
initProof,
TextInput.unpack(initProof.publicInput.packed),
Character.fromString('Z')
)
).proof;
proofTextInput.assertEquals(p1.publicInput);
});
});
});