cdp-sdk 0.5.0

SDK for interacting with the Coinbase Developer Platform Wallet API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
use alloy::consensus::SignableTransaction;
use alloy::primitives::{address, hex};
use alloy::{network::TransactionBuilder, primitives::U256, rpc::types::TransactionRequest};
use base64::Engine;
use cdp_sdk::{auth::WalletAuth, types, Client, CDP_BASE_URL};
use rand::Rng;
use reqwest_middleware::ClientBuilder;
use std::env;

/// Helper struct for logging
struct Logger {
    enabled: bool,
}

impl Logger {
    fn new() -> Self {
        Self {
            enabled: env::var("E2E_LOGGING").unwrap_or_default() == "true",
        }
    }

    fn log(&self, msg: &str) {
        if self.enabled {
            println!("{}", msg);
        }
    }

    fn _warn(&self, msg: &str) {
        if self.enabled {
            eprintln!("WARN: {}", msg);
        }
    }

    fn _error(&self, msg: &str) {
        if self.enabled {
            eprintln!("ERROR: {}", msg);
        }
    }
}

/// Helper function to generate random account names
fn generate_random_name() -> String {
    let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    let chars_with_hyphen = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
    let min_length = 5;

    let mut rng = rand::rng();

    let first_char = chars.chars().nth(rng.random_range(0..chars.len())).unwrap();

    let middle_length = std::cmp::max(rng.random_range(0..34), min_length);
    let middle_part: String = (0..middle_length)
        .map(|_| {
            chars_with_hyphen
                .chars()
                .nth(rng.random_range(0..chars_with_hyphen.len()))
                .unwrap()
        })
        .collect();

    let last_char = chars.chars().nth(rng.random_range(0..chars.len())).unwrap();

    format!("{}{}{}", first_char, middle_part, last_char)
}

/// Create test client with authentication
fn create_test_client() -> Result<Client, Box<dyn std::error::Error>> {
    let base_path = env::var("E2E_BASE_PATH").unwrap_or_else(|_| CDP_BASE_URL.to_string());

    let wallet_auth = WalletAuth::builder().debug(true).build()?;

    let http_client = ClientBuilder::new(reqwest::Client::new())
        .with(wallet_auth)
        .build();

    let client = Client::new_with_client(&base_path, http_client);

    Ok(client)
}

#[tokio::test]
async fn test_evm_account_crud_operations() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing EVM account CRUD operations");

    // Test create account
    let random_name = generate_random_name();
    logger.log(&format!("Creating account with name: {}", random_name));

    let body = types::CreateEvmAccountBody::builder().name(Some(random_name.clone().parse()?));

    let response = client
        .create_evm_account()
        .x_wallet_auth("") // Added by WalletAuth middleware
        .body(body)
        .send()
        .await?;

    // Verify the response is successful
    assert!(response.status().is_success());
    let account = response.into_inner();

    // Verify the name and address
    assert_eq!(
        account.name.as_ref().map(|n| n.as_str()),
        Some(random_name.as_str())
    );
    assert!(!account.address.is_empty());
    assert!(account.address.starts_with("0x"));

    logger.log(&format!(
        "Successfully created EVM account with name: {:?} and address: {:?}",
        account.name, account.address
    ));

    let account_address = account.address.clone();
    let account_name = account.name.clone();

    // Test get_evm_account by address
    logger.log("Testing get_evm_account by address");
    let get_response = client
        .get_evm_account()
        .address(account_address.to_string())
        .send()
        .await?;

    assert!(get_response.status().is_success());
    let retrieved_account = get_response.into_inner();

    assert_eq!(retrieved_account.address, account_address);
    assert_eq!(retrieved_account.name, account_name);
    logger.log("Successfully retrieved account by address");

    // Test get_evm_account_by_name
    logger.log("Testing get_evm_account_by_name");
    let get_by_name_response = client
        .get_evm_account_by_name()
        .name(&random_name)
        .send()
        .await?;

    assert!(get_by_name_response.status().is_success());
    let retrieved_by_name_account = get_by_name_response.into_inner();

    assert_eq!(retrieved_by_name_account.address, account_address);
    assert_eq!(retrieved_by_name_account.name, account_name);
    logger.log("Successfully retrieved account by name");

    // Test list_evm_accounts
    logger.log("Testing list_evm_accounts");
    let list_response = client.list_evm_accounts().page_size(10).send().await?;

    assert!(list_response.status().is_success());
    let accounts_list = list_response.into_inner();

    // Verify our account is in the list
    logger.log(&format!(
        "Successfully listed accounts, found {} accounts",
        accounts_list.accounts.len()
    ));
    assert!(
        !accounts_list.accounts.is_empty(),
        "Accounts list should not be empty"
    );

    // Test update_evm_account
    logger.log("Testing update_evm_account");
    let updated_name = generate_random_name();

    let update_body =
        types::UpdateEvmAccountBody::builder().name(Some(updated_name.clone().parse()?));

    let update_response = client
        .update_evm_account()
        .address(account_address.to_string())
        .body(update_body)
        .send()
        .await?;

    assert!(update_response.status().is_success());
    let updated_account = update_response.into_inner();

    assert_eq!(updated_account.address, account_address);
    assert_eq!(
        updated_account.name.as_ref().map(|n| n.as_str()),
        Some(updated_name.as_str())
    );
    logger.log(&format!(
        "Successfully updated account name to: {}",
        updated_name
    ));

    // Verify the update by getting the account again
    logger.log("Verifying account update");
    let verify_response = client
        .get_evm_account()
        .address(account_address.to_string())
        .send()
        .await?;

    assert!(verify_response.status().is_success());
    let verified_account = verify_response.into_inner();

    assert_eq!(verified_account.address, account_address);
    assert_eq!(
        verified_account.name.as_ref().map(|n| n.as_str()),
        Some(updated_name.as_str())
    );
    logger.log("Successfully verified account update");

    logger.log("All EVM account CRUD operations completed successfully!");
    Ok(())
}

