Skip to content

Commit 0dd2966

Browse files
committed
added test for get_signed_block_count_in_tenure
1 parent 90d7101 commit 0dd2966

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,57 @@ mod tests {
19581958
assert_eq!(pendings.len(), 0);
19591959
}
19601960

1961+
#[test]
1962+
fn check_signed_block_count() {
1963+
let db_path = tmp_db_path();
1964+
let consensus_hash_1 = ConsensusHash([0x01; 20]);
1965+
let mut db = SignerDb::new(db_path).expect("Failed to create signer db");
1966+
let (mut block_info, _) = create_block_override(|b| {
1967+
b.block.header.consensus_hash = consensus_hash_1;
1968+
});
1969+
1970+
assert_eq!(
1971+
db.get_signed_block_count_in_tenure(&consensus_hash_1)
1972+
.unwrap(),
1973+
0
1974+
);
1975+
1976+
block_info.signed_over = true;
1977+
block_info.block.header.chain_length = 1;
1978+
db.insert_block(&block_info).unwrap();
1979+
1980+
assert_eq!(
1981+
db.get_signed_block_count_in_tenure(&consensus_hash_1)
1982+
.unwrap(),
1983+
1
1984+
);
1985+
1986+
block_info.signed_over = true;
1987+
block_info.block.header.chain_length = 2;
1988+
db.insert_block(&block_info).unwrap();
1989+
1990+
block_info.signed_over = true;
1991+
block_info.block.header.chain_length = 3;
1992+
db.insert_block(&block_info).unwrap();
1993+
1994+
assert_eq!(
1995+
db.get_signed_block_count_in_tenure(&consensus_hash_1)
1996+
.unwrap(),
1997+
3
1998+
);
1999+
2000+
// add an unsigned block
2001+
block_info.signed_over = false;
2002+
block_info.block.header.chain_length = 4;
2003+
db.insert_block(&block_info).unwrap();
2004+
2005+
assert_eq!(
2006+
db.get_signed_block_count_in_tenure(&consensus_hash_1)
2007+
.unwrap(),
2008+
3
2009+
);
2010+
}
2011+
19612012
#[test]
19622013
fn has_signed_block() {
19632014
let db_path = tmp_db_path();

0 commit comments

Comments
 (0)