Esempio n. 1
0
def test_block_hash_should_be_created_by_id_prvhash_and_nonce():
    block = Block()
    block.id = 100
    block.previous_hash = 100
    block.data = {'name': 'Onur', 'surname': 'Aykaç'}
    block.nonce = 100
    block.calculate_hash()
    assert block.hash == "1477b8d1c6b66c77015684ecaae6b23d6373bcab23d067f3926cf8cdd6761b07"
Esempio n. 2
0
def test_if_a_block_is_changed_then_chain_should_not_be_a_valid_chain():
    chain = Blockchain()
    block_id_zero = Block()
    block_id_one = Block()
    block_id_two = Block()

    chain.add_block(block_id_zero)
    chain.add_block(block_id_one)
    chain.add_block(block_id_two)

    block_id_one.data = {'hacked'}
    block_id_one.calculate_hash()

    validation = chain.validate()
    assert validation == False