Exemplo n.º 1
0
def test_state_machine(initial_chaindb,
                       genesis_block,
                       genesis_crystallized_state):
    chaindb = initial_chaindb

    block_1 = genesis_block.copy(
        parent_hash=genesis_block.hash,
        slot_number=1,
        active_state_root=b'\x11' * 32,
    )
    chaindb.persist_block(block_1)

    block_2 = block_1.copy(
        parent_hash=block_1.hash,
        slot_number=2,
        active_state_root=b'\x22' * 32,
    )
    # canonical head is block_2
    chaindb.persist_block(block_2)

    # building block_3
    block_3 = block_2.copy(
        parent_hash=block_2.hash,
        slot_number=3,
        active_state_root=b'\x33' * 32,
    )

    sm = SerenityStateMachine(chaindb, block_3)

    assert sm.crystallized_state == genesis_crystallized_state
    expect = tuple(
        [ZERO_HASH32] * (sm.config.CYCLE_LENGTH * 2 - 2) +
        [genesis_block.hash] + [block_1.hash]
    )
    assert sm.active_state.recent_block_hashes == expect
Exemplo n.º 2
0
def test_state_machine_canonical(initial_chaindb, genesis_block,
                                 genesis_crystallized_state,
                                 genesis_active_state):
    chaindb = initial_chaindb
    sm = SerenityStateMachine(chaindb)
    assert sm.block == genesis_block.copy(
        slot_number=genesis_block.slot_number + 1,
        parent_hash=genesis_block.hash)
    assert sm.crystallized_state == genesis_crystallized_state
    assert sm.active_state == genesis_active_state
Exemplo n.º 3
0
def fixture_sm_class(config):
    return SerenityStateMachine.configure(
        __name__='SerenityStateMachineForTesting',
        config=config,
    )