Skip to content

Commit d6d52cb

Browse files
committed
Add tests for repeated and comma-separated --uri parsing
1 parent d7dc141 commit d6d52cb

3 files changed

Lines changed: 58 additions & 15 deletions

File tree

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,29 @@ cargo build --features try-runtime --release && cp target/release/substrate .
184184

185185
```bash
186186
# Assuming local nodes are running (e.g., `./substrate --dev --tmp --ws-port 9999`).
187-
# Multiple --uri flags can be provided for parallel state download.
187+
# Multiple URIs can be provided for parallel state download, either
188+
# comma-separated or via repeated --uri flags.
188189
try-runtime \
189190
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
190191
on-runtime-upgrade \
191192
--disable-mbm-checks \
192193
live \
193-
--uri ws://localhost:9999 \
194-
--uri ws://localhost:9998
194+
--uri ws://localhost:9999,ws://localhost:9998
195195
...
196196
```
197197

198198
To speed up state download, you can provide multiple URIs for parallel fetching:
199199

200200
```bash
201201
# assuming multiple substrate nodes running on ports 9999, 9998, 9997
202+
# comma-separated:
203+
try-runtime \
204+
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
205+
on-runtime-upgrade \
206+
live \
207+
--uri ws://localhost:9999,ws://localhost:9998,ws://localhost:9997
208+
209+
# or repeated flags:
202210
try-runtime \
203211
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
204212
on-runtime-upgrade \
@@ -210,8 +218,8 @@ try-runtime \
210218

211219
* Same as the previous example, but run it at specific block number's state and using the live
212220
polkadot network. This means that this block hash's state should not yet have been pruned by
213-
the node running at `rpc.polkadot.io`. Multiple `--uri` flags can be provided for parallel
214-
state download.
221+
the node running at `rpc.polkadot.io`. Multiple URIs can be provided for parallel
222+
state download (comma-separated or via repeated `--uri` flags).
215223

216224
```bash
217225
try-runtime \
@@ -236,8 +244,7 @@ For faster snapshot creation with large state, use multiple RPC endpoints:
236244

237245
```bash
238246
try-runtime --runtime existing create-snapshot \
239-
--uri ws://localhost:9999 \
240-
--uri ws://localhost:9998 \
247+
--uri ws://localhost:9999,ws://localhost:9998 \
241248
-- my-snapshot.snap
242249
```
243250

cli/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,28 @@
200200
//!
201201
//! ```bash
202202
//! # Assuming local nodes are running (e.g., `./substrate --dev --tmp --ws-port 9999`).
203-
//! # Multiple --uri flags can be provided for parallel state download.
203+
//! # Multiple URIs can be provided for parallel state download, either
204+
//! # comma-separated or via repeated --uri flags.
204205
//! try-runtime \
205206
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
206207
//! on-runtime-upgrade \
207208
//! --disable-mbm-checks \
208209
//! live \
209-
//! --uri ws://localhost:9999 \
210-
//! --uri ws://localhost:9998
210+
//! --uri ws://localhost:9999,ws://localhost:9998
211211
//! ...
212212
//! ```
213213
//!
214214
//! To speed up state download, you can provide multiple URIs for parallel fetching:
215215
//!
216216
//! ```bash
217-
//! # assuming multiple substrate nodes running on ports 9999, 9998, 9997
217+
//! # comma-separated:
218+
//! try-runtime \
219+
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
220+
//! on-runtime-upgrade \
221+
//! live \
222+
//! --uri ws://localhost:9999,ws://localhost:9998,ws://localhost:9997
223+
//!
224+
//! # or repeated flags:
218225
//! try-runtime \
219226
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
220227
//! on-runtime-upgrade \
@@ -226,8 +233,8 @@
226233
//!
227234
//! * Same as the previous example, but run it at specific block number's state and using the live
228235
//! polkadot network. This means that this block hash's state should not yet have been pruned by
229-
//! the node running at `rpc.polkadot.io`. Multiple `--uri` flags can be provided for parallel
230-
//! state download.
236+
//! the node running at `rpc.polkadot.io`. Multiple URIs can be provided for parallel
237+
//! state download (comma-separated or via repeated `--uri` flags).
231238
//!
232239
//! ```bash
233240
//! try-runtime \
@@ -252,8 +259,7 @@
252259
//!
253260
//! ```bash
254261
//! try-runtime --runtime existing create-snapshot \
255-
//! --uri ws://localhost:9999 \
256-
//! --uri ws://localhost:9998 \
262+
//! --uri ws://localhost:9999,ws://localhost:9998 \
257263
//! -- my-snapshot.snap
258264
//! ```
259265
//!

core/src/common/state.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ mod tests {
495495
state: State,
496496
}
497497

498+
/// Multiple URIs via repeated `--uri` flags.
498499
#[test]
499500
fn uri_repeated_flags() {
500501
let cli = TestCli::parse_from([
@@ -513,6 +514,7 @@ mod tests {
513514
}
514515
}
515516

517+
/// Multiple URIs via comma-separated value in a single `--uri`.
516518
#[test]
517519
fn uri_comma_separated() {
518520
let cli = TestCli::parse_from([
@@ -529,6 +531,33 @@ mod tests {
529531
}
530532
}
531533

534+
/// Mixing repeated flags with comma-separated values in a single invocation.
535+
#[test]
536+
fn uri_mixed_repeated_and_comma() {
537+
let cli = TestCli::parse_from([
538+
"test",
539+
"live",
540+
"--uri",
541+
"ws://localhost:9999,ws://localhost:9998",
542+
"--uri",
543+
"ws://localhost:9997",
544+
]);
545+
match cli.state {
546+
State::Live(live) => {
547+
assert_eq!(
548+
live.uri,
549+
vec![
550+
"ws://localhost:9999",
551+
"ws://localhost:9998",
552+
"ws://localhost:9997",
553+
]
554+
);
555+
}
556+
_ => panic!("expected Live variant"),
557+
}
558+
}
559+
560+
/// Single URI, the common case.
532561
#[test]
533562
fn uri_single_value() {
534563
let cli = TestCli::parse_from(["test", "live", "--uri", "wss://rpc.polkadot.io:443"]);
@@ -540,6 +569,7 @@ mod tests {
540569
}
541570
}
542571

572+
/// Arguments after `--uri` are not greedily consumed (the original bug).
543573
#[test]
544574
fn uri_positional_not_swallowed() {
545575
let cli = TestCli::parse_from([

0 commit comments

Comments
 (0)