File tree Expand file tree Collapse file tree 5 files changed +57
-11
lines changed
Expand file tree Collapse file tree 5 files changed +57
-11
lines changed Original file line number Diff line number Diff line change 1010
1111# nix
1212result
13- * .log
13+ * .log
14+ .idea
Original file line number Diff line number Diff line change 1+ # Network Token Replacement Example: Custom Base Path
2+ #
3+ # This example demonstrates how to use network token replacement to customize
4+ # the --base-path argument while reusing zombienet's auto-generated base directory.
5+ #
6+ # The token {{'network'|zombie('base_path')}} gets replaced with the network's
7+ # temporary directory path at runtime (e.g., /tmp/zombie-abc123/alice/data),
8+ # allowing you to append custom suffixes like "/alice-custom-data".
9+ #
10+ # Available network token:
11+ # - {{'network'|zombie('base_path')}} - Node-specific data path (tmpDir + /custom_data_path)
12+
13+ [relaychain ]
14+ default_image = " docker.io/paritypr/polkadot-debug:master"
15+ default_command = " polkadot"
16+ default_args = [ " -lparachain=debug" ]
17+ default_substrate_cli_args_version = " 2"
18+
19+ chain = " rococo-local"
20+
21+ [[relaychain .nodes ]]
22+ name = " alice"
23+ validator = true
24+ args = [
25+ " --database=paritydb-experimental" ,
26+ " --base-path={{'network'|zombie('base_path')}}/alice-custom-data" ,
27+ ]
28+
29+ [[parachains ]]
30+ id = 100
31+ default_substrate_cli_args_version = " 2"
32+
33+ [parachains .collator ]
34+ name = " collator01"
35+ image = " docker.io/parity/polkadot-parachain:latest"
36+ command = " polkadot-parachain"
37+ args = [" -lparachain=debug" ]
Original file line number Diff line number Diff line change @@ -312,11 +312,13 @@ export async function genCmd(
312312 ) ;
313313 }
314314
315- // set our base path
316- const basePathFlagIndex = args . findIndex ( ( arg ) => arg === "--base-path" ) ;
317- if ( basePathFlagIndex >= 0 ) args . splice ( basePathFlagIndex , 2 ) ;
318- args . push ( ...[ "--base-path" , dataPath ] ) ;
319-
315+ // set our base path - only if user hasn't provided one
316+ const hasUserBasePath = args . some (
317+ ( arg ) => arg === "--base-path" || arg . startsWith ( "--base-path=" ) ,
318+ ) ;
319+ if ( ! hasUserBasePath ) {
320+ args . push ( ...[ "--base-path" , dataPath ] ) ;
321+ }
320322 if ( nodeSetup . substrateCliArgsVersion === SubstrateCliArgsVersion . V0 )
321323 args . push ( "--unsafe-ws-external" ) ;
322324
Original file line number Diff line number Diff line change @@ -384,9 +384,14 @@ export class Network {
384384 replaceWithNetworInfo ( placeholder : string ) : string {
385385 return placeholder . replace (
386386 TOKEN_PLACEHOLDER ,
387- ( _substring , nodeName , key : keyof NetworkNode ) => {
388- const node = this . getNodeByName ( nodeName ) ;
389- return node [ key ] ;
387+ ( _substring , nodeNameOrNetwork , key : keyof NetworkNode ) => {
388+ if ( nodeNameOrNetwork === "network" ) {
389+ const key_to_use = ( key as string ) == "base_path" ? "tmpDir" : key ;
390+ return this [ key_to_use as keyof Network ] ;
391+ } else {
392+ const node = this . getNodeByName ( nodeNameOrNetwork ) ;
393+ return node [ key as keyof NetworkNode ] ;
394+ }
390395 } ,
391396 ) ;
392397 }
Original file line number Diff line number Diff line change @@ -161,8 +161,9 @@ export function readNetworkConfig(filepath: string): LaunchConfig {
161161 const configBasePath = path . dirname ( filepath ) ;
162162 const env = new Environment ( new RelativeLoader ( [ configBasePath ] ) ) ;
163163
164- env . addFilter ( "zombie" , function ( nodeName , key ) {
165- return `{{ZOMBIE:${ nodeName } :${ key } }}` ;
164+ // 'network' or 'node name' replacement keywords
165+ env . addFilter ( "zombie" , function ( networkOrNodeName , key ) {
166+ return `{{ZOMBIE:${ networkOrNodeName } :${ key } }}` ;
166167 } ) ;
167168
168169 const temmplateContent = fs . readFileSync ( filepath ) . toString ( ) ;
You can’t perform that action at this time.
0 commit comments