Added some tests
This commit is contained in:
27
src/lib.rs
27
src/lib.rs
@@ -61,6 +61,7 @@ pub fn time_to_blockheight(time: DateTime<Utc>, bi: BlockchainInfo) -> BlockHeig
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use chrono::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one_block_time_away() {
|
fn one_block_time_away() {
|
||||||
@@ -100,4 +101,30 @@ mod tests {
|
|||||||
let result = time_to_blockheight(wanted_negative_block_time, blockchain_info);
|
let result = time_to_blockheight(wanted_negative_block_time, blockchain_info);
|
||||||
assert_eq!(result, -1);
|
assert_eq!(result, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_next_block_on_some_blockchains() {
|
||||||
|
// Doesn't feel like an overly good test - but I can't think of anyother way that's "dynamic"
|
||||||
|
// to me manually updating the times above
|
||||||
|
let bi: BlockchainInfo = BlockchainSupported::BTC.into();
|
||||||
|
let wanted_time = bi.latest_block_time + Duration::seconds(bi.block_period as i64 + 1);
|
||||||
|
let bh = time_to_blockheight_specific_chain(wanted_time, BlockchainSupported::BTC);
|
||||||
|
assert_eq!(bh, bi.latest_block_height + 1);
|
||||||
|
let bi: BlockchainInfo = BlockchainSupported::BSV.into();
|
||||||
|
let wanted_time = bi.latest_block_time + Duration::seconds(bi.block_period as i64 + 2);
|
||||||
|
let bh = time_to_blockheight_specific_chain(wanted_time, BlockchainSupported::BSV);
|
||||||
|
assert_eq!(bh, bi.latest_block_height + 1);
|
||||||
|
let bi: BlockchainInfo = BlockchainSupported::XMR.into();
|
||||||
|
let wanted_time = bi.latest_block_time + Duration::seconds(bi.block_period as i64 + 3);
|
||||||
|
let bh = time_to_blockheight_specific_chain(wanted_time, BlockchainSupported::XMR);
|
||||||
|
assert_eq!(bh, bi.latest_block_height + 1);
|
||||||
|
let bi: BlockchainInfo = BlockchainSupported::ETH.into();
|
||||||
|
let wanted_time = bi.latest_block_time + Duration::seconds(bi.block_period as i64 + 4);
|
||||||
|
let bh = time_to_blockheight_specific_chain(wanted_time, BlockchainSupported::ETH);
|
||||||
|
assert_eq!(bh, bi.latest_block_height + 1);
|
||||||
|
let bi: BlockchainInfo = BlockchainSupported::ETH.into();
|
||||||
|
let wanted_time = bi.latest_block_time + Duration::seconds(bi.block_period as i64 + 5);
|
||||||
|
let bh = time_to_blockheight_specific_chain(wanted_time, BlockchainSupported::XMR);
|
||||||
|
assert_ne!(bh, bi.latest_block_height + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user