Skip to content

Commit

Permalink
feat: init fork tests from Fork.t.sol instead from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e committed Jul 27, 2023
1 parent 84f59dd commit 06fc03e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
run: forge build

- name: Run Forge tests
run: forge test --fork-url https://gateway.tenderly.co/public/polygon-mumbai -vvvv
run: forge test -vvvv
20 changes: 12 additions & 8 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ fs_permissions = [{ access = "read-write", path = "./"}]

bytecode_hash="none"

[fmt]
ignore = ["test/libs/SimoConnectLib.t.sol"]

[rpc_endpoints]
polygon = "${RPC_URL}"
gnosis = "${RPC_URL}"
goerli = "${RPC_URL}"
mumbai = "${RPC_URL}"
mainnet = "${RPC_URL}"
arbitrum_one = "https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
arbitrum_goerli = "https://arb-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
goerli = "https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
gnosis = "https://rpc.gnosischain.com"
localhost = "http://localhost:8545"
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
mumbai = "https://polygon-mumbai.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
optimism = "https://opt-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
optimism_goerli = "https://opt-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
polygon = "https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
scroll_testnet_goerli = "https://alpha-rpc.scroll.io/l2"
sepolia = "https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prettier-plugin-solidity": "^1.0.0-beta.13"
},
"scripts": {
"test": "forge test --fork-url https://gateway.tenderly.co/public/polygon-mumbai",
"test": "forge test",
"lint": "prettier --write **.sol"
}
}
40 changes: 0 additions & 40 deletions test/base/BaseTest.t.sol

This file was deleted.

52 changes: 52 additions & 0 deletions test/fork/Fork.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "forge-std/Test.sol";
import "forge-std/console.sol";
import {IAddressesProvider, AuthRequestBuilder, ClaimRequestBuilder, SignatureBuilder, RequestBuilder} from "src/SismoConnectLib.sol";

interface IAvailableRootsRegistry {
event RegisteredRoot(uint256 root);

function registerRoot(uint256 root) external;

function owner() external view returns (address);
}

contract ForkTest is Test {
IAddressesProvider sismoAddressesProvider;
IAvailableRootsRegistry availableRootsRegistry;

AuthRequestBuilder authRequestBuilder;
ClaimRequestBuilder claimRequestBuilder;
SignatureBuilder signatureBuilder;
RequestBuilder requestBuilder;

function setUp() public virtual {
vm.createSelectFork({urlOrAlias: "mainnet"});

sismoAddressesProvider = IAddressesProvider(0x3Cd5334eB64ebBd4003b72022CC25465f1BFcEe6);
availableRootsRegistry = IAvailableRootsRegistry(
sismoAddressesProvider.get(string("sismoConnectAvailableRootsRegistry"))
);

authRequestBuilder = AuthRequestBuilder(
sismoAddressesProvider.get(string("authRequestBuilder-v1.1"))
);
claimRequestBuilder = ClaimRequestBuilder(
sismoAddressesProvider.get(string("claimRequestBuilder-v1.1"))
);
signatureBuilder = SignatureBuilder(
sismoAddressesProvider.get(string("signatureBuilder-v1.1"))
);
requestBuilder = RequestBuilder(sismoAddressesProvider.get(string("requestBuilder-v1.1")));
}

function _registerTreeRoot(uint256 root) internal {
address rootsRegistryOwner = availableRootsRegistry.owner();
// prank to the rootsRegistryOwner
vm.startPrank(rootsRegistryOwner);
availableRootsRegistry.registerRoot(root);
vm.stopPrank();
}
}
43 changes: 24 additions & 19 deletions test/fork/SismoConnectE2E.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "forge-std/console.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {BaseTest} from "../base/BaseTest.t.sol";
import {ForkTest} from "./Fork.t.sol";
import {CheatSheet} from "test/misc/CheatSheet.sol";
import {Proofs} from "./proofs/Proofs.sol";
import {ResponseBuilder, ResponseWithoutProofs} from "test/utils/ResponseBuilderLib.sol";
Expand All @@ -18,12 +18,10 @@ import "src/utils/Fmt.sol";
// E2E tests for SismoConnect Solidity Library
// These tests are fork tests made with proofs generated from the Vault App

