@@ -4,6 +4,7 @@ mod tests {
44 use serde_json:: json;
55 use tokio;
66 use bitcoin_da_client:: { SyscoinClient } ;
7+ use hex;
78
89
910 #[ tokio:: test]
@@ -226,7 +227,59 @@ mod tests {
226227 assert ! ( result. is_err( ) ) ;
227228 }
228229
229-
230+ #[ tokio:: test]
231+ async fn test_get_blob ( ) {
232+ use hex:: encode;
233+
234+ let mut mock_server = std:: thread:: spawn ( || {
235+ Server :: new ( )
236+ } ) . join ( ) . expect ( "Failed to create mock server" ) ;
237+
238+ let expected_data = b"hello world blob data" . to_vec ( ) ;
239+ let hex_data = encode ( & expected_data) ;
240+ let blob_id = "deadbeef123" ;
241+
242+ // Mock the RPC endpoint
243+ let mock_response = json ! ( {
244+ "result" : {
245+ "data" : hex_data
246+ } ,
247+ "error" : null,
248+ "id" : 1
249+ } ) ;
250+
251+ // Mock the JSON-RPC POST request
252+ mock_server
253+ . mock ( "POST" , "/" )
254+ . with_status ( 200 )
255+ . with_header ( "content-type" , "application/json" )
256+ . with_body ( mock_response. to_string ( ) )
257+ . create ( ) ;
258+
259+ // ALSO mock the fallback cloud GET endpoint
260+ // The url format should match what's in get_blob_from_cloud
261+ mock_server
262+ . mock ( "GET" , format ! ( "/{}" , blob_id) . as_str ( ) )
263+ . with_status ( 200 )
264+ . with_body ( & expected_data)
265+ . create ( ) ;
266+
267+ let client = SyscoinClient :: new (
268+ & mock_server. url ( ) ,
269+ "user" ,
270+ "password" ,
271+ & mock_server. url ( ) , // Same server for both
272+ None
273+ ) . unwrap ( ) ;
274+
275+ // Add very detailed debug info
276+ println ! ( "Server URL: {}" , & mock_server. url( ) ) ;
277+ println ! ( "Blob ID: {}" , blob_id) ;
278+
279+ let result = client. get_blob ( blob_id) . await ;
280+ assert ! ( result. is_ok( ) , "Error: {:?}" , result. err( ) ) ;
281+ assert_eq ! ( result. unwrap( ) , expected_data) ;
282+ }
230283
231284}
232285
0 commit comments