1- use anyhow:: { anyhow, Context } ;
1+ use anyhow:: anyhow;
22use cargo_lock:: Lockfile ;
33use cargo_toml:: Manifest ;
44use clap:: { App , Arg , SubCommand } ;
@@ -13,7 +13,7 @@ use solana_sdk::{
1313 pubkey:: Pubkey ,
1414} ;
1515use std:: {
16- io:: { Read , Write } ,
16+ io:: Read ,
1717 path:: PathBuf ,
1818 process:: { exit, Stdio } ,
1919 sync:: {
@@ -28,6 +28,9 @@ pub mod image_config;
2828pub mod solana_program;
2929use image_config:: IMAGE_MAP ;
3030
31+ #[ cfg( test) ]
32+ mod test;
33+
3134use crate :: {
3235 api:: send_job_to_remote,
3336 solana_program:: { process_close, upload_program} ,
@@ -1001,153 +1004,3 @@ pub fn get_pkg_name_from_cargo_toml(cargo_toml_file: &str) -> Option<String> {
10011004 let pkg = manifest. package ?;
10021005 Some ( pkg. name )
10031006}
1004-
1005- #[ cfg( test) ]
1006- fn test_verify_program_hash_helper ( expected_hash : & str , args : & [ & str ] ) -> anyhow:: Result < ( ) > {
1007- let mut child = std:: process:: Command :: new ( "./target/debug/solana-verify" )
1008- . args ( args)
1009- . stdin ( Stdio :: piped ( ) )
1010- . stdout ( Stdio :: piped ( ) )
1011- . stderr ( Stdio :: piped ( ) )
1012- . spawn ( )
1013- . context ( "Failed to execute solana-verify command" ) ?;
1014-
1015- if let Some ( mut stdin) = child. stdin . take ( ) {
1016- stdin. write_all ( b"n" ) ?;
1017- }
1018-
1019- let output = child
1020- . wait_with_output ( )
1021- . context ( "Failed to wait for solana-verify command" ) ?;
1022-
1023- if !output. status . success ( ) {
1024- let error = String :: from_utf8_lossy ( & output. stderr ) ;
1025- anyhow:: bail!( "Command failed: {}" , error) ;
1026- }
1027-
1028- // Print the last 10 lines of the output
1029- let output_str = String :: from_utf8_lossy ( & output. stdout ) ;
1030- let lines: Vec < & str > = output_str. split ( '\n' ) . collect ( ) ;
1031- let last_10_lines: Vec < String > = lines. iter ( ) . rev ( ) . take ( 10 ) . map ( |s| s. to_string ( ) ) . collect ( ) ;
1032- println ! ( "Last 10 lines of output:\n {}" , last_10_lines. join( "\n " ) ) ;
1033-
1034- let re = regex:: Regex :: new ( r"Executable Program Hash from repo: ([a-f0-9]{64})" )
1035- . context ( "Failed to compile regex" ) ?;
1036-
1037- let program_hash = re
1038- . captures ( & output_str)
1039- . context ( "Could not find program hash in output" ) ?
1040- . get ( 1 )
1041- . context ( "Invalid capture group" ) ?
1042- . as_str ( ) ;
1043-
1044- assert_eq ! (
1045- program_hash, expected_hash,
1046- "Program hash {} does not match expected value {}" ,
1047- program_hash, expected_hash
1048- ) ;
1049-
1050- Ok ( ( ) )
1051- }
1052-
1053- #[ test]
1054- fn test_phoenix_v1 ( ) -> anyhow:: Result < ( ) > {
1055- const EXPECTED_HASH : & str = "6877a5b732b3494b828a324ec846d526d962223959534dbaf4209e0da3b2d6a9" ;
1056- let args: Vec < & str > =
1057- "verify-from-repo -um --program-id PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY https://github.com/Ellipsis-Labs/phoenix-v1" . split ( " " ) . collect ( ) ;
1058- test_verify_program_hash_helper ( EXPECTED_HASH , & args) ?;
1059- Ok ( ( ) )
1060- }
1061-
1062- #[ test]
1063- fn test_squads_v3 ( ) -> anyhow:: Result < ( ) > {
1064- const EXPECTED_HASH : & str = "72da599d9ee14b2a03a23ccfa6f06d53eea4a00825ad2191929cbd78fb69205c" ;
1065- let args: Vec < & str > = "verify-from-repo https://github.com/Squads-Protocol/squads-mpl --commit-hash c95b7673d616c377a349ca424261872dfcf8b19d --program-id SMPLecH534NA9acpos4G6x7uf3LWbCAwZQE9e8ZekMu -um --library-name squads_mpl --bpf" . split ( " " ) . collect ( ) ;
1066- test_verify_program_hash_helper ( EXPECTED_HASH , & args) ?;
1067- Ok ( ( ) )
1068- }
1069-
1070- #[ test]
1071- fn test_drift_v2 ( ) -> anyhow:: Result < ( ) > {
1072- const EXPECTED_HASH : & str = "e31d58edeabc3c30bf6f2aa60bfaa5e492b41ec203e9006404b463e5adee5828" ;
1073- let args: Vec < & str > = "verify-from-repo -um --program-id dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH https://github.com/drift-labs/protocol-v2 --commit-hash 110d3ff4f8ba07c178d69f9bfc7b30194fac56d6 --library-name drift" . split ( " " ) . collect ( ) ;
1074- test_verify_program_hash_helper ( EXPECTED_HASH , & args) ?;
1075- Ok ( ( ) )
1076- }
1077-
1078- #[ test]
1079- fn test_marginfi_v2 ( ) -> anyhow:: Result < ( ) > {
1080- const EXPECTED_HASH : & str = "890d68f48f96991016222b1fcbc2cc81b8ef2dcbf280c44fe378c523c108fad5" ;
1081- let args: Vec < & str > = "verify-from-repo -um --program-id MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA https://github.com/mrgnlabs/marginfi-v2 --commit-hash d33e649e415c354cc2a1e3c49131725552d69ba0 --library-name marginfi" . split ( " " ) . collect ( ) ;
1082- test_verify_program_hash_helper ( EXPECTED_HASH , & args) ?;
1083- Ok ( ( ) )
1084- }
1085-
1086- #[ test]
1087- fn test_local_example ( ) -> anyhow:: Result < ( ) > {
1088- const EXPECTED_HASH : & str = "08d91368d349c2b56c712422f6d274a1e8f1946ff2ecd1dc3efc3ebace52a760" ;
1089-
1090- let args: Vec < & str > = "build ./examples/hello_world" . split ( " " ) . collect ( ) ;
1091- let child = std:: process:: Command :: new ( "./target/debug/solana-verify" )
1092- . args ( args)
1093- . stdin ( Stdio :: piped ( ) )
1094- . stdout ( Stdio :: piped ( ) )
1095- . stderr ( Stdio :: piped ( ) )
1096- . spawn ( )
1097- . context ( "Failed to execute solana-verify command" ) ?;
1098-
1099- let output = child
1100- . wait_with_output ( )
1101- . context ( "Failed to wait for solana-verify command" ) ?;
1102-
1103- if !output. status . success ( ) {
1104- let error = String :: from_utf8_lossy ( & output. stderr ) ;
1105- anyhow:: bail!( "Command failed: {}" , error) ;
1106- }
1107-
1108-
1109- let args: Vec < & str > = "get-executable-hash ./examples/hello_world/target/deploy/hello_world.so" . split ( " " ) . collect ( ) ;
1110- let child = std:: process:: Command :: new ( "./target/debug/solana-verify" )
1111- . args ( & args)
1112- . stdin ( Stdio :: piped ( ) )
1113- . stdout ( Stdio :: piped ( ) )
1114- . stderr ( Stdio :: piped ( ) )
1115- . spawn ( )
1116- . context ( "Failed to execute solana-verify command" ) ?;
1117-
1118- let output = child
1119- . wait_with_output ( )
1120- . context ( "Failed to wait for solana-verify command" ) ?;
1121-
1122- if !output. status . success ( ) {
1123- let error = String :: from_utf8_lossy ( & output. stderr ) . trim ( ) . to_string ( ) ;
1124- anyhow:: bail!( "Command failed: {}" , error) ;
1125- }
1126-
1127- let hash = String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) ;
1128- assert_eq ! ( hash, EXPECTED_HASH , "Program hash {} does not match expected value {}" , hash, EXPECTED_HASH ) ;
1129- Ok ( ( ) )
1130- }
1131-
1132-
1133- #[ test]
1134- fn test_verify_from_image ( ) -> anyhow:: Result < ( ) > {
1135- let args: Vec < & str > = "verify-from-image -e examples/hello_world/target/deploy/hello_world.so -i ellipsislabs/hello_world_verifiable_build:latest -p 2ZrriTQSVekoj414Ynysd48jyn4AX6ZF4TTJRqHfbJfn" . split ( " " ) . collect ( ) ;
1136- let child = std:: process:: Command :: new ( "./target/debug/solana-verify" )
1137- . args ( args)
1138- . stdin ( Stdio :: piped ( ) )
1139- . stdout ( Stdio :: piped ( ) )
1140- . stderr ( Stdio :: piped ( ) )
1141- . spawn ( )
1142- . context ( "Failed to execute solana-verify command" ) ?;
1143-
1144- let output = child
1145- . wait_with_output ( )
1146- . context ( "Failed to wait for solana-verify command" ) ?;
1147-
1148- if !output. status . success ( ) {
1149- let error = String :: from_utf8_lossy ( & output. stderr ) ;
1150- anyhow:: bail!( "Command failed: {}" , error) ;
1151- }
1152- Ok ( ( ) )
1153- }
0 commit comments