#[tokio::test]
async fn test_evm_signing_operations() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing EVM account CRUD operations");

    let response = client
        .get_evm_account_by_name()
        .name("E2EServerAccount2")
        .send()
        .await?;

    // Verify the response is successful
    assert!(response.status().is_success());
    let account = response.into_inner();

    let tx = TransactionRequest::default()
        .with_to(address!("f39Fd6e51aad88F6F4ce6aB8827279cffFb92266"))
        .with_nonce(124)
        .with_chain_id(84532)
        .with_value(U256::from(100))
        .with_gas_limit(21_000)
        .with_max_fee_per_gas(20_000_000_000) // 20 gwei in wei
        .with_max_priority_fee_per_gas(1_000_000_000) // 1 gwei tip in wei
        .build_typed_tx()
        .map_err(|_e| "Failed to build transaction".to_string())?;

    let mut buffer = Vec::new();
    tx.encode_for_signing(&mut buffer);
    let hex_encoded = hex::encode(&buffer);

    let body = types::SignEvmTransactionBody::builder().transaction(format!("0x{}", hex_encoded));

    let sign_response = client
        .sign_evm_transaction()
        .address(account.address.to_string())
        .x_wallet_auth("".to_string())
        .body(body)
        .send()
        .await?;

    assert!(sign_response.status().is_success());
    logger.log("Successfully signed transaction");

    Ok(())
}

#[tokio::test]
async fn test_evm_sign_functions() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing EVM sign functions");

    // Create a test account
    let random_name = generate_random_name();
    let body = types::CreateEvmAccountBody::builder().name(Some(random_name.parse()?));

    let response = client
        .create_evm_account()
        .x_wallet_auth("")
        .body(body)
        .send()
        .await?;

    let account = response.into_inner();
    logger.log(&format!("Created test account: {:?}", account.address));

    // Test sign hash
    logger.log("Testing sign hash");
    let hash_body = types::SignEvmHashBody::builder().hash(format!("0x{}", "1".repeat(64)));

    let hash_response = client
        .sign_evm_hash()
        .address(account.address.to_string())
        .x_wallet_auth("")
        .body(hash_body)
        .send()
        .await?;

    assert!(hash_response.status().is_success());
    let hash_result = hash_response.into_inner();
    assert!(!hash_result.signature.is_empty());
    logger.log("Successfully signed hash");

    // Test sign message
    logger.log("Testing sign message");
    let message_body = types::SignEvmMessageBody::builder().message("0x123".to_string());

    let message_response = client
        .sign_evm_message()
        .address(account.address.to_string())
        .x_wallet_auth("")
        .body(message_body)
        .send()
        .await?;

    assert!(message_response.status().is_success());
    let message_result = message_response.into_inner();
    assert!(!message_result.signature.is_empty());
    logger.log("Successfully signed message");

    // Test sign transaction (already covered in test_evm_signing_operations)
    logger.log("Testing sign transaction");
    let tx = TransactionRequest::default()
        .with_to(address!("0000000000000000000000000000000000000000"))
        .with_nonce(0)
        .with_chain_id(84532)
        .with_value(U256::from(10000000000000000u64)) // 0.01 ETH
        .with_gas_limit(21_000)
        .with_max_fee_per_gas(20_000_000_000) // 20 gwei
        .with_max_priority_fee_per_gas(1_000_000_000) // 1 gwei
        .build_typed_tx()
        .map_err(|_e| "Failed to build transaction")?;

    let mut buffer = Vec::new();
    tx.encode_for_signing(&mut buffer);
    let hex_encoded = hex::encode(&buffer);

    let sign_body =
        types::SignEvmTransactionBody::builder().transaction(format!("0x{}", hex_encoded));

    let sign_response = client
        .sign_evm_transaction()
        .address(account.address.to_string())
        .x_wallet_auth("")
        .body(sign_body)
        .send()
        .await?;

    assert!(sign_response.status().is_success());
    let sign_result = sign_response.into_inner();
    assert!(!sign_result.signed_transaction.is_empty());
    logger.log("Successfully signed transaction");

    logger.log("All EVM sign functions completed successfully!");
    Ok(())
}

