From 0e5087ca8fe1df5adb40f751da317d8063e35b76 Mon Sep 17 00:00:00 2001 From: Oleksandr Pravdyvyi Date: Wed, 24 Sep 2025 16:44:03 +0300 Subject: [PATCH] fix: tests run 1 --- ci_scripts/test-ubuntu.sh | 5 ++- .../debug/sequencer/sequencer_config.json | 32 +++++++++---------- .../configs/debug/wallet/wallet_config.json | 32 +++++++++---------- integration_tests/src/lib.rs | 17 +++++----- nssa/core/src/program.rs | 10 ------ wallet/src/token_transfers/deshielded.rs | 9 ++++-- wallet/src/token_transfers/private.rs | 16 +++++----- wallet/src/token_transfers/shielded.rs | 8 +++-- 8 files changed, 64 insertions(+), 65 deletions(-) diff --git a/ci_scripts/test-ubuntu.sh b/ci_scripts/test-ubuntu.sh index 9efa2d5..ebc50aa 100644 --- a/ci_scripts/test-ubuntu.sh +++ b/ci_scripts/test-ubuntu.sh @@ -8,4 +8,7 @@ RISC0_DEV_MODE=1 cargo test --release cd integration_tests export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/wallet/ export RUST_LOG=info -RISC0_DEV_MODE=1 cargo run $(pwd)/configs/debug test_success_private_transfer_to_another_owned_account +echo "Try test valid proof at least once" +cargo run $(pwd)/configs/debug test_success_private_transfer_to_another_owned_account +echo "Continuing in dev mode" +RISC0_DEV_MODE=1 cargo run $(pwd)/configs/debug all diff --git a/integration_tests/configs/debug/sequencer/sequencer_config.json b/integration_tests/configs/debug/sequencer/sequencer_config.json index f40e731..824d0a7 100644 --- a/integration_tests/configs/debug/sequencer/sequencer_config.json +++ b/integration_tests/configs/debug/sequencer/sequencer_config.json @@ -54,14 +54,14 @@ ], "account": { "program_owner": [ - 2357946808, - 1250390931, - 1946783766, - 2395930623, - 2256469211, - 3226409911, - 3251831113, - 2343238083 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 ], "balance": 10000, "data": [], @@ -105,14 +105,14 @@ ], "account": { "program_owner": [ - 2357946808, - 1250390931, - 1946783766, - 2395930623, - 2256469211, - 3226409911, - 3251831113, - 2343238083 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 ], "balance": 20000, "data": [], diff --git a/integration_tests/configs/debug/wallet/wallet_config.json b/integration_tests/configs/debug/wallet/wallet_config.json index 17e7f4d..f30c9a5 100644 --- a/integration_tests/configs/debug/wallet/wallet_config.json +++ b/integration_tests/configs/debug/wallet/wallet_config.json @@ -90,14 +90,14 @@ "address": "6ffe0893c4b2c956fdb769b11fe4e3b2dd36ac4bd0ad90c810844051747c8c04", "account": { "program_owner": [ - 2357946808, - 1250390931, - 1946783766, - 2395930623, - 2256469211, - 3226409911, - 3251831113, - 2343238083 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 ], "balance": 10000, "data": [], @@ -319,14 +319,14 @@ "address": "4ee9de60e33da96fd72929f1485fb365bcc9c1634dd44e4ba55b1ab96692674b", "account": { "program_owner": [ - 2357946808, - 1250390931, - 1946783766, - 2395930623, - 2256469211, - 3226409911, - 3251831113, - 2343238083 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 ], "balance": 20000, "data": [], diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index 5b0d4ea..bc2c73c 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -407,6 +407,7 @@ pub async fn test_success_private_transfer_to_another_foreign_account() { .get_private_account_mut(&from) .unwrap(); + from_acc.1.program_owner = nssa::program::Program::authenticated_transfer_program().id(); from_acc.1.balance -= 100; from_acc.1.nonce += 1; @@ -415,10 +416,7 @@ pub async fn test_success_private_transfer_to_another_foreign_account() { let new_commitment2 = { let to_acc = nssa_core::account::Account { - program_owner: [ - 1793544791, 852173979, 3315478100, 4158236927, 146723505, 3793635251, 999304864, - 2535706995, - ], + program_owner: nssa::program::Program::authenticated_transfer_program().id(), balance: 100, data: vec![], nonce: 1, @@ -471,6 +469,7 @@ pub async fn test_success_deshielded_transfer_to_another_account() { .get_private_account_mut(&from) .unwrap(); + from_acc.1.program_owner = nssa::program::Program::authenticated_transfer_program().id(); from_acc.1.balance -= 100; from_acc.1.nonce += 1; @@ -521,6 +520,7 @@ pub async fn test_success_shielded_transfer_to_another_owned_account() { .get_private_account_mut(&to) .unwrap(); + to_acc.1.program_owner = nssa::program::Program::authenticated_transfer_program().id(); to_acc.1.balance += 100; to_acc.1.nonce += 1; @@ -568,10 +568,7 @@ pub async fn test_success_shielded_transfer_to_another_foreign_account() { let new_commitment2 = { let to_acc = nssa_core::account::Account { - program_owner: [ - 1793544791, 852173979, 3315478100, 4158236927, 146723505, 3793635251, 999304864, - 2535706995, - ], + program_owner: nssa::program::Program::authenticated_transfer_program().id(), balance: 100, data: vec![], nonce: 1, @@ -687,6 +684,10 @@ pub async fn main_tests_runner() -> Result<()> { home_dir, test_success_shielded_transfer_to_another_owned_account ); + test_cleanup_wrap!( + home_dir, + test_success_shielded_transfer_to_another_foreign_account + ); } _ => { anyhow::bail!("Unknown test name"); diff --git a/nssa/core/src/program.rs b/nssa/core/src/program.rs index 046eb1e..d284bbc 100644 --- a/nssa/core/src/program.rs +++ b/nssa/core/src/program.rs @@ -53,30 +53,22 @@ pub fn validate_execution( return false; } - println!("HELLO 1"); - for (pre, post) in pre_states.iter().zip(post_states) { // 2. Nonce must remain unchanged if pre.account.nonce != post.nonce { return false; } - println!("HELLO 2"); - // 3. Ownership change only allowed from default accounts if pre.account.program_owner != post.program_owner && pre.account != Account::default() { return false; } - println!("HELLO 3"); - // 4. Decreasing balance only allowed if owned by executing program if post.balance < pre.account.balance && pre.account.program_owner != executing_program_id { return false; } - println!("HELLO 4"); - // 5. Data changes only allowed if owned by executing program if pre.account.data != post.data && (executing_program_id != pre.account.program_owner @@ -84,8 +76,6 @@ pub fn validate_execution( { return false; } - - println!("HELLO 5"); } // 6. Total balance is preserved diff --git a/wallet/src/token_transfers/deshielded.rs b/wallet/src/token_transfers/deshielded.rs index 1daf367..7243146 100644 --- a/wallet/src/token_transfers/deshielded.rs +++ b/wallet/src/token_transfers/deshielded.rs @@ -12,10 +12,10 @@ impl WalletCore { to: Address, balance_to_move: u128, ) -> Result<(SendTxResponse, nssa_core::SharedSecretKey), ExecutionFailureKind> { - let from_data = self.storage.user_data.get_private_account(&from); + let from_data = self.storage.user_data.get_private_account(&from).cloned(); let to_data = self.get_account(to).await; - let Some((from_keys, from_acc)) = from_data else { + let Some((from_keys, mut from_acc)) = from_data else { return Err(ExecutionFailureKind::KeyNotFoundError); }; @@ -25,8 +25,11 @@ impl WalletCore { if from_acc.balance >= balance_to_move { let program = nssa::program::Program::authenticated_transfer_program(); + + from_acc.program_owner = program.id(); + let sender_commitment = - nssa_core::Commitment::new(&from_keys.nullifer_public_key, from_acc); + nssa_core::Commitment::new(&from_keys.nullifer_public_key, &from_acc); let sender_pre = nssa_core::account::AccountWithMetadata { account: from_acc.clone(), diff --git a/wallet/src/token_transfers/private.rs b/wallet/src/token_transfers/private.rs index 3d2eaf8..919055c 100644 --- a/wallet/src/token_transfers/private.rs +++ b/wallet/src/token_transfers/private.rs @@ -12,9 +12,9 @@ impl WalletCore { to_ipk: nssa_core::encryption::IncomingViewingPublicKey, balance_to_move: u128, ) -> Result<(SendTxResponse, nssa_core::SharedSecretKey), ExecutionFailureKind> { - let from_data = self.storage.user_data.get_private_account(&from); + let from_data = self.storage.user_data.get_private_account(&from).cloned(); - let Some((from_keys, from_acc)) = from_data else { + let Some((from_keys, mut from_acc)) = from_data else { return Err(ExecutionFailureKind::KeyNotFoundError); }; @@ -22,8 +22,11 @@ impl WalletCore { if from_acc.balance >= balance_to_move { let program = nssa::program::Program::authenticated_transfer_program(); + + from_acc.program_owner = program.id(); + let sender_commitment = - nssa_core::Commitment::new(&from_keys.nullifer_public_key, from_acc); + nssa_core::Commitment::new(&from_keys.nullifer_public_key, &from_acc); let sender_pre = nssa_core::account::AccountWithMetadata { account: from_acc.clone(), @@ -127,11 +130,8 @@ impl WalletCore { if from_acc.balance >= balance_to_move { let program = nssa::program::Program::authenticated_transfer_program(); - //Kind of hacky solution - //The issue is that we don't have deterministic builds - //and native_token_transfer at different machine may be different - from_acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); - to_acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); + from_acc.program_owner = program.id(); + to_acc.program_owner = program.id(); let sender_commitment = nssa_core::Commitment::new(&from_keys.nullifer_public_key, &from_acc); diff --git a/wallet/src/token_transfers/shielded.rs b/wallet/src/token_transfers/shielded.rs index 0c25d83..e0108c7 100644 --- a/wallet/src/token_transfers/shielded.rs +++ b/wallet/src/token_transfers/shielded.rs @@ -13,13 +13,13 @@ impl WalletCore { balance_to_move: u128, ) -> Result<(SendTxResponse, nssa_core::SharedSecretKey), ExecutionFailureKind> { let from_data = self.get_account(from).await; - let to_data = self.storage.user_data.get_private_account(&to); + let to_data = self.storage.user_data.get_private_account(&to).cloned(); let Ok(from_acc) = from_data else { return Err(ExecutionFailureKind::KeyNotFoundError); }; - let Some((to_keys, to_acc)) = to_data else { + let Some((to_keys, mut to_acc)) = to_data else { return Err(ExecutionFailureKind::KeyNotFoundError); }; @@ -29,8 +29,10 @@ impl WalletCore { if from_acc.balance >= balance_to_move { let program = nssa::program::Program::authenticated_transfer_program(); + to_acc.program_owner = program.id(); + let receiver_commitment = - nssa_core::Commitment::new(&to_keys.nullifer_public_key, to_acc); + nssa_core::Commitment::new(&to_keys.nullifer_public_key, &to_acc); let sender_pre = nssa_core::account::AccountWithMetadata { account: from_acc.clone(),