From 9fe70c86181962ac5227dfc9f237ea482ae0795a Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Thu, 19 Sep 2024 12:50:56 +0800 Subject: [PATCH] Refactor & cleanup: Immutable RPC references --- .../forester-build-and-push-to-docr.yml | 2 +- client/src/indexer/mod.rs | 2 +- client/src/indexer/test_indexer.rs | 6 +- client/src/rpc/merkle_tree.rs | 4 +- .../programs/name-service/tests/test.rs | 61 +++++++++---------- 5 files changed, 36 insertions(+), 39 deletions(-) diff --git a/.github/workflows/forester-build-and-push-to-docr.yml b/.github/workflows/forester-build-and-push-to-docr.yml index ac0bccd460..809246f137 100644 --- a/.github/workflows/forester-build-and-push-to-docr.yml +++ b/.github/workflows/forester-build-and-push-to-docr.yml @@ -3,7 +3,7 @@ name: Docker Build and Push to DOCR on: push: branches: - - main + - release pull_request: branches: - "**" diff --git a/client/src/indexer/mod.rs b/client/src/indexer/mod.rs index 0d36f48604..2ff5b27df6 100644 --- a/client/src/indexer/mod.rs +++ b/client/src/indexer/mod.rs @@ -47,7 +47,7 @@ pub trait Indexer: Sync + Send + 'static { state_merkle_tree_pubkeys: Option<&[Pubkey]>, new_addresses: Option<&[[u8; 32]]>, address_merkle_tree_pubkeys: Option>, - rpc: &mut R, + rpc: &R, ) -> impl Future; fn get_compressed_accounts_by_owner( diff --git a/client/src/indexer/test_indexer.rs b/client/src/indexer/test_indexer.rs index be5d6d4757..0e2f7a43f1 100644 --- a/client/src/indexer/test_indexer.rs +++ b/client/src/indexer/test_indexer.rs @@ -218,7 +218,7 @@ where state_merkle_tree_pubkeys: Option<&[solana_sdk::pubkey::Pubkey]>, new_addresses: Option<&[[u8; 32]]>, address_merkle_tree_pubkeys: Option>, - rpc: &mut R, + rpc: &R, ) -> ProofRpcResult { if compressed_accounts.is_some() && ![1usize, 2usize, 3usize, 4usize, 8usize] @@ -401,7 +401,7 @@ where &self, merkle_tree_pubkeys: &[Pubkey], accounts: &[[u8; 32]], - rpc: &mut R, + rpc: &R, ) -> (BatchInclusionJsonStruct, Vec) { let mut inclusion_proofs = Vec::new(); let mut root_indices = Vec::new(); @@ -440,7 +440,7 @@ where &self, address_merkle_tree_pubkeys: &[Pubkey], addresses: &[[u8; 32]], - rpc: &mut R, + rpc: &R, ) -> (BatchNonInclusionJsonStruct, Vec) { let mut non_inclusion_proofs = Vec::new(); let mut address_root_indices = Vec::new(); diff --git a/client/src/rpc/merkle_tree.rs b/client/src/rpc/merkle_tree.rs index 45b800776d..aeffd5efd0 100644 --- a/client/src/rpc/merkle_tree.rs +++ b/client/src/rpc/merkle_tree.rs @@ -28,7 +28,7 @@ pub enum MerkleTreeExtError { #[async_trait] pub trait MerkleTreeExt: RpcConnection { async fn get_state_merkle_tree( - &mut self, + &self, pubkey: Pubkey, ) -> Result, MerkleTreeExtError> { let account = self.get_account(pubkey).await?.unwrap(); @@ -40,7 +40,7 @@ pub trait MerkleTreeExt: RpcConnection { } async fn get_address_merkle_tree( - &mut self, + &self, pubkey: Pubkey, ) -> Result, MerkleTreeExtError> { let account = self.get_account(pubkey).await?.unwrap(); diff --git a/examples/name-service/programs/name-service/tests/test.rs b/examples/name-service/programs/name-service/tests/test.rs index 5f6c85a4eb..9c9aca2163 100644 --- a/examples/name-service/programs/name-service/tests/test.rs +++ b/examples/name-service/programs/name-service/tests/test.rs @@ -32,10 +32,10 @@ async fn test_name_service() { String::from("name_service"), name_service::ID, )])) - .await; + .await; let payer = rpc.get_payer().await.insecure_clone(); - let test_indexer: TestIndexer = TestIndexer::new( + let mut test_indexer: TestIndexer = TestIndexer::new( &[StateMerkleTreeAccounts { merkle_tree: env.merkle_tree_pubkey, nullifier_queue: env.nullifier_queue_pubkey, @@ -48,7 +48,7 @@ async fn test_name_service() { true, true, ) - .await; + .await; let name = "example.io"; @@ -82,15 +82,15 @@ async fn test_name_service() { &[PROGRAM_ID_LIGHT_SYSTEM.to_bytes().as_slice()], &PROGRAM_ID_ACCOUNT_COMPRESSION, ) - .0; + .0; // Create the example.io -> 10.0.1.25 record. let rdata_1 = RData::A(Ipv4Addr::new(10, 0, 1, 25)); create_record( - name, + &name, &rdata_1, &rpc, - &test_indexer, + &mut test_indexer, &env, &mut remaining_accounts, &payer, @@ -101,15 +101,15 @@ async fn test_name_service() { ®istered_program_pda, &PROGRAM_ID_LIGHT_SYSTEM, ) - .await - .unwrap(); + .await + .unwrap(); // Create with invalid light-system-program ID, should not succeed. { let result = create_record( - name, + &name, &rdata_1, - &mut rpc, + &rpc, &mut test_indexer, &env, &mut remaining_accounts, @@ -121,7 +121,7 @@ async fn test_name_service() { ®istered_program_pda, &Pubkey::new_unique(), ) - .await; + .await; assert!(matches!( result, Err(RpcError::TransactionError( @@ -147,7 +147,7 @@ async fn test_name_service() { // Update the record to example.io -> 2001:db8::1. let rdata_2 = RData::AAAA(Ipv6Addr::new(8193, 3512, 0, 0, 0, 0, 0, 1)); update_record( - &mut rpc, + &rpc, &mut test_indexer, &mut remaining_accounts, &rdata_2, @@ -158,8 +158,8 @@ async fn test_name_service() { ®istered_program_pda, &PROGRAM_ID_LIGHT_SYSTEM, ) - .await - .unwrap(); + .await + .unwrap(); // Update with invalid owner, should not succeed. { @@ -168,7 +168,7 @@ async fn test_name_service() { .await .unwrap(); let result = update_record( - &mut rpc, + &rpc, &mut test_indexer, &mut remaining_accounts, &rdata_2, @@ -179,7 +179,7 @@ async fn test_name_service() { ®istered_program_pda, &PROGRAM_ID_LIGHT_SYSTEM, ) - .await; + .await; assert!(matches!( result, Err(RpcError::TransactionError( @@ -190,7 +190,7 @@ async fn test_name_service() { // Update with invalid light-system-program ID, should not succeed. { let result = update_record( - &mut rpc, + &rpc, &mut test_indexer, &mut remaining_accounts, &rdata_2, @@ -201,7 +201,7 @@ async fn test_name_service() { ®istered_program_pda, &Pubkey::new_unique(), ) - .await; + .await; assert!(matches!( result, Err(RpcError::TransactionError( @@ -231,7 +231,7 @@ async fn test_name_service() { .await .unwrap(); let result = delete_record( - &mut rpc, + &rpc, &mut test_indexer, &mut remaining_accounts, &invalid_signer, @@ -241,7 +241,7 @@ async fn test_name_service() { ®istered_program_pda, &PROGRAM_ID_LIGHT_SYSTEM, ) - .await; + .await; assert!(matches!( result, Err(RpcError::TransactionError( @@ -252,7 +252,7 @@ async fn test_name_service() { // Delete with invalid light-system-program ID, should not succeed. { let result = delete_record( - &mut rpc, + &rpc, &mut test_indexer, &mut remaining_accounts, &payer, @@ -262,7 +262,7 @@ async fn test_name_service() { ®istered_program_pda, &Pubkey::new_unique(), ) - .await; + .await; assert!(matches!( result, Err(RpcError::TransactionError( @@ -273,7 +273,7 @@ async fn test_name_service() { // Delete the example.io record. delete_record( - &mut rpc, + &rpc, &mut test_indexer, &mut remaining_accounts, &payer, @@ -283,16 +283,15 @@ async fn test_name_service() { ®istered_program_pda, &PROGRAM_ID_LIGHT_SYSTEM, ) - .await - .unwrap(); + .await + .unwrap(); } -#[allow(clippy::too_many_arguments)] async fn create_record( name: &str, rdata: &RData, rpc: &R, - test_indexer: &TestIndexer, + test_indexer: &mut TestIndexer, env: &EnvAccounts, remaining_accounts: &mut RemainingAccounts, payer: &Keypair, @@ -356,9 +355,8 @@ where Ok(()) } -#[allow(clippy::too_many_arguments)] async fn update_record( - rpc: &mut R, + rpc: &R, test_indexer: &mut TestIndexer, remaining_accounts: &mut RemainingAccounts, new_rdata: &RData, @@ -435,9 +433,8 @@ where Ok(()) } -#[allow(clippy::too_many_arguments)] async fn delete_record( - rpc: &mut R, + rpc: &R, test_indexer: &mut TestIndexer, remaining_accounts: &mut RemainingAccounts, payer: &Keypair, @@ -509,7 +506,7 @@ where &[instruction], Some(&payer.pubkey()), &[&payer], - rpc.get_latest_blockhash().await?, + rpc.get_latest_blockhash().await.unwrap(), ); rpc.process_transaction(transaction).await?; Ok(())