Skip to content

Commit

Permalink
feat: add light-program-test crate and integrate into existing modules (
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin authored Dec 4, 2024
1 parent 854cc88 commit ab90759
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 27 deletions.
26 changes: 26 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 @@ -95,7 +96,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
2 changes: 0 additions & 2 deletions client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use thiserror::Error;

use crate::rpc::RpcConnection;

pub mod test_indexer;

#[derive(Error, Debug)]
pub enum IndexerError {
#[error("RPC Error: {0}")]
Expand Down
1 change: 0 additions & 1 deletion client/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 rpc_connection::RpcConnection;
Expand Down
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"
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::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
25 changes: 25 additions & 0 deletions light-program-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "light-program-test"
version = "0.1.0"
edition = "2021"

[dependencies]

light-client = { workspace = true }
light-prover-client = { workspace = true }
light-sdk = { workspace = true }
light-indexed-merkle-tree = { workspace = true }
light-merkle-tree-reference = { workspace = true }
light-hasher = { workspace = true }

solana-sdk = { workspace = true }
solana-banks-client = { workspace = true }
solana-program-test = { workspace = true }

log = { workspace = true }
borsh = { workspace = true }
tokio = { workspace = true }
async-trait = { workspace = true }
num-bigint = { workspace = true }
num-traits = { workspace = true }
reqwest = { workspace = true }
2 changes: 2 additions & 0 deletions light-program-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod test_indexer;
pub mod test_rpc;
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::{marker::PhantomData, time::Duration};

use crate::{
indexer::Indexer,
use borsh::BorshDeserialize;
use light_client::{
indexer::{
AddressMerkleTreeAccounts, AddressMerkleTreeBundle, Indexer, StateMerkleTreeAccounts,
StateMerkleTreeBundle,
},
rpc::{merkle_tree::MerkleTreeExt, RpcConnection},
transaction_params::FeeConfig,
};
use borsh::BorshDeserialize;
use light_hasher::Poseidon;
use light_indexed_merkle_tree::{array::IndexedArray, reference::IndexedMerkleTree};
use light_merkle_tree_reference::MerkleTree;
Expand Down Expand Up @@ -39,11 +40,7 @@ use num_bigint::BigInt;
use num_traits::FromBytes;
use reqwest::Client;
use solana_sdk::pubkey::Pubkey;

use super::{
AddressMerkleTreeAccounts, AddressMerkleTreeBundle, StateMerkleTreeAccounts,
StateMerkleTreeBundle,
};
use std::{marker::PhantomData, time::Duration};

#[derive(Debug)]
pub struct TestIndexer<R>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ use solana_sdk::{
transaction::{Transaction, TransactionError},
};

use crate::transaction_params::TransactionParams;

use super::{merkle_tree::MerkleTreeExt, RpcConnection, RpcError};
use light_client::rpc::{merkle_tree::MerkleTreeExt, RpcConnection, RpcError};
use light_client::transaction_params::TransactionParams;

pub struct ProgramTestRpcConnection {
pub context: ProgramTestContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ solana-sdk = { workspace = true }

[dev-dependencies]
light-client = { workspace = true , features = ["devenv"]}
light-program-test = { workspace = true }
light-test-utils = { path = "../../../../test-utils", version = "1.2.0", features = ["devenv"] }
solana-program-test = { workspace = true }
tokio = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![cfg(feature = "test-sbf")]

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::account_meta::LightAccountMeta;
use light_sdk::address::derive_address;
use light_sdk::compressed_account::CompressedAccountWithMerkleContext;
Expand Down
1 change: 1 addition & 0 deletions test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ light-concurrent-merkle-tree = { version = "1.1.0", path = "../merkle-tree/concu
light-indexed-merkle-tree = { path = "../merkle-tree/indexed/", version = "1.1.0" }
light-verifier = { path = "../circuit-lib/verifier", version = "1.1.0" }
light-utils = { path = "../utils", version = "1.1.0" }
light-program-test = { workspace = true }
forester-utils = { workspace = true }
memoffset = "0.9.1"
rand = "0.8"
Expand Down
6 changes: 3 additions & 3 deletions test-utils/src/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub async fn setup_test_programs_with_accounts(
pub async fn setup_test_programs_with_accounts_v2(
additional_programs: Option<Vec<(String, Pubkey)>>,
) -> (
light_client::rpc::test_rpc::ProgramTestRpcConnection,
light_program_test::test_rpc::ProgramTestRpcConnection,
EnvAccounts,
) {
setup_test_programs_with_accounts_with_protocol_config_v2(
Expand Down Expand Up @@ -429,11 +429,11 @@ pub async fn setup_test_programs_with_accounts_with_protocol_config_v2(
protocol_config: ProtocolConfig,
register_forester_and_advance_to_active_phase: bool,
) -> (
light_client::rpc::test_rpc::ProgramTestRpcConnection,
light_program_test::test_rpc::ProgramTestRpcConnection,
EnvAccounts,
) {
let context = setup_test_programs(additional_programs).await;
let mut context = light_client::rpc::test_rpc::ProgramTestRpcConnection { context };
let mut context = light_program_test::test_rpc::ProgramTestRpcConnection { context };
let keypairs = EnvAccountKeypairs::program_test_default();
airdrop_lamports(
&mut context,
Expand Down

0 comments on commit ab90759

Please sign in to comment.