Example #1
0
def test_is_valid_chain():
    blockchain = Blockchain()

    for i in range(3):
        blockchain.add_block(i)

    Blockchain.is_valid_chain(blockchain.chain)
Example #2
0
def test_is_valid_chain(blockchain_three_blocks):
    # blockchain = Blockchain()

    # for i in range(3):
    #     blockchain.add_block(i)

    Blockchain.is_valid_chain(blockchain_three_blocks.chain)
def test_is_valid_chain(blockchain_three_blocks):

    with pytest.raises(Exception, match='chain must have block'):
        Blockchain.is_valid_chain([])

    blockchain_three_blocks.chain[1].hash = 'evil_hash'

    with pytest.raises(Exception, match='must be formatted correctly'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
Example #4
0
def test_is_valid_chain_bad_genesis():
    blockchain = Blockchain()

    for i in range(3):
        blockchain.add_block(i)

    blockchain.chain[0].hash = 'bad-hash'
    
    with pytest.raises(Exception, match='The genesis block must be valid'):
        Blockchain.is_valid_chain(blockchain.chain)
Example #5
0
def test_is_valid_chain_invalid_genesis(blockchain_with_blocks):
    blockchain_with_blocks.chain[0].hash = 3000
    with pytest.raises(Exception, match="genesis block is invalid"):
        Blockchain.is_valid_chain(blockchain_with_blocks.chain)
Example #6
0
def test_is_valid_chain(blockchain_with_blocks):
    Blockchain.is_valid_chain(blockchain_with_blocks.chain)
Example #7
0
def test_is_valid_chain_bad_genesis(blockchain_four_blocks):
    blockchain_four_blocks.chain[0].hash = "bad_hash"

    with pytest.raises(Exception, match = "Invalid genesis block"):
        Blockchain.is_valid_chain(blockchain_four_blocks.chain)
Example #8
0
def test_is_valid_chain(blockchain_three_blocks):
    Blockchain.is_valid_chain(blockchain_three_blocks.chain)
Example #9
0
def test_is_valid_chain(populated_blockchain):
    Blockchain.is_valid_chain(populated_blockchain.chain)
Example #10
0
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].hash = 'evil_hash'
    with pytest.raises(Exception, match='The genesis block is not valid'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].data = 'evil'

    with pytest.raises(Exception,
                       match='chain must start with the genesis block'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
def test_is_valid_chain_bad_gensis(blockchain_five_blocks):
    blockchain_five_blocks.chain[0].hash = 'evil hash haha'

    # Because we expect an exception
    with pytest.raises(Exception, match="genesis block must be valid"):
        Blockchain.is_valid_chain(blockchain_five_blocks.chain)
def test_is_valid_chain(blockchain_five_blocks):

    # Tests code implicitly by virtue of no exception
    Blockchain.is_valid_chain(blockchain_five_blocks.chain)
Example #14
0
def test_is_valid_chain_bad_genesis(blockchain_init):
    blockchain_init.chain[0].hash = "evil_hash"

    with pytest.raises(Exception, match="The genesis block must be valid."):
        Blockchain.is_valid_chain(blockchain_init.chain)
Example #15
0
def test_is_valid_chain(blockchain_init):
    Blockchain.is_valid_chain(blockchain_init.chain)
def test_is_valid_chain(blockchain):
    Blockchain.is_valid_chain(blockchain.chain)
def test_is_valid_chain_bad_genesis(blockchain):
    blockchain.chain[0].hash = 'evil_hash'

    with raises(Exception, match='Invalid genesis block'):
        Blockchain.is_valid_chain(blockchain.chain)
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].data = 'evil_data'

    with pytest.raises(Exception, match='The genesis block must be valid'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
def test_replace_chain_bad_chain(blockchain_three_blocks):
    Blockchain.is_valid_chain(blockchain_three_blocks.chain)
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].hash = 'evil_hash'
    
    with pytest.raises(Exception, match='The chain must start with genesis'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
def test_valid_transaction_chain(blockchain_three_blocks):
    Blockchain.is_valid_chain(blockchain_three_blocks.chain)
Example #22
0
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].hash = 'evil_hash'
    #Below code allows to catch exceptions
    with pytest.raises(Exception, match='The Genesis block must be valid'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
Example #23
0
def test_is_valid_chain_bad_genesis(populated_blockchain):
    populated_blockchain.chain[0].hash = 'bad_hash'

    with pytest.raises(Exception, match="The Genesis block is not valid!"):
        Blockchain.is_valid_chain(populated_blockchain.chain)
Example #24
0
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].hash = 'bas_hash'
    with pytest.raises(Exception, match='The genesis block must be valid.'):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
Example #25
0
def test_is_valid_chain_bad_genesis(blockchain_three_blocks):
    blockchain_three_blocks.chain[0].block_hash = 'evil_hash'

    with pytest.raises(Exception, match="genesis block must be valid"):
        Blockchain.is_valid_chain(blockchain_three_blocks.chain)
Example #26
0
def test_is_valid_chain(blockchain_four_blocks):
    Blockchain.is_valid_chain(blockchain_four_blocks.chain)