From 52441ae8f880071944db8ecba6d1dc1202016182 Mon Sep 17 00:00:00 2001 From: bigq <99990370+yum0e@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:56:05 +0200 Subject: [PATCH] feat: add fork tests using cheatsheet contract as example (#2) --- .github/workflows/forge.yml | 27 +++++++++++ README.md | 16 ++----- test/CheatSheet.t.sol | 27 +++++++++++ test/base/BaseTest.t.sol | 32 +++++++++++++ test/misc/CheatSheet.sol | 92 +++++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/forge.yml create mode 100644 test/CheatSheet.t.sol create mode 100644 test/base/BaseTest.t.sol create mode 100644 test/misc/CheatSheet.sol diff --git a/.github/workflows/forge.yml b/.github/workflows/forge.yml new file mode 100644 index 0000000..147dc15 --- /dev/null +++ b/.github/workflows/forge.yml @@ -0,0 +1,27 @@ +on: [push] + +name: Forge Tests + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Install submodules + run: | + git config --global url."https://github.com/".insteadOf "git@github.com:" + git submodule update --init --recursive + - name: Install dependencies + run: forge install + + - name: Compile + run: forge build + + - name: Run Forge tests + run: forge test --fork-url https://rpc.ankr.com/polygon_mumbai -vvvv \ No newline at end of file diff --git a/README.md b/README.md index ef50180..fd65e92 100644 --- a/README.md +++ b/README.md @@ -23,32 +23,26 @@

- -Sismo Connect Solidity is a Solidity library that allows you to verify the zk-proofs of your Sismo Connect Application onchain and simplify the use of the [sismo-connect-onchain-verifier](https://github.com/sismo-core/sismo-connect-onchain-verifier). +Sismo Connect Solidity is a Solidity library that allows you to verify the zk-proofs of your Sismo Connect Application onchain. Here is the link to the full documentation of the library: [Sismo Connect Solidity Library](https://docs.sismo.io/build-with-sismo-connect/technical-documentation/solidity) -You can learn more on Sismo Connect [here](https://docs.sismo.io/discover-sismo-connect/empower-your-app). +You can learn more on Sismo Connect [here](https://docs.sismo.io/sismo-docs/build-with-sismo-connect/getting-started). ### Prerequisites - [Node.js](https://nodejs.org/en/download/) >= 18.15.0 (Latest LTS version) - [Yarn](https://classic.yarnpkg.com/en/docs/install) - [Foundry](https://book.getfoundry.sh/) - ## Usage - ### Installation - ```bash # update foundry foundryup - # install the package forge install sismo-core/sismo-connect-solidity --no-commit - # add the remapping in remappings.txt -echo $'sismo-connect-solidity/=lib/sismo-connect-packages/src/' >> remappings.txt +echo $'sismo-connect-solidity/=lib/sismo-connect-solidity/src/' >> remappings.txt ``` ### Import the library @@ -56,9 +50,9 @@ In your solidity file: ```solidity // SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; +pragma solidity ^0.8.20; -import "sismo-connect-solidity/SismoLib.sol"; // import the library +import "sismo-connect-solidity/SismoConnectLib.sol"; // import the library ``` ## License diff --git a/test/CheatSheet.t.sol b/test/CheatSheet.t.sol new file mode 100644 index 0000000..dcf5a8c --- /dev/null +++ b/test/CheatSheet.t.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.17; + +import "forge-std/console.sol"; +import "src/utils/Fmt.sol"; +import {SismoConnect, RequestBuilder, ClaimRequestBuilder} from "src/SismoConnectLib.sol"; +import {CheatSheet} from "test/misc/CheatSheet.sol"; +import "src/utils/Structs.sol"; +import {AuthBuilder} from "src/utils/AuthBuilder.sol"; +import {ClaimBuilder} from "src/utils/ClaimBuilder.sol"; +import {BaseTest} from "test/base/BaseTest.t.sol"; + +contract CheatSheetTest is BaseTest { + CheatSheet cheatsheet; + + function setUp() public { + cheatsheet = new CheatSheet(); + } + + function test_CheatSheet() public { + _registerTreeRoot(6019938179908949948260031779305182307740658158839075528652774771326767878672); + bytes + memory responseBytes = hex"000000000000000000000000000000000000000000000000000000000000002032403ced4b65f2079eda77c84e7d2be600000000000000000000000000000000b8e2054f8a912367e38a22ce773328ff000000000000000000000000000000007369736d6f2d636f6e6e6563742d76312e31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d49206c6f7665205369736d6f2100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000ac00000000000000000000000000000000000000000000000000000000000000f80000000000000000000000000000000000000000000000000000000000000144000000000000000000000000000000000000000000000000000000000000019000000000000000000000000000000000000000000000000000000000000001de000000000000000000000000000000000000000000000000000000000000022c000000000000000000000000000000000000000000000000000000000000027a00000000000000000000000000000000000000000000000000000000000002c8000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c02ee756e8d291546c67b5573b9b751b5bd5a0dbcede35464ef2a6e2c14f11b033151164d686f667393f18dcd27584954f2126998bcbed6ed9b9982cd99069bb830d2e1f84055faad2b66fd81c5db45b47356df5f8a3e3c3f852b63ffb83579b25221a09032e42863c6847ff2dd1ad2843628b7cae34ce0eee41c2c95829526ba611abc4b47a83f51174c44304a3ec7fc5e0a4d2661c6e0516f1f932c5258d788a14165f2fac0ff540383b5d74113f799dc98b5e6bc9cad1d8c1706b8606ff7d400877d9fc97b985ab302afe17621dd1ede1379dc2671aeb791d104097ce7a2b7c2d27c3487bda0b24a491c70c021aee29840c77400e3612e6959cd78c1d29e55000000000000000000000000000000000000000000000000000000000000000001304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008ab1760889f26cbbf33a75fd2cf1696bfccdc9e600000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c024d4b21c846468fc5e45041225279dbaf181db1d30c0ca47ba531e2139d9eaf7280d33b782823298589f29aaba714eea5acb96ebe2826de93f633d7f3c0a008f2f32d3204f8911a2bcfa70a0ef4e197b1807f8cfbb23f8e5686d79ccce4a40a10d7cf559488b27861bd1cc1b63275ccdceb49daaf8639ee099df558ceec868ed0edc00ae97888c6e213a4922f25c33e2e9de1d9a84f65101e071ac07297799eb2ca5e5cc67ee3d6c3a747ee9f0da812d8cbcb477a162dcabc40860092b8e4985049dded4313ca1c7fd8c2bb2341dc239b4c0b7db930ecc7e2b849e5dcdfe9317247dc2c6229691441432bffb6228a40d4096290a347bed1a215bf4203b6932a80000000000000000000000008ab1760889f26cbbf33a75fd2cf1696bfccdc9e61304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4c94a6091545e40fc9c3e0982aec8942e282f3800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c005e9a85d4b9401511669228989a3ff0c30b5b9f459e900fc75d4ab9a70c49ef80e46b75f5cf3bccbf05d7af71f87fe8d132b7f85a1607b0bfd6e4feaa8213f9f1063f2f84a7ce96e52f5e43003dfab677a74c1ec96a1d626225a4033cde26ebc0e54e534d6de2002f1a08033821a7fd348fd0f9dae7e85e0796f76319ff8c8e5251c6201cecdbd21885dd4d341227cdbf8f7f5693146166d99192c0ada581d5924b9ebe2e3dd193f95bbfc462a64bddcce25b799936a919452a704138a60c35d1534cb185dc6762a446321ad3b0ac40720cde123c86d8ada6ed050b0c106adc81ee271099e4702a5925e134d668eea626c19b220a2c39dd16d0400168d99d791000000000000000000000000a4c94a6091545e40fc9c3e0982aec8942e282f381304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000100100000000000000000000000000003577409700000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0137081498c847bdc10ace33d22949bfc73b674d4812b66a8f53e878ddffc190f0cda340c783fd25566dfd14394dcc8fc9e7af60237bbec04d70b097721f7e6e70e0998b7010de2546274bb5c03238e5ffd2340c319ba85327f11e8dd0279f1f217e1c040a49739304d4025d7c42d97f2b41102d4b504b49693666d6fffae1ea5279e58b6b2a415acd5db0706921a85985d348386637463751a7de73448ac35fd215517307d716502bc580dff5ba4c8f484eeb7a1f2f9cc69f49052a09f6887b70803efb5635d81e2f07eb7ae6024bcd4ffd2b927209865e183747523f7d274c51464ceea457eb61b7c2a132177ec531842ceb568a51fe6a4e145a0f9a564a0ee00000000000000000000000010010000000000000000000000000000357740971304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001a068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100300000000000000000000000000087560811000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c01cab87335090f31f2c858c45dbe40ac1e3fd5eda4b584bbc8b8784991a5c9f91041986364178d5d6a6a9cfbe96e6679111feff038be558c436df97c113d8f10e25b99ceb0082c9df5bb7e90739e1c1f4d4588bae1169c88c5422356294e86b7e0b43cb521b0b664462993aea9666d18a84e6684afeed6ba49b0b42402b67685e0b82bfa1c7724f214cd6fd624e7300ab4372f955ebfd9b489aa935ed5e074eb2239b65a6f9f51888891d69f57ce2d4a6fd1a1594d77090edf526d16242feb4a2157bec5129edd6e86f43d73f12b2561250a8835cfa5eb1533f1a15d5d1513ca11129beec3cd8288b1beb42352734cb93173f72679402a51db226dbe1a01ce49900000000000000000000000010030000000000000000000000000008756081101304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000fae674b6cba3ff2f8ce2114defb200b1000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0068a54cba7e80eea17652e5399bac0f373a37289e19e4990f03b14f5304ba97b0e86c7b9ff626dad18a91068c36cfaca3b4bba8c23ccbd8aa89a50478632bb3808dac983625c650c8ee73594fd9b6cc609696db35f213f4efa3c7355436c61d9273d66565e35cd47df9763521fcb24813b0070b920aa7d13206d3f541540a4542ff6e85db5be75a22c067551f70000275568339f0e67155907ce6aaacdd9c35120e1c6f0752cb5565b7324847eadc5b568b60b356976f6194b59cddd32f72bcd0c60c6907df2d4e1dfc7fd7cafb77170d74deed3b60f4565d8814ad3345c489d2073030d081ad0615e2898c77db05842544e08d1909daffd4b1f51af41d0c1a600000000000000000000000000000000000000000000000000000000000000001304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b0d4f2a0d3c9c82fbdb9f118c948baa9d8c0b2f467855c6b4cb43a95631d85210223889be50de6309c4a51edd039aa1fb882c9964a746581ff319bbe982debcf82efc4cc7c03398856dbf08377861fb15549f5a9137456a615d4da264e7d69cd4000000000000000000000000000000000000000000000000000000000000000108f0ec7865abde5ef350b4bd682b46dfa35deafb12d4cd29ac96341c4ffffffb000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000001cde61966decb8600dfd0749bd371f12000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c02c7c25b4657897bdb2bc62112bdac39f1fcb4fd090b44a73b9e17125754d0f9a26321b26cb19ac752eb7f7557ef0b868d9e1c0cb22a6f3354d8bf1eae8efb02f2ea24f5c4265ed8439dfa93a3742164e91bad77e6fee1b2f88ecd7c58fbe802027f44df7403fb133ce8cc8c5fd23b458c4bc53c455727e28d753bfea20f1445d2182c405df59bec7da832b42cfa3edbbd48bdf42dbfb073950d13ee7b0a55f1c1d4eb48a63d9d4f67c61a932a830101e76b501cd1145ffc755d8d5450b554bbd2fbd2b04120d8ef1e5bd290b00ff4a25a917bccfa03f13da4f70e7d30ac792932e716a0f4c76aa9a197419c2125257cfcfd36fd4e7c7de28c145ec429e3c5a1700000000000000000000000000000000000000000000000000000000000000001304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b0d4f2a0d3c9c82fbdb9f118c948baa9d8c0b2f467855c6b4cb43a95631d852101e7a3215d4d02e734fa653c5ca96357521ac260e6ba94a1f05c413b0143e15bd2113caea8c11ac1bdcde3d297ebd9f24df376b1ae881a18e62e49c81b5db8267000000000000000000000000000000000000000000000000000000000000000f1cde61966decb8600dfd0749bd371f126c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002fae674b6cba3ff2f8ce2114defb200b1000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0107ecc33ddbb094a870b4f300a5fff992ce214effaf8e441b1d3de2d2b9ae0a012842d6a54fd89bc48444701e99eb26114f4bf767490bb13d0446f214c55ce7603ecc0efc47b9d2fe6683d856ddc141d234da6e80845263c4bcc1e823443da430c50c00649710842967c9755f99bafc7219a19fad38cce29f1bcf1316c1469061c0b6468c29704188ddece490bd2723cc392b4ca7b1f6501c6469236cb535bf61df114f50ba48448088c440823c7cf811003b2c1707f124d8ab2b262c7400c982b14db09cfabca6f7fd817457ae68a882cbd72c01839cc326408e938e3deb0140323af36a396c8b906ecfda2d92e82383e4693cef14d94a2b2b77f4b61b3859000000000000000000000000000000000000000000000000000000000000000001304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b0d4f2a0d3c9c82fbdb9f118c948baa9d8c0b2f467855c6b4cb43a95631d85210223889be50de6309c4a51edd039aa1fb882c9964a746581ff319bbe982debcf82efc4cc7c03398856dbf08377861fb15549f5a9137456a615d4da264e7d69cd4000000000000000000000000000000000000000000000000000000000000000a08f0ec7865abde5ef350b4bd682b46dfa35deafb12d4cd29ac96341c4ffffffb000000000000000000000000000000000000000000000000000000000000000110915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000fae674b6cba3ff2f8ce2114defb200b1000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c02699914aaa5bb1b11b49261603cd894aee490c39b8ca5ea5c1625f05c60c3e2e2e4bef13a3cc0df3f3dc1bf5d601b699f4c2d94b1ca2b62622f91874f3a600832f057ff2148e63bc50db8c9f049e33929d195610f8b8a826d75941d2ef7c46ef1a108ab29c16b6498990fa5767f4e3594648c444a71dd16924366d03e1f31a9813f954aaf7916663320a9baa8de31cb14f3e4ce8fb7fc88d7ae2356f8d91404f1c21b77322002fdfcea7df847cf31f4dc7c4485d535392f4583aa67eb63bfcd214ca04a230eca28910992acf54cb9682f8b7a4240b193ccdd7ac081181e9ee3f1fbfc685affa356338b832c8c49dc2d33cafb950af2377e2ea73e53cc101020400000000000000000000000000000000000000000000000000000000000000001304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b0d4f2a0d3c9c82fbdb9f118c948baa9d8c0b2f467855c6b4cb43a95631d85210223889be50de6309c4a51edd039aa1fb882c9964a746581ff319bbe982debcf82efc4cc7c03398856dbf08377861fb15549f5a9137456a615d4da264e7d69cd4000000000000000000000000000000000000000000000000000000000000000108f0ec7865abde5ef350b4bd682b46dfa35deafb12d4cd29ac96341c4ffffffb000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c068796472612d73332e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000001cde61966decb8600dfd0749bd371f12000000000000000000000000000000006c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001900000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c01376d89c862093d8af4faece2845d584a7f5adbce6415f91185445053066db272b55dfb2d1f4d34239c3dde1e396bec29e5a1398dc9cc589a1c4a01dc6b5a190038bbde989bdaa41ae06c00e806e8b05698557a1ee2b7bcba05173cb72e5a22b2b4b2be01439457de5fbee80ca58c442b0a98239810cd611ab1db95e2806d81a194d33e4750fa3d1dc0417bc8c620935c888ad3a5af607fc4ccf21af83b539980c8017f171ea205708d7d16dd2d6968682c92a4f6aa60c4a2b397849c064f1d71f2c626c4108ab3566301144a75f0964791e8770d014da3c6b986cadc296763d19d3935c9924bd88b558920f376f4cd31833d1f69dcaa8b747bd8fab8a83305300000000000000000000000000000000000000000000000000000000000000001304dc6e4c90bc43f257c55a1c5ec90070d73f4356bca95b502a7bbc28d13a071801b584700a740f9576cc7e83745895452edc518a9ce60b430e1272fc4eb93b057cf80de4f8dd3e4c56f948f40c28c3acbeca71ef9f825597bf8cc059f1238b0d4f2a0d3c9c82fbdb9f118c948baa9d8c0b2f467855c6b4cb43a95631d852101e7a3215d4d02e734fa653c5ca96357521ac260e6ba94a1f05c413b0143e15bd2113caea8c11ac1bdcde3d297ebd9f24df376b1ae881a18e62e49c81b5db826700000000000000000000000000000000000000000000000000000000000000191cde61966decb8600dfd0749bd371f126c617465737400000000000000000000000000000000000000000000000000000000000000000000000000000000000010915e40a7c9ce7f97e81541c24893b4f714de4794fc4a3c71898cb9f25bb55f0fe61c3a8c717465050c08081b2efe7d66020da96e00293df4c354c783d06b6b000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; + + cheatsheet.verifySismoConnectResponse(responseBytes); + } +} diff --git a/test/base/BaseTest.t.sol b/test/base/BaseTest.t.sol new file mode 100644 index 0000000..cbe85c2 --- /dev/null +++ b/test/base/BaseTest.t.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import "forge-std/Test.sol"; +import "forge-std/console.sol"; +import {IAddressesProvider} from "src/SismoConnectLib.sol"; + +interface IAvailableRootsRegistry { + event RegisteredRoot(uint256 root); + + function registerRoot(uint256 root) external; + + function owner() external view returns (address); +} + +contract BaseTest is Test { + IAddressesProvider sismoAddressesProvider = + IAddressesProvider(0x3Cd5334eB64ebBd4003b72022CC25465f1BFcEe6); + IAvailableRootsRegistry availableRootsRegistry; + + function _registerTreeRoot(uint256 root) internal { + // get availableRootsRegistry from the sismoAddressesProvider + availableRootsRegistry = IAvailableRootsRegistry( + sismoAddressesProvider.get("sismoConnectAvailableRootsRegistry") + ); + address rootsRegistryOwner = availableRootsRegistry.owner(); + // prank to the rootsRegistryOwner + vm.startPrank(rootsRegistryOwner); + availableRootsRegistry.registerRoot(root); + vm.stopPrank(); + } +} diff --git a/test/misc/CheatSheet.sol b/test/misc/CheatSheet.sol new file mode 100644 index 0000000..cbe7fae --- /dev/null +++ b/test/misc/CheatSheet.sol @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import "src/SismoConnectLib.sol"; +import "forge-std/console.sol"; + +contract CheatSheet is SismoConnect { + // reference your appId + bytes16 private _appId = 0x32403ced4b65f2079eda77c84e7d2be6; + // allow impersonation + bool private _isImpersonationMode = true; + + constructor() + // use buildConfig helper to easily build a Sismo Connect config in Solidity + SismoConnect(buildConfig({appId: _appId, isImpersonationMode: _isImpersonationMode})) + {} + + function verifySismoConnectResponse(bytes memory response) public { + // Recreate the request made in the fontend to verify the proof + AuthRequest[] memory auths = new AuthRequest[](6); + auths[0] = _authRequestBuilder.build({authType: AuthType.VAULT}); + auths[1] = _authRequestBuilder.build({authType: AuthType.EVM_ACCOUNT}); + auths[2] = _authRequestBuilder.build({ + authType: AuthType.EVM_ACCOUNT, + userId: uint160(0xA4C94A6091545e40fc9c3E0982AEc8942E282F38) + }); + auths[3] = _authRequestBuilder.build({authType: AuthType.GITHUB}); + auths[4] = _authRequestBuilder.build({ + authType: AuthType.TWITTER, + userId: 295218901, + isOptional: true, + isSelectableByUser: false + }); + auths[5] = _authRequestBuilder.build({ + authType: AuthType.TELEGRAM, + userId: 875608110, + isOptional: true, + isSelectableByUser: false + }); + + ClaimRequest[] memory claims = new ClaimRequest[](6); + claims[0] = _claimRequestBuilder.build({groupId: 0xfae674b6cba3ff2f8ce2114defb200b1}); + claims[1] = _claimRequestBuilder.build({ + groupId: 0x1cde61966decb8600dfd0749bd371f12, + claimType: ClaimType.GTE, + value: 15 + }); + claims[2] = _claimRequestBuilder.build({ + groupId: 0xfae674b6cba3ff2f8ce2114defb200b1, + claimType: ClaimType.EQ, + value: 10 + }); + claims[3] = _claimRequestBuilder.build({ + groupId: 0x1cde61966decb8600dfd0749bd371f12, + claimType: ClaimType.EQ, + value: 15, + isSelectableByUser: true, + isOptional: true + }); + claims[4] = _claimRequestBuilder.build({ + groupId: 0xfae674b6cba3ff2f8ce2114defb200b1, + claimType: ClaimType.GTE, + isSelectableByUser: true, + isOptional: true + }); + claims[5] = _claimRequestBuilder.build({ + groupId: 0x1cde61966decb8600dfd0749bd371f12, + claimType: ClaimType.GTE, + value: 25, + isSelectableByUser: true, + isOptional: false + }); + + SismoConnectVerifiedResult memory result = verify({ + responseBytes: response, + auths: auths, + claims: claims, + signature: _signatureBuilder.build({message: abi.encode("I love Sismo!")}) + }); + + uint256 vaultId = SismoConnectHelper.getUserId(result, AuthType.VAULT); + uint256 githubId = SismoConnectHelper.getUserId(result, AuthType.GITHUB); + uint256 telegramId = SismoConnectHelper.getUserId(result, AuthType.TELEGRAM); + uint256[] memory evmAccountIds = SismoConnectHelper.getUserIds(result, AuthType.EVM_ACCOUNT); + + console.log("Vault ID: %s", vaultId); + console.log("Github ID: %s", githubId); + console.log("Telegram ID: %s", telegramId); + console.log("First EVM Account ID: %s", evmAccountIds[0]); + console.log("Second EVM Account ID: %s", evmAccountIds[1]); + } +}