def test_mineBlock(): # testing mine block data ='test' block = Block.mineBlock(Block.genesisBlock(),data) assert isinstance(block, Block) assert block.previousHash==GENESIS_DATA['hash'] assert block.data==data assert block.hash[0:block.difficulty]=='0'*block.difficulty
def isValidLedger(ledger): ''' validate the ledger ''' if ledger[0] != Block.genesisBlock(): raise Exception('genesis block must be valid') for i in range(1, len(ledger)): block = ledger[i] lastBlock = ledger[i - 1] Block.isValidBlock(lastBlock, block)
def lastBlock(): return Block.genesisBlock()
def __init__(self): self.ledger = [Block.genesisBlock()]