mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-11 17:53:12 +00:00
add test
This commit is contained in:
parent
c9574b0d09
commit
98631721fa
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4359,6 +4359,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"storage",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -15,7 +15,7 @@ pub type CipherText = Vec<u8>;
|
||||
pub type Nonce = GenericArray<u8, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>;
|
||||
pub type Tag = u8;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum TxKind {
|
||||
Public,
|
||||
Private,
|
||||
@ -23,7 +23,7 @@ pub enum TxKind {
|
||||
Deshielded,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
///General transaction object
|
||||
pub struct Transaction {
|
||||
pub tx_kind: TxKind,
|
||||
|
||||
@ -13,6 +13,7 @@ serde.workspace = true
|
||||
rand.workspace = true
|
||||
elliptic-curve.workspace = true
|
||||
k256.workspace = true
|
||||
tempfile.workspace = true
|
||||
|
||||
[dependencies.storage]
|
||||
path = "../storage"
|
||||
|
||||
@ -70,3 +70,61 @@ fn block_to_transactions_map(block: &Block) -> HashMap<TreeHashType, u64> {
|
||||
.map(|transaction| (transaction.hash(), block.block_id))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
fn create_genesis_block_with_transaction() -> (Block, Transaction) {
|
||||
let tx = Transaction {
|
||||
tx_kind: common::transaction::TxKind::Public,
|
||||
execution_input: Default::default(),
|
||||
execution_output: Default::default(),
|
||||
utxo_commitments_spent_hashes: Default::default(),
|
||||
utxo_commitments_created_hashes: Default::default(),
|
||||
nullifier_created_hashes: Default::default(),
|
||||
execution_proof_private: Default::default(),
|
||||
encoded_data: Default::default(),
|
||||
ephemeral_pub_key: Default::default(),
|
||||
commitment: Default::default(),
|
||||
tweak: Default::default(),
|
||||
secret_r: Default::default(),
|
||||
sc_addr: Default::default(),
|
||||
state_changes: Default::default(),
|
||||
};
|
||||
(
|
||||
Block {
|
||||
block_id: 0,
|
||||
prev_block_id: 0,
|
||||
prev_block_hash: [0; 32],
|
||||
hash: [1; 32],
|
||||
transactions: vec![tx.clone()],
|
||||
data: vec![],
|
||||
},
|
||||
tx,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_transaction_by_hash_for_existing_transaction() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let path = temp_dir.path();
|
||||
|
||||
let (block, tx) = create_genesis_block_with_transaction();
|
||||
let node_store = SequecerBlockStore::open_db_with_genesis(path, Some(block)).unwrap();
|
||||
let retrieved_tx = node_store.get_transaction_by_hash(tx.hash());
|
||||
assert_eq!(Some(tx), retrieved_tx);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_transaction_by_hash_for_non_existent_transaction() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let path = temp_dir.path();
|
||||
|
||||
let (block, tx) = create_genesis_block_with_transaction();
|
||||
let node_store = SequecerBlockStore::open_db_with_genesis(path, Some(block)).unwrap();
|
||||
let retrieved_tx = node_store.get_transaction_by_hash([0; 32]);
|
||||
assert_eq!(None, retrieved_tx);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user