示例#1
0
def test_if_jumped_difficulty_in_block_is_valid(last_block, block):
    jumped_difficulty = 10
    block.difficulty = jumped_difficulty
    block.hash = f'{"0" * jumped_difficulty}111abc'

    with pytest.raises(Exception, match='Block Difficulty Can Only Be Adjusted by 1'):
        Block.block_is_valid(last_block, block)
示例#2
0
    def chain_is_valid(chain):
        """
        In this block, I validate the incoming chain.
        The whole point, it to ednforce the following rules of the blockchain:
          - the chain starts with the genesis block
          - blocks must be formatted correctly
        """
        if chain[0] != Block.genesis_block_generator():
            raise Exception('The Genesis Block Must Be Valid')

        for i in range(1, len(chain)):
            block = chain[i]
            last_block = chain[i-1]
            Block.block_is_valid(last_block, block)      

        Blockchain.transaction_chain_is_valid(chain)
示例#3
0
def test_if_bad_block_hash_in_block_is_valid(last_block, block):
	block.hash = '0000000000000000bacabc'

	with pytest.raises(Exception, match='Block Hash Must be Correct'):
		Block.block_is_valid(last_block, block)
示例#4
0
def test_if_bad_proof_of_work_in_block_is_valid(last_block, block):
    block.hash = 'fff'

    with pytest.raises(Exception, match='`Proof of Work` Requirement has not Been Met'):
        Block.block_is_valid(last_block, block)
示例#5
0
def test_if_bad_last_hash_in_block_is_valid(last_block, block):
    block.last_hash = 'bad_last_hash'

    with pytest.raises(Exception, match='`last_hash` Must be Correct'):
        Block.block_is_valid(last_block, block)
示例#6
0
def test_if_block_is_valid(last_block, block):
    Block.block_is_valid(last_block, block)