Skip to main content
Version: Next

Real-World Examples

These examples demonstrate how to use Merobox for common real-world scenarios, from multi-node testing to performance testing.

Example 1: Multi-Node Testing

Test your application across multiple nodes to simulate real-world scenarios.

description: Multi-node application testing
name: Multi-Node Test

nodes:
chain_id: testnet-1
count: 3
image: ghcr.io/calimero-network/merod:edge
prefix: test-node

steps:
# Install application on first node
- name: Install Application
type: install_application
node: test-node-1
path: ./my-app.wasm
dev: true
outputs:
app_id: applicationId

# Create context on first node
- name: Create Context
type: create_context
node: test-node-1
application_id: '{{app_id}}'
outputs:
context_id: contextId
member_key: memberPublicKey

# Create identities on other nodes
- name: Create Identity on Node 2
type: create_identity
node: test-node-2
outputs:
node2_key: publicKey

- name: Create Identity on Node 3
type: create_identity
node: test-node-3
outputs:
node3_key: publicKey

# Invite nodes to context
- name: Invite Node 2
type: invite_identity
node: test-node-1
context_id: '{{context_id}}'
grantee_id: '{{node2_key}}'
granter_id: '{{member_key}}'
capability: member
outputs:
invite2: invitation

- name: Invite Node 3
type: invite_identity
node: test-node-1
context_id: '{{context_id}}'
grantee_id: '{{node3_key}}'
granter_id: '{{member_key}}'
capability: member
outputs:
invite3: invitation

# Join contexts
- name: Join from Node 2
type: join_context
node: test-node-2
context_id: '{{context_id}}'
invitee_id: '{{node2_key}}'
invitation: '{{invite2}}'

- name: Join from Node 3
type: join_context
node: test-node-3
context_id: '{{context_id}}'
invitee_id: '{{node3_key}}'
invitation: '{{invite3}}'

# Test cross-node communication
- name: Set Data from Node 1
type: call
node: test-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: set
args:
key: shared_data
value: 'set from node 1'

- name: Read from Node 2
type: call
node: test-node-2
context_id: '{{context_id}}'
executor_public_key: '{{node2_key}}'
method: get
args:
key: shared_data
outputs:
result2: result

- name: Read from Node 3
type: call
node: test-node-3
context_id: '{{context_id}}'
executor_public_key: '{{node3_key}}'
method: get
args:
key: shared_data
outputs:
result3: result

# Validate cross-node consistency
- name: Validate Cross-Node Data
type: assert
statements:
- "contains({{result2}}, 'set from node 1')"
- "contains({{result3}}, 'set from node 1')"
- '{{result2}} == {{result3}}'

stop_all_nodes: true

Example 2: Authentication Service Integration

Use Merobox with authentication services for production-like testing.

description: Workflow with authentication service
name: Auth Service Example

# Enable authentication service
auth_service: true

nodes:
chain_id: testnet-1
count: 2
image: ghcr.io/calimero-network/merod:edge
prefix: auth-node

steps:
- name: Wait for Auth Service
type: wait
seconds: 10
message: 'Waiting for authentication service to start...'

- name: Install Application
type: install_application
node: auth-node-1
path: ./my-app.wasm
dev: true
outputs:
app_id: applicationId

- name: Create Context
type: create_context
node: auth-node-1
application_id: '{{app_id}}'
outputs:
context_id: contextId
member_key: memberPublicKey

- name: Test with Auth Service
type: script
script: |
echo "Testing with authentication service..."
echo "Node 1 URL: http://auth-node-1.127.0.0.1.nip.io"
echo "Node 2 URL: http://auth-node-2.127.0.0.1.nip.io"
echo "Auth Login: http://auth-node-1.127.0.0.1.nip.io/auth/login"
echo "Admin Dashboard: http://auth-node-1.127.0.0.1.nip.io/admin-dashboard"

stop_all_nodes: true

Example 3: Performance Testing

Test your application's performance with repeated operations.

description: Performance testing workflow
name: Performance Test

nodes:
chain_id: testnet-1
count: 1
image: ghcr.io/calimero-network/merod:edge
prefix: perf-node

steps:
- name: Install Application
type: install_application
node: perf-node-1
path: ./my-app.wasm
dev: true
outputs:
app_id: applicationId

- name: Create Context
type: create_context
node: perf-node-1
application_id: '{{app_id}}'
outputs:
context_id: contextId
member_key: memberPublicKey

- name: Performance Test
type: repeat
count: 100
outputs:
iteration: iteration
steps:
- name: Set Data
type: call
node: perf-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: set
args:
key: 'perf_key_{{iteration}}'
value: 'perf_value_{{iteration}}'

- name: Get Data
type: call
node: perf-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: get
args:
key: 'perf_key_{{iteration}}'
outputs:
result: result

