Skip to content

Commit fca1c6e

Browse files
authored
Add submitUserOp integration tests (#3619)
* add first version * add test in ci * Update README * fmt * Updated the CI configuration to include JSON-RPC and SubmitUserOp tests; * update ts_submit_user_op_test.sh * Update the deployment script to support outputting contract addresses * Update CI configuration * fix JSON-RPC mock test file * fix jsonrpc_mock_test ci * test contract addresses * add logs * Add debug logs in the user operation * fix sh * add gas * Optimize the test scripts, remove redundant debugging information * rename yml file * fmt * fix container_name * Update the submission user operation test to obtain the root signer address * Added functionality for new user operation submission testing. * add logs * add logs * fix steps from aa-demo-app * Enhance user operation submission testing * Optimize user operation submission testing. * Optimize the log output * fix services name * rename file * fix file name one more * fix OMNI_WORKER_ENDPOINT
1 parent e13c6d5 commit fca1c6e

File tree

16 files changed

+1436
-19
lines changed

16 files changed

+1436
-19
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ jobs:
959959
include:
960960
- test_name: omni-account-test
961961
- test_name: jsonrpc-mock-tests
962+
- test_name: submit-user-op-tests
962963
# disable it during RPC method refactoring
963964
# - test_name: omni-client-sdk-test
964965
name: ${{ matrix.test_name }}

tee-worker/omni-executor/aa-contracts/deploy-docker.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CHAIN_ID=31337
1717
DEPLOYER_ADDRESS="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
1818
OMNI_EXECUTOR_SIGNER="0x90F79bf6EB2c4f870365E785982E1f101E93b906"
1919
OUTPUT_FILE="/shared/contract-addresses.env"
20+
JSON_OUTPUT_FILE="/shared/deployed-addresses.json"
2021

2122
# Function to check if anvil is running
2223
check_anvil() {
@@ -100,7 +101,18 @@ deploy_contracts() {
100101
echo "OE_TEST_USDC_ADDRESS=$USDC_ADDRESS" >> "$OUTPUT_FILE"
101102
echo "OE_TEST_USDT_ADDRESS=$USDT_ADDRESS" >> "$OUTPUT_FILE"
102103

103-
echo "📝 Contract addresses written to $OUTPUT_FILE"
104+
# Also write addresses to JSON format for test scripts
105+
cat > "$JSON_OUTPUT_FILE" << EOF
106+
{
107+
"EntryPoint": "$ENTRYPOINT_ADDRESS",
108+
"OmniAccountFactory": "$FACTORY_ADDRESS",
109+
"SimplePaymaster": "$PAYMASTER_ADDRESS",
110+
"TestUSDC": "$USDC_ADDRESS",
111+
"TestUSDT": "$USDT_ADDRESS"
112+
}
113+
EOF
114+
115+
echo "📝 Contract addresses written to $OUTPUT_FILE and $JSON_OUTPUT_FILE"
104116
echo "✅ Deployment complete!"
105117

106118
else

tee-worker/omni-executor/cli/ts_jsonrpc_mock_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ cd /ts-tests
2929
pnpm install --force
3030

3131
echo "Running JSON-RPC tests"
32-
OMNI_WORKER_ENDPOINT=http://omni-executor:2100 pnpm --filter jsonrpc-mock-tests test jsonrpc.test.ts
32+
OMNI_WORKER_ENDPOINT=http://omni-executor:2100 pnpm --filter jsonrpc-mock-tests test jsonrpc_mock_test.test.ts
3333

34-
echo "JSON-RPC tests completed successfully"
34+
echo "JSON-RPC tests completed successfully"
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020-2024 Trust Computing GmbH.
4+
5+
# Enable strict error handling: exit on error (-e), error on undefined vars (-u), exit on pipe failures (-o pipefail)
6+
set -euo pipefail
7+
8+
# Parse command line options:
9+
# -u: Node URL to connect to
10+
while getopts ":u" opt; do
11+
case $opt in
12+
u)
13+
NODE_URL=$OPTARG
14+
;;
15+
?)
16+
echo "Invalid option: -${OPTARG}."
17+
exit 1
18+
;;
19+
esac
20+
done
21+
22+
NODE_URL=${NODE_URL:-"http://heima-node:9944"}
23+
echo "Using node url $NODE_URL"
24+
25+
echo "Running SubmitUserOp integration tests"
26+
27+
echo "Installing dependencies and building ts-tests"
28+
cd /ts-tests
29+
pnpm install --force
30+
31+
# Set environment variables for the SubmitUserOp test
32+
export TEST_RPC_URL="http://ethereum-node:8545"
33+
export TEST_CHAIN_ID="31337"
34+
export TEE_WORKER_RPC_URL="http://omni-executor:2100"
35+
36+
# Wait for contract deployment to complete
37+
echo "Waiting for contract deployment..."
38+
DEPLOYED_ADDRESSES_FILE="/shared/deployed-addresses.json"
39+
MAX_WAIT=120 # 2 minutes
40+
WAIT_COUNT=0
41+
42+
43+
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
44+
if [ -f "$DEPLOYED_ADDRESSES_FILE" ]; then
45+
echo "Contract deployment file found!"
46+
break
47+
fi
48+
49+
50+
sleep 1
51+
WAIT_COUNT=$((WAIT_COUNT + 1))
52+
if [ $((WAIT_COUNT % 10)) -eq 0 ]; then
53+
echo "Still waiting for contracts... (${WAIT_COUNT}s)"
54+
fi
55+
done
56+
57+
# Contract addresses should be available from the shared volume
58+
if [ -f "/shared/deployed-addresses.json" ]; then
59+
echo "Loading deployed contract addresses..."
60+
export TEST_ENTRY_POINT_ADDRESS=$(cat /shared/deployed-addresses.json | jq -r '.EntryPoint // "0x5FbDB2315678afecb367f032d93F642f64180aa3"')
61+
export TEST_FACTORY_ADDRESS=$(cat /shared/deployed-addresses.json | jq -r '.OmniAccountFactory // "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"')
62+
export TEST_USDC_ADDRESS=$(cat /shared/deployed-addresses.json | jq -r '.TestUSDC // "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"')
63+
export TEST_USDT_ADDRESS=$(cat /shared/deployed-addresses.json | jq -r '.TestUSDT // "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"')
64+
echo "Successfully loaded contract addresses from deployment file"
65+
else
66+
echo "⚠️ Contract deployment file not found, using default addresses..."
67+
# These are deterministic addresses from Anvil/Hardhat local blockchain
68+
# Anvil uses CREATE2 with predictable deployer nonce, so contracts deploy to same addresses
69+
# See: https://book.getfoundry.sh/reference/anvil/#deterministic-addresses
70+
export TEST_ENTRY_POINT_ADDRESS="0x5FbDB2315678afecb367f032d93F642f64180aa3" # First deployment (nonce=0)
71+
export TEST_FACTORY_ADDRESS="0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" # Second deployment (nonce=1)
72+
export TEST_USDC_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" # Third deployment (nonce=2)
73+
export TEST_USDT_ADDRESS="0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" # Fourth deployment (nonce=3)
74+
fi
75+
76+
echo "Environment configured for SubmitUserOp test"
77+
78+
echo "Running SubmitUserOp tests"
79+
OMNI_WORKER_ENDPOINT=http://omni-executor:2100 PARACHAIN_ENDPOINT=ws://heima-node:9944 pnpm --filter jsonrpc-mock-tests test submitUserOp.test.ts
80+
81+
echo "SubmitUserOp tests completed successfully"

tee-worker/omni-executor/docker/jsonrpc-mock-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
jsonrpc-mock-tests:
33
image: litentry/omni-executor:latest
4-
container_name: litentry-jsonrpc-mock-tests
4+
container_name: litentry-jsonrpc-mock-test
55
volumes:
66
- ../ts-tests:/ts-tests
77
- ../../client-api:/client-api
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
submit-user-op-tests:
3+
image: litentry/omni-executor:latest
4+
container_name: litentry-submit-user-op-tests
5+
volumes:
6+
- ../ts-tests:/ts-tests
7+
- ../../client-api:/client-api
8+
- ../cli:/usr/local/executor-worker-cli
9+
- shared-data:/shared
10+
build:
11+
context: ${PWD}/../../
12+
dockerfile: tee-worker/omni-executor/Dockerfile
13+
target: executor-worker
14+
depends_on:
15+
omni-executor:
16+
condition: service_healthy
17+
restart: true
18+
aa-contracts-deploy:
19+
condition: service_completed_successfully
20+
networks:
21+
- litentry-test-network
22+
entrypoint: "sh -c '/usr/local/executor-worker-cli/ts_submit_user_op_test.sh 3>&1' "
23+
restart: "no"
24+
volumes:
25+
shared-data:
26+
networks:
27+
litentry-test-network:
28+
driver: bridge
Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,59 @@
11
# JSON-RPC Mock Tests
22

3-
This project contains TypeScript-based mock tests for the Omni Executor JSON-RPC API endpoints.
3+
This project contains TypeScript-based integration tests for the Omni Executor JSON-RPC API endpoints, including:
4+
5+
- **JSON-RPC API Tests** (`jsonrpc_mock_test`) - Basic API endpoint testing
6+
- **SubmitUserOp Integration Tests** (`submitUserOp.test.ts`) - Complete Account Abstraction flow testing
47

58
## Quick Start
69

710
### Local Development Setup
811

9-
1. **Start the worker services:**
12+
1. **Start the complete development environment:**
1013

1114
```bash
12-
make build-docker-test
13-
make start-test
15+
cd ../../docker
16+
docker compose up
1417
```
1518

16-
2. **Run the JSON-RPC tests:**
19+
This will automatically:
20+
21+
- Deploy all Account Abstraction contracts
22+
- Start Anvil (Ethereum node) on port 8545
23+
- Start Omni Executor with mock server on port 2100
24+
- Start Heima node on port 9944
25+
- Set up all required environment variables
26+
27+
2. **Run all tests:**
28+
1729
```bash
18-
pnpm --filter jsonrpc-mock-tests run test jsonrpc.test.ts
30+
cd ../ts-tests/jsonrpc-mock-tests
31+
pnpm install
32+
pnpm test
1933
```
34+
35+
3. **Run specific tests:**
36+
37+
```bash
38+
# JSON-RPC API tests only
39+
pnpm test jsonrpc_mock_test
40+
41+
# SubmitUserOp integration tests only
42+
pnpm test submitUserOp.test.ts
43+
```
44+
45+
## Available Services
46+
47+
When running `docker compose up`, the following services are available:
48+
49+
- **Omni-Executor RPC**: http://localhost:2100
50+
- **Mock Server**: http://localhost:3456
51+
- **Ethereum Node (Anvil)**: http://localhost:8545
52+
53+
## Contract Addresses
54+
55+
All contracts are automatically deployed and configured. To view deployed addresses:
56+
57+
```bash
58+
docker compose logs aa-contracts-deploy
59+
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Test configuration constants
2+
export const TEST_CONFIG = {
3+
// Network configuration
4+
RPC_URL: process.env.TEST_RPC_URL || 'http://127.0.0.1:8545',
5+
CHAIN_ID: process.env.TEST_CHAIN_ID ? parseInt(process.env.TEST_CHAIN_ID) : 31337,
6+
7+
// Test accounts from Anvil/Hardhat default test mnemonic:
8+
// "test test test test test test test test test test test junk"
9+
// These addresses are deterministically generated and have public private keys
10+
ACCOUNTS: {
11+
DEPLOYER: {
12+
address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' as const, // Account #0
13+
privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' as const,
14+
},
15+
USER: {
16+
address: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' as const, // Account #1
17+
privateKey: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d' as const,
18+
},
19+
TEE_WORKER: {
20+
address: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC' as const, // Account #2
21+
privateKey: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a' as const,
22+
},
23+
},
24+
25+
// Contract addresses - these are deployed by local-deploy.sh
26+
CONTRACTS: {
27+
ENTRY_POINT: process.env.TEST_ENTRY_POINT_ADDRESS || '0x5FbDB2315678afecb367f032d93F642f64180aa3',
28+
OMNI_ACCOUNT_FACTORY: process.env.TEST_FACTORY_ADDRESS || '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
29+
SIMPLE_PAYMASTER: process.env.TEST_PAYMASTER_ADDRESS || '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
30+
TEST_USDC: process.env.TEST_USDC_ADDRESS || '0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9',
31+
TEST_USDT: process.env.TEST_USDT_ADDRESS || '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
32+
},
33+
34+
// TEE Worker RPC configuration
35+
TEE_WORKER: {
36+
RPC_URL: process.env.TEE_WORKER_RPC_URL || 'http://localhost:2100',
37+
CLIENT_ID: 'wildmeta' as const,
38+
CHAIN_TYPE: 'Evm' as const,
39+
SIGNER_INDEX: 0,
40+
},
41+
42+
// Gas configuration for UserOperations
43+
GAS_CONFIG: {
44+
CALL_GAS_LIMIT: BigInt(2000000),
45+
VERIFICATION_GAS_LIMIT: BigInt(3000000),
46+
PRE_VERIFICATION_GAS: BigInt(100000),
47+
MAX_FEE_PER_GAS: BigInt(20000000000), // 20 gwei
48+
MAX_PRIORITY_FEE_PER_GAS: BigInt(1000000000), // 1 gwei
49+
},
50+
51+
// Token amounts
52+
AMOUNTS: {
53+
FUNDING_ETH: '1', // ETH amount to fund OmniAccount
54+
MINT_TOKENS: '1000', // Amount of test tokens to mint
55+
TRANSFER_TOKENS: '500', // Amount to transfer to OmniAccount
56+
SEND_TOKENS: '100', // Amount to send in test transaction
57+
},
58+
59+
// UserOp signer types
60+
SIGNER_TYPES: {
61+
OWNER: 0x00,
62+
ROOT_KEY: 0x01,
63+
SESSION_KEY: 0x02,
64+
PASSKEY: 0x03,
65+
} as const,
66+
67+
// Test timeouts
68+
TIMEOUTS: {
69+
DEFAULT: 120000, // 2 minutes
70+
TRANSACTION: 30000, // 30 seconds
71+
},
72+
} as const;
73+
74+
// Utility type for contract addresses
75+
export type ContractAddress = `0x${string}`;
76+
77+
// Environment validation
78+
export function validateTestEnvironment() {
79+
const requiredEnvVars = ['TEST_RPC_URL', 'TEST_ENTRY_POINT_ADDRESS', 'TEST_FACTORY_ADDRESS'];
80+
81+
const missing = requiredEnvVars.filter((envVar) => envVar.startsWith('TEST_') && !process.env[envVar]);
82+
83+
if (missing.length > 0) {
84+
console.warn('⚠️ Missing environment variables (using defaults):', missing.join(', '));
85+
console.warn(' Set these variables or run local-deploy.sh to deploy contracts');
86+
}
87+
88+
return {
89+
rpcUrl: TEST_CONFIG.RPC_URL,
90+
chainId: TEST_CONFIG.CHAIN_ID,
91+
contracts: TEST_CONFIG.CONTRACTS,
92+
};
93+
}

0 commit comments

Comments
 (0)