Skip to content

Commit f7e49f6

Browse files
authored
test(batcher): add script to test unlocked funds flow (#2126)
1 parent 92f097f commit f7e49f6

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

scripts/unlocked_funds/.env.devnet

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RPC_URL=http://localhost:8545
2+
NETWORK=devnet
3+
BATCHER_PAYMENT_SERVICE_ADDRESS=0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650
4+
# Anvil address 6
5+
PRIVATE_KEY=0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
6+
SLEEP_SECONDS=3600
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RPC_URL=
2+
NETWORK=
3+
BATCHER_PAYMENT_SERVICE_ADDRESS
4+
PRIVATE_KEY=
5+
SLEEP_SECONDS=

scripts/unlocked_funds/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Unlocked Funds Test Script
2+
3+
## Overview
4+
5+
The `test_unlocked_funds.sh` script tests the unlocked funds flow in the Aligned protocol by continuously cycling between locking and unlocking funds while submitting proofs.
6+
7+
## Usage
8+
9+
**Important: This script must be run from the root of the repository.**
10+
11+
```bash
12+
./scripts/unlocked_funds/test_unlocked_funds.sh <env_file_path>
13+
```
14+
15+
## Required Environment Variables
16+
17+
The script requires an environment file with the following variables:
18+
19+
- `RPC_URL` - RPC endpoint URL for the blockchain network
20+
- `NETWORK` - Network identifier (e.g., holesky, mainnet)
21+
- `BATCHER_PAYMENT_SERVICE_ADDRESS` - Contract address of the batcher payment service
22+
- `PRIVATE_KEY` - Private key for transaction signing
23+
- `SLEEP_SECONDS` - Sleep duration between cycles (in seconds)
24+
25+
## How It Works
26+
27+
1. **Initial Setup**: Locks funds using the batcher payment service contract
28+
2. **Continuous Loop**:
29+
- Submits a proof to Aligned (runs in background)
30+
- Waits 5 minutes
31+
- Unlocks funds from the contract
32+
- Sleeps for the configured duration
33+
- Locks funds again
34+
- Repeats the cycle
35+
36+
## Test Files
37+
38+
The script uses test files located at:
39+
- `./scripts/test_files/circom_groth16_bn256_script/proof.json`
40+
- `./scripts/test_files/circom_groth16_bn256_script/public.json`
41+
- `./scripts/test_files/circom_groth16_bn256_script/verification_key.json`
42+
43+
## Success Criteria
44+
45+
The test is considered successful when the `UserFundsUnlocked` event is detected in the proof submission output.
46+
47+
## Dependencies
48+
49+
- `aligned` CLI tool
50+
- `cast` (from Foundry)
51+
- Bash shell environment
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# ENV VARIABLES:
4+
# - RPC_URL
5+
# - NETWORK
6+
# - BATCHER_PAYMENT_SERVICE_ADDRESS
7+
# - PRIVATE_KEY
8+
# - SLEEP_SECONDS
9+
10+
# Load env file from $1 path
11+
source "$1"
12+
13+
### FUNCTIONS ###
14+
15+
# Function to log with timestamp and severity
16+
function log() {
17+
local severity=$1
18+
local message=$2
19+
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
20+
21+
echo "[$timestamp] [$severity] $message"
22+
}
23+
24+
# Function to send a proof to Aligned
25+
function send_proof() {
26+
log "INFO" "⏳ Sending proof to Aligned..."
27+
28+
submit=$(aligned submit \
29+
--rpc_url $RPC_URL \
30+
--network $NETWORK \
31+
--private_key $PRIVATE_KEY \
32+
--proving_system CircomGroth16Bn256 \
33+
--proof ./scripts/test_files/circom_groth16_bn256_script/proof.json \
34+
--public_input ./scripts/test_files/circom_groth16_bn256_script/public.json \
35+
--vk ./scripts/test_files/circom_groth16_bn256_script/verification_key.json \
36+
--custom_fee_estimate 64 \
37+
2>&1)
38+
39+
# Check if UserFundsUnlocked appears in the output
40+
if echo "$submit" | grep -q "UserFundsUnlocked"; then
41+
log "INFO" "✅ Test successful - UserFundsUnlocked event detected"
42+
else
43+
log "ERROR" "❌ Test failed - UserFundsUnlocked event not detected"
44+
log "ERROR" "Submit output: $submit"
45+
fi
46+
}
47+
48+
49+
# Function to unlock funds
50+
function unlock_funds() {
51+
log "INFO" "⏳ Unlocking funds..."
52+
output=$(cast send $BATCHER_PAYMENT_SERVICE_ADDRESS "unlock()" \
53+
--rpc-url $RPC_URL \
54+
--private-key $PRIVATE_KEY 2>&1)
55+
56+
if echo "$output" | grep -q "status.*1 (success)"; then
57+
log "INFO" "✅ Unlock transaction successful"
58+
else
59+
log "ERROR" "❌ Unlock transaction failed"
60+
fi
61+
}
62+
63+
# Function to lock funds
64+
function lock_funds() {
65+
log "INFO" "⏳ Locking funds..."
66+
output=$(cast send $BATCHER_PAYMENT_SERVICE_ADDRESS "lock()" \
67+
--rpc-url $RPC_URL \
68+
--private-key $PRIVATE_KEY 2>&1)
69+
70+
if echo "$output" | grep -q "status.*1 (success)"; then
71+
log "INFO" "✅ Lock transaction successful"
72+
else
73+
log "ERROR" "❌ Lock transaction failed"
74+
fi
75+
}
76+
77+
### MAIN LOOP ###
78+
log "INFO" "🚀 Running..."
79+
lock_funds
80+
while true
81+
do
82+
send_proof &
83+
sleep 300
84+
unlock_funds
85+
sleep $SLEEP_SECONDS
86+
lock_funds
87+
done

0 commit comments

Comments
 (0)