2025-12-01 12:48:39 +01:00
|
|
|
# Builder API Quick Reference
|
|
|
|
|
|
|
|
|
|
Quick reference for the scenario builder DSL. All methods are chainable.
|
|
|
|
|
|
|
|
|
|
## Imports
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
use testing_framework_core::scenario::{Deployer, ScenarioBuilder};
|
|
|
|
|
use testing_framework_runner_local::LocalDeployer;
|
|
|
|
|
use testing_framework_runner_compose::ComposeDeployer;
|
|
|
|
|
use testing_framework_runner_k8s::K8sDeployer;
|
|
|
|
|
use testing_framework_workflows::{ScenarioBuilderExt, ChaosBuilderExt};
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Topology
|
|
|
|
|
|
|
|
|
|
```rust
|
2025-12-03 06:20:59 +01:00
|
|
|
ScenarioBuilder::topology_with(|t| {
|
|
|
|
|
t.network_star() // Star topology (all connect to seed node)
|
|
|
|
|
.validators(3) // Number of validator nodes
|
|
|
|
|
.executors(2) // Number of executor nodes
|
|
|
|
|
}) // Finish topology configuration
|
2025-12-01 12:48:39 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Wallets
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
.wallets(50) // Seed 50 funded wallet accounts
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Transaction Workload
|
|
|
|
|
|
|
|
|
|
```rust
|
2025-12-03 06:20:59 +01:00
|
|
|
.transactions_with(|txs| {
|
|
|
|
|
txs.rate(5) // 5 transactions per block
|
|
|
|
|
.users(20) // Use 20 of the seeded wallets
|
|
|
|
|
}) // Finish transaction workload config
|
2025-12-01 12:48:39 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## DA Workload
|
|
|
|
|
|
|
|
|
|
```rust
|
2025-12-03 06:20:59 +01:00
|
|
|
.da_with(|da| {
|
|
|
|
|
da.channel_rate(1) // 1 channel operation per block
|
|
|
|
|
.blob_rate(2) // 2 blob dispersals per block
|
|
|
|
|
}) // Finish DA workload config
|
2025-12-01 12:48:39 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Chaos Workload (Requires `enable_node_control()`)
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
.enable_node_control() // Enable node control capability
|
2025-12-03 06:20:59 +01:00
|
|
|
.chaos_with(|c| {
|
2025-12-06 10:17:06 +01:00
|
|
|
c.restart() // Random restart chaos
|
2025-12-03 06:20:59 +01:00
|
|
|
.min_delay(Duration::from_secs(30)) // Min time between restarts
|
|
|
|
|
.max_delay(Duration::from_secs(60)) // Max time between restarts
|
|
|
|
|
.target_cooldown(Duration::from_secs(45)) // Cooldown after restart
|
2025-12-06 10:17:06 +01:00
|
|
|
.apply() // Required for chaos configuration
|
2025-12-03 06:20:59 +01:00
|
|
|
})
|
2025-12-01 12:48:39 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Expectations
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
.expect_consensus_liveness() // Assert blocks are produced continuously
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Run Duration
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
.with_run_duration(Duration::from_secs(120)) // Run for 120 seconds
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Build
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
.build() // Construct the final Scenario
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Deployers
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
// Local processes
|
|
|
|
|
let deployer = LocalDeployer::default();
|
|
|
|
|
|
|
|
|
|
// Docker Compose
|
|
|
|
|
let deployer = ComposeDeployer::default();
|
|
|
|
|
|
|
|
|
|
// Kubernetes
|
|
|
|
|
let deployer = K8sDeployer::default();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Execution
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
let runner = deployer.deploy(&plan).await?;
|
|
|
|
|
let _handle = runner.run(&mut plan).await?;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Complete Example
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
|
use testing_framework_core::scenario::{Deployer, ScenarioBuilder};
|
|
|
|
|
use testing_framework_runner_local::LocalDeployer;
|
|
|
|
|
use testing_framework_workflows::ScenarioBuilderExt;
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
async fn run_test() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
2025-12-03 06:20:59 +01:00
|
|
|
let mut plan = ScenarioBuilder::topology_with(|t| {
|
|
|
|
|
t.network_star()
|
|
|
|
|
.validators(3)
|
|
|
|
|
.executors(2)
|
|
|
|
|
})
|
2025-12-01 12:48:39 +01:00
|
|
|
.wallets(50)
|
2025-12-03 06:20:59 +01:00
|
|
|
.transactions_with(|txs| {
|
|
|
|
|
txs.rate(5) // 5 transactions per block
|
|
|
|
|
.users(20)
|
|
|
|
|
})
|
|
|
|
|
.da_with(|da| {
|
|
|
|
|
da.channel_rate(1) // 1 channel operation per block
|
|
|
|
|
.blob_rate(2) // 2 blob dispersals per block
|
|
|
|
|
})
|
2025-12-01 12:48:39 +01:00
|
|
|
.expect_consensus_liveness()
|
|
|
|
|
.with_run_duration(Duration::from_secs(90))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
let deployer = LocalDeployer::default();
|
|
|
|
|
let runner = deployer.deploy(&plan).await?;
|
|
|
|
|
let _handle = runner.run(&mut plan).await?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
```
|