#[tokio::test]
async fn test_smart_account_operations() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing smart account operations");

    // Create owner account first
    let owner_name = generate_random_name();
    let owner_body = types::CreateEvmAccountBody::builder().name(Some(owner_name.parse()?));

    let owner_response = client
        .create_evm_account()
        .x_wallet_auth("")
        .body(owner_body)
        .send()
        .await?;

    let owner_account = owner_response.into_inner();
    logger.log(&format!(
        "Created owner account: {:?}",
        owner_account.address
    ));

    // Test create smart account
    logger.log("Testing create smart account");
    let smart_account_name = generate_random_name();
    let smart_body = types::CreateEvmSmartAccountBody::builder()
        .name(Some(smart_account_name.clone().parse()?))
        .owners(vec![owner_account.address.to_string().parse()?]);

    let smart_response = client
        .create_evm_smart_account()
        .body(smart_body)
        .send()
        .await?;

    assert!(smart_response.status().is_success());
    let smart_account = smart_response.into_inner();
    assert!(!smart_account.address.is_empty());
    assert!(smart_account.address.starts_with("0x"));
    logger.log(&format!(
        "Created smart account: {:?}",
        smart_account.address
    ));

    // Test list smart accounts
    logger.log("Testing list smart accounts");
    let list_response = client
        .list_evm_smart_accounts()
        .page_size(10)
        .send()
        .await?;

    assert!(list_response.status().is_success());
    let smart_accounts_list = list_response.into_inner();
    assert!(!smart_accounts_list.accounts.is_empty());
    logger.log(&format!(
        "Found {} smart accounts",
        smart_accounts_list.accounts.len()
    ));

    // Test get smart account by address
    logger.log("Testing get smart account by address");
    let get_smart_response = client
        .get_evm_smart_account()
        .address(smart_account.address.to_string())
        .send()
        .await?;

    assert!(get_smart_response.status().is_success());
    let retrieved_smart_account = get_smart_response.into_inner();
    assert_eq!(retrieved_smart_account.address, smart_account.address);
    logger.log("Successfully retrieved smart account by address");

    // Test update smart account
    logger.log("Testing update smart account");
    let updated_name = generate_random_name();
    let update_smart_body =
        types::UpdateEvmSmartAccountBody::builder().name(Some(updated_name.clone().parse()?));

    let update_smart_response = client
        .update_evm_smart_account()
        .address(smart_account.address.to_string())
        .body(update_smart_body)
        .send()
        .await?;

    assert!(update_smart_response.status().is_success());
    let updated_smart_account = update_smart_response.into_inner();
    assert_eq!(updated_smart_account.address, smart_account.address);
    assert_eq!(
        updated_smart_account.name.as_ref().map(|n| n.as_str()),
        Some(updated_name.as_str())
    );
    logger.log(&format!(
        "Successfully updated smart account name to: {}",
        updated_name
    ));

    logger.log("All smart account operations completed successfully!");
    Ok(())
}

