Exemple #1
0
def test_adjust_difficulty_limits_at_1():
    last_block = Block(time.time_ns(), "test_previous_hash", "test_hash",
                       "test_data", 1, 0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine(last_block, "bar")

    assert mined_block.difficulty == 1
Exemple #2
0
def test_mine():
    previous_block = Block.genesis()
    data = "test data"
    block = Block.mine(previous_block, data)

    assert isinstance(block, Block)
    assert block.data == data
    assert hex_to_binary(
        block.hash)[0:block.difficulty] == "0" * block.difficulty
Exemple #3
0
 def add_block(self, data):
     self.chain.append(Block.mine(self.chain[-1], data))
Exemple #4
0
def block(prev_block):
    return Block.mine(prev_block, "foo")
Exemple #5
0
def test_adjust_difficulty_fast_mining():
    last_block = Block.mine(Block.genesis(), "foo")
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine(last_block, "bar")

    assert mined_block.difficulty == last_block.difficulty - 1
Exemple #6
0
def test_adjust_difficulty_slow_mining():
    last_block = Block.mine(Block.genesis(), "foo")
    mined_block = Block.mine(last_block, "bar")

    assert mined_block.difficulty == last_block.difficulty + 1