| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | use assert_cmd::prelude::*;
 | 
					
						
							| 
									
										
										
										
											2019-11-13 08:14:09 -07:00
										 |  |  | use solana_ledger::create_new_tmp_ledger;
 | 
					
						
							| 
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 |  |  | use solana_ledger::genesis_utils::create_genesis_config;
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | use std::process::Command;
 | 
					
						
							|  |  |  | use std::process::Output;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fn run_ledger_tool(args: &[&str]) -> Output {
 | 
					
						
							| 
									
										
										
										
											2019-01-29 13:10:48 -06:00
										 |  |  |     Command::cargo_bin(env!("CARGO_PKG_NAME"))
 | 
					
						
							|  |  |  |         .unwrap()
 | 
					
						
							|  |  |  |         .args(args)
 | 
					
						
							|  |  |  |         .output()
 | 
					
						
							|  |  |  |         .unwrap()
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fn count_newlines(chars: &[u8]) -> usize {
 | 
					
						
							| 
									
										
										
										
											2020-05-15 17:35:43 +01:00
										 |  |  |     bytecount::count(chars, b'\n')
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn bad_arguments() {
 | 
					
						
							|  |  |  |     // At least a ledger path is required
 | 
					
						
							|  |  |  |     assert!(!run_ledger_tool(&[]).status.success());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Invalid ledger path should fail
 | 
					
						
							|  |  |  |     assert!(!run_ledger_tool(&["-l", "invalid_ledger", "verify"])
 | 
					
						
							|  |  |  |         .status
 | 
					
						
							|  |  |  |         .success());
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn nominal() {
 | 
					
						
							| 
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 |  |  |     let genesis_config = create_genesis_config(100).genesis_config;
 | 
					
						
							|  |  |  |     let ticks_per_slot = genesis_config.ticks_per_slot;
 | 
					
						
							| 
									
										
										
										
											2020-04-09 20:10:51 -07:00
										 |  |  |     let meta_lines = 2;
 | 
					
						
							| 
									
										
										
										
											2019-02-26 16:35:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-08 23:56:57 -05:00
										 |  |  |     let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
 | 
					
						
							| 
									
										
										
										
											2019-02-26 16:35:00 -08:00
										 |  |  |     let ticks = ticks_per_slot as usize;
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-30 15:53:41 -07:00
										 |  |  |     let ledger_path = ledger_path.to_str().unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  |     // Basic validation
 | 
					
						
							| 
									
										
										
										
											2021-06-18 15:34:46 +02:00
										 |  |  |     let output = run_ledger_tool(&["-l", ledger_path, "verify"]);
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  |     assert!(output.status.success());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Print everything
 | 
					
						
							| 
									
										
										
										
											2021-06-18 15:34:46 +02:00
										 |  |  |     let output = run_ledger_tool(&["-l", ledger_path, "print", "-vvv"]);
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  |     assert!(output.status.success());
 | 
					
						
							| 
									
										
										
										
											2020-06-27 10:47:02 -07:00
										 |  |  |     assert_eq!(count_newlines(&output.stdout), ticks + meta_lines);
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | }
 |