- name: Validate Performance
type: assert
statements:
- "contains({{result}}, 'perf_value_{{iteration}}')"

- name: Performance Summary
type: script
script: |
echo "Performance test completed!"
echo "Executed 100 set/get operations successfully"

stop_all_nodes: true

Example 4: Database Integration

Test applications that interact with databases.

description: Database integration testing
name: Database Integration

nodes:
chain_id: testnet-1
count: 1
image: ghcr.io/calimero-network/merod:edge
prefix: db-node

# Add database service
services:
- name: postgres
image: postgres:15
environment:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
ports:
- 5432:5432

steps:
- name: Wait for Database
type: wait
seconds: 10
message: 'Waiting for database to start...'

- name: Install Application
type: install_application
node: db-node-1
path: ./db-app.wasm
dev: true
outputs:
app_id: applicationId

- name: Create Context
type: create_context
node: db-node-1
application_id: '{{app_id}}'
outputs:
context_id: contextId
member_key: memberPublicKey

- name: Test Database Connection
type: call
node: db-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: test_db_connection
args:
host: postgres
port: 5432
database: testdb
username: testuser
password: testpass
outputs:
db_result: result

- name: Validate Database Connection
type: assert
statements:
- "contains({{db_result}}, 'connected')"

stop_all_nodes: true

Example 5: Load Balancing

Test applications behind load balancers.

description: Load balancing testing
name: Load Balancing Test

nodes:
chain_id: testnet-1
count: 3
image: ghcr.io/calimero-network/merod:edge
prefix: lb-node

# Add load balancer
services:
- name: nginx
image: nginx:alpine
ports:
- 8080:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf

steps:
- name: Wait for Load Balancer
type: wait
seconds: 5
message: 'Waiting for load balancer to start...'

- name: Install Application on All Nodes
type: parallel
steps:
- name: Install on Node 1
type: install_application
node: lb-node-1
path: ./my-app.wasm
dev: true
outputs:
app_id_1: applicationId

- name: Install on Node 2
type: install_application
node: lb-node-2
path: ./my-app.wasm
dev: true
outputs:
app_id_2: applicationId

- name: Install on Node 3
type: install_application
node: lb-node-3
path: ./my-app.wasm
dev: true
outputs:
app_id_3: applicationId

- name: Test Load Balancer
type: script
script: |
echo "Testing load balancer..."
for i in {1..10}; do
echo "Request $i:"
curl -s http://localhost:8080/health
echo
done

stop_all_nodes: true

Example 6: Monitoring and Alerting

Set up monitoring and alerting for your applications.

description: Monitoring and alerting setup
name: Monitoring Example

nodes:
chain_id: testnet-1
count: 2
image: ghcr.io/calimero-network/merod:edge
prefix: monitor-node

# Add monitoring stack
services:
- name: prometheus
image: prom/prometheus:latest
ports:
- 9090:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml

- name: grafana
image: grafana/grafana:latest
ports:
- 3000:3000
environment:
GF_SECURITY_ADMIN_PASSWORD: admin

steps:
- name: Wait for Monitoring Stack
type: wait
seconds: 15
message: 'Waiting for monitoring stack to start...'

- name: Install Application
type: install_application
node: monitor-node-1
path: ./monitored-app.wasm
dev: true
outputs:
app_id: applicationId

- name: Create Context
type: create_context
node: monitor-node-1
application_id: '{{app_id}}'
outputs:
context_id: contextId
member_key: memberPublicKey

- name: Generate Load
type: repeat
count: 50
steps:
- name: Call Application
type: call
node: monitor-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: process_data
args:
data: 'load_test_{{iteration}}'

- name: Check Monitoring
type: script
script: |
echo "Monitoring stack is running:"
echo "Prometheus: http://localhost:9090"
echo "Grafana: http://localhost:3000 (admin/admin)"
echo "Application metrics should be visible in Prometheus"

stop_all_nodes: true

Best Practices for Real-World Examples

1. Environment Configuration

# Use environment-specific settings
nodes:
image: ghcr.io/calimero-network/merod:edge
environment:
RUST_LOG: info
CALIMERO_CHAIN_ID: testnet-1
CALIMERO_NETWORK: testnet

2. Resource Management

# Set appropriate resource limits
nodes:
resources:
memory: '2G'
cpus: '1.0'
count: 3 # Scale based on needs

3. Error Handling

# Include comprehensive error handling
steps:
- name: Risky Operation
type: call
node: calimero-node-1
method: risky_method
retry:
attempts: 3
delay: 5
on_error:
- name: Log Error
type: script
script: echo "Operation failed: {{error}}"

4. Monitoring and Validation

# Always validate results
steps:
- name: Validate Results
type: assert
statements:
- '{{result}} != null'
- "contains({{result}}, 'expected_value')"

Next Steps

Now that you've seen real-world examples:

Was this page helpful?
Need some help? Check Support page