Skip to content

Commit f844a41

Browse files
committed
Fix and add tests for Elgamal
1 parent 850e73d commit f844a41

File tree

8 files changed

+364
-313
lines changed

8 files changed

+364
-313
lines changed

.prettierrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"semi": true,
3-
"singleQuote": true,
4-
"tabWidth": 2,
5-
"trailingComma": "es5"
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 4,
5+
"trailingComma": "es5"
66
}

package.json

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
11
{
2-
"name": "dkg-libs",
3-
"version": "0.1.0",
4-
"description": "",
5-
"author": "",
6-
"license": "Apache-2.0",
7-
"keywords": [
8-
"mina-zkapp",
9-
"mina-zk-app",
10-
"mina-dapp",
11-
"zkapp"
12-
],
13-
"type": "module",
14-
"main": "build/src/index.js",
15-
"types": "build/src/index.d.ts",
16-
"scripts": {
17-
"build": "tsc",
18-
"buildw": "tsc --watch",
19-
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
20-
"format": "prettier --write --ignore-unknown **/*",
21-
"prepare": "husky install",
22-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
23-
"testw": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
24-
"lint": "npx eslint src/* --fix"
25-
},
26-
"lint-staged": {
27-
"**/*": [
28-
"eslint src/* --fix",
29-
"prettier --write --ignore-unknown"
30-
]
31-
},
32-
"devDependencies": {
33-
"@babel/preset-env": "^7.16.4",
34-
"@babel/preset-typescript": "^7.16.0",
35-
"@types/jest": "^27.0.3",
36-
"@typescript-eslint/eslint-plugin": "^5.5.0",
37-
"@typescript-eslint/parser": "^5.5.0",
38-
"eslint": "^8.7.0",
39-
"eslint-plugin-o1js": "^0.4.0",
40-
"husky": "^7.0.1",
41-
"jest": "^27.3.1",
42-
"lint-staged": "^11.0.1",
43-
"prettier": "^2.3.2",
44-
"ts-jest": "^27.0.7",
45-
"typescript": "^4.7.2"
46-
},
47-
"peerDependencies": {
48-
"o1js": "0.13.*"
49-
}
2+
"name": "dkg-libs",
3+
"version": "0.1.0",
4+
"description": "",
5+
"author": "",
6+
"license": "Apache-2.0",
7+
"keywords": [
8+
"mina-zkapp",
9+
"mina-zk-app",
10+
"mina-dapp",
11+
"zkapp"
12+
],
13+
"type": "module",
14+
"main": "build/src/index.js",
15+
"types": "build/src/index.d.ts",
16+
"scripts": {
17+
"build": "tsc",
18+
"buildw": "tsc --watch",
19+
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
20+
"format": "prettier --write --ignore-unknown **/*",
21+
"prepare": "husky install",
22+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
23+
"testw": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch",
24+
"lint": "npx eslint src/* --fix"
25+
},
26+
"lint-staged": {
27+
"**/*": [
28+
"eslint src/* --fix",
29+
"prettier --write --ignore-unknown"
30+
]
31+
},
32+
"devDependencies": {
33+
"@babel/preset-env": "^7.16.4",
34+
"@babel/preset-typescript": "^7.16.0",
35+
"@types/jest": "^27.0.3",
36+
"@typescript-eslint/eslint-plugin": "^5.5.0",
37+
"@typescript-eslint/parser": "^5.5.0",
38+
"eslint": "^8.7.0",
39+
"eslint-plugin-o1js": "^0.4.0",
40+
"husky": "^7.0.1",
41+
"jest": "^27.3.1",
42+
"lint-staged": "^11.0.1",
43+
"prettier": "^2.3.2",
44+
"ts-jest": "^27.0.7",
45+
"typescript": "^4.7.2"
46+
},
47+
"peerDependencies": {
48+
"o1js": "0.13.*"
49+
},
50+
"dependencies": {
51+
"big-integer": "^1.6.51",
52+
"o1js": "^0.13.1"
53+
}
5054
}

src/Add.test.ts

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,57 @@ import { Field, Mina, PrivateKey, PublicKey, AccountUpdate } from 'o1js';
1111
let proofsEnabled = false;
1212

