lighthouse/slasher/tests/proposer_slashings.rs
ethDreamer ba55e140ae Enable Compatibility with Windows (#2333)
## Issue Addressed

Windows incompatibility.

## Proposed Changes

On windows, lighthouse needs to default to STDIN as tty doesn't exist. Also Windows uses ACLs for file permissions. So to mirror chmod 600, we will remove every entry in a file's ACL and add only a single SID that is an alias for the file owner.

Beyond that, there were several changes made to different unit tests because windows has slightly different error messages as well as frustrating nuances around killing a process :/

## Additional Info

Tested on my Windows VM and it appears to work, also compiled & tested on Linux with these changes. Permissions look correct on both platforms now. Just waiting for my validator to activate on Prater so I can test running full validator client on windows.

Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>
Co-authored-by: Michael Sproul <micsproul@gmail.com>
2021-05-19 23:05:16 +00:00

62 lines
2.1 KiB
Rust

use slasher::{
test_utils::{block as test_block, logger, E},
Config, Slasher,
};
use tempfile::tempdir;
use types::{Epoch, EthSpec};
#[test]
fn empty_pruning() {
let tempdir = tempdir().unwrap();
let config = Config::new(tempdir.path().into()).for_testing();
let slasher = Slasher::<E>::open(config, logger()).unwrap();
slasher.prune_database(Epoch::new(0)).unwrap();
}
#[test]
fn block_pruning() {
let slots_per_epoch = E::slots_per_epoch();
let tempdir = tempdir().unwrap();
let mut config = Config::new(tempdir.path().into()).for_testing();
config.chunk_size = 2;
config.history_length = 2;
let slasher = Slasher::<E>::open(config.clone(), logger()).unwrap();
let current_epoch = Epoch::from(2 * config.history_length);
// Pruning the empty database should be safe.
slasher.prune_database(Epoch::new(0)).unwrap();
slasher.prune_database(current_epoch).unwrap();
// Add blocks in excess of the history length and prune them away.
let proposer_index = 100_000; // high to check sorting by slot
for slot in 1..=current_epoch.as_u64() * slots_per_epoch {
slasher.accept_block_header(test_block(slot, proposer_index, 0));
}
slasher.process_queued(current_epoch).unwrap();
slasher.prune_database(current_epoch).unwrap();
// Add more conflicting blocks, and check that only the ones within the non-pruned
// section are detected as slashable.
for slot in 1..=current_epoch.as_u64() * slots_per_epoch {
slasher.accept_block_header(test_block(slot, proposer_index, 1));
}
slasher.process_queued(current_epoch).unwrap();
let proposer_slashings = slasher.get_proposer_slashings();
// Check number of proposer slashings, accounting for single block in current epoch.
assert_eq!(
proposer_slashings.len(),
(config.history_length - 1) * slots_per_epoch as usize + 1
);
// Check epochs of all slashings are from within range.
assert!(proposer_slashings.iter().all(|slashing| slashing
.signed_header_1
.message
.slot
.epoch(slots_per_epoch)
> current_epoch - config.history_length as u64));
}