| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  | use serde_json::{json, Value};
 | 
					
						
							| 
									
										
										
										
											2019-08-22 13:51:16 -07:00
										 |  |  | use solana_cli::wallet::{process_command, WalletCommand, WalletConfig};
 | 
					
						
							| 
									
										
										
										
											2019-03-16 22:37:20 -07:00
										 |  |  | use solana_client::rpc_client::RpcClient;
 | 
					
						
							|  |  |  | use solana_client::rpc_request::RpcRequest;
 | 
					
						
							| 
									
										
										
										
											2019-08-21 10:23:33 -07:00
										 |  |  | use solana_core::validator::new_validator_for_tests;
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  | use solana_drone::drone::run_local_drone;
 | 
					
						
							|  |  |  | use solana_sdk::bpf_loader;
 | 
					
						
							|  |  |  | use std::fs::{remove_dir_all, File};
 | 
					
						
							|  |  |  | use std::io::Read;
 | 
					
						
							|  |  |  | use std::path::PathBuf;
 | 
					
						
							|  |  |  | use std::sync::mpsc::channel;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn test_wallet_deploy_program() {
 | 
					
						
							| 
									
										
										
										
											2019-02-05 08:03:52 -08:00
										 |  |  |     solana_logger::setup();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  |     let mut pathbuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
 | 
					
						
							|  |  |  |     pathbuf.push("tests");
 | 
					
						
							|  |  |  |     pathbuf.push("fixtures");
 | 
					
						
							|  |  |  |     pathbuf.push("noop");
 | 
					
						
							|  |  |  |     pathbuf.set_extension("so");
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-23 22:05:16 -07:00
										 |  |  |     let (server, leader_data, alice, ledger_path) = new_validator_for_tests();
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let (sender, receiver) = channel();
 | 
					
						
							| 
									
										
										
										
											2019-04-08 12:37:01 -07:00
										 |  |  |     run_local_drone(alice, sender, None);
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  |     let drone_addr = receiver.recv().unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-15 22:42:36 -07:00
										 |  |  |     let rpc_client = RpcClient::new_socket(leader_data.rpc);
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let mut config = WalletConfig::default();
 | 
					
						
							| 
									
										
										
										
											2019-05-06 07:38:26 -07:00
										 |  |  |     config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
 | 
					
						
							| 
									
										
										
										
											2019-08-29 20:45:53 -07:00
										 |  |  |     config.command = WalletCommand::Airdrop {
 | 
					
						
							|  |  |  |         drone_host: None,
 | 
					
						
							|  |  |  |         drone_port: drone_addr.port(),
 | 
					
						
							|  |  |  |         lamports: 50,
 | 
					
						
							|  |  |  |     };
 | 
					
						
							| 
									
										
										
										
											2019-01-28 14:52:35 -08:00
										 |  |  |     process_command(&config).unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     config.command = WalletCommand::Deploy(pathbuf.to_str().unwrap().to_string());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let response = process_command(&config);
 | 
					
						
							|  |  |  |     let json: Value = serde_json::from_str(&response.unwrap()).unwrap();
 | 
					
						
							|  |  |  |     let program_id_str = json
 | 
					
						
							|  |  |  |         .as_object()
 | 
					
						
							|  |  |  |         .unwrap()
 | 
					
						
							|  |  |  |         .get("programId")
 | 
					
						
							|  |  |  |         .unwrap()
 | 
					
						
							|  |  |  |         .as_str()
 | 
					
						
							|  |  |  |         .unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let params = json!([program_id_str]);
 | 
					
						
							|  |  |  |     let account_info = rpc_client
 | 
					
						
							| 
									
										
										
										
											2019-03-16 21:51:41 -07:00
										 |  |  |         .retry_make_rpc_request(&RpcRequest::GetAccountInfo, Some(params), 0)
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  |         .unwrap();
 | 
					
						
							|  |  |  |     let account_info_obj = account_info.as_object().unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-03-05 16:28:14 -08:00
										 |  |  |     assert_eq!(
 | 
					
						
							|  |  |  |         account_info_obj.get("lamports").unwrap().as_u64().unwrap(),
 | 
					
						
							|  |  |  |         1
 | 
					
						
							|  |  |  |     );
 | 
					
						
							| 
									
										
										
										
											2019-02-14 12:32:26 -07:00
										 |  |  |     let owner_array = account_info.get("owner").unwrap();
 | 
					
						
							|  |  |  |     assert_eq!(owner_array, &json!(bpf_loader::id()));
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  |     assert_eq!(
 | 
					
						
							|  |  |  |         account_info_obj
 | 
					
						
							|  |  |  |             .get("executable")
 | 
					
						
							|  |  |  |             .unwrap()
 | 
					
						
							|  |  |  |             .as_bool()
 | 
					
						
							|  |  |  |             .unwrap(),
 | 
					
						
							|  |  |  |         true
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let mut file = File::open(pathbuf.to_str().unwrap().to_string()).unwrap();
 | 
					
						
							|  |  |  |     let mut elf = Vec::new();
 | 
					
						
							|  |  |  |     file.read_to_end(&mut elf).unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2019-03-14 10:48:27 -06:00
										 |  |  |         account_info_obj.get("data").unwrap().as_array().unwrap(),
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  |         &elf
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-03 16:44:06 -08:00
										 |  |  |     server.close().unwrap();
 | 
					
						
							| 
									
										
										
										
											2019-01-17 09:49:32 -07:00
										 |  |  |     remove_dir_all(ledger_path).unwrap();
 | 
					
						
							|  |  |  | }
 |