1
1
import {
2
2
AccountUpdate ,
3
+ Field ,
3
4
MerkleTree ,
4
5
Mina ,
5
6
PrivateKey
6
7
} from "o1js" ;
7
8
import { Airdrop } from "./Airdrop" ;
9
+ import { HumanIDWitness } from "../src/humanIDv1" ;
8
10
9
11
describe ( 'Example Airdrop zkApp' , ( ) => {
10
12
const deployerKey = PrivateKey . random ( ) ;
@@ -13,35 +15,39 @@ describe('Example Airdrop zkApp', () => {
13
15
const sender = senderKey . toPublicKey ( ) ;
14
16
const appKey = PrivateKey . random ( ) ;
15
17
const appAddr = appKey . toPublicKey ( ) ;
18
+ let tree : MerkleTree ;
16
19
let app : Airdrop ;
17
20
18
21
beforeAll ( ( ) => Airdrop . compile ( ) ) ;
19
22
20
23
beforeEach ( ( ) => Mina . LocalBlockchain ( { proofsEnabled : true } )
21
24
. then ( ( local ) => {
25
+ tree = new MerkleTree ( 32 ) ;
22
26
Mina . setActiveInstance ( local ) ;
23
27
app = new Airdrop ( appAddr ) ;
24
28
local . addAccount ( deployer , "1000000000" ) ;
25
29
local . addAccount ( sender , "1000000000" ) ;
26
30
} ) ) ;
27
31
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 ( ) )
38
38
39
+ it ( 'should deploy the app' , async ( ) => {
40
+ await deploy ( ) ;
39
41
console . log ( 'Deployed HumanIDs contract at' , app . address ) ;
40
42
} ) ;
41
43
42
44
it ( 'should let people claimReward()' , async ( ) => {
43
- const tree = new MerkleTree ( 32 ) ;
45
+ await deploy ( ) ;
44
46
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 ( ) ) ;
46
52
} )
47
53
} ) ;
0 commit comments