Created
March 25, 2019 17:44
-
-
Save djrtwo/7eac134bcedc570c637ca202085466be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import build.phase0.spec as spec | |
from tests.phase0.helpers import ( | |
create_genesis_state, | |
) | |
from tests.phase0.conftest import ( | |
overwrite_spec_config, | |
) | |
from state_test_gen import ( | |
generate_from_test, | |
dump_json, | |
dump_yaml, | |
) | |
from tests.phase0.test_sanity import ( | |
test_empty_block_transition, | |
test_skipped_slots, | |
test_empty_epoch_transition, | |
test_empty_epoch_transition_not_finalizing, | |
test_proposer_slashing, | |
test_deposit_in_block, | |
test_deposit_top_up, | |
test_attestation, | |
test_voluntary_exit, | |
test_transfer, | |
test_ejection, | |
test_historical_batch, | |
) | |
def sanity_tests(num_validators=100, config=None): | |
print() | |
if config: | |
overwrite_spec_config(config) | |
genesis_state = create_genesis_state(num_validators=num_validators) | |
print("done!") | |
print() | |
test_cases = [] | |
print("Running some sanity check tests...\n") | |
test_cases.append( | |
generate_from_test(test_empty_block_transition, genesis_state, config=config, fields=['slot']) | |
) | |
print("Passed empty block transition test\n") | |
test_cases.append( | |
generate_from_test(test_skipped_slots, genesis_state, config=config, fields=['slot', 'latest_block_roots']) | |
) | |
print("Passed skipped slot test\n") | |
test_cases.append( | |
generate_from_test(test_empty_epoch_transition, genesis_state, config=config, fields=['slot', 'latest_block_roots']) | |
) | |
print("Passed empty epoch transition test\n") | |
test_cases.append( | |
generate_from_test(test_empty_epoch_transition_not_finalizing, genesis_state, config=config, fields=['slot', 'finalized_epoch']) | |
) | |
print("Passed non-finalizing epoch test\n") | |
test_cases.append( | |
generate_from_test(test_proposer_slashing, genesis_state, config=config, fields=['validator_registry', 'validator_balances']) | |
) | |
print("Passed proposer slashing test\n") | |
test_cases.append( | |
generate_from_test(test_attestation, genesis_state, config=config, fields=['previous_epoch_attestations', 'current_epoch_attestations']) | |
) | |
print("Passed attestation test\n") | |
test_cases.append( | |
generate_from_test(test_deposit_in_block, genesis_state, config=config, fields=['validator_registry', 'validator_balances']) | |
) | |
print("Passed deposit test\n") | |
test_cases.append( | |
generate_from_test(test_deposit_top_up, genesis_state, config=config, fields=['validator_registry', 'validator_balances']) | |
) | |
print("Passed deposit top up test\n") | |
test_cases.append( | |
generate_from_test(test_voluntary_exit, genesis_state, config=config, fields=['validator_registry']) | |
) | |
print("Passed voluntary exit test\n") | |
test_cases.append( | |
generate_from_test(test_transfer, genesis_state, config=config, fields=['validator_balances']) | |
) | |
print("Passed transfer test\n") | |
test_cases.append( | |
generate_from_test(test_ejection, genesis_state, config=config, fields=['validator_registry']) | |
) | |
print("Passed ejection test\n") | |
test_cases.append( | |
generate_from_test(test_historical_batch, genesis_state, config=config, fields=['historical_roots']) | |
) | |
print("Passed historical batch test\n") | |
print("done!") | |
return test_cases | |
if __name__ == "__main__": | |
config = { | |
"SHARD_COUNT": 8, | |
"MIN_ATTESTATION_INCLUSION_DELAY": 2, | |
"TARGET_COMMITTEE_SIZE": 4, | |
"SLOTS_PER_EPOCH": 8, | |
"GENESIS_EPOCH": spec.GENESIS_SLOT // 8, | |
"SLOTS_PER_HISTORICAL_ROOT": 64, | |
"LATEST_RANDAO_MIXES_LENGTH": 64, | |
"LATEST_ACTIVE_INDEX_ROOTS_LENGTH": 64, | |
"LATEST_SLASHED_EXIT_LENGTH": 64, | |
} | |
# test_cases = sanity_tests(32, config) | |
# uncomment below to run/generate against the default config | |
test_cases = sanity_tests(100) | |
test = {} | |
metadata = {} | |
metadata['title'] = "Sanity tests" | |
metadata['summary'] = "Basic sanity checks from phase 0 spec pythonization. All tests are run with `verify_signatures` as set to False." | |
metadata['test_suite'] = "beacon_state" | |
metadata['fork'] = "tchaikovsky" | |
metadata['version'] = "v0.5.1" | |
test['metadata'] = metadata | |
test['test_cases'] = test_cases | |
if '--output-json' in sys.argv: | |
os.makedirs('output', exist_ok=True) | |
with open("output/sanity_check_tests.json", "w+") as outfile: | |
dump_json(test, outfile) | |
if '--output-yaml' in sys.argv: | |
os.makedirs('output', exist_ok=True) | |
with open("output/sanity_check_tests.yaml", "w+") as outfile: | |
dump_yaml(test, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment