feat: foundry integration

This commit is contained in:
rymnc 2023-03-29 12:28:42 +05:30
parent 5d59fbfe41
commit 2cc32d000a
No known key found for this signature in database
GPG Key ID: C740033EE3F41EBD
13 changed files with 81 additions and 9 deletions

View File

@ -1,3 +1,3 @@
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1 ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY> SEPOLIA_URL=https://eth-sepolia.alchemyapi.io/v2/<YOUR ALCHEMY KEY>
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1

4
.gitignore vendored
View File

@ -7,3 +7,7 @@ typechain
#Hardhat files #Hardhat files
cache cache
artifacts artifacts
#Foundry files
cache_forge
out

4
.gitmodules vendored Normal file
View File

@ -0,0 +1,4 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.5.2

View File

@ -1,4 +1,4 @@
// SPDX-License-Identifier: (MIT OR Apache-2.0) // SPDX-License-Identifier: MIT
// Forked from https://github.com/kilic/rlnapp/ // Forked from https://github.com/kilic/rlnapp/

View File

@ -1,4 +1,4 @@
// SPDX-License-Identifier: (MIT OR Apache-2.0) // SPDX-License-Identifier: MIT
pragma solidity 0.8.15; pragma solidity 0.8.15;

6
foundry.toml Normal file
View File

@ -0,0 +1,6 @@
[profile.default]
src = 'contracts'
out = 'out'
libs = ['node_modules', 'lib']
test = 'test'
cache_path = 'cache_forge'

View File

