Real-World Examples
These examples demonstrate how to use Merobox for common real-world scenarios, from multi-node testing to basic 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: Basic Error Handling
Implement basic error handling in your workflows.
description: Error handling example
name: Error Handling Test
nodes:
chain_id: testnet-1
count: 1
image: ghcr.io/calimero-network/merod:edge
prefix: error-node
steps:
- name: Install Application
type: install_application
node: error-node-1
path: ./my-app.wasm
dev: true
outputs:
app_id: applicationId
- name: Create Context
type: create_context
node: error-node-1
application_id: '{{app_id}}'
outputs:
context_id: contextId
member_key: memberPublicKey
- name: Test Error Handling
type: call
node: error-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: test_error_handling
args:
should_fail: true
outputs:
error_result: result
- name: Validate Error Response
type: assert
statements:
- "contains({{error_result}}, 'error')"
- name: Recovery Test
type: call
node: error-node-1
context_id: '{{context_id}}'
executor_public_key: '{{member_key}}'
method: test_recovery
args:
should_succeed: true
outputs:
recovery_result: result
- name: Validate Recovery
type: assert
statements:
- "contains({{recovery_result}}, 'success')"
stop_all_nodes: true
Example 5: Parallel Operations
Execute multiple operations in parallel for improved performance.
description: Parallel operations example
name: Parallel Operations
nodes:
chain_id: testnet-1
count: 3
image: ghcr.io/calimero-network/merod:edge
prefix: parallel-node
steps:
- name: Install Applications in Parallel
type: parallel
steps:
- name: Install App 1
type: install_application
node: parallel-node-1
path: ./app1.wasm
dev: true
outputs:
app_id_1: applicationId
- name: Install App 2
type: install_application
node: parallel-node-2
path: ./app2.wasm
dev: true
outputs:
app_id_2: applicationId
- name: Install App 3
type: install_application
node: parallel-node-3
path: ./app3.wasm
dev: true
outputs:
app_id_3: applicationId
- name: Create Contexts in Parallel
type: parallel
steps:
- name: Create Context 1
type: create_context
node: parallel-node-1
application_id: '{{app_id_1}}'
outputs:
context_id_1: contextId
member_key_1: memberPublicKey
- name: Create Context 2
type: create_context
node: parallel-node-2
application_id: '{{app_id_2}}'
outputs:
context_id_2: contextId
member_key_2: memberPublicKey
- name: Create Context 3
type: create_context
node: parallel-node-3
application_id: '{{app_id_3}}'
outputs:
context_id_3: contextId
member_key_3: memberPublicKey
- name: Test All Applications
type: parallel
steps:
- name: Test App 1
type: call
node: parallel-node-1
context_id: '{{context_id_1}}'
executor_public_key: '{{member_key_1}}'
method: test_functionality
args:
test_data: 'app1_test'
- name: Test App 2
type: call
node: parallel-node-2
context_id: '{{context_id_2}}'
executor_public_key: '{{member_key_2}}'
method: test_functionality
args:
test_data: 'app2_test'
- name: Test App 3
type: call
node: parallel-node-3
context_id: '{{context_id_3}}'
executor_public_key: '{{member_key_3}}'
method: test_functionality
args:
test_data: 'app3_test'
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
2. Error Handling
# Include basic 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}}"
3. 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:
- Testing Integration Examples - Integration with testing frameworks
- Advanced Examples - Complex workflows and advanced features
- Best Practices - Guidelines for effective Merobox usage
Was this page helpful?