Esempio n. 1
0
def test_difficulty_not_less_one():
    last_block = Block(time.time_ns(), 'test_last_hash', 'test_hash',
                       'test_data', 1, 0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, 'new')

    assert mined_block.difficulty == 1
Esempio n. 2
0
def test_mined_difficulty_limits_at_1():
    last_block = Block(time(), 'test_last_hash', 'test_hash', 'test_data', 1,
                       0)
    sleep(MINE_RATE)
    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == 1
Esempio n. 3
0
def test_mined_block_difficulty_limits_at_1():
    last_block = Block(time.time_ns(), 'test_last_hash', 'test_hash',
                       'test_data', 1, 0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == 1
def test_limit_mined_block_difficulty_to_1():
    last_block = Block(time.time_ns(), "test_last_hash", "test_hash",
                       "test_data", 1, 0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, "bar")

    assert mined_block.difficulty == 1
Esempio n. 5
0
def test_quickly_mined_block_difficulty_limits_at_lower_difficulty():
    last_block = Block(time.time_ns(), 'test_last_hash', 'test_hash', 'foo',
                       LOWER_DIFFICULTY, 0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == LOWER_DIFFICULTY
Esempio n. 6
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
Esempio n. 7
0
def test_lowest_mining_difficulty():
    last_block = Block(time.time_ns(), 'test-last_hash', 'test-hash',
                       'test-data', 1, 0)

    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == 1  #ensure that it isnt lower than 1
Esempio n. 8
0
def test_mined_block_minimum_difficulty():
    last_block = Block(time_ns(), 'test_last_hash', 'test_hash', 'test_data',
                       1, 0)

    sleep(MINE_RATE / SECONDS)

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

    assert last_block.difficulty == mined_block.difficulty
Esempio n. 9
0
def test_mine_block_difficulty_limits_at_1():
    # Create a mined block with lowest possible difficulty (1)
    last_block = Block(time.time_ns(), "test_last_hash", "test_hash",
                       "test-data", 1, 0)

    time.sleep(DELAY)
    mined_block = Block.mine_block(last_block, "bar")

    assert mined_block.difficulty == 1
Esempio n. 10
0
def test_mined_block_difficulty_limits_at_1():
    last_block = Block(time.time_ns(),
                       last_hash='test_hash',
                       hash='test_last_hash',
                       data='test_nonce',
                       difficulty=1,
                       nonce=0)

    time.sleep(MINE_RATE / SECONDS)
    mine_block = Block.mine_block(last_block, 'test2')

    assert mine_block.difficulty == 1
Esempio n. 11
0
def test_mined_block_diffculty_lower_bound_limit():
    '''
        Purpose:
            Test that the difficulty to mine a block will never fall below its
            lower bound.
    '''
    last_block = Block(time.time_ns(), 'test_last_hash', 'test_hash',
                       'test_data', 0, 1)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, 'bar')
    # Assert that difficulty is lower-bounded at 1 when a block's difficulty
    # attempts to decrease below 1 after being mined too quickly.
    assert (mined_block.difficulty == 1)
def test_mined_block_difficulty_limits_at_1():
    """Queremos simular la situación donde tenemos un bloque minado lentamente, para
	   ello necesitamos un last_block en el que la dificultad ya este en su nivel
	   más bajo (1)
	"""
    last_block = Block(timestamp=time.time_ns(),
                       last_hash='test_last_hash',
                       hash='test_hash',
                       data='test_data',
                       difficulty=1,
                       nonce=0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(last_block, 'bar')

    assert mined_block.difficulty == 1
Esempio n. 13
0
def test_mining_rate_1():
    last_block = Block(time.time_ns(), "last_hash", "foo", "hash", 1, 0)
    time.sleep(MINE_RATE / TIME_S)
    mined_block = Block.mine_block(last_block, "bar")

    assert mined_block.difficulty == 1
def test_mined_block_difficulty_static():
    prev_block = Block(time.time_ns(), "test_prev_hash", "test_hash",
                       "test_data", 1, 0)
    time.sleep(MINE_RATE / SECONDS)
    mined_block = Block.mine_block(prev_block, "bar")
    assert mined_block.difficulty == 1