From 64184b686adb2e09d9e73cfc0252f06b76f5be65 Mon Sep 17 00:00:00 2001 From: bigq Date: Mon, 17 Jul 2023 16:57:15 +0200 Subject: [PATCH] feat: add tests --- script/Airdrop.s.sol | 7 ++-- tests/Airdrop.t.sol | 49 ++++++++++++++++++++++++++++ tests/sismo-connect-config.test.json | 33 +++++++++++++++++++ 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 tests/Airdrop.t.sol create mode 100644 tests/sismo-connect-config.test.json diff --git a/script/Airdrop.s.sol b/script/Airdrop.s.sol index 016b282..2f83c9b 100644 --- a/script/Airdrop.s.sol +++ b/script/Airdrop.s.sol @@ -2,16 +2,13 @@ pragma solidity ^0.8.20; import "forge-std/Script.sol"; -import "forge-std/console.sol"; import "sismo-connect-solidity/SismoLib.sol"; -import {SismoConnectConfigReader} from "./utils/SismoConnectConfigReader.sol"; +import {SismoConnectConfigReader} from "script/utils/SismoConnectConfigReader.sol"; import {Airdrop} from "src/Airdrop.sol"; contract DeployAirdrop is Script, SismoConnectConfigReader { - using stdJson for string; - function run() public { - console.log("Deploying Airdrop contract"); + console.log("Deploying Airdrop contract..."); string memory json = vm.readFile(string.concat(vm.projectRoot(), "/sismo-connect-config.json")); ( bytes16 appId, diff --git a/tests/Airdrop.t.sol b/tests/Airdrop.t.sol new file mode 100644 index 0000000..273d4fd --- /dev/null +++ b/tests/Airdrop.t.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import "tests/base/BaseTest.t.sol"; +import "sismo-connect-solidity/SismoLib.sol"; +import {SismoConnectConfigReader} from "script/utils/SismoConnectConfigReader.sol"; +import {Airdrop} from "src/Airdrop.sol"; + +contract Airdroptest is BaseTest, SismoConnectConfigReader { + Airdrop airdrop; + address claimAddress = 0x061060a65146b3265C62fC8f3AE977c9B27260fF; + + function setUp() public { + string memory json = vm.readFile( + string.concat(vm.projectRoot(), "/tests/sismo-connect-config.test.json") + ); + ( + bytes16 appId, + AuthRequest[] memory authRequests, + ClaimRequest[] memory claimRequests, + bool isImpersonationMode + ) = readSismoConnectRequest(json); + + airdrop = new Airdrop( + "my Airdrop", + "AIR", + appId, + isImpersonationMode, + authRequests, + claimRequests + ); + } + + function testAirdrop() public { + _registerTreeRoot(0x04f0ace60fdf560415b93173156e67c6735946e9889973bfd56f1bcbe6fc5bcf); + + bytes + memory response = hex"000000000000000000000000000000000000000000000000000000000000002032403ced4b65f2079eda77c84e7d2be600000000000000000000000000000000b8e2054f8a912367e38a22ce773328ff000000000000000000000000000000007369736d6f2d636f6e6e6563742d76312e31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000061060a65146b3265c62fc8f3ae977c9b27260ff000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000a400000000000000000000000000000000000000000000000000000000000000f0000000000000000000000000000000000000000000000000000000000000013e000000000000000000000000000000000000000000000000000000000000018c000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000117bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f200000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0047544dc2f35dc1c4b885d8a39cb82608ebf83e3feed1f436171709d37d51a8a2526935b27d929b4b064636ece29905178ce4981e5f7b01f970d1cf8a6226b8c2ad15a49879fae99e9e00062b8ea9a660b1cb2579665f4358b6253bbc5a7be4c0fcea2b209a292c511231b684633fa201aee9def4d3b4fb137ba3910239316f9073bdd0d5e951032122e1ad1e07abc04c6600bf304115d03ffdc29b2a2caf15f2054b55ae9609f928b3d93ce05cc82d6e29d0d9cab1ccbc24f59331630803cd4063e68ccf7a9a27348e46123914d2333734340acaa9dab114376f18e4b865fab15c93376b31f2736c6372123d2ea212c7a3567f978a9302722c2a8aee359192b0000000000000000000000000000000000000000000000000000000000000000214649c394fbf6e29bf4e81a343902ccc2f24ba2f2b04a2a3277ca2f7b5aa4091801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f20fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008ab1760889f26cbbf33a75fd2cf1696bfccdc9e600000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c02f50b16bfc61dc9c2f0c09fd67e91db58f2239be60dd0f9602dd3d8a8a15c603089fd93bba0dad603da177c2f11ac78412ee19bd5c7aefdd8b4f431a2ab5b5721eb5eb10c05df8bdcc3b7f97e8030aea630f698d62b840a34e61811f6a118cc726f6d0e2c7ea2341b3ff70a1f76df109feed6ef759423f041488cb2d951344cb1a9fc57246776ad917aec9ee1416540b23c40b8ba979da8b3c9eeb9f84bfde5510f3d0cce20b5e39b8633b3d6078b5f635e6aa200874aee8fa893c47104c3ec80a00a15e66a3e899111de783b97f43cfd7b0123e09ced51df86c390deb2a1786180eb8a60bcb504f1643e2ae2da2e016708cf5851524db2c1aa93a15656c39300000000000000000000000008ab1760889f26cbbf33a75fd2cf1696bfccdc9e6214649c394fbf6e29bf4e81a343902ccc2f24ba2f2b04a2a3277ca2f7b5aa4091801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f20fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000100100000000000000000000000000003577409700000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c00ed0c2b835363cf36bdfd3e557fce01eacfcf727275e17f33c6f0e406a75b2900e25d818d02c196094ecf6ba71e2a6f69ad14835602211a9de1cfcc1041fb14027498765b2b63ba02c0f26a189b93b17e243edb8e8f3195b6f97c61f47d78bf411c24f20aa363bacbd83d5ccf8f820601fc2970e55ddd7d403ef50efc60f4ebf19a3bd29e3aa810f5b87f54f64c85871c49fa35fa806205c547de02088702c1b03bb38c075a924ae8824e4b7828c1d254a70397c5b82ea7c2fc3632dcbe1140a16efdc2de7bda8929db7627b39ab8ae925c4fa36eb5f3488de5776a2c05b4e040358247d87f7a94afcbd5470b2eb635268ab8400d5cc90bb66183fe0e8605ff50000000000000000000000001001000000000000000000000000000035774097214649c394fbf6e29bf4e81a343902ccc2f24ba2f2b04a2a3277ca2f7b5aa4091801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f20fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000da1c3726426d5639f4c6352c2c976b87000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0200b870b6b98208d64a6a4a05b1e4bfb9f22922c115ae5dd7ff17a6a299acb152ec097dd3db6c9926960112a5320d3a65a0d12944c90719f0516125323879271057355333193b52f7423c4d13509425d9293e0cf27cddce4667a4e07da41ad6b2ee11ca5311ca4bcc0b7de512c868b5cb3daa27105beaa93ca759b80153d3df80fba9733a0e267e24de218f2723153eec9bf31f8a6fc51ad91b3b2effa6a6b350008859dc9c8eb5e7e9fa813bfc0ef9ac2b55d3bdba00f4e4be2d7c1ea13ee2d05e9098974f5741855eeb36a5d8921f915acdffbd7df6f7f40345598495f118d29acbb12432bc8d88957aead179cb8255c6852182308083ede772059510911100000000000000000000000000000000000000000000000000000000000000000214649c394fbf6e29bf4e81a343902ccc2f24ba2f2b04a2a3277ca2f7b5aa4091801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b04f0ace60fdf560415b93173156e67c6735946e9889973bfd56f1bcbe6fc5bcf047893723e9a7bacfb1a78d3cd7a46475d5235d4e6539843243601e011ea612c297e95db0e54e9c86eaeee09512f6206998a6f3bd1b071767c582f637f1131350000000000000000000000000000000000000000000000000000000000000001188afd5abda6d59313851e5226920a12cb91d3438c8e3dbaf07829b03ffffffc000000000000000000000000000000000000000000000000000000000000000017bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f20fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000085c7ee90829de70d0d51f52336ea4722000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c022bea6b85886dee008027530930cc26baf788b020b9401f114baab7ed8abaf2d2749fdcdb221b31bb9362905af39e36eadc9da9df12afbc302cefa3013387ca12ffa0f366307c0efb87d025ae1aae93a14b216e0af8b70ce0aa8ca0fde2ec85627cbe663d8f8a14ac1f26608740b0dff356872b44a070eaff87346978657e3cd043dfbd4adfc118a40614b28f92efef78b75731203220cb0b512c2e1f791f7bc28f4c97b27a44e2fd95a2697a7c5d9b57b8a136f99537da68e27346908590a9018abf5491106cecbed78655fa49410233167f4ac53f126074166172965de31dd20155e5b0433e1a672476a09510a3df44eb9875b6fc6a0b4dbeb4d25c5ebd49f0000000000000000000000000000000000000000000000000000000000000000214649c394fbf6e29bf4e81a343902ccc2f24ba2f2b04a2a3277ca2f7b5aa4091801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b04f0ace60fdf560415b93173156e67c6735946e9889973bfd56f1bcbe6fc5bcf26fe397125972c6a5376a768ad125e677b231ecd6aba4f42b2ba35563ecf7f1d05b412ea09364d5333c4bf39518baeec82596273ee6351b0a4ce42429cdb1ec1000000000000000000000000000000000000000000000000000000000000000424ff51aac03aa6b99cb169b633e796681bf9a3d480011edd783c14d81ffffffe000000000000000000000000000000000000000000000000000000000000000017bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f20fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002fae674b6cba3ff2f8ce2114defb200b1000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c001198ba630cf788a0ed3cb2f1ddc11c8baff54595185d9065899967a228046fd0786997fbfa50284fb978fd9f2e4ebb511a473bd14573090a4614b283d8c49230ac7248891c0d967b50b52f090ed9fc5f05b93a3473d5fd667d84f878fa82c701e8e6811710d8fbd247f9a91e9ed2797028f9726bc96fa89687f8dee79d526001220876eeb625ce5cab9d088058a94e7d70eba9899fa7ff8f2d67217136d788313c1e2bff0cf8f09f2c6bc3342ead78b1b1d499d79b34c52a18077b5674d44332076f464760de54fc68a8e49040af7f02d5cc90fe8fb75e1eaab6d3279a0aa87110b7635aae4f499c80aa0af433d83c10fdce8c969e480a19542360d134cee790000000000000000000000000000000000000000000000000000000000000000214649c394fbf6e29bf4e81a343902ccc2f24ba2f2b04a2a3277ca2f7b5aa4091801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b04f0ace60fdf560415b93173156e67c6735946e9889973bfd56f1bcbe6fc5bcf223889be50de6309c4a51edd039aa1fb882c9964a746581ff319bbe982debcf82efc4cc7c03398856dbf08377861fb15549f5a9137456a615d4da264e7d69cd4000000000000000000000000000000000000000000000000000000000000000a08f0ec7865abde5ef350b4bd682b46dfa35deafb12d4cd29ac96341c4ffffffb000000000000000000000000000000000000000000000000000000000000000117bf88d1838c2d751d4024ecfb1380715632ca591ce68f8067d85d2c8d8939f20fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + + // balance should be zero before airdrop claiming + assertEq(airdrop.balanceOf(claimAddress), 0); + + // verify ZK proofs contained in response + airdrop.claimWithSismo({response: response, to: claimAddress}); + + // balance should be updated witht the right amount of tokens after proofs verification + assertEq(airdrop.balanceOf(claimAddress), 6 * 10 ** 18); + } +} diff --git a/tests/sismo-connect-config.test.json b/tests/sismo-connect-config.test.json new file mode 100644 index 0000000..f816faa --- /dev/null +++ b/tests/sismo-connect-config.test.json @@ -0,0 +1,33 @@ +{ + "appId": "0x32403ced4b65f2079eda77c84e7d2be6", + "isImpersonationMode": true, + "authRequests": [ + { + "authType": 0 + }, + { + "authType": 3 + }, + { + "authType": 1, + "isOptional": true + } + ], + "claimRequests": [ + { + "groupId": "0xda1c3726426d5639f4c6352c2c976b87" + }, + { + "groupId": "0x85c7ee90829de70d0d51f52336ea4722", + "claimType": 0, + "value": 4, + "isSelectableByUser": true + }, + { + "groupId": "0xfae674b6cba3ff2f8ce2114defb200b1", + "claimType": 2, + "value": 10, + "isOptional": true + } + ] +}