diff --git a/.github/workflows/light-examples-tests.yml b/.github/workflows/light-examples-tests.yml index 4ab1463cdc..51c191f229 100644 --- a/.github/workflows/light-examples-tests.yml +++ b/.github/workflows/light-examples-tests.yml @@ -56,6 +56,7 @@ jobs: - name: ${{ matrix.program }} run: | source ./scripts/devenv.sh + npx nx build @lightprotocol/zk-compression-cli IFS=',' read -r -a sub_tests <<< "${{ join(fromJSON(matrix['sub-tests']), ', ') }}" for subtest in "${sub_tests[@]}" diff --git a/.github/workflows/light-system-programs-tests.yml b/.github/workflows/light-system-programs-tests.yml index 8584e45cdd..b647ed1486 100644 --- a/.github/workflows/light-system-programs-tests.yml +++ b/.github/workflows/light-system-programs-tests.yml @@ -64,15 +64,6 @@ jobs: sub-tests: '[ "RUST_MIN_STACK=8388608 cargo-test-sbf -p e2e-test -- --nocapture --test-threads=1" ]' - - program: token-escrow-test - sub-tests: '[ - "cargo test-sbf -p token-escrow -- --test-threads=1" - ]' - - program: name-service-test - sub-tests: '[ - "cargo test-sbf -p name-service -- --test-threads=1" - ]' - steps: - name: Checkout sources uses: actions/checkout@v4 diff --git a/circuit-lib/light-prover-client/src/gnark/helpers.rs b/circuit-lib/light-prover-client/src/gnark/helpers.rs index 468562f38f..63c0828862 100644 --- a/circuit-lib/light-prover-client/src/gnark/helpers.rs +++ b/circuit-lib/light-prover-client/src/gnark/helpers.rs @@ -14,7 +14,7 @@ use serde_json::json; use sysinfo::{Signal, System}; static IS_LOADING: AtomicBool = AtomicBool::new(false); -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum ProofType { Inclusion, NonInclusion, @@ -96,7 +96,7 @@ pub async fn health_check(retries: usize, timeout: usize) -> bool { result } -fn get_project_root() -> Option { +pub fn get_project_root() -> Option { let output = Command::new("git") .args(["rev-parse", "--show-toplevel"]) .output() diff --git a/cli/src/utils/processProverServer.ts b/cli/src/utils/processProverServer.ts index 8247cc44b0..a551bb8e62 100644 --- a/cli/src/utils/processProverServer.ts +++ b/cli/src/utils/processProverServer.ts @@ -37,7 +37,6 @@ export async function startProver( args.push(`--non-inclusion=${proveNewAddresses ? "true" : "false"}`); args.push("--keys-dir", keysDir); args.push("--prover-address", `0.0.0.0:${proverPort}`); - console.log("Starting prover..."); spawnBinary(getProverNameByArch(), args); await waitForServers([{ port: proverPort, path: "/" }]); diff --git a/client/src/indexer/test_indexer.rs b/client/src/indexer/test_indexer.rs index be5d6d4757..375b2798ab 100644 --- a/client/src/indexer/test_indexer.rs +++ b/client/src/indexer/test_indexer.rs @@ -8,7 +8,7 @@ use light_prover_client::{ gnark::{ combined_json_formatter::CombinedJsonStruct, constants::{PROVE_PATH, SERVER_ADDRESS}, - helpers::{spawn_prover, ProofType}, + helpers::health_check, inclusion_json_formatter::BatchInclusionJsonStruct, non_inclusion_json_formatter::BatchNonInclusionJsonStruct, proof_helpers::{compress_proof, deserialize_gnark_proof_json, proof_from_json_struct}, @@ -57,7 +57,6 @@ where pub token_compressed_accounts: Vec, pub token_nullified_compressed_accounts: Vec, pub events: Vec, - proof_types: Vec, _rpc: PhantomData, } @@ -301,7 +300,6 @@ where } else { warn!("Error: {}", response_result.text().await.unwrap()); tokio::time::sleep(Duration::from_secs(1)).await; - spawn_prover(true, self.proof_types.as_slice()).await; retries -= 1; } } @@ -351,16 +349,23 @@ where .map(|accounts| Self::add_address_merkle_tree_bundle(accounts)) .collect::>(); - let mut proof_types = vec![]; - if inclusion { - proof_types.push(ProofType::Inclusion); + let mut types = vec!["start-prover"]; + if !inclusion { + types.push("-c"); } - if non_inclusion { - proof_types.push(ProofType::NonInclusion); - } - if !proof_types.is_empty() { - spawn_prover(true, proof_types.as_slice()).await; + if !non_inclusion { + types.push("-n"); } + let project_root = light_prover_client::gnark::helpers::get_project_root().unwrap(); + let project_root = project_root.trim_end_matches('\n').to_string(); + let cli_bin_path = format!("{}/cli/test_bin", project_root); + + std::process::Command::new("./run") + .args(types.as_slice()) + .current_dir(cli_bin_path) + .spawn() + .expect("Failed to start prover"); + health_check(20, 1).await; Self { state_merkle_trees, @@ -370,7 +375,6 @@ where token_compressed_accounts: Vec::new(), token_nullified_compressed_accounts: Vec::new(), events: Vec::new(), - proof_types, _rpc: PhantomData, } } diff --git a/examples/name-service/package.json b/examples/name-service/package.json index 5edd8adafb..03fba00db6 100644 --- a/examples/name-service/package.json +++ b/examples/name-service/package.json @@ -8,6 +8,8 @@ "@coral-xyz/anchor": "^0.29.0" }, "devDependencies": { + "@lightprotocol/zk-compression-cli": "workspace:*", + "chai": "^4.3.4", "mocha": "^10.7.3", "ts-mocha": "^10.0.0", diff --git a/examples/name-service/programs/name-service/Cargo.toml b/examples/name-service/programs/name-service/Cargo.toml index 6233011b85..c03168aa90 100644 --- a/examples/name-service/programs/name-service/Cargo.toml +++ b/examples/name-service/programs/name-service/Cargo.toml @@ -21,7 +21,7 @@ bench-sbf = [] idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] -anchor-lang = { workspace = true, features = ["init-if-needed"] } +anchor-lang = { workspace=true} borsh = { workspace = true } light-hasher = { workspace = true, features = ["solana"] } light-macros = { workspace = true } @@ -35,6 +35,6 @@ solana-sdk = { workspace = true } [dev-dependencies] light-client = { workspace = true } -light-test-utils = { path = "../../../../test-utils", version = "1.0.0" } +light-test-utils = { path = "../../../../test-utils", version = "1.0.0", features = ["devenv"] } solana-program-test = { workspace = true } tokio = "1.36.0" diff --git a/examples/token-escrow/programs/token-escrow/Cargo.toml b/examples/token-escrow/programs/token-escrow/Cargo.toml index dada45c6e3..f114c83fbb 100644 --- a/examples/token-escrow/programs/token-escrow/Cargo.toml +++ b/examples/token-escrow/programs/token-escrow/Cargo.toml @@ -33,7 +33,7 @@ solana-sdk = { workspace = true } [dev-dependencies] solana-program-test = { workspace = true } -light-test-utils = { version = "1.0.0", path = "../../../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../../../test-utils", features = ["devenv"] } reqwest = "0.12" tokio = { workspace = true } light-prover-client = { path = "../../../../circuit-lib/light-prover-client", version = "1.0.0" } diff --git a/js/compressed-token/src/idl/light_compressed_token.ts b/js/compressed-token/src/idl/light_compressed_token.ts index a83a93650d..3aa132b539 100644 --- a/js/compressed-token/src/idl/light_compressed_token.ts +++ b/js/compressed-token/src/idl/light_compressed_token.ts @@ -1549,128 +1549,23 @@ export type LightCompressedToken = { errors: [ { code: 6000; - name: 'PublicKeyAmountMissmatch'; - msg: 'public keys and amounts must be of same length'; + name: 'SignerCheckFailed'; + msg: 'Signer check failed'; }, { code: 6001; - name: 'ComputeInputSumFailed'; - msg: 'ComputeInputSumFailed'; + name: 'CreateTransferInstructionFailed'; + msg: 'Create transfer instruction failed'; }, { code: 6002; - name: 'ComputeOutputSumFailed'; - msg: 'ComputeOutputSumFailed'; + name: 'AccountNotFound'; + msg: 'Account not found'; }, { code: 6003; - name: 'ComputeCompressSumFailed'; - msg: 'ComputeCompressSumFailed'; - }, - { - code: 6004; - name: 'ComputeDecompressSumFailed'; - msg: 'ComputeDecompressSumFailed'; - }, - { - code: 6005; - name: 'SumCheckFailed'; - msg: 'SumCheckFailed'; - }, - { - code: 6006; - name: 'DecompressRecipientUndefinedForDecompress'; - msg: 'DecompressRecipientUndefinedForDecompress'; - }, - { - code: 6007; - name: 'CompressedPdaUndefinedForDecompress'; - msg: 'CompressedPdaUndefinedForDecompress'; - }, - { - code: 6008; - name: 'DeCompressAmountUndefinedForDecompress'; - msg: 'DeCompressAmountUndefinedForDecompress'; - }, - { - code: 6009; - name: 'CompressedPdaUndefinedForCompress'; - msg: 'CompressedPdaUndefinedForCompress'; - }, - { - code: 6010; - name: 'DeCompressAmountUndefinedForCompress'; - msg: 'DeCompressAmountUndefinedForCompress'; - }, - { - code: 6011; - name: 'DelegateSignerCheckFailed'; - msg: 'DelegateSignerCheckFailed'; - }, - { - code: 6012; - name: 'MintTooLarge'; - msg: 'Minted amount greater than u64::MAX'; - }, - { - code: 6013; - name: 'SplTokenSupplyMismatch'; - msg: 'SplTokenSupplyMismatch'; - }, - { - code: 6014; - name: 'HeapMemoryCheckFailed'; - msg: 'HeapMemoryCheckFailed'; - }, - { - code: 6015; - name: 'InstructionNotCallable'; - msg: 'The instruction is not callable'; - }, - { - code: 6016; - name: 'ArithmeticUnderflow'; - msg: 'ArithmeticUnderflow'; - }, - { - code: 6017; - name: 'HashToFieldError'; - msg: 'HashToFieldError'; - }, - { - code: 6018; - name: 'InvalidAuthorityMint'; - msg: 'Expected the authority to be also a mint authority'; - }, - { - code: 6019; - name: 'InvalidFreezeAuthority'; - msg: 'Provided authority is not the freeze authority'; - }, - { - code: 6020; - name: 'InvalidDelegateIndex'; - }, - { - code: 6021; - name: 'TokenPoolPdaUndefined'; - }, - { - code: 6022; - name: 'IsTokenPoolPda'; - msg: 'Compress or decompress recipient is the same account as the token pool pda.'; - }, - { - code: 6023; - name: 'InvalidTokenPoolPda'; - }, - { - code: 6024; - name: 'NoInputTokenAccountsProvided'; - }, - { - code: 6025; - name: 'NoInputsProvided'; + name: 'SerializationError'; + msg: 'Serialization error'; }, ]; }; @@ -3230,128 +3125,23 @@ export const IDL: LightCompressedToken = { errors: [ { code: 6000, - name: 'PublicKeyAmountMissmatch', - msg: 'public keys and amounts must be of same length', + name: 'SignerCheckFailed', + msg: 'Signer check failed', }, { code: 6001, - name: 'ComputeInputSumFailed', - msg: 'ComputeInputSumFailed', + name: 'CreateTransferInstructionFailed', + msg: 'Create transfer instruction failed', }, { code: 6002, - name: 'ComputeOutputSumFailed', - msg: 'ComputeOutputSumFailed', + name: 'AccountNotFound', + msg: 'Account not found', }, { code: 6003, - name: 'ComputeCompressSumFailed', - msg: 'ComputeCompressSumFailed', - }, - { - code: 6004, - name: 'ComputeDecompressSumFailed', - msg: 'ComputeDecompressSumFailed', - }, - { - code: 6005, - name: 'SumCheckFailed', - msg: 'SumCheckFailed', - }, - { - code: 6006, - name: 'DecompressRecipientUndefinedForDecompress', - msg: 'DecompressRecipientUndefinedForDecompress', - }, - { - code: 6007, - name: 'CompressedPdaUndefinedForDecompress', - msg: 'CompressedPdaUndefinedForDecompress', - }, - { - code: 6008, - name: 'DeCompressAmountUndefinedForDecompress', - msg: 'DeCompressAmountUndefinedForDecompress', - }, - { - code: 6009, - name: 'CompressedPdaUndefinedForCompress', - msg: 'CompressedPdaUndefinedForCompress', - }, - { - code: 6010, - name: 'DeCompressAmountUndefinedForCompress', - msg: 'DeCompressAmountUndefinedForCompress', - }, - { - code: 6011, - name: 'DelegateSignerCheckFailed', - msg: 'DelegateSignerCheckFailed', - }, - { - code: 6012, - name: 'MintTooLarge', - msg: 'Minted amount greater than u64::MAX', - }, - { - code: 6013, - name: 'SplTokenSupplyMismatch', - msg: 'SplTokenSupplyMismatch', - }, - { - code: 6014, - name: 'HeapMemoryCheckFailed', - msg: 'HeapMemoryCheckFailed', - }, - { - code: 6015, - name: 'InstructionNotCallable', - msg: 'The instruction is not callable', - }, - { - code: 6016, - name: 'ArithmeticUnderflow', - msg: 'ArithmeticUnderflow', - }, - { - code: 6017, - name: 'HashToFieldError', - msg: 'HashToFieldError', - }, - { - code: 6018, - name: 'InvalidAuthorityMint', - msg: 'Expected the authority to be also a mint authority', - }, - { - code: 6019, - name: 'InvalidFreezeAuthority', - msg: 'Provided authority is not the freeze authority', - }, - { - code: 6020, - name: 'InvalidDelegateIndex', - }, - { - code: 6021, - name: 'TokenPoolPdaUndefined', - }, - { - code: 6022, - name: 'IsTokenPoolPda', - msg: 'Compress or decompress recipient is the same account as the token pool pda.', - }, - { - code: 6023, - name: 'InvalidTokenPoolPda', - }, - { - code: 6024, - name: 'NoInputTokenAccountsProvided', - }, - { - code: 6025, - name: 'NoInputsProvided', + name: 'SerializationError', + msg: 'Serialization error', }, ], }; diff --git a/js/stateless.js/src/idls/light_compressed_token.ts b/js/stateless.js/src/idls/light_compressed_token.ts index a83a93650d..3aa132b539 100644 --- a/js/stateless.js/src/idls/light_compressed_token.ts +++ b/js/stateless.js/src/idls/light_compressed_token.ts @@ -1549,128 +1549,23 @@ export type LightCompressedToken = { errors: [ { code: 6000; - name: 'PublicKeyAmountMissmatch'; - msg: 'public keys and amounts must be of same length'; + name: 'SignerCheckFailed'; + msg: 'Signer check failed'; }, { code: 6001; - name: 'ComputeInputSumFailed'; - msg: 'ComputeInputSumFailed'; + name: 'CreateTransferInstructionFailed'; + msg: 'Create transfer instruction failed'; }, { code: 6002; - name: 'ComputeOutputSumFailed'; - msg: 'ComputeOutputSumFailed'; + name: 'AccountNotFound'; + msg: 'Account not found'; }, { code: 6003; - name: 'ComputeCompressSumFailed'; - msg: 'ComputeCompressSumFailed'; - }, - { - code: 6004; - name: 'ComputeDecompressSumFailed'; - msg: 'ComputeDecompressSumFailed'; - }, - { - code: 6005; - name: 'SumCheckFailed'; - msg: 'SumCheckFailed'; - }, - { - code: 6006; - name: 'DecompressRecipientUndefinedForDecompress'; - msg: 'DecompressRecipientUndefinedForDecompress'; - }, - { - code: 6007; - name: 'CompressedPdaUndefinedForDecompress'; - msg: 'CompressedPdaUndefinedForDecompress'; - }, - { - code: 6008; - name: 'DeCompressAmountUndefinedForDecompress'; - msg: 'DeCompressAmountUndefinedForDecompress'; - }, - { - code: 6009; - name: 'CompressedPdaUndefinedForCompress'; - msg: 'CompressedPdaUndefinedForCompress'; - }, - { - code: 6010; - name: 'DeCompressAmountUndefinedForCompress'; - msg: 'DeCompressAmountUndefinedForCompress'; - }, - { - code: 6011; - name: 'DelegateSignerCheckFailed'; - msg: 'DelegateSignerCheckFailed'; - }, - { - code: 6012; - name: 'MintTooLarge'; - msg: 'Minted amount greater than u64::MAX'; - }, - { - code: 6013; - name: 'SplTokenSupplyMismatch'; - msg: 'SplTokenSupplyMismatch'; - }, - { - code: 6014; - name: 'HeapMemoryCheckFailed'; - msg: 'HeapMemoryCheckFailed'; - }, - { - code: 6015; - name: 'InstructionNotCallable'; - msg: 'The instruction is not callable'; - }, - { - code: 6016; - name: 'ArithmeticUnderflow'; - msg: 'ArithmeticUnderflow'; - }, - { - code: 6017; - name: 'HashToFieldError'; - msg: 'HashToFieldError'; - }, - { - code: 6018; - name: 'InvalidAuthorityMint'; - msg: 'Expected the authority to be also a mint authority'; - }, - { - code: 6019; - name: 'InvalidFreezeAuthority'; - msg: 'Provided authority is not the freeze authority'; - }, - { - code: 6020; - name: 'InvalidDelegateIndex'; - }, - { - code: 6021; - name: 'TokenPoolPdaUndefined'; - }, - { - code: 6022; - name: 'IsTokenPoolPda'; - msg: 'Compress or decompress recipient is the same account as the token pool pda.'; - }, - { - code: 6023; - name: 'InvalidTokenPoolPda'; - }, - { - code: 6024; - name: 'NoInputTokenAccountsProvided'; - }, - { - code: 6025; - name: 'NoInputsProvided'; + name: 'SerializationError'; + msg: 'Serialization error'; }, ]; }; @@ -3230,128 +3125,23 @@ export const IDL: LightCompressedToken = { errors: [ { code: 6000, - name: 'PublicKeyAmountMissmatch', - msg: 'public keys and amounts must be of same length', + name: 'SignerCheckFailed', + msg: 'Signer check failed', }, { code: 6001, - name: 'ComputeInputSumFailed', - msg: 'ComputeInputSumFailed', + name: 'CreateTransferInstructionFailed', + msg: 'Create transfer instruction failed', }, { code: 6002, - name: 'ComputeOutputSumFailed', - msg: 'ComputeOutputSumFailed', + name: 'AccountNotFound', + msg: 'Account not found', }, { code: 6003, - name: 'ComputeCompressSumFailed', - msg: 'ComputeCompressSumFailed', - }, - { - code: 6004, - name: 'ComputeDecompressSumFailed', - msg: 'ComputeDecompressSumFailed', - }, - { - code: 6005, - name: 'SumCheckFailed', - msg: 'SumCheckFailed', - }, - { - code: 6006, - name: 'DecompressRecipientUndefinedForDecompress', - msg: 'DecompressRecipientUndefinedForDecompress', - }, - { - code: 6007, - name: 'CompressedPdaUndefinedForDecompress', - msg: 'CompressedPdaUndefinedForDecompress', - }, - { - code: 6008, - name: 'DeCompressAmountUndefinedForDecompress', - msg: 'DeCompressAmountUndefinedForDecompress', - }, - { - code: 6009, - name: 'CompressedPdaUndefinedForCompress', - msg: 'CompressedPdaUndefinedForCompress', - }, - { - code: 6010, - name: 'DeCompressAmountUndefinedForCompress', - msg: 'DeCompressAmountUndefinedForCompress', - }, - { - code: 6011, - name: 'DelegateSignerCheckFailed', - msg: 'DelegateSignerCheckFailed', - }, - { - code: 6012, - name: 'MintTooLarge', - msg: 'Minted amount greater than u64::MAX', - }, - { - code: 6013, - name: 'SplTokenSupplyMismatch', - msg: 'SplTokenSupplyMismatch', - }, - { - code: 6014, - name: 'HeapMemoryCheckFailed', - msg: 'HeapMemoryCheckFailed', - }, - { - code: 6015, - name: 'InstructionNotCallable', - msg: 'The instruction is not callable', - }, - { - code: 6016, - name: 'ArithmeticUnderflow', - msg: 'ArithmeticUnderflow', - }, - { - code: 6017, - name: 'HashToFieldError', - msg: 'HashToFieldError', - }, - { - code: 6018, - name: 'InvalidAuthorityMint', - msg: 'Expected the authority to be also a mint authority', - }, - { - code: 6019, - name: 'InvalidFreezeAuthority', - msg: 'Provided authority is not the freeze authority', - }, - { - code: 6020, - name: 'InvalidDelegateIndex', - }, - { - code: 6021, - name: 'TokenPoolPdaUndefined', - }, - { - code: 6022, - name: 'IsTokenPoolPda', - msg: 'Compress or decompress recipient is the same account as the token pool pda.', - }, - { - code: 6023, - name: 'InvalidTokenPoolPda', - }, - { - code: 6024, - name: 'NoInputTokenAccountsProvided', - }, - { - code: 6025, - name: 'NoInputsProvided', + name: 'SerializationError', + msg: 'Serialization error', }, ], }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4796aa0cd..a97ed206fc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -245,6 +245,9 @@ importers: specifier: ^0.29.0 version: 0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) devDependencies: + '@lightprotocol/zk-compression-cli': + specifier: workspace:* + version: link:../../cli '@types/bn.js': specifier: ^5.1.0 version: 5.1.5 diff --git a/sdk/src/compressed_account.rs b/sdk/src/compressed_account.rs index 7d8f4b6993..20b02e9c8f 100644 --- a/sdk/src/compressed_account.rs +++ b/sdk/src/compressed_account.rs @@ -547,7 +547,6 @@ where let address_merkle_context = unpack_address_merkle_context(*address_merkle_context, remaining_accounts); let address = derive_address(address_seed, &address_merkle_context); - anchor_lang::prelude::msg!("ADDRESS: {:?}", address); let compressed_account = CompressedAccount { owner: *program_id, diff --git a/test-programs/account-compression-test/Cargo.toml b/test-programs/account-compression-test/Cargo.toml index 59d5b7ccc3..99dcef1981 100644 --- a/test-programs/account-compression-test/Cargo.toml +++ b/test-programs/account-compression-test/Cargo.toml @@ -23,7 +23,7 @@ default = ["custom-heap"] ark-bn254 = "0.4.0" ark-ff = "0.4.0" solana-program-test = { workspace = true} -light-test-utils = { version = "1.0.0", path = "../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../test-utils", features=["devenv"] } reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = {path = "../../circuit-lib/light-prover-client" } diff --git a/test-programs/compressed-token-test/Cargo.toml b/test-programs/compressed-token-test/Cargo.toml index 5596ed161b..7cb9f507c1 100644 --- a/test-programs/compressed-token-test/Cargo.toml +++ b/test-programs/compressed-token-test/Cargo.toml @@ -32,7 +32,7 @@ solana-sdk = { workspace = true } [dev-dependencies] solana-program-test = { workspace = true } -light-test-utils = { version = "1.0.0", path = "../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../test-utils", features=["devenv"] } reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = {path = "../../circuit-lib/light-prover-client" } diff --git a/test-programs/e2e-test/Cargo.toml b/test-programs/e2e-test/Cargo.toml index 6826b48060..7190176032 100644 --- a/test-programs/e2e-test/Cargo.toml +++ b/test-programs/e2e-test/Cargo.toml @@ -36,7 +36,7 @@ solana-client = { workspace = true } [dev-dependencies] solana-program-test = { workspace = true } -light-test-utils = { version = "1.0.0", path = "../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../test-utils", features=["devenv"] } reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = {path = "../../circuit-lib/light-prover-client" } diff --git a/test-programs/registry-test/Cargo.toml b/test-programs/registry-test/Cargo.toml index 5b7e88aeeb..b07a523a27 100644 --- a/test-programs/registry-test/Cargo.toml +++ b/test-programs/registry-test/Cargo.toml @@ -22,7 +22,7 @@ default = ["custom-heap"] [dev-dependencies] solana-program-test = { workspace = true } -light-test-utils = { version = "1.0.0", path = "../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../test-utils", features=["devenv"] } reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = {path = "../../circuit-lib/light-prover-client" } diff --git a/test-programs/system-cpi-test/Cargo.toml b/test-programs/system-cpi-test/Cargo.toml index c2a13ae54f..7603aa587e 100644 --- a/test-programs/system-cpi-test/Cargo.toml +++ b/test-programs/system-cpi-test/Cargo.toml @@ -34,7 +34,7 @@ solana-sdk = { workspace = true } [dev-dependencies] solana-program-test = { workspace = true } -light-test-utils = { version = "1.0.0", path = "../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../test-utils", features=["devenv"] } reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = { path = "../../circuit-lib/light-prover-client", version = "1.0.0" } diff --git a/test-programs/system-test/Cargo.toml b/test-programs/system-test/Cargo.toml index 2d350a8955..c793e0ba89 100644 --- a/test-programs/system-test/Cargo.toml +++ b/test-programs/system-test/Cargo.toml @@ -22,7 +22,7 @@ default = ["custom-heap"] [dev-dependencies] solana-program-test = { workspace = true } -light-test-utils = { version = "1.0.0", path = "../../test-utils" } +light-test-utils = { version = "1.0.0", path = "../../test-utils", features=["devenv"]} reqwest = "0.11.26" tokio = { workspace = true } light-prover-client = {path = "../../circuit-lib/light-prover-client" } diff --git a/test-utils/Cargo.toml b/test-utils/Cargo.toml index 1b9f37056b..5ce9749458 100644 --- a/test-utils/Cargo.toml +++ b/test-utils/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [features] default = [] +devenv = [] [dependencies] anchor-lang = { workspace = true } diff --git a/test-utils/src/test_env.rs b/test-utils/src/test_env.rs index a558f69d01..ea40a8a3d5 100644 --- a/test-utils/src/test_env.rs +++ b/test-utils/src/test_env.rs @@ -36,6 +36,7 @@ use solana_sdk::{ transaction::Transaction, }; use std::cmp; +use std::path::PathBuf; pub const CPI_CONTEXT_ACCOUNT_RENT: u64 = 143487360; // lamports of the cpi context account pub const NOOP_PROGRAM_ID: Pubkey = pubkey!("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); @@ -50,11 +51,16 @@ pub async fn setup_test_programs( additional_programs: Option>, ) -> ProgramTestContext { let mut program_test = ProgramTest::default(); + let sbf_path = std::env::var("SBF_OUT_DIR").unwrap(); + // find path to bin where light cli stores program binaries. + let path = find_light_bin().unwrap(); + std::env::set_var("SBF_OUT_DIR", path.to_str().unwrap()); program_test.add_program("light_registry", light_registry::ID, None); program_test.add_program("account_compression", account_compression::ID, None); program_test.add_program("light_compressed_token", light_compressed_token::ID, None); program_test.add_program("light_system_program", light_system_program::ID, None); program_test.add_program("spl_noop", NOOP_PROGRAM_ID, None); + std::env::set_var("SBF_OUT_DIR", sbf_path); let registered_program = env_accounts::get_registered_program_pda(); program_test.add_account( get_registered_program_pda(&light_system_program::ID), @@ -74,6 +80,48 @@ pub async fn setup_test_programs( program_test.start_with_context().await } +fn find_light_bin() -> Option { + // Run the 'which light' command to find the location of 'light' binary + + #[cfg(not(feature = "devenv"))] + { + use std::process::Command; + let output = Command::new("which") + .arg("light") + .output() + .expect("Failed to execute 'which light'"); + + if !output.status.success() { + return None; + } + // Convert the output into a string (removing any trailing newline) + let light_path = String::from_utf8_lossy(&output.stdout).trim().to_string(); + // Get the parent directory of the 'light' binary + let mut light_bin_path = PathBuf::from(light_path); + light_bin_path.pop(); // Remove the 'light' binary itself + + // Assuming the node_modules path starts from '/lib/node_modules/...' + let node_modules_bin = + light_bin_path.join("../lib/node_modules/@lightprotocol/zk-compression-cli/bin"); + + Some(node_modules_bin.canonicalize().unwrap_or(node_modules_bin)) + } + #[cfg(feature = "devenv")] + { + let light_protocol_toplevel = String::from_utf8_lossy( + &std::process::Command::new("git") + .arg("rev-parse") + .arg("--show-toplevel") + .output() + .expect("Failed to get top-level directory") + .stdout, + ) + .trim() + .to_string(); + let light_path = PathBuf::from(format!("{}/target/deploy/", light_protocol_toplevel)); + Some(light_path) + } +} #[derive(Debug)] pub struct EnvAccounts { pub merkle_tree_pubkey: Pubkey,