Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify test indexer #1356

Draft
wants to merge 5 commits into
base: jorrit/test-rebase-audit-branch
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/light-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
sub-tests: '[
"cargo test-sbf -p token-escrow -- --test-threads=1"
]'
- program: name-service-without-macros-test
sub-tests: '[
"cargo test-sbf -p name-service-without-macros -- --test-threads=1"
]'
# - program: name-service-without-macros-test
# sub-tests: '[
# "cargo test-sbf -p name-service-without-macros -- --test-threads=1"
# ]'

steps:
- name: Checkout sources
Expand Down
31 changes: 31 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ members = [
"test-programs/sdk-test-program/programs/sdk-test/",
"forester-utils",
"forester",
"photon-api",
"photon-api",
"light-program-test",
]

[profile.release]
Expand Down Expand Up @@ -94,7 +95,7 @@ account-compression = { path = "programs/account-compression", version = "1.2.0"
light-compressed-token = { path = "programs/compressed-token", version = "1.2.0", features = ["cpi"] }
light-system-program = { path = "programs/system", version = "1.2.0", features = ["cpi"] }
light-registry = { path = "programs/registry", version = "1.2.0", features = ["cpi"]}

light-program-test = { path = "light-program-test", version = "0.1.0" }
# Math and crypto
num-bigint = "0.4.6"
num-traits = "0.2.19"
Expand Down
3 changes: 3 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ light-merkle-tree-reference = { workspace = true }
light-prover-client = { workspace = true }
light-sdk = { workspace = true }
light-hasher = { workspace = true }
light-verifier = { workspace = true }
light-system-program = { workspace = true }
light-compressed-token = { workspace = true }

# Math and crypto
num-bigint = { workspace = true }
Expand Down
24 changes: 13 additions & 11 deletions client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ use light_indexed_merkle_tree::{
use light_merkle_tree_reference::MerkleTree;
use light_sdk::{
compressed_account::CompressedAccountWithMerkleContext, event::PublicTransactionEvent,
proof::ProofRpcResult, token::TokenDataWithMerkleContext,
proof::CompressedProofWithContext, token::TokenDataWithMerkleContext,
};
use num_bigint::BigUint;
use solana_sdk::pubkey::Pubkey;
use thiserror::Error;

use crate::rpc::RpcConnection;

pub mod test_indexer;

#[derive(Error, Debug)]
pub enum IndexerError {
#[error("RPC Error: {0}")]
Expand Down Expand Up @@ -48,7 +46,7 @@ pub trait Indexer<R: RpcConnection>: Sync + Send + Debug + 'static {
new_addresses: Option<&[[u8; 32]]>,
address_merkle_tree_pubkeys: Option<Vec<Pubkey>>,
rpc: &mut R,
) -> impl Future<Output = ProofRpcResult>;
) -> impl Future<Output = CompressedProofWithContext>;

fn get_compressed_accounts_by_owner(
&self,
Expand Down Expand Up @@ -94,17 +92,21 @@ pub struct AddressMerkleTreeAccounts {
pub queue: Pubkey,
}

#[derive(Debug, Clone)]
pub struct StateMerkleTreeBundle {
pub rollover_fee: u64,
pub merkle_tree: Box<MerkleTree<Poseidon>>,
pub accounts: StateMerkleTreeAccounts,
}

#[derive(Debug, Clone)]
pub struct AddressMerkleTreeBundle {
pub rollover_fee: u64,
pub merkle_tree: Box<IndexedMerkleTree<Poseidon, usize>>,
pub indexed_array: Box<IndexedArray<Poseidon, usize>>,
pub accounts: AddressMerkleTreeAccounts,
}

#[derive(Debug, Clone)]
pub struct StateMerkleTreeBundle {
pub rollover_fee: u64,
pub merkle_tree: Box<MerkleTree<Poseidon>>,
pub accounts: StateMerkleTreeAccounts,
pub version: u64,
pub output_queue_elements: Vec<[u8; 32]>,
/// leaf index, leaf, tx hash
pub input_leaf_indices: Vec<(u32, [u8; 32], [u8; 32])>,
}
18 changes: 17 additions & 1 deletion client/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ pub mod errors;
pub mod merkle_tree;
pub mod rpc_connection;
pub mod solana_rpc;
pub mod test_rpc;

pub use errors::{assert_rpc_error, RpcError};
pub use light_compressed_token::TokenData;
pub use light_system_program::sdk::compressed_account::CompressedAccountWithMerkleContext;
use light_verifier::CompressedProof;
pub use rpc_connection::RpcConnection;
pub use solana_rpc::{RetryConfig, SolanaRpcConnection};

#[derive(Debug, Default)]
pub struct BatchedTreeProofRpcResult {
pub proof: Option<CompressedProof>,
// If none -> proof by index, else included in zkp
pub root_indices: Vec<Option<u16>>,
pub address_root_indices: Vec<u16>,
}

#[derive(Debug, Clone)]
pub struct TokenDataWithContext {
pub token_data: TokenData,
pub compressed_account: CompressedAccountWithMerkleContext,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::net::{Ipv4Addr, Ipv6Addr};

use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas};
use light_client::indexer::test_indexer::TestIndexer;
use light_client::indexer::{AddressMerkleTreeAccounts, Indexer, StateMerkleTreeAccounts};
use light_client::rpc::merkle_tree::MerkleTreeExt;
use light_client::rpc::test_rpc::ProgramTestRpcConnection;
use light_program_test::test_indexer::TestIndexer;
use light_sdk::account_meta::LightAccountMeta;
use light_sdk::address::derive_address;
use light_sdk::compressed_account::CompressedAccountWithMerkleContext;
Expand Down
1 change: 1 addition & 0 deletions examples/name-service/programs/name-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ solana-sdk = { workspace = true }
[dev-dependencies]
light-client = { workspace = true , features = ["devenv"]}
light-test-utils = { path = "../../../../test-utils", version = "1.2.0", features = ["devenv"] }
light-program-test = { workspace = true }
solana-program-test = { workspace = true }
tokio = "1.36.0"
4 changes: 2 additions & 2 deletions examples/name-service/programs/name-service/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::net::{Ipv4Addr, Ipv6Addr};

use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas};
use light_client::indexer::test_indexer::TestIndexer;
use light_client::indexer::{AddressMerkleTreeAccounts, Indexer, StateMerkleTreeAccounts};
use light_client::rpc::merkle_tree::MerkleTreeExt;
use light_client::rpc::test_rpc::ProgramTestRpcConnection;
use light_program_test::test_indexer::TestIndexer;
use light_program_test::test_rpc::ProgramTestRpcConnection;
use light_sdk::address::{derive_address, derive_address_seed};
use light_sdk::compressed_account::CompressedAccountWithMerkleContext;
use light_sdk::error::LightSdkError;
Expand Down
11 changes: 10 additions & 1 deletion examples/token-escrow/programs/token-escrow/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@ pub async fn perform_withdrawal<R: RpcConnection>(
)
.await;

let proof = match rpc_result.proof {
Some(proof) => Some(light_system_program::invoke::processor::CompressedProof {
a: proof.a,
b: proof.b,
c: proof.c,
}),
None => None,
};

let create_ix_inputs = CreateEscrowInstructionInputs {
input_token_data: &[escrow_token_data_with_context.token_data.clone()],
lock_up_time: 0,
Expand All @@ -428,7 +437,7 @@ pub async fn perform_withdrawal<R: RpcConnection>(
],
output_compressed_accounts: &Vec::new(),
root_indices: &rpc_result.root_indices,
proof: &Some(rpc_result.proof),
proof: &proof,
mint: &escrow_token_data_with_context.token_data.mint,
input_compressed_accounts: &[compressed_input_account_with_context.compressed_account],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ pub async fn perform_withdrawal<R: RpcConnection>(
)
.await;

let proof = match rpc_result.proof {
Some(proof) => Some(light_system_program::invoke::processor::CompressedProof {
a: proof.a,
b: proof.b,
c: proof.c,
}),
None => None,
};

let create_withdrawal_ix_inputs = CreateCompressedPdaWithdrawalInstructionInputs {
input_token_data: &[token_escrow.token_data.clone()],
signer: &payer_pubkey,
Expand All @@ -486,7 +495,7 @@ pub async fn perform_withdrawal<R: RpcConnection>(
],
output_compressed_accounts: &Vec::new(),
root_indices: &rpc_result.root_indices,
proof: &Some(rpc_result.proof),
proof: &proof,
mint: &token_escrow.token_data.mint,
cpi_context_account: &env.cpi_context_account_pubkey,
old_lock_up_time,
Expand Down
2 changes: 1 addition & 1 deletion forester-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ light-prover-client = { path = "../circuit-lib/light-prover-client", version = "
light-registry = { workspace = true }
light-system-program = { path = "../programs/system", version = "1.2.0", features = ["cpi"] }
light-utils = { path = "../utils", version = "1.1.0" }

light-sdk = { workspace = true }
photon-api = { workspace = true }
light-client = { workspace = true }

Expand Down
7 changes: 2 additions & 5 deletions forester-utils/src/address_merkle_tree_config.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::{
get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree,
indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts},
AccountZeroCopy,
};
use crate::{get_concurrent_merkle_tree, get_hash_set, get_indexed_merkle_tree, AccountZeroCopy};
use account_compression::{
batched_merkle_tree::BatchedMerkleTreeAccount, AddressMerkleTreeAccount,
AddressMerkleTreeConfig, AddressQueueConfig, NullifierQueueConfig, QueueAccount,
StateMerkleTreeAccount, StateMerkleTreeConfig,
};
use anchor_lang::Discriminator;
use light_client::indexer::{AddressMerkleTreeAccounts, StateMerkleTreeAccounts};
use light_client::rpc::RpcConnection;
use light_hasher::Poseidon;
use num_traits::Zero;
Expand Down
Loading