#[tokio::test]
async fn test_solana_account_operations() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing Solana account operations");

    // Test create Solana account
    let random_name = generate_random_name();
    let body = types::CreateSolanaAccountBody::builder().name(Some(random_name.clone().parse()?));

    let response = client
        .create_solana_account()
        .x_wallet_auth("")
        .body(body)
        .send()
        .await?;

    assert!(response.status().is_success());
    let account = response.into_inner();
    assert!(!account.address.is_empty());
    assert_eq!(
        account.name.as_ref().map(|n| n.as_str()),
        Some(random_name.as_str())
    );
    logger.log(&format!("Created Solana account: {:?}", account.address));

    let account_address = account.address.clone();
    let account_name = account.name.clone();

    // Test get Solana account by address
    logger.log("Testing get Solana account by address");
    let get_response = client
        .get_solana_account()
        .address(account_address.to_string())
        .send()
        .await?;

    assert!(get_response.status().is_success());
    let retrieved_account = get_response.into_inner();
    assert_eq!(retrieved_account.address, account_address);
    assert_eq!(retrieved_account.name, account_name);
    logger.log("Successfully retrieved Solana account by address");

    // Test get Solana account by name
    logger.log("Testing get Solana account by name");
    let get_by_name_response = client
        .get_solana_account_by_name()
        .name(&random_name)
        .send()
        .await?;

    assert!(get_by_name_response.status().is_success());
    let retrieved_by_name_account = get_by_name_response.into_inner();
    assert_eq!(retrieved_by_name_account.address, account_address);
    assert_eq!(retrieved_by_name_account.name, account_name);
    logger.log("Successfully retrieved Solana account by name");

    // Test list Solana accounts
    logger.log("Testing list Solana accounts");
    let list_response = client.list_solana_accounts().page_size(10).send().await?;

    assert!(list_response.status().is_success());
    let accounts_list = list_response.into_inner();
    assert!(!accounts_list.accounts.is_empty());
    logger.log(&format!(
        "Found {} Solana accounts",
        accounts_list.accounts.len()
    ));

    // Test update Solana account
    logger.log("Testing update Solana account");
    let updated_name = generate_random_name();
    let update_body =
        types::UpdateSolanaAccountBody::builder().name(Some(updated_name.clone().parse()?));

    let update_response = client
        .update_solana_account()
        .address(account_address.to_string())
        .body(update_body)
        .send()
        .await?;

    assert!(update_response.status().is_success());
    let updated_account = update_response.into_inner();
    assert_eq!(updated_account.address, account_address);
    assert_eq!(
        updated_account.name.as_ref().map(|n| n.as_str()),
        Some(updated_name.as_str())
    );
    logger.log(&format!(
        "Successfully updated Solana account name to: {}",
        updated_name
    ));

    logger.log("All Solana account operations completed successfully!");
    Ok(())
}

#[tokio::test]
async fn test_solana_sign_functions() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing Solana sign functions");

    // Create a test account
    let random_name = generate_random_name();
    let body = types::CreateSolanaAccountBody::builder().name(Some(random_name.parse()?));

    let response = client
        .create_solana_account()
        .x_wallet_auth("")
        .body(body)
        .send()
        .await?;

    let account = response.into_inner();
    logger.log(&format!(
        "Created test Solana account: {:?}",
        account.address
    ));

    // Test sign message
    logger.log("Testing Solana sign message");
    let message = "Hello Solana!";
    let encoded_message = base64::engine::general_purpose::STANDARD.encode(message.as_bytes());

    let message_body = types::SignSolanaMessageBody::builder().message(encoded_message);

    let message_response = client
        .sign_solana_message()
        .address(account.address.to_string())
        .x_wallet_auth("")
        .body(message_body)
        .send()
        .await?;

    assert!(message_response.status().is_success());
    let message_result = message_response.into_inner();
    assert!(!message_result.signature.is_empty());
    logger.log("Successfully signed Solana message");

    // Test sign transaction
    logger.log("Testing Solana sign transaction");

    // Create a minimal valid transaction structure for the API
    let unsigned_tx_bytes = vec![
        0, // Number of signatures (0 for unsigned)
        1, // Number of required signatures
        0, // Number of read-only signed accounts
        0, // Number of read-only unsigned accounts
        1, // Number of account keys
    ];

    // Add the actual account's public key (32 bytes)
    let mut tx_bytes = unsigned_tx_bytes;
    let account_pubkey = bs58::decode(&*account.address)
        .into_vec()
        .map_err(|e| format!("Failed to decode Solana address: {}", e))?;
    if account_pubkey.len() != 32 {
        return Err(format!("Invalid Solana public key length: {}", account_pubkey.len()).into());
    }
    tx_bytes.extend_from_slice(&account_pubkey);
    tx_bytes.extend_from_slice(&[1u8; 32]); // Recent blockhash (32 bytes)
    tx_bytes.extend_from_slice(&[
        1, // Number of instructions
        0, // Program ID index
        1, // Number of accounts in instruction
        0, // Account index
        4, // Data length
        1, 2, 3, 4, // Instruction data
    ]);

    let base64_tx = base64::engine::general_purpose::STANDARD.encode(&tx_bytes);

    let tx_body = types::SignSolanaTransactionBody::builder().transaction(base64_tx);

    let tx_response = client
        .sign_solana_transaction()
        .address(account.address.to_string())
        .x_wallet_auth("")
        .body(tx_body)
        .send()
        .await?;

    assert!(tx_response.status().is_success());
    let tx_result = tx_response.into_inner();
    assert!(!tx_result.signed_transaction.is_empty());
    logger.log("Successfully signed Solana transaction");

    logger.log("All Solana sign functions completed successfully!");
    Ok(())
}

