def test_isValidBlockJumpDifficulty(lastBlock, block): jump_difficulty = 10 block.difficulty = jump_difficulty block.__hash__ = f'{"0" * jump_difficulty}111abbc' with pytest.raises(Exception,match='difficulty change is more than 1'): Block.isValidBlock(lastBlock, block)
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 test_isValidBlockBadHash(lastBlock, block): block.hash = '0000000000000000000000000bbabc' with pytest.raises(Exception,match='Hash does not match'): Block.isValidBlock(lastBlock, block)
def test_isValidBlockBadProofOfWork(lastBlock, block): block.hash = 'bad_hash' with pytest.raises(Exception,match='Proof of work mismatch'): Block.isValidBlock(lastBlock, block)
def test_isValidBlockBadLastHash(lastBlock, block): block.previousHash = 'bad_hash' with pytest.raises(Exception,match='previous hash of this block\ does not match with hash of previous block'): Block.isValidBlock(lastBlock, block)
def test_isValidBlock(lastBlock, block): Block.isValidBlock(lastBlock, block)