Skip to content

Commit

Permalink
Refactor & cleanup: Immutable RPC references
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Sep 19, 2024
1 parent 8c0fad8 commit 9fe70c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/forester-build-and-push-to-docr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Docker Build and Push to DOCR
on:
push:
branches:
- main
- release
pull_request:
branches:
- "**"
Expand Down
2 changes: 1 addition & 1 deletion client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait Indexer<R: RpcConnection>: Sync + Send + 'static {
state_merkle_tree_pubkeys: Option<&[Pubkey]>,
new_addresses: Option<&[[u8; 32]]>,
address_merkle_tree_pubkeys: Option<Vec<Pubkey>>,
rpc: &mut R,
rpc: &R,
) -> impl Future<Output = ProofRpcResult>;

fn get_compressed_accounts_by_owner(
Expand Down
6 changes: 3 additions & 3 deletions client/src/indexer/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ where
state_merkle_tree_pubkeys: Option<&[solana_sdk::pubkey::Pubkey]>,
new_addresses: Option<&[[u8; 32]]>,
address_merkle_tree_pubkeys: Option<Vec<solana_sdk::pubkey::Pubkey>>,
rpc: &mut R,
rpc: &R,
) -> ProofRpcResult {
if compressed_accounts.is_some()
&& ![1usize, 2usize, 3usize, 4usize, 8usize]
Expand Down Expand Up @@ -401,7 +401,7 @@ where
&self,
merkle_tree_pubkeys: &[Pubkey],
accounts: &[[u8; 32]],
rpc: &mut R,
rpc: &R,
) -> (BatchInclusionJsonStruct, Vec<u16>) {
let mut inclusion_proofs = Vec::new();
let mut root_indices = Vec::new();
Expand Down Expand Up @@ -440,7 +440,7 @@ where
&self,
address_merkle_tree_pubkeys: &[Pubkey],
addresses: &[[u8; 32]],
rpc: &mut R,
rpc: &R,
) -> (BatchNonInclusionJsonStruct, Vec<u16>) {
let mut non_inclusion_proofs = Vec::new();
let mut address_root_indices = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions client/src/rpc/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConcurrentMerkleTreeCopy<Poseidon, 26>, MerkleTreeExtError> {
let account = self.get_account(pubkey).await?.unwrap();
Expand All @@ -40,7 +40,7 @@ pub trait MerkleTreeExt: RpcConnection {
}

async fn get_address_merkle_tree(
&mut self,
&self,
pubkey: Pubkey,
) -> Result<IndexedMerkleTreeCopy<Poseidon, usize, 26, 16>, MerkleTreeExtError> {
let account = self.get_account(pubkey).await?.unwrap();
Expand Down
61 changes: 29 additions & 32 deletions examples/name-service/programs/name-service/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProgramTestRpcConnection> = TestIndexer::new(
let mut test_indexer: TestIndexer<ProgramTestRpcConnection> = TestIndexer::new(
&[StateMerkleTreeAccounts {
merkle_tree: env.merkle_tree_pubkey,
nullifier_queue: env.nullifier_queue_pubkey,
Expand All @@ -48,7 +48,7 @@ async fn test_name_service() {
true,
true,
)
.await;
.await;

let name = "example.io";

Expand Down Expand Up @@ -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,
Expand All @@ -101,15 +101,15 @@ async fn test_name_service() {
&registered_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,
Expand All @@ -121,7 +121,7 @@ async fn test_name_service() {
&registered_program_pda,
&Pubkey::new_unique(),
)
.await;
.await;
assert!(matches!(
result,
Err(RpcError::TransactionError(
Expand All @@ -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,
Expand All @@ -158,8 +158,8 @@ async fn test_name_service() {
&registered_program_pda,
&PROGRAM_ID_LIGHT_SYSTEM,
)
.await
.unwrap();
.await
.unwrap();

// Update with invalid owner, should not succeed.
{
Expand All @@ -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,
Expand All @@ -179,7 +179,7 @@ async fn test_name_service() {
&registered_program_pda,
&PROGRAM_ID_LIGHT_SYSTEM,
)
.await;
.await;
assert!(matches!(
result,
Err(RpcError::TransactionError(
Expand All @@ -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,
Expand All @@ -201,7 +201,7 @@ async fn test_name_service() {
&registered_program_pda,
&Pubkey::new_unique(),
)
.await;
.await;
assert!(matches!(
result,
Err(RpcError::TransactionError(
Expand Down Expand Up @@ -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,
Expand All @@ -241,7 +241,7 @@ async fn test_name_service() {
&registered_program_pda,
&PROGRAM_ID_LIGHT_SYSTEM,
)
.await;
.await;
assert!(matches!(
result,
Err(RpcError::TransactionError(
Expand All @@ -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,
Expand All @@ -262,7 +262,7 @@ async fn test_name_service() {
&registered_program_pda,
&Pubkey::new_unique(),
)
.await;
.await;
assert!(matches!(
result,
Err(RpcError::TransactionError(
Expand All @@ -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,
Expand All @@ -283,16 +283,15 @@ async fn test_name_service() {
&registered_program_pda,
&PROGRAM_ID_LIGHT_SYSTEM,
)
.await
.unwrap();
.await
.unwrap();
}

#[allow(clippy::too_many_arguments)]
async fn create_record<R>(
name: &str,
rdata: &RData,
rpc: &R,
test_indexer: &TestIndexer<R>,
test_indexer: &mut TestIndexer<R>,
env: &EnvAccounts,
remaining_accounts: &mut RemainingAccounts,
payer: &Keypair,
Expand Down Expand Up @@ -356,9 +355,8 @@ where
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn update_record<R>(
rpc: &mut R,
rpc: &R,
test_indexer: &mut TestIndexer<R>,
remaining_accounts: &mut RemainingAccounts,
new_rdata: &RData,
Expand Down Expand Up @@ -435,9 +433,8 @@ where
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn delete_record<R>(
rpc: &mut R,
rpc: &R,
test_indexer: &mut TestIndexer<R>,
remaining_accounts: &mut RemainingAccounts,
payer: &Keypair,
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 9fe70c8

Please sign in to comment.