63 lines
1.3 KiB
Rust
Raw Normal View History

2025-08-06 20:05:04 -03:00
use serde::{Deserialize, Serialize};
use crate::program::ProgramId;
mod commitment;
mod nullifier;
pub use commitment::Commitment;
pub use nullifier::Nullifier;
2025-08-06 20:05:04 -03:00
pub type Nonce = u128;
type Data = Vec<u8>;
/// Account to be used both in public and private contexts
2025-08-08 13:32:50 -03:00
#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2025-08-06 20:05:04 -03:00
pub struct Account {
pub program_owner: ProgramId,
pub balance: u128,
pub data: Data,
pub nonce: Nonce,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct AccountWithMetadata {
pub account: Account,
pub is_authorized: bool,
}
2025-08-08 13:32:50 -03:00
#[cfg(test)]
mod tests {
use crate::program::DEFAULT_PROGRAM_ID;
2025-08-08 13:32:50 -03:00
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();
2025-08-10 18:59:29 -03:00
assert!(new_acc.data.is_empty());
2025-08-08 13:32:50 -03:00
}
#[test]
fn test_default_program_owner_account_data_creation() {
let new_acc = Account::default();
assert_eq!(new_acc.program_owner, DEFAULT_PROGRAM_ID);
2025-08-06 20:05:04 -03:00
}
}