From 3dfcb475340b0e0876aa0d2f7426e51a3b0b136b Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Fri, 8 Aug 2025 13:32:50 -0300 Subject: [PATCH] add tests for default account --- nssa/Cargo.toml | 2 +- nssa/core/src/account/mod.rs | 40 ++++++++++++++++++----- sequencer_core/src/sequencer_store/mod.rs | 10 ------ sequencer_rpc/src/process.rs | 2 +- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/nssa/Cargo.toml b/nssa/Cargo.toml index c50dc59..ece3262 100644 --- a/nssa/Cargo.toml +++ b/nssa/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" [dependencies] risc0-zkvm = "2.3.1" -nssa-core = {path="core"} +nssa-core = { path = "core"} program-methods = { path = "program_methods" } serde = "1.0.219" serde_cbor = "0.11.2" diff --git a/nssa/core/src/account/mod.rs b/nssa/core/src/account/mod.rs index 5d4cdd9..7761309 100644 --- a/nssa/core/src/account/mod.rs +++ b/nssa/core/src/account/mod.rs @@ -11,7 +11,7 @@ pub type Nonce = u128; type Data = Vec; /// Account to be used both in public and private contexts -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Account { pub program_owner: ProgramId, pub balance: u128, @@ -25,13 +25,35 @@ pub struct AccountWithMetadata { pub is_authorized: bool, } -impl Default for Account { - fn default() -> Self { - Self { - program_owner: [0; 8], - balance: 0, - data: vec![], - nonce: 0, - } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_zero_balance_account_data_creation() { + let new_acc = Account::default(); + + assert_eq!(new_acc.balance, 0); + } + + #[test] + fn test_zero_nonce_account_data_creation() { + let new_acc = Account::default(); + + assert_eq!(new_acc.nonce, 0); + } + + #[test] + fn test_empty_data_account_data_creation() { + let new_acc = Account::default(); + + assert_eq!(new_acc.data, vec![]); + } + + #[test] + fn test_default_program_owner_account_data_creation() { + let new_acc = Account::default(); + + assert_eq!(new_acc.program_owner, [0; 8]); } } diff --git a/sequencer_core/src/sequencer_store/mod.rs b/sequencer_core/src/sequencer_store/mod.rs index ac06ac1..d77af1c 100644 --- a/sequencer_core/src/sequencer_store/mod.rs +++ b/sequencer_core/src/sequencer_store/mod.rs @@ -1,7 +1,6 @@ use std::{collections::HashSet, path::Path}; use accounts::account_core::address::AccountAddress; -use accounts_store::SequencerAccountsStore; use block_store::SequecerBlockStore; use common::{ block::{Block, HashableBlockData}, @@ -13,14 +12,11 @@ use nssa; use crate::config::AccountInitialData; -pub mod accounts_store; pub mod block_store; pub struct SequecerChainStore { pub state: nssa::V01State, pub block_store: SequecerBlockStore, - pub nullifier_store: HashSet, - pub utxo_commitments_store: UTXOCommitmentsMerkleTree, } impl SequecerChainStore { @@ -44,9 +40,6 @@ impl SequecerChainStore { .collect(); let state = nssa::V01State::new_with_genesis_accounts(&init_accs); - let nullifier_store = HashSet::new(); - let utxo_commitments_store = UTXOCommitmentsMerkleTree::new(vec![]); - // let pub_tx_store = PublicTransactionMerkleTree::new(vec![]); let mut data = [0; 32]; let mut prev_block_hash = [0; 32]; @@ -77,9 +70,6 @@ impl SequecerChainStore { Self { state, block_store, - nullifier_store, - utxo_commitments_store, - // pub_tx_store, } } } diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index 7f4386a..d80c6f3 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -481,7 +481,7 @@ mod tests { let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_transaction_by_hash", - "params": { "hash": "e5f0c9b4b7732a2f4946b8e7a5f7c641b004559b1a13b1ccc600f29477725240"}, + "params": { "hash":"fc96dbd7603f1f97bfd96c31e09c35dc877a436c4aa71437b3e8f5bbf69b77fc"}, "id": 1 });