Skip to content

Commit

Permalink
Simplify error handling and refactor import order in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Jun 25, 2024
1 parent 0857c37 commit e03eed2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 398 deletions.
2 changes: 1 addition & 1 deletion forester/tests/e2e_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use env_logger::Env;
use forester::external_services_config::ExternalServicesConfig;
use forester::nullifier::{get_nullifier_queue, nullify, Config};
use forester::utils::spawn_validator;
use light_test_utils::e2e_test_env::{E2ETestEnv, GeneralActionConfig, KeypairActionConfig};
Expand All @@ -10,7 +11,6 @@ use log::info;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use solana_sdk::signature::{Keypair, Signer};
use std::sync::Arc;
use forester::external_services_config::ExternalServicesConfig;

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_state_tree_nullifier() {
Expand Down
4 changes: 2 additions & 2 deletions forester/tests/empty_address_tree_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;
use anchor_lang::solana_program::native_token::LAMPORTS_PER_SOL;
use env_logger::Env;
use forester::external_services_config::ExternalServicesConfig;
use forester::nullifier::{empty_address_queue, get_nullifier_queue, Config};
use forester::utils::spawn_validator;
use light_test_utils::e2e_test_env::{E2ETestEnv, GeneralActionConfig, KeypairActionConfig};
Expand All @@ -10,7 +10,7 @@ use light_test_utils::rpc::SolanaRpcConnection;
use light_test_utils::test_env::{get_test_env_accounts, REGISTRY_ID_TEST_KEYPAIR};
use log::info;
use solana_sdk::signature::{Keypair, Signer};
use forester::external_services_config::ExternalServicesConfig;
use std::sync::Arc;

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn empty_address_tree_test() {
Expand Down
2 changes: 1 addition & 1 deletion forester/tests/interop_address_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use env_logger::Env;
use forester::external_services_config::ExternalServicesConfig;
use forester::indexer::PhotonIndexer;
use forester::utils::{spawn_validator, LightValidatorConfig};
use light_test_utils::e2e_test_env::{E2ETestEnv, GeneralActionConfig, KeypairActionConfig};
Expand All @@ -11,7 +12,6 @@ use log::info;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signer;
use forester::external_services_config::ExternalServicesConfig;

// truncate to <254 bit
pub fn generate_pubkey_254() -> Pubkey {
Expand Down
31 changes: 15 additions & 16 deletions forester/tests/interop_nullify_test.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use account_compression::StateMerkleTreeAccount;
use env_logger::Env;
use forester::external_services_config::{INDEXER_URL, SERVER_URL};
use forester::external_services_config::ExternalServicesConfig;
use forester::indexer::PhotonIndexer;
use forester::nullifier::{get_nullifier_queue, nullify, Config};
use forester::utils::{get_state_queue_length, spawn_validator, LightValidatorConfig};
use light_hasher::Poseidon;
use forester::utils::{spawn_validator, LightValidatorConfig};
use light_test_utils::e2e_test_env::{E2ETestEnv, GeneralActionConfig, KeypairActionConfig, User};
use light_test_utils::get_concurrent_merkle_tree;
use light_test_utils::indexer::Indexer;
use light_test_utils::indexer::TestIndexer;
use light_test_utils::rpc::rpc_connection::RpcConnection;
use light_test_utils::rpc::solana_rpc::SolanaRpcUrl;
use light_test_utils::rpc::SolanaRpcConnection;
use light_test_utils::test_env::{get_test_env_accounts, REGISTRY_ID_TEST_KEYPAIR};
use light_test_utils::test_env::get_test_env_accounts;
use log::info;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, Signer};
use solana_sdk::signature::Signer;

pub async fn assert_accounts_by_owner(
indexer: &mut TestIndexer<500, SolanaRpcConnection>,
Expand Down Expand Up @@ -106,11 +102,14 @@ pub async fn assert_account_proofs_for_photon_and_test_indexer(
async fn test_photon_interop_nullify_account() {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();

let mut validator_config = LightValidatorConfig::default();
validator_config.enable_indexer = true;
validator_config.enable_prover = true;
validator_config.enable_forester = true;
validator_config.wait_time = 25;
let validator_config = LightValidatorConfig {
enable_indexer: true,
enable_prover: true,
enable_forester: true,
wait_time: 25,
..LightValidatorConfig::default()
};

spawn_validator(validator_config).await;

let env_accounts = get_test_env_accounts();
Expand Down Expand Up @@ -139,14 +138,14 @@ async fn test_photon_interop_nullify_account() {
add_keypair: None,
create_state_mt: None,
create_address_mt: None,
..GeneralActionConfig::default()
},
0,
Some(1),
)
.await;

let photon_indexer = PhotonIndexer::new(INDEXER_URL.to_string());
let photon_indexer =
PhotonIndexer::new(ExternalServicesConfig::local().indexer_url.to_string());
let user_index = 0;
let balance = env
.rpc
Expand Down Expand Up @@ -197,7 +196,7 @@ async fn test_photon_interop_nullify_account() {
let alice = &mut env.users[0];
assert_accounts_by_owner(&mut env.indexer, alice, &photon_indexer).await;
// TODO(photon): Test-indexer and photon should return equivalent
// merkleproofs for the same account.
// merkle proofs for the same account.
assert_account_proofs_for_photon_and_test_indexer(
&mut env.indexer,
&alice.keypair.pubkey(),
Expand Down
12 changes: 6 additions & 6 deletions forester/tests/nullifier_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem;
use std::sync::Arc;

use account_compression::StateMerkleTreeAccount;
use forester::external_services_config::{INDEXER_URL, SERVER_URL};
use forester::external_services_config::ExternalServicesConfig;
use forester::indexer::PhotonIndexer;
use forester::nullifier::{get_nullifier_queue, nullify, subscribe_nullify, Config};
use forester::utils::u8_arr_to_hex_string;
Expand All @@ -23,7 +23,7 @@ fn test_config() -> Config {

let env_accounts = get_test_env_accounts();
Config {
server_url: SERVER_URL.to_string(),
external_services: ExternalServicesConfig::local(),
nullifier_queue_pubkey: env_accounts.nullifier_queue_pubkey,
state_merkle_tree_pubkey: env_accounts.merkle_tree_pubkey,
address_merkle_tree_pubkey: env_accounts.address_merkle_tree_pubkey,
Expand Down Expand Up @@ -72,7 +72,7 @@ async fn tree_info_test() {
nullifier_queue_pubkey, merkle_tree_pubkey
);

let client = RpcClient::new(SERVER_URL);
let client = RpcClient::new(test_config().external_services.rpc_url);
client
.request_airdrop(&payer_pubkey, LAMPORTS_PER_SOL * 1000)
.unwrap();
Expand All @@ -94,10 +94,10 @@ async fn tree_info_test() {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[ignore]
async fn test_nullify_leaves() {
let config = test_config();
let config = Arc::new(test_config());
let rpc = SolanaRpcConnection::new(SolanaRpcUrl::Localnet, None);
let indexer = Arc::new(tokio::sync::Mutex::new(PhotonIndexer::new(
INDEXER_URL.to_string(),
config.external_services.indexer_url.to_string(),
)));
let rpc = Arc::new(tokio::sync::Mutex::new(rpc));
rpc.lock()
Expand All @@ -107,7 +107,7 @@ async fn test_nullify_leaves() {
.unwrap();

let time = std::time::Instant::now();
match nullify(indexer, rpc, &config).await {
match nullify(indexer, rpc, config).await {
Ok(_) => {
info!("Nullify completed");
info!("Total time elapsed: {:?}", time.elapsed());
Expand Down
Loading

0 comments on commit e03eed2

Please sign in to comment.