1- use crate :: { cli:: test:: SovereignParams , start_maybe_quiet } ;
1+ use crate :: { cli:: test:: SovereignParams , logging :: create_with_logs } ;
22use anyhow:: bail;
33use duct:: cmd;
44use tracing:: info;
55
6- pub struct Sovereign ( duct:: Handle ) ;
6+ pub struct Sovereign {
7+ process : duct:: Handle ,
8+ with_logs : Box < dyn Fn ( & str , duct:: Expression ) -> duct:: Expression > ,
9+ }
710
811impl Sovereign {
912 // Try launching the sovereing rollup using zombienet
1013 pub fn try_new ( params : SovereignParams ) -> anyhow:: Result < Self > {
1114 info ! ( "Deleting rollup db if it already exists" ) ;
1215 cmd ! ( "rm" , "-r" , "demo/sovereign/demo-rollup/demo_data" )
1316 . unchecked ( )
17+ . stderr_null ( )
18+ . stdout_null ( )
1419 . run ( ) ?;
1520
21+ info ! ( "Sovereign logs redirected to {}" , params. log_path) ;
22+ let with_logs = create_with_logs ( params. log_path . clone ( ) ) ;
23+
1624 //TODO: https://github.com/thrumdev/blobs/issues/227
17- info ! ( "Launching sovereign rollup" ) ;
1825 #[ rustfmt:: skip]
19- let sovereign_handle = start_maybe_quiet (
26+ let sovereign_handle = with_logs (
27+ "Launching sovereign rollup" ,
2028 cmd ! (
2129 "sh" , "-c" ,
2230 "cd demo/sovereign/demo-rollup && ./../target/release/sov-demo-rollup"
2331 ) ,
24- params. quiet ,
25- ) ?;
32+ ) . start ( ) ?;
2633
27- Ok ( Self ( sovereign_handle) )
34+ Ok ( Self {
35+ process : sovereign_handle,
36+ with_logs,
37+ } )
2838 }
2939
3040 // All the networks must be up (relaychain and sugondat-node), including the sovereign rollup."
@@ -34,37 +44,43 @@ impl Sovereign {
3444 //TODO: https://github.com/thrumdev/blobs/issues/227
3545 let cli = "../target/release/sov-cli" ;
3646 let test_data_path = "../test-data/" ;
37- let run_cli_cmd = |args : & str | {
38- let args = [
39- "-c" ,
40- & format ! ( "cd demo/sovereign/demo-rollup/ && ./{} {}" , cli, args) ,
41- ] ;
42-
43- duct:: cmd ( "sh" , args) . run ( )
44- } ;
45-
46- info ! ( "setup rpc endpoint" ) ;
47- run_cli_cmd ( "rpc set-url http://127.0.0.1:12345" ) ?;
48-
49- info ! ( "import keys" ) ;
50- run_cli_cmd ( & format ! (
51- "keys import --nickname token_deployer --path {}keys/token_deployer_private_key.json" ,
52- test_data_path
53- ) ) ?;
54-
55- info ! ( "create and mint a new token" ) ;
56- run_cli_cmd ( & format ! (
57- "transactions import from-file bank --path {}requests/create_token.json" ,
58- test_data_path
59- ) ) ?;
60-
61- run_cli_cmd ( & format ! (
62- "transactions import from-file bank --path {}requests/mint.json" ,
63- test_data_path
64- ) ) ?;
65-
66- info ! ( "submit batch with two transactions" ) ;
67- run_cli_cmd ( "rpc submit-batch by-nickname token_deployer" ) ?;
47+ let run_cli_cmd =
48+ |description : & str , args : & str | -> std:: io:: Result < std:: process:: Output > {
49+ let args = [
50+ "-c" ,
51+ & format ! ( "cd demo/sovereign/demo-rollup/ && ./{} {}" , cli, args) ,
52+ ] ;
53+
54+ ( self . with_logs ) ( description, duct:: cmd ( "sh" , args) ) . run ( )
55+ } ;
56+
57+ run_cli_cmd ( "setup rpc endpoint" , "rpc set-url http://127.0.0.1:12345" ) ?;
58+
59+ run_cli_cmd (
60+ "import keys" ,
61+ & format ! ( "keys import --nickname token_deployer --path {}keys/token_deployer_private_key.json" , test_data_path) ,
62+ ) ?;
63+
64+ run_cli_cmd (
65+ "create a new token" ,
66+ & format ! (
67+ "transactions import from-file bank --path {}requests/create_token.json" ,
68+ test_data_path
69+ ) ,
70+ ) ?;
71+
72+ run_cli_cmd (
73+ "mint just created token" ,
74+ & format ! (
75+ "transactions import from-file bank --path {}requests/mint.json" ,
76+ test_data_path
77+ ) ,
78+ ) ?;
79+
80+ run_cli_cmd (
81+ "submit batch with two transactions" ,
82+ "rpc submit-batch by-nickname token_deployer" ,
83+ ) ?;
6884
6985 // TODO: https://github.com/thrumdev/blobs/issues/226
7086 info ! ( "waiting for the rollup to process the transactions" ) ;
@@ -90,6 +106,6 @@ impl Drop for Sovereign {
90106 // duct::Handle does not implement kill on drop
91107 fn drop ( & mut self ) {
92108 info ! ( "Sovereign rollup process is going to be killed" ) ;
93- let _ = self . 0 . kill ( ) ;
109+ let _ = self . process . kill ( ) ;
94110 }
95111}
0 commit comments