BlockProcessing testing (#559)

* Add valid_deposit test and build_with_deposit method

* Insert_deposit takes a num_deposit param

* Deposit with spec.max_effective_balance

* Copy int_to_bytes32 implem from beacon_chain_builder

* Add debug information to insert_deposit

* Remove length-proof assertion

* Insert_deposit displays error

* Batch deposits now pass tests

* Optimize insert_deposit

* Rename insert_deposits and set num_deposits to 2 in valid_deposit test

* update test_utils to pass tests

* fix typo in test_utils

* update cast in test_utils

* Add DepositCountInvalid tests

* Add tests for bad deposit signature

* Add tests and test utils in test_builder

* Return error instead of ok on bad signature

* Update DepositTestTask enum

* Add comment about manually setting deposit_count and deposit_index

* add badblsbytes test

* add bad_index var for clarity ; remove underflow test

* cargo fmt

* Add insert 3 exits tests

* Add validator_unknwon test

* Add far_future_epoch test and already exited

* Add MaxVoluntaryExits + 1 test

* Add exit_already_initiated test

* Add exit_not_active test

* Add too_young_to_leave test

* Cargo fmt

* Confirm already_anitiated test

* Fix typo in enum variant

* Adjust some tests to return ok(()) and revert changes for early return in per_block_processing.rs

* cargo fmt

* Adjust AlreadyIniated test to expect Ok(()) and revert changes in per_block_processing.rs

* Remove extraneous newline

* Add insert_valid_attester_slashing

* Initial cargo fmt

* Add NotSlashable test

* Cargo fmt

* Remove AttestationDataIdentical

* Make test_task pass through reference ; fix max_attester_slashing_plus_one test

* Initial cargo fmt

* Add InvalidIndexedAttestation1 and 2

* Add comments

* Add ProposalsIdenticalTest

* Add ProposalsIdentical test

* Cargo fmt

* Add ProposerUnknown test

* Add ProposalEpochMismatch test

* Add BadProposal1Signature and Badproposal2Signature tests

* Add ProposerNotSlashable test

* Derive PartialEq and use if instead of match

* Merge attestation tests

* Remove useless AlreadyInitiated variant in beacon_state

* Remove MaxOperations plus one tests for each operation

* Clean comments

* add IncludedTooLate and BadTargetEpoch tests

* Update AttestationDataBuilder call in operation_pool testing

* Cargo fmt

* Remove BadIndex enum variant, unused in the code

* Cargo fmt

* Cargo fmt updated

* simply increment deposit_count instead of hardsetting deposit_index in insert_deposits

* Fix bad_merkle_proof when calling insert_deposits
This commit is contained in:
pscott
2019-11-12 06:09:33 +01:00
committed by Paul Hauner
parent 613fdbeda6
commit c7b3a7abd8
16 changed files with 1936 additions and 118 deletions

View File

@@ -1,5 +1,8 @@
use log::info;
use types::test_utils::{TestingBeaconBlockBuilder, TestingBeaconStateBuilder};
use types::test_utils::{
AttestationTestTask, AttesterSlashingTestTask, DepositTestTask, ExitTestTask,
ProposerSlashingTestTask, TestingBeaconBlockBuilder, TestingBeaconStateBuilder,
};
use types::{EthSpec, *};
pub struct BlockBuilder<T: EthSpec> {
@@ -77,6 +80,7 @@ impl<T: EthSpec> BlockBuilder<T> {
let validator_index = validators_iter.next().expect("Insufficient validators.");
builder.insert_proposer_slashing(
&ProposerSlashingTestTask::Valid,
validator_index,
&keypairs[validator_index as usize].sk,
&state.fork,
@@ -102,7 +106,13 @@ impl<T: EthSpec> BlockBuilder<T> {
secret_keys.push(&keypairs[validator_index as usize].sk);
}
builder.insert_attester_slashing(&attesters, &secret_keys, &state.fork, spec);
builder.insert_attester_slashing(
&AttesterSlashingTestTask::Valid,
&attesters,
&secret_keys,
&state.fork,
spec,
);
}
info!(
"Inserted {} attester slashings.",
@@ -113,6 +123,7 @@ impl<T: EthSpec> BlockBuilder<T> {
let all_secret_keys: Vec<&SecretKey> = keypairs.iter().map(|keypair| &keypair.sk).collect();
builder
.insert_attestations(
&AttestationTestTask::Valid,
&state,
&all_secret_keys,
self.num_attestations as usize,
@@ -125,15 +136,14 @@ impl<T: EthSpec> BlockBuilder<T> {
);
// Insert `Deposit` objects.
for i in 0..self.num_deposits {
builder.insert_deposit(
32_000_000_000,
state.eth1_data.deposit_count + (i as u64),
&state,
spec,
);
}
state.eth1_data.deposit_count += self.num_deposits as u64;
builder.insert_deposits(
32_000_000_000,
DepositTestTask::NoReset,
state.eth1_data.deposit_count,
self.num_deposits as u64,
&mut state,
spec,
);
info!("Inserted {} deposits.", builder.block.body.deposits.len());
// Insert the maximum possible number of `Exit` objects.
@@ -141,7 +151,8 @@ impl<T: EthSpec> BlockBuilder<T> {
let validator_index = validators_iter.next().expect("Insufficient validators.");
builder.insert_exit(
&state,
&ExitTestTask::Valid,
&mut state,
validator_index,
&keypairs[validator_index as usize].sk,
spec,