@ -3,24 +3,31 @@ import * as dotenv from "dotenv";
import { HardhatUserConfig } from "hardhat/config"; import { HardhatUserConfig } from "hardhat/config";
import { NetworksUserConfig } from "hardhat/types"; import { NetworksUserConfig } from "hardhat/types";
import "@nomicfoundation/hardhat-foundry";
import "hardhat-deploy"; import "hardhat-deploy";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-ethers"; import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-waffle"; import "@nomiclabs/hardhat-waffle";
import "hardhat-gas-reporter"; import "hardhat-gas-reporter";
import "solidity-coverage"; import "solidity-coverage";
dotenv.config(); dotenv.config();
const { SEPOLIA_URL, PRIVATE_KEY } = process.env; const { SEPOLIA_URL, PRIVATE_KEY, ETHERSCAN_API_KEY } = process.env;
const getNetworkConfig = (): NetworksUserConfig | undefined => { const getNetworkConfig = (): NetworksUserConfig | undefined => {
if (SEPOLIA_URL && PRIVATE_KEY) { if (SEPOLIA_URL && PRIVATE_KEY) {
return { return {
goerli: { sepolia: {
url: SEPOLIA_URL, url: SEPOLIA_URL,
accounts: [PRIVATE_KEY], accounts: [PRIVATE_KEY],
forking: { forking: {
url: SEPOLIA_URL, url: SEPOLIA_URL,
}, },
verify: {
etherscan: {
apiKey: ETHERSCAN_API_KEY,
}
}
}, },
localhost_integration: { localhost_integration: {
url: "http://localhost:8545", url: "http://localhost:8545",

1
lib/forge-std Submodule

@ -0,0 +1 @@
Subproject commit 2b58ecbcf3dfde7a75959dc7b4eb3d0670278de6

View File

@ -2,25 +2,30 @@
"name": "rln-contract", "name": "rln-contract",
"license": "(MIT OR Apache-2.0)", "license": "(MIT OR Apache-2.0)",
"scripts": { "scripts": {
"start": "hardhat node", "start": "hardhat node --export-all=deployments/allDeployments.json",
"compile": "hardhat compile", "compile": "hardhat compile",
"test": "yarn test:foundry && yarn test:hardhat",
"test:hardhat": "hardhat test", "test:hardhat": "hardhat test",
"test:hardhat:localhost": "yarn test:hardhat --network localhost", "test:hardhat:localhost": "yarn test:hardhat --network localhost",
"test:hardhat:sepolia": "yarn test:hardhat --network sepolia", "test:hardhat:sepolia": "yarn test:hardhat --network sepolia",
"test:foundry": "forge test", "test:foundry": "forge test",
"deploy": "hardhat run scripts/deploy.ts --network", "deploy": "hardhat deploy --export-all=deployments/allDeployments.json --network",
"deploy:sepolia": "yarn deploy sepolia", "deploy:sepolia": "yarn deploy sepolia",
"deploy:localhost": "yarn deploy localhost", "deploy:localhost": "yarn deploy localhost",
"verify:sepolia": "hardhat --network sepolia etherscan-verify",
"coverage": "hardhat coverage", "coverage": "hardhat coverage",
"fmt": "prettier --write \"**/*.{js,ts}\"", "fmt": "prettier --write \"**/*.{js,ts}\"",
"lint": "prettier --check \"**/*.{js,ts}\"", "lint": "prettier --check \"**/*.{js,ts}\"",
"prepare": "husky install" "prepare": "husky install"
}, },
"devDependencies": { "devDependencies": {
"@nomicfoundation/hardhat-foundry": "^1.0.0",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers", "@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@nomiclabs/hardhat-etherscan": "^3.1.0", "@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-waffle": "^2.0.3", "@nomiclabs/hardhat-waffle": "^2.0.3",
"@types/chai": "^4.3.6",
"@types/mocha": "^9.1.1", "@types/mocha": "^9.1.1",
"@types/node": "^16.11.6",
"chai": "^4.3.6", "chai": "^4.3.6",
"ethereum-waffle": "^3.4.4", "ethereum-waffle": "^3.4.4",
"ethers": "^5.7.2", "ethers": "^5.7.2",

28
test/PoseidonHasher.t.sol Normal file
View File

@ -0,0 +1,28 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.15;
import "../contracts/PoseidonHasher.sol";
import "forge-std/Test.sol";
contract PoseidonHasherTest is Test {
PoseidonHasher public poseidon;
/// @dev Setup the testing environment.
function setUp() public {
poseidon = new PoseidonHasher();
}
/// @dev Ensure that you can hash a value.
function testHasher(uint256 value) public {
assertEq(poseidon.hash(value), poseidon.hash(value));
}
function testHasher() public {
assertEq(
poseidon.hash(
19014214495641488759237505126948346942972912379615652741039992445865937985820
),
0x0c3ac305f6a4fe9bfeb3eba978bc876e2a99208b8b56c80160cfb54ba8f02368
);
}
}

View File

@ -659,6 +659,13 @@
mcl-wasm "^0.7.1" mcl-wasm "^0.7.1"
rustbn.js "~0.2.0" rustbn.js "~0.2.0"
"@nomicfoundation/hardhat-foundry@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-foundry/-/hardhat-foundry-1.0.0.tgz#14eba643138b09e4a8f2fed2a99bc9c96c487b0a"
integrity sha512-/2cmtIZPnsQj/SRIu9idbBan5j19RD35MECAGmZCcuXX4AO6Wn0nOnpUwpcvGomKW403h4+rXh8AHMWC4Vvw0Q==
dependencies:
chalk "^2.4.2"
"@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1": "@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1":
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz#4c858096b1c17fe58a474fe81b46815f93645c15" resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz#4c858096b1c17fe58a474fe81b46815f93645c15"
@ -730,7 +737,7 @@
resolved "https://registry.yarnpkg.com/hardhat-deploy-ethers/-/hardhat-deploy-ethers-0.3.0-beta.13.tgz#b96086ff768ddf69928984d5eb0a8d78cfca9366" resolved "https://registry.yarnpkg.com/hardhat-deploy-ethers/-/hardhat-deploy-ethers-0.3.0-beta.13.tgz#b96086ff768ddf69928984d5eb0a8d78cfca9366"
integrity sha512-PdWVcKB9coqWV1L7JTpfXRCI91Cgwsm7KLmBcwZ8f0COSm1xtABHZTyz3fvF6p42cTnz1VM0QnfDvMFlIRkSNw== integrity sha512-PdWVcKB9coqWV1L7JTpfXRCI91Cgwsm7KLmBcwZ8f0COSm1xtABHZTyz3fvF6p42cTnz1VM0QnfDvMFlIRkSNw==
"@nomiclabs/hardhat-etherscan@^3.1.0": "@nomiclabs/hardhat-etherscan@^3.1.7":
version "3.1.7" version "3.1.7"
resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-3.1.7.tgz#72e3d5bd5d0ceb695e097a7f6f5ff6fcbf062b9a" resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-etherscan/-/hardhat-etherscan-3.1.7.tgz#72e3d5bd5d0ceb695e097a7f6f5ff6fcbf062b9a"
integrity sha512-tZ3TvSgpvsQ6B6OGmo1/Au6u8BrAkvs1mIC/eURA3xgIfznUZBhmpne8hv7BXUzw9xNL3fXdpOYgOQlVMTcoHQ== integrity sha512-tZ3TvSgpvsQ6B6OGmo1/Au6u8BrAkvs1mIC/eURA3xgIfznUZBhmpne8hv7BXUzw9xNL3fXdpOYgOQlVMTcoHQ==
@ -996,6 +1003,11 @@
"@types/node" "*" "@types/node" "*"
"@types/responselike" "^1.0.0" "@types/responselike" "^1.0.0"
"@types/chai@^4.3.6":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
integrity sha512-KnRanxnpfpjUTqTCXslZSEdLfXExwgNxYPdiO2WGUj8+HDjFi8R3k5RVKPeSCzLjCcshCAtVO2QBbVuAV4kTnw==
"@types/concat-stream@^1.6.0": "@types/concat-stream@^1.6.0":
version "1.6.1" version "1.6.1"
resolved "https://registry.yarnpkg.com/@types/concat-stream/-/concat-stream-1.6.1.tgz#24bcfc101ecf68e886aaedce60dfd74b632a1b74" resolved "https://registry.yarnpkg.com/@types/concat-stream/-/concat-stream-1.6.1.tgz#24bcfc101ecf68e886aaedce60dfd74b632a1b74"
@ -1075,6 +1087,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240"
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==
"@types/node@^16.11.6":
version "16.18.22"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.22.tgz#a6505a5da1387aae03fddfb93591118f27b4c0ea"
integrity sha512-LJSIirgASa1LicFGTUFwDY7BfKDtLIbijqDLkH47LxEo/jtdrtiZ4/kLPD99bEQhTcPcuh6KhDllHqRxygJD2w==
"@types/node@^8.0.0": "@types/node@^8.0.0":
version "8.10.66" version "8.10.66"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.66.tgz#dd035d409df322acc83dff62a602f12a5783bbb3" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.66.tgz#dd035d409df322acc83dff62a602f12a5783bbb3"