contract SismoConnectE2E is BaseTest {
contract SismoConnectE2E_ForkTest is ForkTest {
using ResponseBuilder for SismoConnectResponse;
using ResponseBuilder for ResponseWithoutProofs;

Proofs proofs = new Proofs();

SismoConnectHarness sismoConnect;
address user = 0x7def1d6D28D6bDa49E69fa89aD75d160BEcBa3AE;

Expand All @@ -46,18 +44,22 @@ contract SismoConnectE2E is BaseTest {
ClaimRequest claimRequest;
AuthRequest authRequest;
SignatureRequest signature;
Proofs proofs;

bytes16 immutable APP_ID_ZK_DROP = 0x11b1de449c6c4adb0b5775b3868b28b3;
bytes16 immutable SISMO_CONTRIBUTORS_GROUP_ID = 0xe9ed316946d3d98dfcd829a53ec9822e;
ZKDropERC721 zkdrop;

CheatSheet cheatsheet;

function setUp() public {
function setUp() public virtual override {
ForkTest.setUp();

sismoConnect = new SismoConnectHarness(DEFAULT_APP_ID, DEFAULT_IS_IMPERSONATION_MODE);
claimRequest = sismoConnect.exposed_buildClaim({groupId: 0xe9ed316946d3d98dfcd829a53ec9822e});
authRequest = sismoConnect.exposed_buildAuth({authType: AuthType.VAULT});
signature = sismoConnect.exposed_buildSignature({message: abi.encode(user)});
proofs = new Proofs();

zkdrop = new ZKDropERC721({
appId: APP_ID_ZK_DROP,
Expand All @@ -73,7 +75,7 @@ contract SismoConnectE2E is BaseTest {
_registerTreeRoot(proofs.getRoot());
}

function test_SismoConnectLibWithOnlyClaimAndMessage() public view {
function testFork_SismoConnectLibWithOnlyClaimAndMessage() public view {
(, bytes memory responseEncoded) = proofs.getResponseWithOneClaimAndSignature();

sismoConnect.exposed_verify({
Expand All @@ -85,7 +87,7 @@ contract SismoConnectE2E is BaseTest {
});
}

function test_SismoConnectLibWithTwoClaimsAndMessage() public view {
function testFork_SismoConnectLibWithTwoClaimsAndMessage() public view {
(, bytes memory responseEncoded) = proofs.getResponseWithTwoClaimsAndSignature();

ClaimRequest[] memory claims = new ClaimRequest[](2);
Expand All @@ -101,7 +103,7 @@ contract SismoConnectE2E is BaseTest {
});
}

function test_SismoConnectLibWithOnlyOneAuth() public {
function testFork_SismoConnectLibWithOnlyOneAuth() public {
(, bytes memory responseEncoded) = proofs.getResponseWithOnlyOneAuthAndMessage();

SismoConnectRequest memory request = requestBuilder.build({
Expand All @@ -116,7 +118,7 @@ contract SismoConnectE2E is BaseTest {
assertTrue(verifiedResult.auths[0].userId != 0);
}

function test_SismoConnectLibWithClaimAndAuth() public {
function testFork_SismoConnectLibWithClaimAndAuth() public {
(, bytes memory responseEncoded) = proofs.getResponseWithOneClaimOneAuthAndOneMessage();
SismoConnectRequest memory request = requestBuilder.build({
auth: sismoConnect.exposed_buildAuth({authType: AuthType.VAULT}),
Expand All @@ -131,7 +133,7 @@ contract SismoConnectE2E is BaseTest {
assertTrue(verifiedResult.auths[0].userId != 0);
}

function test_ClaimAndAuthWithSignedMessageZKDROP() public {
function testFork_ClaimAndAuthWithSignedMessageZKDROP() public {
// address that reverts if not modulo SNARK_FIELD after hashing the signedMessage for the circuit
// should keep this address for testing purposes
user = 0x7def1d6D28D6bDa49E69fa89aD75d160BEcBa3AE;
Expand All @@ -144,7 +146,7 @@ contract SismoConnectE2E is BaseTest {
zkdrop.claimWithSismoConnect(responseEncoded, user);
}

function test_TwoClaimsOneVaultAuthWithSignature() public view {
function testFork_TwoClaimsOneVaultAuthWithSignature() public view {
ClaimRequest[] memory claims = new ClaimRequest[](2);
claims[0] = claimRequestBuilder.build({groupId: 0xe9ed316946d3d98dfcd829a53ec9822e});
claims[1] = claimRequestBuilder.build({groupId: 0x02d241fdb9d4330c564ffc0a36af05f6});
Expand All @@ -167,7 +169,7 @@ contract SismoConnectE2E is BaseTest {
console.log("Claims in Verified result: %s", verifiedResult.claims.length);
}

function test_ThreeClaimsOneVaultAuthWithSignatureOneClaimOptional() public view {
function testFork_ThreeClaimsOneVaultAuthWithSignatureOneClaimOptional() public view {
ClaimRequest[] memory claims = new ClaimRequest[](3);
claims[0] = claimRequestBuilder.build({groupId: 0xe9ed316946d3d98dfcd829a53ec9822e});
claims[1] = claimRequestBuilder.build({groupId: 0x02d241fdb9d4330c564ffc0a36af05f6});
Expand Down Expand Up @@ -195,7 +197,10 @@ contract SismoConnectE2E is BaseTest {
console.log("Claims in Verified result: %s", verifiedResult.claims.length);
}

function test_ThreeClaimsOneVaultAuthOneTwitterAuthWithSignatureOneClaimOptional() public view {
function testFork_ThreeClaimsOneVaultAuthOneTwitterAuthWithSignatureOneClaimOptional()
public
view
{
ClaimRequest[] memory claims = new ClaimRequest[](3);
claims[0] = claimRequestBuilder.build({groupId: 0xe9ed316946d3d98dfcd829a53ec9822e});
claims[1] = claimRequestBuilder.build({groupId: 0x02d241fdb9d4330c564ffc0a36af05f6});
Expand Down Expand Up @@ -228,7 +233,7 @@ contract SismoConnectE2E is BaseTest {
console.log("Claims in Verified result: %s", verifiedResult.claims.length);
}

function test_OneClaimOneOptionalTwitterAuthOneGithubAuthWithSignature() public view {
function testFork_OneClaimOneOptionalTwitterAuthOneGithubAuthWithSignature() public view {
ClaimRequest[] memory claims = new ClaimRequest[](1);
claims[0] = claimRequestBuilder.build({groupId: 0xe9ed316946d3d98dfcd829a53ec9822e});

Expand Down Expand Up @@ -256,7 +261,7 @@ contract SismoConnectE2E is BaseTest {
console.log("Claims in Verified result: %s", verifiedResult.claims.length);
}

function test_GitHubAuth() public view {
function testFork_GitHubAuth() public view {
(, bytes memory encodedResponse) = proofs.getResponseWithGitHubAuth();

SismoConnectRequest memory request = requestBuilder.build({
Expand All @@ -267,7 +272,7 @@ contract SismoConnectE2E is BaseTest {
sismoConnect.exposed_verify({responseBytes: encodedResponse, request: request});
}

function test_GitHubAuthWithoutSignature() public view {
function testFork_GitHubAuthWithoutSignature() public view {
(, bytes memory encodedResponse) = proofs.getResponseWithGitHubAuthWithoutSignature();

SismoConnectRequest memory request = requestBuilder.build({
Expand All @@ -277,7 +282,7 @@ contract SismoConnectE2E is BaseTest {
sismoConnect.exposed_verify({responseBytes: encodedResponse, request: request});
}

function test_withProxy() public {
function testFork_withProxy() public {
SignatureRequest memory signatureRequest = sismoConnect.exposed_buildSignature({
message: abi.encode(user)
});
Expand Down Expand Up @@ -317,7 +322,7 @@ contract SismoConnectE2E is BaseTest {
upgradeable.exposed_verify({responseBytes: responseEncoded, signature: signatureRequest});
}

function test_RevertWithInvalidSismoIdentifier() public {
function testFork_RevertWithInvalidSismoIdentifier() public {
(SismoConnectResponse memory response, ) = proofs.getResponseWithGitHubAuthWithoutSignature();

// specify in the response that the proof comes from a telegram ownership
Expand All @@ -339,7 +344,7 @@ contract SismoConnectE2E is BaseTest {
sismoConnect.exposed_verify({responseBytes: abi.encode(response), request: request});
}

function test_CheatSheet() public view {
function testFork_CheatSheet() public view {
bytes memory responseBytes = proofs.getCheatSheetResponse();
cheatsheet.verifySismoConnectResponse(responseBytes);
}
Expand Down

0 comments on commit 06fc03e

Please sign in to comment.