fix: add tests

This commit is contained in:
rymnc 2024-04-15 23:07:12 +05:30
parent 055942a482
commit 766a1ab359
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
1 changed files with 9 additions and 87 deletions

View File

@ -219,100 +219,22 @@ contract RlnTest is Test {
assertEq(rln.withdrawalBalance(to), 0); assertEq(rln.withdrawalBalance(to), 0);
} }
function test__kats__root() public { function test__subtreeRoot() public {
uint256[] memory idCommitments = new uint256[](20);
idCommitments[0] =
20_247_267_680_401_005_346_274_578_821_543_189_710_026_653_465_287_274_953_093_311_729_853_323_564_993;
idCommitments[1] =
17_156_989_550_607_148_435_222_849_763_909_493_047_059_958_780_520_493_064_916_232_951_463_175_150_232;
idCommitments[2] =
19_407_226_803_745_267_103_608_182_642_384_012_885_199_367_851_532_943_079_325_397_211_138_049_136_059;
idCommitments[3] =
10_843_159_696_774_792_948_443_591_344_995_886_877_305_260_668_485_645_797_849_607_534_704_262_422_614;
idCommitments[4] =
15_752_850_412_139_811_972_088_845_441_337_097_950_281_706_419_552_473_737_567_891_612_825_963_973_284;
idCommitments[5] =
4_519_863_328_057_168_189_298_631_669_175_527_040_337_788_759_018_171_546_425_601_895_038_423_288_676;
idCommitments[6] =
20_627_603_771_378_896_374_342_882_478_326_393_493_797_675_723_581_644_707_860_442_401_185_847_711_606;
idCommitments[7] =
15_154_129_217_924_019_401_315_002_167_199_740_344_372_362_483_772_641_456_490_923_254_762_406_760_783;
idCommitments[8] =
3_015_981_008_465_776_671_380_535_237_073_859_585_910_422_946_858_408_575_400_681_261_858_382_907_193;
idCommitments[9] =
224_054_746_800_950_089_703_161_552_547_065_908_637_798_421_998_793_333_020_881_640_418_719_302_913;
idCommitments[10] =
11_312_879_727_214_499_351_626_352_295_289_579_557_712_856_071_583_396_259_776_980_542_429_783_930_998;
idCommitments[11] =
12_465_380_480_462_031_386_424_255_751_937_172_435_855_917_781_265_550_857_371_960_580_299_590_023_804;
idCommitments[12] =
10_532_759_670_323_423_548_160_832_454_733_716_332_118_269_972_426_626_732_736_793_882_239_669_630_595;
idCommitments[13] =
5_363_974_916_211_877_996_441_994_123_101_828_809_420_707_174_378_417_661_497_477_404_431_739_760_929;
idCommitments[14] =
16_136_233_734_969_897_677_998_619_926_295_968_066_529_681_582_940_418_030_166_845_477_723_796_227_875;
idCommitments[15] =
19_482_780_886_140_959_996_233_254_660_604_422_414_723_443_061_405_603_031_287_446_813_590_162_051_267;
idCommitments[16] =
10_229_567_829_413_302_626_314_791_721_752_882_914_790_767_942_876_437_744_444_365_366_344_582_485_888;
idCommitments[17] =
13_243_196_170_549_739_682_068_942_953_623_914_146_349_583_225_049_284_668_843_899_390_874_999_176_721;
idCommitments[18] =
10_860_831_981_296_153_559_626_134_370_426_776_811_139_720_916_552_827_925_568_614_682_099_174_768_128;
idCommitments[19] =
18_217_334_211_520_937_958_971_536_517_166_530_749_184_547_628_672_204_353_760_850_739_130_586_503_124;
vm.pauseGasMetering(); vm.pauseGasMetering();
// before we insert into the tree, the kats must pass rln.register{ value: MEMBERSHIP_DEPOSIT }(10, 1);
assertEq( rln.register{ value: MEMBERSHIP_DEPOSIT }(20, 1);
rln.root(0), rln.register{ value: MEMBERSHIP_DEPOSIT }(30, 1);
12_413_880_268_183_407_374_852_357_075_976_609_371_175_688_755_676_981_206_018_884_971_008_854_919_922
);
for (uint256 i = 0; i < idCommitments.length; i++) {
// default 1 message limit
rln.register{ value: MEMBERSHIP_DEPOSIT }(idCommitments[i], 1);
}
vm.resumeGasMetering();
assertEq( uint256 expectedSubtreeRoot =
rln.root(0), 17_424_862_670_140_480_877_998_532_811_050_196_939_288_692_320_297_833_372_090_184_339_457_611_465_301;
2_435_591_050_584_562_785_273_516_085_683_091_349_247_653_357_522_297_485_884_387_709_399_190_797_862 assertEq(rln.root(0), expectedSubtreeRoot);
);
uint256[] memory roots = new uint256[](1024); uint256[] memory roots = new uint256[](1024);
roots[0] = 2_435_591_050_584_562_785_273_516_085_683_091_349_247_653_357_522_297_485_884_387_709_399_190_797_862; roots[0] = expectedSubtreeRoot;
assertEq(
rln.fullRoot(roots),
3_881_711_806_223_377_894_370_509_479_419_308_415_025_371_832_767_296_831_624_691_168_726_496_442_721
);
}
function test__root() public {
vm.pauseGasMetering();
uint256[] memory commitments = new uint256[](1024);
for (uint256 i = 0; i < 1024; i++) {
commitments[i] = i + 1;
}
for (uint256 i = 0; i < 1024; i++) {
rln.register{ value: MEMBERSHIP_DEPOSIT }(commitments[i], 1);
}
vm.resumeGasMetering(); vm.resumeGasMetering();
assertEq( assertEq(
rln.root(0),
10_424_638_537_885_815_866_594_133_227_550_095_274_095_476_771_249_698_162_779_016_221_356_823_894_456
);
}
function test__fullRoot() public {
uint256[] memory roots = new uint256[](1024);
assertEq(
// repeat 0 1024 times
rln.fullRoot(roots), rln.fullRoot(roots),
12_413_880_268_183_407_374_852_357_075_976_609_371_175_688_755_676_981_206_018_884_971_008_854_919_922 20_795_753_628_257_795_865_704_929_639_740_460_679_489_193_917_102_219_533_570_676_475_358_368_440_035
); );
} }
} }