mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-01-02 13:23:13 +00:00
Update book code snippets to block-style DSL helpers
This commit is contained in:
parent
61e7fe4e25
commit
0fb44c6955
@ -45,20 +45,20 @@ These binaries use the framework API (`ScenarioBuilder`) to construct and execut
|
||||
Scenarios are defined using a fluent builder pattern:
|
||||
|
||||
```rust
|
||||
let mut plan = ScenarioBuilder::topology()
|
||||
.network_star() // Topology configuration
|
||||
.validators(3)
|
||||
.executors(2)
|
||||
.apply()
|
||||
let mut plan = ScenarioBuilder::topology_with(|t| {
|
||||
t.network_star() // Topology configuration
|
||||
.validators(3)
|
||||
.executors(2)
|
||||
})
|
||||
.wallets(50) // Wallet seeding
|
||||
.transactions() // Transaction workload
|
||||
.rate(5)
|
||||
.users(20)
|
||||
.apply()
|
||||
.da() // DA workload
|
||||
.channel_rate(1)
|
||||
.blob_rate(2)
|
||||
.apply()
|
||||
.transactions_with(|txs| {
|
||||
txs.rate(5)
|
||||
.users(20)
|
||||
})
|
||||
.da_with(|da| {
|
||||
da.channel_rate(1)
|
||||
.blob_rate(2)
|
||||
})
|
||||
.expect_consensus_liveness() // Expectations
|
||||
.with_run_duration(Duration::from_secs(90))
|
||||
.build();
|
||||
|
||||
@ -23,21 +23,19 @@ use std::time::Duration;
|
||||
use testing_framework_core::scenario::ScenarioBuilder;
|
||||
use testing_framework_workflows::workloads::chaos::RandomRestartWorkload;
|
||||
|
||||
let plan = ScenarioBuilder::topology()
|
||||
.network_star()
|
||||
.validators(2)
|
||||
.executors(1)
|
||||
.apply()
|
||||
let plan = ScenarioBuilder::topology_with(|t| {
|
||||
t.network_star()
|
||||
.validators(2)
|
||||
.executors(1)
|
||||
})
|
||||
.enable_node_control()
|
||||
.with_workload(
|
||||
RandomRestartWorkload::new(
|
||||
Duration::from_secs(45), // min delay
|
||||
Duration::from_secs(75), // max delay
|
||||
Duration::from_secs(120), // target cooldown
|
||||
true, // include validators
|
||||
true, // include executors
|
||||
)
|
||||
)
|
||||
.with_workload(RandomRestartWorkload::new(
|
||||
Duration::from_secs(45), // min delay
|
||||
Duration::from_secs(75), // max delay
|
||||
Duration::from_secs(120), // target cooldown
|
||||
true, // include validators
|
||||
true, // include executors
|
||||
))
|
||||
.expect_consensus_liveness()
|
||||
.with_run_duration(Duration::from_secs(150))
|
||||
.build();
|
||||
|
||||
@ -16,11 +16,11 @@ use std::time::Duration;
|
||||
## Topology
|
||||
|
||||
```rust
|
||||
ScenarioBuilder::topology()
|
||||
.network_star() // Star topology (all connect to seed node)
|
||||
.validators(3) // Number of validator nodes
|
||||
.executors(2) // Number of executor nodes
|
||||
.apply() // Finish topology configuration
|
||||
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
|
||||
```
|
||||
|
||||
## Wallets
|
||||
@ -32,31 +32,32 @@ ScenarioBuilder::topology()
|
||||
## Transaction Workload
|
||||
|
||||
```rust
|
||||
.transactions()
|
||||
.rate(5) // 5 transactions per block
|
||||
.users(20) // Use 20 of the seeded wallets
|
||||
.apply() // Finish transaction workload config
|
||||
.transactions_with(|txs| {
|
||||
txs.rate(5) // 5 transactions per block
|
||||
.users(20) // Use 20 of the seeded wallets
|
||||
}) // Finish transaction workload config
|
||||
```
|
||||
|
||||
## DA Workload
|
||||
|
||||
```rust
|
||||
.da()
|
||||
.channel_rate(1) // 1 channel operation per block
|
||||
.blob_rate(2) // 2 blob dispersals per block
|
||||
.apply() // Finish DA workload config
|
||||
.da_with(|da| {
|
||||
da.channel_rate(1) // 1 channel operation per block
|
||||
.blob_rate(2) // 2 blob dispersals per block
|
||||
}) // Finish DA workload config
|
||||
```
|
||||
|
||||
## Chaos Workload (Requires `enable_node_control()`)
|
||||
|
||||
```rust
|
||||
.enable_node_control() // Enable node control capability
|
||||
.chaos()
|
||||
.restart() // Random restart chaos
|
||||
.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
|
||||
.apply() // Finish chaos workload config
|
||||
.chaos_with(|c| {
|
||||
c.restart() // Random restart chaos
|
||||
.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
|
||||
.apply()
|
||||
})
|
||||
```
|
||||
|
||||
## Expectations
|
||||
@ -106,20 +107,20 @@ use testing_framework_workflows::ScenarioBuilderExt;
|
||||
use std::time::Duration;
|
||||
|
||||
async fn run_test() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut plan = ScenarioBuilder::topology()
|
||||
.network_star()
|
||||
.validators(3)
|
||||
.executors(2)
|
||||
.apply()
|
||||
let mut plan = ScenarioBuilder::topology_with(|t| {
|
||||
t.network_star()
|
||||
.validators(3)
|
||||
.executors(2)
|
||||
})
|
||||
.wallets(50)
|
||||
.transactions()
|
||||
.rate(5) // 5 transactions per block
|
||||
.users(20)
|
||||
.apply()
|
||||
.da()
|
||||
.channel_rate(1) // 1 channel operation per block
|
||||
.blob_rate(2) // 2 blob dispersals per block
|
||||
.apply()
|
||||
.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
|
||||
})
|
||||
.expect_consensus_liveness()
|
||||
.with_run_duration(Duration::from_secs(90))
|
||||
.build();
|
||||
|
||||
@ -29,20 +29,20 @@ use testing_framework_workflows::ScenarioBuilderExt;
|
||||
use std::time::Duration;
|
||||
|
||||
// Define the scenario (1 validator + 1 executor, tx + DA workload)
|
||||
let mut plan = ScenarioBuilder::topology()
|
||||
.network_star()
|
||||
.validators(1)
|
||||
.executors(1)
|
||||
.apply()
|
||||
let mut plan = ScenarioBuilder::topology_with(|t| {
|
||||
t.network_star()
|
||||
.validators(1)
|
||||
.executors(1)
|
||||
})
|
||||
.wallets(64)
|
||||
.transactions()
|
||||
.rate(5) // 5 transactions per block
|
||||
.users(8)
|
||||
.apply()
|
||||
.da()
|
||||
.channel_rate(1) // 1 channel operation per block
|
||||
.blob_rate(1) // 1 blob dispersal per block
|
||||
.apply()
|
||||
.transactions_with(|txs| {
|
||||
txs.rate(5) // 5 transactions per block
|
||||
.users(8)
|
||||
})
|
||||
.da_with(|da| {
|
||||
da.channel_rate(1) // 1 channel operation per block
|
||||
.blob_rate(1) // 1 blob dispersal per block
|
||||
})
|
||||
.expect_consensus_liveness()
|
||||
.with_run_duration(Duration::from_secs(60))
|
||||
.build();
|
||||
@ -71,11 +71,11 @@ Let's unpack the code:
|
||||
### 1. Topology Configuration
|
||||
|
||||
```rust
|
||||
ScenarioBuilder::topology()
|
||||
.network_star() // Star topology: all nodes connect to seed
|
||||
.validators(1) // 1 validator node
|
||||
.executors(1) // 1 executor node (validator + DA dispersal)
|
||||
.apply()
|
||||
ScenarioBuilder::topology_with(|t| {
|
||||
t.network_star() // Star topology: all nodes connect to seed
|
||||
.validators(1) // 1 validator node
|
||||
.executors(1) // 1 executor node (validator + DA dispersal)
|
||||
})
|
||||
```
|
||||
|
||||
This defines **what** your test network looks like.
|
||||
@ -184,4 +184,3 @@ Now that you have a working test:
|
||||
- **See more examples**: [Examples](examples.md)
|
||||
- **API reference**: [Builder API Quick Reference](dsl-cheat-sheet.md)
|
||||
- **Debug failures**: [Troubleshooting](troubleshooting.md)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user