Ejemplo n.º 1
0
def test_slowly_mined_block():
    last_block = Block.mine_block(Block.genesis(), 'bar')

    time.sleep(MINE_RATE / SECONDS)

    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == last_block.difficulty - 1
Ejemplo n.º 2
0
def test_mine_block():
    last_block = Block.genesis()
    data = 'test-data'
    block = Block.mine_block(last_block, data)

    assert isinstance(block, Block)
    assert block.data == data
    assert block.last_hash == last_block.hash
    assert hex_to_binary(
        block.hash)[0:block.difficulty] == '0' * block.difficulty
Ejemplo n.º 3
0
 def last_block():
     return Block.genesis()
Ejemplo n.º 4
0
def test_quickly_mined_block():
    last_block = Block.mine_block(Block.genesis(), 'foo')
    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == last_block.difficulty + 1
Ejemplo n.º 5
0
def test_genesis():
    genesis = Block.genesis()

    assert isinstance(genesis, Block)
    for key, value in GENESIS_DATA.items():
        assert getattr(genesis, key) == value