Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
holisticode committed Apr 19, 2023
1 parent 007a9a2 commit e7cc2ad
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
110 changes: 55 additions & 55 deletions src/blockchain/.block_store.rs.rustfmt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ use crate::{
Error, Result,
};

use darkfi_sdk::{
crypto::{MerkleNode},
pasta::pallas,
};
use darkfi_sdk::{crypto::MerkleNode, pasta::pallas};

const SLED_HEADER_TREE: &[u8] = b"_headers";
const SLED_BLOCK_TREE: &[u8] = b"_blocks";
Expand Down Expand Up @@ -93,7 +90,7 @@ impl HeaderStore {
} else {
if strict {
let s = hash.to_hex().as_str().to_string();
return Err(Error::HeaderNotFound(s))
return Err(Error::HeaderNotFound(s));
}
ret.push(None);
}
Expand Down Expand Up @@ -121,8 +118,7 @@ impl HeaderStore {

/// The `BlockStore` is a `sled` tree storing all the blockchain's blocks
/// where the key is the blocks' hash, and value is the serialized block.
#[derive(Clone)]
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct BlockStore(sled::Tree);

impl BlockStore {
Expand Down Expand Up @@ -183,7 +179,7 @@ impl BlockStore {
} else {
if strict {
let s = hash.to_hex().as_str().to_string();
return Err(Error::BlockNotFound(s))
return Err(Error::BlockNotFound(s));
}
ret.push(None);
}
Expand Down Expand Up @@ -265,7 +261,7 @@ impl BlockOrderStore {
ret.push(Some(hash));
} else {
if strict {
return Err(Error::SlotNotFound(*slot))
return Err(Error::SlotNotFound(*slot));
}
ret.push(None);
}
Expand Down Expand Up @@ -307,9 +303,9 @@ impl BlockOrderStore {
let blockhash = deserialize(&found.1)?;
ret.push(blockhash);
counter += 1;
continue
continue;
}
break
break;
}

Ok(ret)
Expand Down Expand Up @@ -342,48 +338,52 @@ impl BlockOrderStore {

#[cfg(test)]
mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;

fn create_tmp_db() -> Result<BlockStore> {
let db = sled::Config::new().temporary(true).open()?;
return BlockStore::new(&db,Timestamp::current_time(),blake3::hash(b"unit-testing-blockstore"));
}

#[test]
fn test_new() {
let bs = create_tmp_db();
assert_eq!(bs.is_ok(), true);
}

#[test]
fn test_insert() {
let res = create_tmp_db();
let bs = res.unwrap();
let txs:Vec<blake3::Hash> = gen_hashes(3);
let merkle = MerkleNode::new(pallas::Base::from(42));
let blk = Block::new(blake3::hash(b"some-block"),1,0,txs, merkle, LeadInfo::default());
let hres = bs.insert(&[blk]);
let hh = hres.unwrap();
let first = hh[0];

let mut contains = bs.contains(&first);
assert_eq!(contains.is_ok(), true);
let badhash = blake3::hash(b"blabla");
contains = bs.contains(&badhash);
assert_eq!(contains.is_ok(), true);
let v=contains.unwrap();
assert_eq!(v, false);
let g = bs.get(&[first], true);
assert_eq!(g.is_ok(), true);
}

fn gen_hashes(num:u64) -> Vec<blake3::Hash> {
let mut v:Vec<blake3::Hash> = Vec::new();
for n in 0..num {
let h = blake3::hash(&n.to_be_bytes());
v.push(h);
}
return v;
}
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;

fn create_tmp_db() -> Result<BlockStore> {
let db = sled::Config::new().temporary(true).open()?;
return BlockStore::new(
&db,
Timestamp::current_time(),
blake3::hash(b"unit-testing-blockstore"),
);
}

#[test]
fn test_new() {
let bs = create_tmp_db();
assert_eq!(bs.is_ok(), true);
}

#[test]
fn test_insert() {
let res = create_tmp_db();
let bs = res.unwrap();
let txs: Vec<blake3::Hash> = gen_hashes(3);
let merkle = MerkleNode::new(pallas::Base::from(42));
let blk = Block::new(blake3::hash(b"some-block"), 1, 0, txs, merkle, LeadInfo::default());
let hres = bs.insert(&[blk]);
let hh = hres.unwrap();
let first = hh[0];

let mut contains = bs.contains(&first);
assert_eq!(contains.is_ok(), true);
let badhash = blake3::hash(b"blabla");
contains = bs.contains(&badhash);
assert_eq!(contains.is_ok(), true);
let v = contains.unwrap();
assert_eq!(v, false);
let g = bs.get(&[first], true);
assert_eq!(g.is_ok(), true);
}

fn gen_hashes(num: u64) -> Vec<blake3::Hash> {
let mut v: Vec<blake3::Hash> = Vec::new();
for n in 0..num {
let h = blake3::hash(&n.to_be_bytes());
v.push(h);
}
return v;
}
}
14 changes: 7 additions & 7 deletions src/blockchain/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl HeaderStore {
} else {
if strict {
let s = hash.to_hex().as_str().to_string();
return Err(Error::HeaderNotFound(s));
return Err(Error::HeaderNotFound(s))
}
ret.push(None);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ impl BlockStore {
} else {
if strict {
let s = hash.to_hex().as_str().to_string();
return Err(Error::BlockNotFound(s));
return Err(Error::BlockNotFound(s))
}
ret.push(None);
}
Expand Down Expand Up @@ -261,7 +261,7 @@ impl BlockOrderStore {
ret.push(Some(hash));
} else {
if strict {
return Err(Error::SlotNotFound(*slot));
return Err(Error::SlotNotFound(*slot))
}
ret.push(None);
}
Expand Down Expand Up @@ -303,9 +303,9 @@ impl BlockOrderStore {
let blockhash = deserialize(&found.1)?;
ret.push(blockhash);
counter += 1;
continue;
continue
}
break;
break
}

Ok(ret)
Expand Down Expand Up @@ -347,7 +347,7 @@ mod tests {
&db,
Timestamp::current_time(),
blake3::hash(b"unit-testing-blockstore"),
);
)
}

#[test]
Expand Down Expand Up @@ -384,6 +384,6 @@ mod tests {
let h = blake3::hash(&n.to_be_bytes());
v.push(h);
}
return v;
return v
}
}

0 comments on commit e7cc2ad

Please sign in to comment.