def test_compute_cycle_transitions(genesis_crystallized_state, genesis_active_state, genesis_block, config): parent_crystallized_state = genesis_crystallized_state parent_active_state = genesis_active_state parent_block = genesis_block block = copy.deepcopy(genesis_block) block.slot_number = 258 active_state = fill_recent_block_hashes(parent_active_state, parent_block, block) crystallized_state, active_state = compute_cycle_transitions( parent_crystallized_state, active_state, block, config=config, ) assert crystallized_state.last_state_recalc == (block.slot_number // config['cycle_length'] * config['cycle_length'])
def test_initialize_new_cycle( genesis_crystallized_state, genesis_active_state, genesis_block, last_state_recalc, last_justified_slot, justified_streak, last_finalized_slot, fraction_voted, result_last_state_recalc, result_justified_streak, result_last_finalized_slot, config): # Fill the parent_crystallized_state with parematers parent_crystallized_state = genesis_crystallized_state parent_crystallized_state.last_state_recalc = last_state_recalc parent_crystallized_state.last_justified_slot = last_justified_slot parent_crystallized_state.justified_streak = justified_streak parent_crystallized_state.last_finalized_slot = last_finalized_slot parent_active_state = genesis_active_state parent_block = genesis_block block = copy.deepcopy(genesis_block) block.slot_number = 258 block.parent_hash = blake(serialize(parent_block)) active_state = fill_recent_block_hashes(parent_active_state, parent_block, block) fraction_voted *= 1.01 # add margin for rounding error # Fill the total_voter_deposits to simulate the different committee results active_state.block_vote_cache[block.parent_hash] = { 'voter_indices': set(), 'total_voter_deposits': int(parent_crystallized_state.total_deposits * fraction_voted) } crystallized_state, active_state = initialize_new_cycle( parent_crystallized_state, active_state, block, config=config, ) assert crystallized_state.last_state_recalc == result_last_state_recalc assert crystallized_state.justified_streak == result_justified_streak assert crystallized_state.last_finalized_slot == result_last_finalized_slot