mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-01-31 02:52:14 +00:00
Invalid blocks test
This commit is contained in:
parent
123485c1a3
commit
e08dbb45a0
@ -825,7 +825,7 @@ impl LightWallet {
|
||||
let block: CompactBlock = match parse_from_bytes(block) {
|
||||
Ok(block) => block,
|
||||
Err(e) => {
|
||||
eprintln!("Could not parse CompactBlock from bytes: {}", e);
|
||||
error!("Could not parse CompactBlock from bytes: {}", e);
|
||||
return Err(-1);
|
||||
}
|
||||
};
|
||||
@ -2349,4 +2349,32 @@ pub mod tests {
|
||||
|
||||
assert_eq!(seed_phrase, Some(wallet.get_seed_phrase()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_scan_blocks() {
|
||||
const AMOUNT: u64 = 500000;
|
||||
let (wallet, _txid1, block_hash) = get_test_wallet(AMOUNT);
|
||||
|
||||
let prev_hash = add_blocks(&wallet, 2, 1, block_hash).unwrap();
|
||||
assert_eq!(wallet.blocks.read().unwrap().len(), 3);
|
||||
|
||||
// Block fails to scan for bad encoding
|
||||
assert_eq!(wallet.scan_block(&[0; 32]), Err(-1));
|
||||
|
||||
// Block is invalid height
|
||||
let new_blk = FakeCompactBlock::new(4, prev_hash);
|
||||
assert_eq!(wallet.scan_block(&new_blk.as_bytes()), Err(2));
|
||||
|
||||
// Block is right height, but invalid prev height (for reorgs)
|
||||
let new_blk = FakeCompactBlock::new(2, BlockHash([0; 32]));
|
||||
assert_eq!(wallet.scan_block(&new_blk.as_bytes()), Err(2));
|
||||
|
||||
// Block is right height, but invalid prev height (for reorgs)
|
||||
let new_blk = FakeCompactBlock::new(3, BlockHash([0; 32]));
|
||||
assert_eq!(wallet.scan_block(&new_blk.as_bytes()), Err(2));
|
||||
|
||||
// Then the rest add properly
|
||||
let _ = add_blocks(&wallet, 3, 2, prev_hash).unwrap();
|
||||
assert_eq!(wallet.blocks.read().unwrap().len(), 5);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user