Tools used: Kurtosis CDK Β· Docker Β· Foundry Β· Node.js Β· Ethers.js Β· Jest Β· Axios
- β At least 16 GB of RAM
- β Node.js installed (>= v20.*)
- β Foundry installed
- β Docker installed (>= v4.27.0)
- β jq installed
- β Kurtosis CLI installed
- β pnpm installed
- βοΈ Setting Up Local L1 & L2 Using Kurtosis CDK
- π οΈ MacOS (Apple Silicon) Troubleshooting
- π§΅ End-to-End Deployment and Testing Script
- π§ͺ Manual & Dedicated Stage-by-Stage Test Flows
- π§° Additionally, Unit Tests on Foundry for Smart Contracts
βοΈ Setting Up Local L1 & L2 Using Kurtosis CDK (that based on cdk-erigon)
Steps based on kurtosis-cdk
git clone https://github.com/0xPolygon/kurtosis-cdk.git
cd kurtosis-cdk
π§ͺ To have a static port for local RPC URL http://127.0.0.1:61712
(better for testing), run Kurtosis with a custom args file:
kurtosis run --enclave cdk github.com/0xPolygon/kurtosis-cdk --args-file ./.github/tests/nightly/static-ports/custom-static-ports.yml
ποΈ Once completed, you'll see the User Services running successfully (it takes around 5-8 minutes to spin up L1 and L2)
kurtosis clean --all
-
Install Rossetta:
softwareupdate --install-rosetta --agree-to-license
-
Enable Rosetta support in Docker:
- Go to Docker Settings β General
- Enable:
Use Rosetta for x86_64/amd64 emulation on Apple Silicon
- Click Apply & Restart
-
Manually pull the necessary Docker images:
docker pull --platform=linux/amd64 hermeznetwork/zkevm-prover:v8.0.0-RC16-fork.12 docker pull --platform=linux/amd64 leovct/e2e:78df008-cdk
If the deployment process gets stuck, it is likely due to Dockerβs default memory limit being too low (8GB).
Increase Docker memory allocation to at least 16GB or 24GB (32GB recommended) to fix this issue.
- Go to Docker Settings
- Open the Resources tab
- Increase the Memory limit
- Ensure the CPU limit is at least 4
- Click Apply & Restart
kurtosis run --enclave cdk github.com/0xPolygon/kurtosis-cdk --args-file ./.github/tests/nightly/static-ports/custom-static-ports.yml
If you need the Erigon RPC URL (static URL is usually http://127.0.0.1:61712
), run:
kurtosis port print cdk cdk-erigon-rpc-001 rpc
Before running tests, install required dependencies for the repo:
pnpm i
Run to create .env
from example file:
cp .env.example .env
The most recommended way to run all tests and deployment processes in one go.
-
βΆοΈ Simple reporting mode:./scripts/deploy-and-verify.sh
-
π Debug reporting mode (see full logs per stage):
./scripts/deploy-and-verify.sh --debug
- βΉοΈ After running the
deploy-and-verify.sh
shell script, ascript-report.txt
file will be generated.
It contains detailed logs of every stage during the script run.
We will test if the 0x02 precompiled contract correctly computes the SHA-256 hash of the input.
- Input message: "Hello, Erigon"
- Hex representation: 0x48656c6c6f2c20457269676f6e
- Expected SHA-256 hash result: 0x3c5f683f4ecfdf824570081dda764483bb4f259a71a802b348f914b0451c5fab
cast call 0x0000000000000000000000000000000000000002 0x48656c6c6f2c20457269676f6e --rpc-url kurtosis
The project includes an automated test flow using both eth_call via RPC and ethers.js.
pnpm run test-precompile-rpc
pnpm run test-precompile
Run the following command to deploy the smart contract:
forge script script/StorageHash.s.sol --rpc-url kurtosis --legacy --json --broadcast
After deployment, in terminal output you will find JSON like this:
{ "chain": 10101, "status": "success", "tx_hash": "0xf455d4680403f45ca6cc1ec5c9752b14d73a63deb896981729f49e45b27a5dd5", "contract_address": "0x998B1ACBF8E46fB93476aD4482a4490326BC1EDb", "block_number": 9040, "gas_used": 260222, "gas_price": 1000000000 }
For further testing you will need:
- β tx_hash β transaction hash
- β contract_address β deployed contract address
You can also find this information in broadcast/StorageHash.s.sol/10101/run-latest.json
- π Option A: Run Automated Test
pnpm run test-post-deploy
- π§βπ» Option B: Manual Verification Using
curl
To check transaction receipt run:To check deployed contract bytecode:curl -X POST http://127.0.0.1:61712 \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["<tx_hash>"],"id":1}'
π§° (Alternative) To check contract code usingcurl -X POST http://127.0.0.1:61712 \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"eth_getCode","params":["<contract_address>", "latest"],"id":2}'
cast
cast code <contract_address> --rpc-url kurtosis
-
Check current hashedValue (default
bytes32
equals to 0x...0), run following:cast call <contract_address> "hashedValue()(bytes32)" --rpc-url kurtosis
-
π’ Call contract function with number to hash it's value and store inside contract:
cast send <contract_address> "hashNumber(uint256)()" 44 --rpc-url kurtosis --legacy --interactive
β οΈ Note:
This command uses the--interactive
flag, so you'll be prompted to paste the private key manually for security reasons.
Since this is a local testing key, it's safe to reveal it:
0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625
-
π Verify that the value was hashed and stored in contract:
cast call <contract_address> "hashedValue()(bytes32)" --rpc-url kurtosis
pnpm run test-contract-invocation
β‘οΈ This script tests contract interaction via ethers.js
.
-
forge test