| 
									
										
										
										
											2019-02-26 19:19:34 -08:00
										 |  |  | #[macro_use]
 | 
					
						
							| 
									
										
										
										
											2019-10-18 10:28:51 -06:00
										 |  |  | extern crate solana_ledger;
 | 
					
						
							| 
									
										
										
										
											2019-02-26 19:19:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | use assert_cmd::prelude::*;
 | 
					
						
							| 
									
										
										
										
											2019-10-18 10:28:51 -06:00
										 |  |  | use solana_ledger::blocktree::create_new_tmp_ledger;
 | 
					
						
							| 
									
										
										
										
											2019-10-20 09:54:38 -06:00
										 |  |  | use solana_ledger::genesis_utils::create_genesis_block;
 | 
					
						
							| 
									
										
										
										
											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 {
 | 
					
						
							|  |  |  |     chars.iter().filter(|&c| *c == '\n' as u8).count()
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[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-05-22 20:39:00 -07:00
										 |  |  |     let genesis_block = create_genesis_block(100).genesis_block;
 | 
					
						
							| 
									
										
										
										
											2019-02-22 22:55:46 -07:00
										 |  |  |     let ticks_per_slot = genesis_block.ticks_per_slot;
 | 
					
						
							| 
									
										
										
										
											2019-02-26 16:35:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-02 10:25:16 -08:00
										 |  |  |     let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |     let output = run_ledger_tool(&["-l", &ledger_path, "verify"]);
 | 
					
						
							|  |  |  |     assert!(output.status.success());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Print everything
 | 
					
						
							|  |  |  |     let output = run_ledger_tool(&["-l", &ledger_path, "print"]);
 | 
					
						
							|  |  |  |     assert!(output.status.success());
 | 
					
						
							| 
									
										
										
										
											2019-07-11 20:33:36 -07:00
										 |  |  |     assert_eq!(count_newlines(&output.stdout), ticks + 1);
 | 
					
						
							| 
									
										
										
										
											2018-12-07 20:44:59 -08:00
										 |  |  | }
 |