Skip to content

Commit 8255b5e

Browse files
committed
🤖 Add Airdrop claimReward() test
1 parent 645c5b1 commit 8255b5e

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

‎mina/examples/Airdrop.test.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
22
AccountUpdate,
3+
Field,
34
MerkleTree,
45
Mina,
56
PrivateKey
67
} from "o1js";
78
import { Airdrop } from "./Airdrop";
9+
import { HumanIDWitness } from "../src/humanIDv1";
810

911
describe('Example Airdrop zkApp', () => {
1012
const deployerKey = PrivateKey.random();
@@ -13,35 +15,39 @@ describe('Example Airdrop zkApp', () => {
1315
const sender = senderKey.toPublicKey();
1416
const appKey = PrivateKey.random();
1517
const appAddr = appKey.toPublicKey();
18+
let tree: MerkleTree;
1619
let app: Airdrop;
1720

1821
beforeAll(() => Airdrop.compile());
1922

2023
beforeEach(() => Mina.LocalBlockchain({ proofsEnabled: true })
2124
.then((local) => {
25+
tree = new MerkleTree(32);
2226
Mina.setActiveInstance(local);
2327
app = new Airdrop(appAddr);
2428
local.addAccount(deployer, "1000000000");
2529
local.addAccount(sender, "1000000000");
2630
}));
2731

28-
it('should deploy the app', async () => {
29-
const tree = new MerkleTree(32);
30-
31-
await Mina.transaction(deployer, async () => {
32-
AccountUpdate.fundNewAccount(deployer);
33-
return app.deploy()
34-
.then(() => app.initRoot(tree.getRoot()));
35-
}).then((txn) => txn.prove())
36-
.then((txn) => txn.sign([deployerKey, appKey]).send())
37-
.then((txn) => txn.wait());
32+
const deploy = () => Mina.transaction(deployer, async () => {
33+
AccountUpdate.fundNewAccount(deployer);
34+
return app.deploy()
35+
.then(() => app.initRoot(tree.getRoot()));
36+
}).then((txn) => txn.prove())
37+
.then((txn) => txn.sign([deployerKey, appKey]).send())
3838

39+
it('should deploy the app', async () => {
40+
await deploy();
3941
console.log('Deployed HumanIDs contract at', app.address);
4042
});
4143

4244
it('should let people claimReward()', async () => {
43-
const tree = new MerkleTree(32);
45+
await deploy();
4446

45-
// TODO
47+
await Mina.transaction(sender, () => {
48+
let zkApp = new Airdrop(appAddr);
49+
return zkApp.claimReward(Field(100), new HumanIDWitness(tree.getWitness(100n)));
50+
}).then((txn) => txn.prove())
51+
.then((txn) => txn.sign([senderKey]).send());
4652
})
4753
});

‎mina/src/humanIDv1.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { State, Field, MerkleWitness } from "o1js";
1+
import { Field, MerkleWitness, State } from "o1js";
22

33
class HumanIDWitness extends MerkleWitness(32) { }
44

@@ -8,4 +8,5 @@ const authenticate = (treeRoot: State<Field>, humanIDv1: Field, witness: HumanID
88
treeRoot.set(witness.calculateRoot(Field(1)));
99
}
1010

11-
export { authenticate, HumanIDWitness };
11+
export { HumanIDWitness, authenticate };
12+

0 commit comments

Comments
 (0)