示例#1
0
    def blockchain_validity(chain):
        """
        Tests the validity of the blockchain using the following rules
            - The blockchain must begin with the genesis block
            - The blockchain must be formatted correctly
        """
        if chain[0] != Block.genesis():
            raise Exception(
                "The chain does not begin with the genesis block !!!")

        for i in range(1, len(chain)):
            block = chain[i]
            last_block = chain[i - 1]
            Block.block_validity(last_block, block)
示例#2
0
def test_hash_validity(last_block, block):
    block.hash = '0000000000000000000000000aabbccdd'

    with pytest.raises(Exception, match="The block hash is invalid !!!"):
        Block.block_validity(last_block, block)
示例#3
0
def test_difficulty_interval(last_block, block):
    block.difficulty = 10
    block.hash = "0000000000000000000000000aabbccdd"

    with pytest.raises(Exception, match="The block difficulty adjustment is not 1 !!!"):
        Block.block_validity(last_block, block)
示例#4
0
def test_proof_of_work(last_block, block):
    block.hash = 'aabbccdd'

    with pytest.raises(Exception, match="The proof of work requirement was not met !!!"):
        Block.block_validity(last_block, block)
示例#5
0
def test_valid_last_hash(last_block, block):
    block.last_hash = "foo bar"

    with pytest.raises(Exception, match="The last hash is invalid !!!"):
        Block.block_validity(last_block, block)
示例#6
0
def test_valid_block(last_block, block):
    Block.block_validity(last_block, block)