1- use osvm:: utils:: ebpf_deploy:: { DeployConfig , load_program_id, load_keypair , load_program } ;
2- use osvm :: utils :: ssh_deploy :: NetworkType ;
3- use std:: fs:: { self , File } ;
1+ use osvm:: utils:: ebpf_deploy:: { DeployConfig , load_program_id, load_program , deploy_to_all_networks } ;
2+ use solana_sdk :: commitment_config :: CommitmentConfig ;
3+ use std:: fs:: File ;
44use std:: io:: Write ;
5- use std:: path:: Path ;
65use tempfile:: tempdir;
76
87#[ test]
@@ -47,7 +46,7 @@ fn test_create_deploy_config() {
4746 owner_path : "path/to/owner.json" . to_string ( ) ,
4847 fee_payer_path : "path/to/fee_payer.json" . to_string ( ) ,
4948 publish_idl : true ,
50- network_type : NetworkType :: Devnet ,
49+ network_filter : "devnet" . to_string ( ) ,
5150 } ;
5251
5352 // Verify config fields
@@ -56,8 +55,87 @@ fn test_create_deploy_config() {
5655 assert_eq ! ( config. owner_path, "path/to/owner.json" ) ;
5756 assert_eq ! ( config. fee_payer_path, "path/to/fee_payer.json" ) ;
5857 assert ! ( config. publish_idl) ;
58+ assert_eq ! ( config. network_filter, "devnet" ) ;
5959
6060 // Clone the config and verify the clone
6161 let config_clone = config. clone ( ) ;
6262 assert_eq ! ( config_clone. binary_path, config. binary_path) ;
63+ }
64+
65+ #[ tokio:: test]
66+ async fn test_network_filter_logic ( ) {
67+ // This test only validates the network filtering logic without actually making network calls
68+ let dir = tempdir ( ) . unwrap ( ) ;
69+
70+ // Create test files
71+ let program_file = dir. path ( ) . join ( "program.so" ) ;
72+ let mut file = File :: create ( & program_file) . unwrap ( ) ;
73+ file. write_all ( b"dummy program" ) . unwrap ( ) ;
74+
75+ let program_id_file = dir. path ( ) . join ( "program_id.json" ) ;
76+ let mut file = File :: create ( & program_id_file) . unwrap ( ) ;
77+ file. write_all ( br#"{"programId": "HN4tEEGheziD9dqcWg4xZd29htcerjXKGoGiQXM5hxiS"}"# ) . unwrap ( ) ;
78+
79+ let owner_file = dir. path ( ) . join ( "owner.json" ) ;
80+ let mut file = File :: create ( & owner_file) . unwrap ( ) ;
81+ // Valid Ed25519 keypair (64 bytes)
82+ let keypair = [
83+ 74 , 97 , 123 , 217 , 156 , 17 , 153 , 238 , 153 , 193 , 31 , 227 , 15 , 68 , 138 , 151 ,
84+ 87 , 14 , 66 , 179 , 187 , 149 , 171 , 224 , 24 , 176 , 206 , 49 , 225 , 173 , 85 , 69 ,
85+ 35 , 85 , 76 , 4 , 41 , 56 , 193 , 80 , 141 , 162 , 202 , 35 , 90 , 29 , 138 , 14 ,
86+ 176 , 85 , 191 , 245 , 106 , 196 , 149 , 53 , 180 , 252 , 241 , 119 , 54 , 11 , 141 , 223
87+ ] ;
88+ file. write_all ( format ! ( "{:?}" , keypair. to_vec( ) ) . as_bytes ( ) ) . unwrap ( ) ;
89+
90+ let fee_payer_file = dir. path ( ) . join ( "fee_payer.json" ) ;
91+ let mut file = File :: create ( & fee_payer_file) . unwrap ( ) ;
92+ file. write_all ( format ! ( "{:?}" , keypair. to_vec( ) ) . as_bytes ( ) ) . unwrap ( ) ;
93+
94+ // Test "all" network filter
95+ let config_all = DeployConfig {
96+ binary_path : program_file. to_string_lossy ( ) . to_string ( ) ,
97+ program_id_path : program_id_file. to_string_lossy ( ) . to_string ( ) ,
98+ owner_path : owner_file. to_string_lossy ( ) . to_string ( ) ,
99+ fee_payer_path : fee_payer_file. to_string_lossy ( ) . to_string ( ) ,
100+ publish_idl : false ,
101+ network_filter : "all" . to_string ( ) ,
102+ } ;
103+
104+ // This would attempt network calls in a real scenario, but we're just testing the logic
105+ // The function should handle "all" and try to deploy to 3 networks (mainnet, testnet, devnet)
106+ let results = deploy_to_all_networks ( config_all, CommitmentConfig :: confirmed ( ) ) . await ;
107+
108+ // Should return 3 results (one for each network)
109+ assert_eq ! ( results. len( ) , 3 ) ;
110+
111+ // Test single network filter
112+ let config_single = DeployConfig {
113+ binary_path : program_file. to_string_lossy ( ) . to_string ( ) ,
114+ program_id_path : program_id_file. to_string_lossy ( ) . to_string ( ) ,
115+ owner_path : owner_file. to_string_lossy ( ) . to_string ( ) ,
116+ fee_payer_path : fee_payer_file. to_string_lossy ( ) . to_string ( ) ,
117+ publish_idl : false ,
118+ network_filter : "devnet" . to_string ( ) ,
119+ } ;
120+
121+ let results = deploy_to_all_networks ( config_single, CommitmentConfig :: confirmed ( ) ) . await ;
122+
123+ // Should return 1 result (devnet only)
124+ assert_eq ! ( results. len( ) , 1 ) ;
125+
126+ // Test invalid network filter
127+ let config_invalid = DeployConfig {
128+ binary_path : program_file. to_string_lossy ( ) . to_string ( ) ,
129+ program_id_path : program_id_file. to_string_lossy ( ) . to_string ( ) ,
130+ owner_path : owner_file. to_string_lossy ( ) . to_string ( ) ,
131+ fee_payer_path : fee_payer_file. to_string_lossy ( ) . to_string ( ) ,
132+ publish_idl : false ,
133+ network_filter : "invalid" . to_string ( ) ,
134+ } ;
135+
136+ let results = deploy_to_all_networks ( config_invalid, CommitmentConfig :: confirmed ( ) ) . await ;
137+
138+ // Should return 1 error result
139+ assert_eq ! ( results. len( ) , 1 ) ;
140+ assert ! ( results[ 0 ] . is_err( ) ) ;
63141}
0 commit comments