Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@ mod test {
use bitcoin::hashes::hex::FromHex;
use bitcoin::Block;
use bitcoin::BlockHash;
use rand::Rng;
use rustreexo::accumulator::proof::Proof;

use super::BlockchainInterface;
Expand All @@ -1384,6 +1385,7 @@ mod test {
use crate::AssumeValidArg;
use crate::KvChainStore;
use crate::Network;

#[test]
fn accept_mainnet_headers() {
// Accepts the first 10235 mainnet headers
Expand Down Expand Up @@ -1489,4 +1491,54 @@ mod test {
panic!("Block {} is not in the store", i);
}
}
#[test]
fn test_chainstate_functions() {
let file = include_bytes!("./testdata/signet_headers.zst");
let uncompressed: Vec<u8> = zstd::decode_all(std::io::Cursor::new(file)).unwrap();
let mut cursor = Cursor::new(uncompressed);

let test_id = rand::random::<u64>();
let chainstore = KvChainStore::new(format!("./data/{test_id}/")).unwrap();
let chain =
ChainState::<KvChainStore>::new(chainstore, Network::Signet, AssumeValidArg::Hardcoded);
let mut headers: Vec<BlockHeader> = Vec::new();
while let Ok(header) = BlockHeader::consensus_decode(&mut cursor) {
headers.push(header);
}
headers.remove(0);

// push_headers
assert!(chain.push_headers(headers.clone(), 1).is_ok());

// get_block_header_by_height
assert_eq!(chain.get_block_header_by_height(1), headers[0]);

// reindex_chain
assert_eq!(chain.reindex_chain().depth, 2015);

// get_block_locator_for_tip
assert!(!chain
.get_block_locator_for_tip(read_lock!(chain).best_block.best_block)
.unwrap()
.is_empty());

// get_block_locator
assert!(!chain.get_block_locator().unwrap().is_empty());

// invalidate_block
let random_height = rand::thread_rng().gen_range(1..=2014);

chain
.invalidate_block(headers[random_height].prev_blockhash)
.unwrap();

assert_eq!(chain.get_height().unwrap() as usize, random_height - 1);

// update_tip
chain.update_tip(headers[1].prev_blockhash, 1);
assert_eq!(
read_lock!(chain).best_block.best_block,
headers[1].prev_blockhash
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"000000200a2c91be5061dee3f53a491de9471a1a01cb935c3c0b0a08c56af73811384f12b8e5cb79921e6e50b0714475f0666d9037f98437717df69edde51d62b10355630a351e64ffff7f200100000001020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff035f0101ffffffff0200f2052a01000000160014f1c468ac955c0518020d8defa90679cd6b0061dd0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000",
"000000202afe578845b61f90eea8ec6d2c508d2508b2e7c76528f8714f63570818096b62c76ea45cf5977706d1c2bea68c0807acb8b291e70ca5dc700eeea3690bb5a17b0b351e64ffff7f200000000001020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff03600101ffffffff0200f2052a01000000160014f1c468ac955c0518020d8defa90679cd6b0061dd0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000"
]
]
]
1 change: 1 addition & 0 deletions crates/floresta-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod rpc_types;

// Those tests doesn't work on windowns
// TODO (Davidson): work on windows?

#[cfg(all(test, not(target_os = "windows")))]
mod tests {
use std::fs;
Expand Down
3 changes: 3 additions & 0 deletions crates/floresta-electrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ bitcoin = { version = "0.31", features = ["serde", "std", "bitcoinconsensus"] }
thiserror = "1.0"
core2 = { version = "0.4.0", default-features = false }
hex = "0.4.3"
zstd = "0.13.1"

[dev-dependencies]
rand = "0.8.5"
Loading