#[tokio::test]
async fn test_evm_token_balances() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    if env::var("CDP_E2E_SKIP_EVM_TOKEN_BALANCES").unwrap_or_default() == "true" {
        logger.log("Skipping EVM token balances test as per environment variable");
        return Ok(());
    }

    logger.log("Testing EVM token balances");

    // Use a known address with token balances
    let test_address = "0x5b76f5B8fc9D700624F78208132f91AD4e61a1f0";

    // Test first page
    let first_page_response = client
        .list_evm_token_balances()
        .address(test_address)
        .network("base-sepolia")
        .page_size(1)
        .send()
        .await?;

    assert!(first_page_response.status().is_success());
    let first_page = first_page_response.into_inner();
    assert_eq!(first_page.balances.len(), 1);

    let first_balance = &first_page.balances[0];
    let token = &first_balance.token;
    assert!(!token.contract_address.is_empty());
    // Network check - just verify it exists
    assert!(!first_balance.amount.amount.is_empty());
    logger.log("Successfully retrieved first page of EVM token balances");

    // Test second page if there's a next page token
    if let Some(ref next_token) = first_page.next_page_token {
        let second_page_response = client
            .list_evm_token_balances()
            .address(test_address)
            .network("base-sepolia")
            .page_size(1)
            .page_token(next_token)
            .send()
            .await?;

        assert!(second_page_response.status().is_success());
        let second_page = second_page_response.into_inner();
        assert_eq!(second_page.balances.len(), 1);

        let second_balance = &second_page.balances[0];
        let token = &second_balance.token;
        assert!(!token.contract_address.is_empty());
        // Network check - just verify it exists
        assert!(!second_balance.amount.amount.is_empty());
        logger.log("Successfully retrieved second page of EVM token balances");
    }

    logger.log("EVM token balances test completed successfully!");
    Ok(())
}

#[tokio::test]
async fn test_solana_token_balances() -> Result<(), Box<dyn std::error::Error>> {
    let logger = Logger::new();
    let client = create_test_client()?;

    logger.log("Testing Solana token balances");

    // Use a known address with token balances
    let test_address = "4PkiqJkUvxr9P8C1UsMqGN8NJsUcep9GahDRLfmeu8UK";

    // Test first page
    let first_page_response = client
        .list_solana_token_balances()
        .address(test_address)
        .network("solana-devnet")
        .page_size(1)
        .send()
        .await?;

    assert!(first_page_response.status().is_success());
    let first_page = first_page_response.into_inner();
    assert_eq!(first_page.balances.len(), 1);

    let first_balance = &first_page.balances[0];
    let token = &first_balance.token;
    assert!(!token.mint_address.is_empty());
    assert!(token.name.is_some());
    assert!(token.symbol.is_some());
    assert!(!first_balance.amount.amount.is_empty());
    logger.log("Successfully retrieved first page of Solana token balances");

    // Test second page if there's a next page token
    if let Some(ref next_token) = first_page.next_page_token {
        let second_page_response = client
            .list_solana_token_balances()
            .address(test_address)
            .network("solana-devnet")
            .page_size(1)
            .page_token(next_token)
            .send()
            .await?;

        assert!(second_page_response.status().is_success());
        let second_page = second_page_response.into_inner();
        assert_eq!(second_page.balances.len(), 1);

        let second_balance = &second_page.balances[0];
        let token = &second_balance.token;
        assert!(!token.mint_address.is_empty());
        assert!(!second_balance.amount.amount.is_empty());
        logger.log("Successfully retrieved second page of Solana token balances");
    }

    logger.log("Solana token balances test completed successfully!");
    Ok(())
}