-
Notifications
You must be signed in to change notification settings - Fork 10
/
Redistribution.test.ts
1570 lines (1233 loc) · 68.3 KB
/
Redistribution.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { expect } from './util/chai';
import { ethers, deployments, getNamedAccounts } from 'hardhat';
import { BigNumber, Contract, ContractTransaction } from 'ethers';
import {
mineNBlocks,
getBlockNumber,
encodeAndHash,
mintAndApprove,
ZERO_32_BYTES,
nextAnchorIfNoReveal,
startRoundFixture,
copyBatchForClaim,
mineToRevealPhase,
calculateStakeDensity,
getWalletOfFdpPlayQueen,
WITNESS_COUNT,
skippedRoundsIncrease,
} from './util/tools';
import { proximity } from './util/tools';
import { node5_proof1, node5_soc_proof1 } from './claim-proofs';
import {
getClaimProofs,
loadWitnesses,
makeSample,
numberToArray,
calculateTransformedAddress,
inProximity,
mineCacWitness,
setWitnesses,
getSocProofAttachment,
} from './util/proofs';
import { arrayify, hexlify } from 'ethers/lib/utils';
import { makeChunk } from '@fairdatasociety/bmt-js';
import { randomBytes } from 'crypto';
import { constructPostageStamp } from './util/postage';
const { read, execute } = deployments;
const phaseLength = 38;
const roundLength = 152;
const increaseRate = [1049417, 1049206, 1048996, 1048786, 1048576, 1048366, 1048156, 1047946, 1047736];
// round anchor after startRoundFixture()
const round2Anchor = '0xac33ff75c19e70fe83507db0d683fd3465c996598dc972688b7ace676c89077b';
// start round number after mintToNode(red, 0) -> without claim
const roundAnchorBase = '0xa54b3e90672405a607381bd4d34034a12c5aad31607067a7ad26573f504ad6e2';
const maxInt256 = 0xffff; //js can't handle the full maxInt256 value
// Named accounts used by tests.
let deployer: string, stamper: string, pauser: string;
let node_0: string;
const overlay_0 = '0xa602fa47b3e8ce39ffc2017ad9069ff95eb58c051b1cfa2b0d86bc44a5433733';
const nonce_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const revealed_overlay_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const hash_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const depth_0 = '0x06';
const reveal_nonce_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const stakeAmount_0 = '100000000000000000';
const stakeAmount_0_n_2 = '400000000000000000';
const effectiveStakeAmount_0 = '99999999999984000';
const obfuscatedHash_0 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const height_0 = 0;
const height_0_n_2 = 2;
//fake
const overlay_f = '0xf4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f415';
const depth_f = '0x0000000000000000000000000000000000000000000000000000000000000007';
const reveal_nonce_f = '0xf4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f4153f415';
let node_1: string;
const overlay_1 = '0xa6f955c72d7053f96b91b5470491a0c732b0175af56dcfb7a604b82b16719406';
const overlay_1_n_25 = '0x676766bbae530fd0483e4734e800569c95929b707b9c50f8717dc99f9f91e915';
const stakeAmount_1 = '100000000000000000';
const nonce_1 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const nonce_1_n_25 = '0x00000000000000000000000000000000000000000000000000000000000325dd';
const stakeAmount_1_n_25 = '200000000000000000';
const depth_1 = '0x06';
const reveal_nonce_1 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const height_1 = 0;
let node_2: string;
const overlay_2 = '0xa40db58e368ea6856a24c0264ebd73b049f3dc1c2347b1babc901d3e09842dec';
const stakeAmount_2 = '100000000000000000';
const effectiveStakeAmount_2 = '99999999999984000';
const effectiveStakeAmount_2_n_2 = '100000000000000000';
const nonce_2 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const hash_2 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const depth_2 = '0x06';
const reveal_nonce_2 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const height_2 = 0;
const height_2_n_2 = 2;
let node_3: string;
const overlay_3 = '0xaf217eb0d652baf39ec9464a350c7afc812743fd75ccadf4fcceb6d19a1f190c';
const stakeAmount_3 = '100000000000000000';
const nonce_3 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const hash_3 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const depth_3 = '0x06';
const reveal_nonce_3 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const height_3_n_2 = 3;
const effectiveStakeAmount_3 = '100000000000000000';
let node_4: string;
const overlay_4 = '0xaedb2a8007316805b4d64b249ea39c5a1c4a9ce51dc8432724241f41ecb02efb';
const nonce_4 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const depth_4 = '0x06';
const height_4 = 0;
// FDP Play node keys - claim data
// queen node
let node_5: string;
const overlay_5 = '0x676720d79d609ed462fadf6f14eb1bf9ec1a90999dd45a671d79a89c7b5ac9d8';
const stakeAmount_5 = '100000000000000000';
const effectiveStakeAmount_5 = '99999999999984000';
const nonce_5 = '0x0000000000000000000000000000000000000000000000000000000000003ba6';
const reveal_nonce_5 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const { depth: depth_5, hash: hash_5 } = node5_proof1;
const height_5 = 0;
let node_6: string;
const overlay_6 = '0x141680b0d9c7ab250672fd4603ac13e39e47de6e2c93d71bbdc66459a6c5e39f';
const stakeAmount_6 = '100000000000000000';
const nonce_6 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const hash_6 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const depth_6 = '0x06';
const reveal_nonce_6 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
let node_7: string;
const overlay_7 = '0x152d169abc6e6a0e0a2a7b78dcfea0bebe32942f05e9bb10ee2996203d5361ef';
const stakeAmount_7 = '100000000000000000';
const nonce_7 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const hash_7 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
const depth_7 = '0x06';
const reveal_nonce_7 = '0xb5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33b5555b33';
// start round number after startRoundFixture()
const startRoundNumber = 3;
// start round number after mintToNode(red, 0) -> without claim
const startRndNumBase = 38;
/**
* Mines blocks until the given node's neighbourhood
* @param redistribution inited Redistribution contract
* @param nodeNo node's index in the top-level defined node data.
*/
const mineToNode = async (redistribution: Contract, nodeNo: number) => {
let currentSeed = await redistribution.currentSeed();
while (proximity(currentSeed, eval(`overlay_${nodeNo}`)) < Number(eval(`depth_${nodeNo}`))) {
await mineNBlocks(roundLength);
currentSeed = await redistribution.currentSeed();
}
};
// Before the tests, assign accounts
before(async function () {
const namedAccounts = await getNamedAccounts();
deployer = namedAccounts.deployer;
stamper = namedAccounts.stamper;
pauser = namedAccounts.pauser;
node_0 = namedAccounts.node_0;
node_1 = namedAccounts.node_1;
node_2 = namedAccounts.node_2;
node_3 = namedAccounts.node_3;
node_4 = namedAccounts.node_4;
node_5 = namedAccounts.node_5;
node_6 = namedAccounts.node_6;
node_7 = namedAccounts.node_7;
});
const errors = {
commit: {
notOwner: 'NotMatchingOwner()',
notStaked: 'NotStaked()',
mustStake2Rounds: 'MustStake2Rounds()',
alreadyCommitted: 'AlreadyCommitted()',
},
reveal: {
noCommits: 'NoCommitsReceived()',
doNotMatch: 'NoMatchingCommit()',
outOfDepth: 'OutOfDepth()',
outOfDepthReveal: 'OutOfDepthReveal()',
notInReveal: 'NotRevealPhase()',
},
claim: {
noReveals: 'NoReveals()',
alreadyClaimed: 'AlreadyClaimed()',
randomCheckFailed: 'RandomElementCheckFailed()',
outOfDepth: 'OutOfDepth()',
reserveCheckFailed: 'ReserveCheckFailed()',
indexOutsideSet: 'IndexOutsideSet()',
batchDoesNotExist: 'BatchDoesNotExist()',
bucketDiffers: 'BucketDiffers()',
sigRecoveryFailed: 'SigRecoveryFailed()',
inclusionProofFailed1: 'InclusionProofFailed',
inclusionProofFailed2: 'InclusionProofFailed',
inclusionProofFailed3: 'InclusionProofFailed',
inclusionProofFailed4: 'InclusionProofFailed',
socVerificationFailed: 'SocVerificationFailed()',
socCalcNotMatching: 'SocCalcNotMatching()',
},
deposit: {
noBalance: 'ERC20: insufficient allowance',
noZeroAddress: 'owner cannot be the zero address',
onlyOwner: 'Unauthorized()',
belowMinimum: 'BelowMinimumStake()',
},
general: {
onlyPauser: 'OnlyPauser()',
},
};
describe('Redistribution', function () {
describe('when deploying contract', function () {
beforeEach(async function () {
await deployments.fixture();
});
it('should deploy Redistribution', async function () {
const redistribution = await ethers.getContract('Redistribution');
expect(redistribution.address).to.be.properAddress;
});
});
describe('with deployed contract and unstaked node in next round', async function () {
let redistribution: Contract;
beforeEach(async function () {
await deployments.fixture();
redistribution = await ethers.getContract('Redistribution');
await mineNBlocks(roundLength * 2);
});
it('should not create a commit with unstaked node', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
const currentRound = await r_node_0.currentRound();
await expect(r_node_0.commit(obfuscatedHash_0, currentRound)).to.be.revertedWith(errors.commit.notStaked);
});
it('should not participation with unstaked node', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
const currentRound = await r_node_0.currentRound();
await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith(
errors.commit.notStaked
);
});
it('should not create a commit with recently staked node', async function () {
const sr_node_0 = await ethers.getContract('StakeRegistry', node_0);
await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0);
await sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0);
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith(
errors.commit.mustStake2Rounds
);
});
it('should create a commit with staked node', async function () {
const sr_node_0 = await ethers.getContract('StakeRegistry', node_0);
await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0);
await sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0);
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith(
errors.commit.mustStake2Rounds
);
});
it('should create a commit with staked node and height 2 and not have enough funds', async function () {
const sr_node_0 = await ethers.getContract('StakeRegistry', node_0);
await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0);
await expect(sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0_n_2)).to.be.revertedWith(
errors.deposit.belowMinimum
);
});
it('should create a commit with staked node and height 2', async function () {
const sr_node_0 = await ethers.getContract('StakeRegistry', node_0);
await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0_n_2);
await sr_node_0.manageStake(nonce_0, stakeAmount_0_n_2, height_0_n_2);
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith(
errors.commit.mustStake2Rounds
);
});
});
describe('with deployed contract and staked node in next round', async function () {
let redistribution: Contract;
let token: Contract;
let postage: Contract;
const price1 = 48000;
const batch = {
nonce: '0x000000000000000000000000000000000000000000000000000000000000abcd',
initialPaymentPerChunk: 20000000000,
depth: 17,
bucketDepth: 16,
immutable: false,
blocks: 100,
};
let stampCreatedBlock: number;
beforeEach(async function () {
await deployments.fixture();
redistribution = await ethers.getContract('Redistribution');
token = await ethers.getContract('TestToken', deployer);
const pauserRole = await read('StakeRegistry', 'DEFAULT_ADMIN_ROLE');
await execute('StakeRegistry', { from: deployer }, 'grantRole', pauserRole, pauser);
//initialise, set minimum price, todo: move to deployment
const priceOracle = await ethers.getContract('PriceOracle', deployer);
await priceOracle.setPrice(price1);
const batchSize = 2 ** batch.depth;
const transferAmount = batch.initialPaymentPerChunk * batchSize;
postage = await ethers.getContract('PostageStamp', stamper);
await mintAndApprove(deployer, stamper, postage.address, transferAmount.toString());
await postage.expireLimited(maxInt256); //for testing
await postage.createBatch(
stamper,
batch.initialPaymentPerChunk,
batch.depth,
batch.bucketDepth,
batch.nonce,
batch.immutable
);
stampCreatedBlock = await getBlockNumber();
const sr_node_0 = await ethers.getContract('StakeRegistry', node_0);
await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0);
await sr_node_0.manageStake(nonce_0, stakeAmount_0, height_0);
const sr_node_1 = await ethers.getContract('StakeRegistry', node_1);
await mintAndApprove(deployer, node_1, sr_node_1.address, stakeAmount_1);
await sr_node_1.manageStake(nonce_1, stakeAmount_1, height_1);
// 16 depth neighbourhood with node_5
const sr_node_1_n_25 = await ethers.getContract('StakeRegistry', node_1);
await mintAndApprove(deployer, node_1, sr_node_1_n_25.address, stakeAmount_1);
await sr_node_1_n_25.manageStake(nonce_1_n_25, stakeAmount_1, height_1);
const sr_node_2 = await ethers.getContract('StakeRegistry', node_2);
await mintAndApprove(deployer, node_2, sr_node_2.address, stakeAmount_2);
await sr_node_2.manageStake(nonce_2, stakeAmount_2, height_2);
const sr_node_3 = await ethers.getContract('StakeRegistry', node_3);
await mintAndApprove(deployer, node_3, sr_node_3.address, stakeAmount_3);
await sr_node_3.manageStake(nonce_3, stakeAmount_3, height_4);
const sr_node_4 = await ethers.getContract('StakeRegistry', node_4);
await mintAndApprove(deployer, node_4, sr_node_4.address, stakeAmount_3);
await sr_node_4.manageStake(nonce_4, stakeAmount_3, height_4);
const sr_node_5 = await ethers.getContract('StakeRegistry', node_5);
await mintAndApprove(deployer, node_5, sr_node_5.address, stakeAmount_5);
await sr_node_5.manageStake(nonce_5, stakeAmount_5, height_5);
// We need to mine 2 rounds to make the staking possible
// as this is the minimum time between staking and committing
await mineNBlocks(roundLength * 2 + 3);
await startRoundFixture();
});
describe('round numbers and phases', function () {
it('should be in the correct round', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentRound()).to.be.eq(startRoundNumber);
await mineNBlocks(roundLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + roundLength);
expect(await redistribution.currentRound()).to.be.eq(startRoundNumber + 1);
});
it('should be in the correct phase', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + phaseLength);
expect(await redistribution.currentPhaseReveal()).to.be.true;
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + 2 * phaseLength);
expect(await redistribution.currentPhaseClaim()).to.be.true;
});
});
describe('utilities', function () {
it('should correctly wrap a commit', async function () {
const obfuscatedHash = encodeAndHash(overlay_0, depth_0, hash_0, reveal_nonce_0);
expect(await redistribution.wrapCommit(overlay_0, depth_0, hash_0, reveal_nonce_0)).to.be.eq(obfuscatedHash);
});
it('should correctly wrap another commit', async function () {
const obfuscatedHash = encodeAndHash(overlay_3, depth_3, hash_3, reveal_nonce_3);
expect(await redistribution.wrapCommit(overlay_3, depth_3, hash_3, reveal_nonce_3)).to.be.eq(obfuscatedHash);
});
});
describe('qualifying participants', async function () {
it('should correctly identify if overlay is allowed to participate in current round', async function () {
await mineNBlocks(1); //because strict equality enforcing time since staking
await mineToNode(redistribution, 0);
expect(await redistribution.currentRound()).to.be.eq(startRndNumBase);
// 0xa6ee...
const firstAnchor = await redistribution.currentRoundAnchor();
expect(firstAnchor).to.be.eq(roundAnchorBase);
expect(await redistribution.inProximity(roundAnchorBase, overlay_0, depth_0)).to.be.true;
expect(await redistribution.inProximity(roundAnchorBase, overlay_1, depth_1)).to.be.true;
expect(await redistribution.inProximity(roundAnchorBase, overlay_2, depth_2)).to.be.true;
// 0xac33...
expect(await redistribution.inProximity(roundAnchorBase, overlay_3, depth_3)).to.be.false;
expect(await redistribution.inProximity(roundAnchorBase, overlay_4, depth_4)).to.be.false;
// 0x00...
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.true;
// Should be false as we are using different nhood then anchor via node_1_25
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_1, depth_1)).to.be.false;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_2, depth_2)).to.be.true;
// 0xa6...
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_3, depth_3)).to.be.false;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_4, depth_4)).to.be.false;
await mineNBlocks(roundLength);
const roundNo = Number(await redistribution.currentRound());
const nextAnchor = nextAnchorIfNoReveal(ZERO_32_BYTES, roundNo);
expect(roundNo).to.be.eq(startRndNumBase + 1);
expect(await redistribution.currentRoundAnchor()).to.be.eq(nextAnchor);
await mineToNode(redistribution, 3);
// test out anchor that mined to address satisfy inProximity and isParticipatingInUpcomingRound
const nextAnchor2 = redistribution.currentSeed();
expect(await redistribution.inProximity(nextAnchor2, overlay_0, depth_0)).to.be.false;
expect(await redistribution.inProximity(nextAnchor2, overlay_1, depth_1)).to.be.false;
expect(await redistribution.inProximity(nextAnchor2, overlay_2, depth_2)).to.be.false;
expect(await redistribution.inProximity(nextAnchor2, overlay_3, depth_3)).to.be.true;
expect(await redistribution.inProximity(nextAnchor2, overlay_4, depth_4)).to.be.true;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.false;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_1, depth_1)).to.be.false;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_2, depth_2)).to.be.false;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_3, depth_3)).to.be.true;
expect(await redistribution['isParticipatingInUpcomingRound(address,uint8)'](node_4, depth_4)).to.be.true;
});
});
describe('commit phase with no reveals', async function () {
it('should have correct round anchors', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
expect(await redistribution.currentRound()).to.be.eq(startRoundNumber);
expect(await redistribution.currentRoundAnchor()).to.be.eq(round2Anchor);
await mineNBlocks(phaseLength);
expect(await redistribution.currentPhaseReveal()).to.be.true;
expect(await redistribution.currentRoundAnchor()).to.be.eq(round2Anchor);
await mineNBlocks(phaseLength);
const nextAnchor = nextAnchorIfNoReveal(ZERO_32_BYTES, startRoundNumber + 1);
expect(await redistribution.currentPhaseClaim()).to.be.true;
expect(await redistribution.currentRoundAnchor()).to.be.eq(nextAnchor);
await mineNBlocks(phaseLength * 2);
expect(await redistribution.currentRound()).to.be.eq(startRoundNumber + 1);
expect(await redistribution.currentRoundAnchor()).to.be.eq(nextAnchor);
});
it('should create a commit with failed reveal if the overlay is out of reported depth', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_3 = await ethers.getContract('Redistribution', node_3);
expect(await redistribution.currentRoundAnchor()).to.be.eq(round2Anchor);
const obfuscatedHash = encodeAndHash(overlay_3, '0x08', hash_3, reveal_nonce_3);
expect(await r_node_3.wrapCommit(overlay_3, '0x08', hash_3, reveal_nonce_3)).to.be.eq(obfuscatedHash);
const currentRound = await r_node_3.currentRound();
await r_node_3.commit(obfuscatedHash, currentRound);
expect((await r_node_3.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await mineNBlocks(phaseLength);
await expect(r_node_3.reveal('0x08', hash_3, reveal_nonce_3)).to.be.revertedWith(
errors.reveal.outOfDepthReveal
);
});
it('should create a commit with failed reveal if the overlay is out of reported depth but good reveal if height is changed', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_3 = await ethers.getContract('Redistribution', node_3);
expect(await redistribution.currentRoundAnchor()).to.be.eq(round2Anchor);
const obfuscatedHash = encodeAndHash(overlay_3, '0x08', hash_3, reveal_nonce_3);
expect(await r_node_3.wrapCommit(overlay_3, '0x08', hash_3, reveal_nonce_3)).to.be.eq(obfuscatedHash);
const currentRound = await r_node_3.currentRound();
await r_node_3.commit(obfuscatedHash, currentRound);
expect((await r_node_3.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await mineNBlocks(phaseLength);
await expect(r_node_3.reveal('0x08', hash_3, reveal_nonce_3)).to.be.revertedWith(
errors.reveal.outOfDepthReveal
);
// Change height and check if node is playing
const sr_node_3 = await ethers.getContract('StakeRegistry', node_3);
await sr_node_3.manageStake(nonce_3, 0, height_3_n_2);
await mineNBlocks(3 * phaseLength);
await mineToNode(redistribution, 3);
expect(await redistribution.currentPhaseCommit()).to.be.true;
const obfuscatedHash2 = encodeAndHash(overlay_3, depth_3, hash_3, reveal_nonce_3);
const currentRound2 = await r_node_3.currentRound();
await expect(r_node_3.commit(obfuscatedHash2, currentRound2))
.to.emit(redistribution, 'Committed')
.withArgs(currentRound2, overlay_3, height_3_n_2);
expect((await r_node_3.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash2);
await mineNBlocks(phaseLength);
await r_node_3.reveal(depth_3, hash_3, reveal_nonce_3);
expect((await r_node_3.currentReveals(0)).hash).to.be.eq(hash_3);
expect((await r_node_3.currentReveals(0)).overlay).to.be.eq(overlay_3);
expect((await r_node_3.currentReveals(0)).owner).to.be.eq(node_3);
expect((await r_node_3.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_3);
expect((await r_node_3.currentReveals(0)).depth).to.be.eq(parseInt(depth_3));
});
it('should create a commit with successful reveal if the overlay is within the reported depth', async function () {
const r_node_2 = await ethers.getContract('Redistribution', node_2);
await mineToNode(redistribution, 2);
expect(await redistribution.currentPhaseCommit()).to.be.true;
const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2);
const currentRound = await r_node_2.currentRound();
await expect(r_node_2.commit(obfuscatedHash, currentRound))
.to.emit(redistribution, 'Committed')
.withArgs(currentRound, overlay_2, height_2);
expect((await r_node_2.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await mineNBlocks(phaseLength);
await r_node_2.reveal(depth_2, hash_2, reveal_nonce_2);
expect((await r_node_2.currentReveals(0)).hash).to.be.eq(hash_2);
expect((await r_node_2.currentReveals(0)).overlay).to.be.eq(overlay_2);
expect((await r_node_2.currentReveals(0)).owner).to.be.eq(node_2);
expect((await r_node_2.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_2);
expect((await r_node_2.currentReveals(0)).depth).to.be.eq(parseInt(depth_2));
});
it('should create a commit with successful reveal if the overlay is within the reported depth with height 2', async function () {
const r_node_2 = await ethers.getContract('Redistribution', node_2);
const sr_node_2 = await ethers.getContract('StakeRegistry', node_2);
await sr_node_2.manageStake(nonce_2, 0, height_2_n_2);
await mineToNode(redistribution, 2);
expect(await redistribution.currentPhaseCommit()).to.be.true;
const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2);
const currentRound = await r_node_2.currentRound();
await expect(r_node_2.commit(obfuscatedHash, currentRound))
.to.emit(redistribution, 'Committed')
.withArgs(currentRound, overlay_2, height_2_n_2);
expect((await r_node_2.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await mineNBlocks(phaseLength);
await r_node_2.reveal(depth_2, hash_2, reveal_nonce_2);
expect((await r_node_2.currentReveals(0)).hash).to.be.eq(hash_2);
expect((await r_node_2.currentReveals(0)).overlay).to.be.eq(overlay_2);
expect((await r_node_2.currentReveals(0)).owner).to.be.eq(node_2);
expect((await r_node_2.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_2_n_2);
expect((await r_node_2.currentReveals(0)).depth).to.be.eq(parseInt(depth_2));
});
it('should create a fake commit with failed reveal', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
const currentRound = await r_node_0.currentRound();
await r_node_0.commit(obfuscatedHash_0, currentRound);
const commit_0 = await r_node_0.currentCommits(0);
expect(commit_0.overlay).to.be.eq(overlay_0);
expect(commit_0.obfuscatedHash).to.be.eq(obfuscatedHash_0);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + 1);
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + 1 + phaseLength);
expect(await r_node_0.currentPhaseReveal()).to.be.true;
await expect(r_node_0.reveal(depth_0, reveal_nonce_0, revealed_overlay_0)).to.be.revertedWith(
errors.reveal.doNotMatch
);
});
it('should not allow duplicate commits', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_2 = await ethers.getContract('Redistribution', node_2);
const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2);
const currentRound = await r_node_2.currentRound();
await r_node_2.commit(obfuscatedHash, currentRound);
expect((await r_node_2.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await expect(r_node_2.commit(obfuscatedHash, currentRound)).to.be.revertedWith(errors.commit.alreadyCommitted);
});
});
describe('reveal phase', async function () {
it('should not allow an overlay to reveal without commits', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + phaseLength);
expect(await redistribution.currentPhaseReveal()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
await expect(r_node_0.reveal(depth_0, reveal_nonce_0, revealed_overlay_0)).to.be.revertedWith(
errors.reveal.noCommits
);
});
it('should not allow reveal in commit phase', async function () {
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
await expect(r_node_0.reveal(depth_0, reveal_nonce_0, revealed_overlay_0)).to.be.revertedWith(
errors.reveal.notInReveal
);
});
it('should not allow reveal in claim phase', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
expect(await getBlockNumber()).to.be.eq(initialBlockNumber);
expect(await redistribution.currentPhaseReveal()).to.be.false;
const r_node_0 = await ethers.getContract('Redistribution', node_0);
await mineNBlocks(phaseLength * 2);
expect(await redistribution.currentPhaseClaim()).to.be.true;
// commented out to allow other tests to pass for now
await expect(r_node_0.reveal(depth_0, reveal_nonce_0, revealed_overlay_0)).to.be.revertedWith(
errors.reveal.notInReveal
);
});
it('should not allow an overlay to reveal with the incorrect nonce', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_2 = await ethers.getContract('Redistribution', node_2);
const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2);
const currentRound = await r_node_2.currentRound();
await r_node_2.commit(obfuscatedHash, currentRound);
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + phaseLength + 1);
expect(await redistribution.currentPhaseReveal()).to.be.true;
await expect(r_node_2.reveal(depth_2, hash_2, reveal_nonce_f)).to.be.revertedWith(errors.reveal.doNotMatch);
});
it('should not allow an overlay to reveal without with the incorrect depth', async function () {
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_2 = await ethers.getContract('Redistribution', node_2);
const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2);
const currentRound = await r_node_2.currentRound();
await r_node_2.commit(obfuscatedHash, currentRound);
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + phaseLength + 1);
expect(await redistribution.currentPhaseReveal()).to.be.true;
await expect(r_node_2.reveal(depth_f, hash_2, reveal_nonce_2)).to.be.revertedWith(errors.reveal.doNotMatch);
});
describe('when pausing', function () {
it('should not allow anybody but the pauser to pause', async function () {
const redistributionContract = await ethers.getContract('Redistribution', stamper);
await expect(redistributionContract.pause()).to.be.revertedWith(errors.general.onlyPauser);
});
});
describe('when unpausing', function () {
it('should unpause when pause and then unpause', async function () {
const redistributionContract = await ethers.getContract('Redistribution', deployer);
await redistributionContract.pause();
await redistributionContract.unPause();
expect(await redistributionContract.paused()).to.be.false;
});
it('should not allow anybody but the pauser to unpause', async function () {
const redistributionContract = await ethers.getContract('Redistribution', deployer);
await redistributionContract.pause();
const redistributionContract2 = await ethers.getContract('Redistribution', stamper);
await expect(redistributionContract2.unPause()).to.be.revertedWith(errors.general.onlyPauser);
});
it('should not allow unpausing when not paused', async function () {
const redistributionContract = await ethers.getContract('Redistribution', deployer);
await expect(redistributionContract.unPause()).to.be.revertedWith('Pausable: not paused');
});
});
it('should emit correct events', async function () {
await mineToNode(redistribution, 2);
const initialBlockNumber = await getBlockNumber();
expect(await redistribution.currentPhaseCommit()).to.be.true;
const r_node_2 = await ethers.getContract('Redistribution', node_2);
const obfuscatedHash = encodeAndHash(overlay_2, depth_2, hash_2, reveal_nonce_2);
const currentRound = await r_node_2.currentRound();
await r_node_2.commit(obfuscatedHash, parseInt(currentRound));
await mineNBlocks(phaseLength);
expect(await getBlockNumber()).to.be.eq(initialBlockNumber + phaseLength + 1);
expect(await redistribution.currentPhaseReveal()).to.be.true;
await expect(r_node_2.reveal(depth_2, hash_2, reveal_nonce_2))
.to.emit(redistribution, 'Revealed')
.withArgs(currentRound, overlay_2, effectiveStakeAmount_2, '6399999999998976000', hash_2, parseInt(depth_2));
});
});
describe('claim phase', async function () {
let skippedRounds: number;
describe('single player', async function () {
let copyBatch: Awaited<ReturnType<typeof copyBatchForClaim>>, currentSeed: string, r_node_5: Contract;
const depth = 1;
const generatedSampling = async (socAttachment = false) => {
const anchor1 = arrayify(currentSeed);
const witnessChunks = socAttachment
? await setWitnesses('claim-pot-soc', anchor1, depth, true)
: await setWitnesses('claim-pot', anchor1, depth);
const sampleChunk = makeSample(witnessChunks);
const sampleHashString = hexlify(sampleChunk.address());
const obfuscatedHash = encodeAndHash(overlay_5, hexlify(depth), sampleHashString, reveal_nonce_5);
const currentRound = await r_node_5.currentRound();
await r_node_5.commit(obfuscatedHash, currentRound);
expect((await r_node_5.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await mineToRevealPhase();
await r_node_5.reveal(hexlify(depth), sampleHashString, reveal_nonce_5);
const anchor2 = await redistribution.currentSeed();
const { proofParams } = await getClaimProofs(
witnessChunks,
sampleChunk,
anchor1,
anchor2,
copyBatch.batchOwner,
copyBatch.batchId
);
expect((await r_node_5.currentReveals(0)).hash).to.be.eq(sampleHashString);
expect((await r_node_5.currentReveals(0)).overlay).to.be.eq(overlay_5);
expect((await r_node_5.currentReveals(0)).owner).to.be.eq(node_5);
expect((await r_node_5.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_5);
expect((await r_node_5.currentReveals(0)).depth).to.be.eq(depth);
await mineNBlocks(phaseLength);
return { proofParams, sampleHashString };
};
const claimEventChecks = async (
claimTx: ContractTransaction,
sanityHash: string,
sanityDepth: string,
options?: {
additionalReward?: number; // in case of there was another copybatch before claim
}
) => {
const receipt2 = await claimTx.wait();
let WinnerSelectedEvent, TruthSelectedEvent, CountCommitsEvent, CountRevealsEvent;
if (!receipt2.events) {
throw new Error('The transaction does not produced any events');
}
for (const e of receipt2.events) {
if (e.event == 'WinnerSelected') {
WinnerSelectedEvent = e;
}
if (e.event == 'TruthSelected') {
TruthSelectedEvent = e;
}
if (e.event == 'CountCommits') {
CountCommitsEvent = e;
}
if (e.event == 'CountReveals') {
CountRevealsEvent = e;
}
}
if (!CountCommitsEvent || !CountCommitsEvent.args) {
throw new Error('CountCommitsEvent has not triggered');
}
if (!WinnerSelectedEvent || !WinnerSelectedEvent.args) {
throw new Error('CountCommitsEvent has not triggered');
}
if (!CountRevealsEvent || !CountRevealsEvent.args) {
throw new Error('CountCommitsEvent has not triggered');
}
if (!TruthSelectedEvent || !TruthSelectedEvent.args) {
throw new Error('CountCommitsEvent has not triggered');
}
const expectedPotPayout =
(receipt2.blockNumber - copyBatch.tx.blockNumber) * price1 * 2 ** copyBatch.postageDepth +
(receipt2.blockNumber - stampCreatedBlock) * price1 * 2 ** batch.depth + // batch in the beforeHook
(options?.additionalReward ? options?.additionalReward : 0);
expect(await token.balanceOf(node_5)).to.be.eq(expectedPotPayout);
expect(CountCommitsEvent.args[0]).to.be.eq(1);
expect(CountRevealsEvent.args[0]).to.be.eq(1);
expect(WinnerSelectedEvent.args[0].owner).to.be.eq(node_5);
expect(WinnerSelectedEvent.args[0].overlay).to.be.eq(overlay_5);
expect(WinnerSelectedEvent.args[0].stake).to.be.eq(effectiveStakeAmount_5);
expect(WinnerSelectedEvent.args[0].stakeDensity).to.be.eq(
BigNumber.from(effectiveStakeAmount_0).mul(BigNumber.from(2).pow(parseInt(sanityDepth)))
);
expect(WinnerSelectedEvent.args[0].hash).to.be.eq(sanityHash);
expect(WinnerSelectedEvent.args[0].depth).to.be.eq(parseInt(sanityDepth));
expect(TruthSelectedEvent.args[0]).to.be.eq(sanityHash);
expect(TruthSelectedEvent.args[1]).to.be.eq(parseInt(sanityDepth));
};
beforeEach(async () => {
//copying batch for claim
copyBatch = await copyBatchForClaim(
deployer,
'0x5bee6f33f47fbe2c3ff4c853dbc95f1a6a4a4191a1a7e3ece999a76c2790a83f'
);
// anchor fixture
await mineToNode(redistribution, 5);
currentSeed = await redistribution.currentSeed();
expect(await redistribution.currentPhaseCommit()).to.be.true;
r_node_5 = await ethers.getContract('Redistribution', node_5);
});
it('should claim pot by bee CAC sampling', async function () {
const { proof1, proof2, proofLast, hash: sanityHash, depth: sanityDepth } = node5_proof1;
const obfuscatedHash = encodeAndHash(overlay_5, sanityDepth, sanityHash, reveal_nonce_5);
const currentRound = await r_node_5.currentRound();
await r_node_5.commit(obfuscatedHash, currentRound);
expect((await r_node_5.currentCommits(0)).obfuscatedHash).to.be.eq(obfuscatedHash);
await mineToRevealPhase();
await r_node_5.reveal(sanityDepth, sanityHash, reveal_nonce_5);
currentSeed = await redistribution.currentSeed();
expect((await r_node_5.currentReveals(0)).hash).to.be.eq(sanityHash);
expect((await r_node_5.currentReveals(0)).overlay).to.be.eq(overlay_5);
expect((await r_node_5.currentReveals(0)).owner).to.be.eq(node_5);
expect((await r_node_5.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_5);
expect((await r_node_5.currentReveals(0)).depth).to.be.eq(parseInt(sanityDepth));
await mineNBlocks(phaseLength);
const tx2 = await r_node_5.claim(proof1, proof2, proofLast);
await claimEventChecks(tx2, sanityHash, sanityDepth);
});
it('should claim pot by bee SOC sampling', async function () {
//copying batch for claim because pull sync does not work correctly
const copyBatch2 = await copyBatchForClaim(
deployer,
'0x6cccd65a68bc5f7c19a273e9567ebf4b968a13c9be74fc99ad90159730eff219'
);
const { proof1, proof2, proofLast, hash: sanityHash, depth: sanityDepth } = node5_soc_proof1;
const obsfucatedHash = encodeAndHash(overlay_5, sanityDepth, sanityHash, reveal_nonce_5);
const currentRound = await r_node_5.currentRound();
await r_node_5.commit(obsfucatedHash, currentRound);
expect((await r_node_5.currentCommits(0)).obfuscatedHash).to.be.eq(obsfucatedHash);
await mineToRevealPhase();
await r_node_5.reveal(sanityDepth, sanityHash, reveal_nonce_5);
currentSeed = await redistribution.currentSeed();
expect((await r_node_5.currentReveals(0)).hash).to.be.eq(sanityHash);
expect((await r_node_5.currentReveals(0)).overlay).to.be.eq(overlay_5);
expect((await r_node_5.currentReveals(0)).owner).to.be.eq(node_5);
expect((await r_node_5.currentReveals(0)).stake).to.be.eq(effectiveStakeAmount_5);
expect((await r_node_5.currentReveals(0)).depth).to.be.eq(parseInt(sanityDepth));
await mineNBlocks(phaseLength);
const tx2 = await r_node_5.claim(proof1, proof2, proofLast);
const receipt2 = await tx2.wait();
await claimEventChecks(tx2, sanityHash, sanityDepth, {
additionalReward:
(receipt2.blockNumber - copyBatch2.tx.blockNumber) * price1 * 2 ** copyBatch2.postageDepth,
});
});
it('should claim pot by generated CAC sampling', async function () {
const { sampleHashString, proofParams } = await generatedSampling();
expect(proofParams.proof1.socProof).to.have.length(0);
expect(proofParams.proof2.socProof).to.have.length(0);
expect(proofParams.proofLast.socProof).to.have.length(0);
const tx2 = await r_node_5.claim(proofParams.proof1, proofParams.proof2, proofParams.proofLast);
await claimEventChecks(tx2, sampleHashString, hexlify(depth));
});
it('should claim pot by generated SOC sampling', async function () {
const { sampleHashString, proofParams } = await generatedSampling(true);
expect(proofParams.proof1.socProof).to.have.length(1);
expect(proofParams.proof2.socProof).to.have.length(1);
expect(proofParams.proofLast.socProof).to.have.length(1);
const tx2 = await r_node_5.claim(proofParams.proof1, proofParams.proof2, proofParams.proofLast);
await claimEventChecks(tx2, sampleHashString, hexlify(depth));
});
it('should not claim pot because of wrong witness order', async () => {
const anchor1 = arrayify(currentSeed);
let witnessChunks = loadWitnesses('claim-pot');
witnessChunks = witnessChunks.reverse();
const sampleChunk = makeSample(witnessChunks);
const sampleHashString = hexlify(sampleChunk.address());
const obfuscatedHash = encodeAndHash(overlay_5, hexlify(depth), sampleHashString, reveal_nonce_5);