1313
describe('Add', () => {
14-
let deployerAccount: PublicKey,
15-
deployerKey: PrivateKey,
16-
senderAccount: PublicKey,
17-
senderKey: PrivateKey,
18-
zkAppAddress: PublicKey,
19-
zkAppPrivateKey: PrivateKey,
20-
zkApp: Add;
14+
let deployerAccount: PublicKey,
15+
deployerKey: PrivateKey,
16+
senderAccount: PublicKey,
17+
senderKey: PrivateKey,
18+
zkAppAddress: PublicKey,
19+
zkAppPrivateKey: PrivateKey,
20+
zkApp: Add;
2121

22-
beforeAll(async () => {
23-
if (proofsEnabled) await Add.compile();
24-
});
22+
beforeAll(async () => {
23+
if (proofsEnabled) await Add.compile();
24+
});
25+
26+
beforeEach(() => {
27+
const Local = Mina.LocalBlockchain({ proofsEnabled });
28+
Mina.setActiveInstance(Local);
29+
({ privateKey: deployerKey, publicKey: deployerAccount } =
30+
Local.testAccounts[0]);
31+
({ privateKey: senderKey, publicKey: senderAccount } =
32+
Local.testAccounts[1]);
33+
zkAppPrivateKey = PrivateKey.random();
34+
zkAppAddress = zkAppPrivateKey.toPublicKey();
35+
zkApp = new Add(zkAppAddress);
36+
});
2537

26-
beforeEach(() => {
27-
const Local = Mina.LocalBlockchain({ proofsEnabled });
28-
Mina.setActiveInstance(Local);
29-
({ privateKey: deployerKey, publicKey: deployerAccount } =
30-
Local.testAccounts[0]);
31-
({ privateKey: senderKey, publicKey: senderAccount } =
32-
Local.testAccounts[1]);
33-
zkAppPrivateKey = PrivateKey.random();
34-
zkAppAddress = zkAppPrivateKey.toPublicKey();
35-
zkApp = new Add(zkAppAddress);
36-
});
38+
async function localDeploy() {
39+
const txn = await Mina.transaction(deployerAccount, () => {
40+
AccountUpdate.fundNewAccount(deployerAccount);
41+
zkApp.deploy();
42+
});
43+
await txn.prove();
44+
// this tx needs .sign(), because `deploy()` adds an account update that requires signature authorization
45+
await txn.sign([deployerKey, zkAppPrivateKey]).send();
46+
}
3747

38-
async function localDeploy() {
39-
const txn = await Mina.transaction(deployerAccount, () => {
40-
AccountUpdate.fundNewAccount(deployerAccount);
41-
zkApp.deploy();
48+
it('generates and deploys the `Add` smart contract', async () => {
49+
await localDeploy();
50+
const num = zkApp.num.get();
51+
expect(num).toEqual(Field(1));
4252
});
43-
await txn.prove();
44-
// this tx needs .sign(), because `deploy()` adds an account update that requires signature authorization
45-
await txn.sign([deployerKey, zkAppPrivateKey]).send();
46-
}
4753

48-
it('generates and deploys the `Add` smart contract', async () => {
49-
await localDeploy();
50-
const num = zkApp.num.get();
51-
expect(num).toEqual(Field(1));
52-
});
54+
it('correctly updates the num state on the `Add` smart contract', async () => {
55+
await localDeploy();
5356

54-
it('correctly updates the num state on the `Add` smart contract', async () => {
55-
await localDeploy();
57+
// update transaction
58+
const txn = await Mina.transaction(senderAccount, () => {
59+
zkApp.update();
60+
});
61+
await txn.prove();
62+
await txn.sign([senderKey]).send();
5663

57-
// update transaction
58-
const txn = await Mina.transaction(senderAccount, () => {
59-
zkApp.update();
64+
const updatedNum = zkApp.num.get();
65+
expect(updatedNum).toEqual(Field(3));
6066
});
61-
await txn.prove();
62-
await txn.sign([senderKey]).send();
63-
64-
const updatedNum = zkApp.num.get();
65-
expect(updatedNum).toEqual(Field(3));
66-
});
6767
});

src/Add.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { Field, SmartContract, state, State, method } from 'o1js';
1010
* This file is safe to delete and replace with your own contract.
1111
*/
1212
export class Add extends SmartContract {
13-
@state(Field) num = State<Field>();
13+
@state(Field) num = State<Field>();
1414

15-
init() {
16-
super.init();
17-
this.num.set(Field(1));
18-
}
15+
init() {
16+
super.init();
17+
this.num.set(Field(1));
18+
}
1919

20-
@method update() {
21-
const currentState = this.num.getAndAssertEquals();
22-
const newState = currentState.add(2);
23-
this.num.set(newState);
24-
}
20+
@method update() {
21+
const currentState = this.num.getAndAssertEquals();
22+
const newState = currentState.add(2);
23+
this.num.set(newState);
24+
}
2525
}

src/CommitteeMember.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { CommitteeMember } from './CommitteeMember';
2+
3+
describe('CommitteeMember', () => {
4+
let committeeMember: CommitteeMember;
5+
it('1', async () => {
6+
let m = 1;
7+
});
8+
});

0 commit comments

Comments
 (0)