Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fork tests using cheatsheet #2

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/forge.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]:"
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
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,36 @@
</p>
</div>


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
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
Expand Down
27 changes: 27 additions & 0 deletions test/CheatSheet.t.sol

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions test/base/BaseTest.t.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
92 changes: 92 additions & 0 deletions test/misc/CheatSheet.sol
Original file line number Diff line number Diff line change
@@ -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]);
}
}