Exemple #1
0
    def test_difficulty_when_block_mined_too_quickly(self):
        previous_block = Block.mine(self.previous_block, "Ethereum")

        # New block mined immediately, quicker than the MINE_RATE.
        mined_block = Block.mine(previous_block, "Verge")

        # Assert that difficulty has increased by increment of one
        self.assertEqual(mined_block.difficulty, previous_block.difficulty + 1)
Exemple #2
0
    def test_difficulty_when_block_mined_too_slowly(self):
        previous_block = Block.mine(self.previous_block, "TRX")

        time.sleep(MINE_RATE / SECOND)

        # New block mined too slowly, slower that the MINE_RATE.
        mined_block = Block.mine(previous_block, "Stellar")

        # Assert that difficulty has decreased by increment of one
        self.assertEqual(mined_block.difficulty, previous_block.difficulty - 1)
Exemple #3
0
    def test_mine_block_difficulty_not_less_than_1(self):
        previous_block = Block.mine(self.previous_block, "Dragonchain")
        # Ensure previous block difficulty is 1
        previous_block.difficulty = 1

        time.sleep(MINE_RATE / SECOND)

        # New block mined too slowly, slower that the MINE_RATE.
        mined_block = Block.mine(previous_block, "Some more data")

        # Assert than even though the block mined slowly,
        # the difficulty is not decreased as it cannot be less than 1
        self.assertEqual(mined_block.difficulty, 1)
Exemple #4
0
    def test_mine(self):
        result = Block.mine(self.previous_block, "Bitcoin")

        self.assertIsInstance(result, Block)
        self.assertEqual(result.data, "Bitcoin")
        self.assertEqual(result.previous_hash, self.previous_block.hash)
        self.assertEqual(result.hash[0:result.difficulty],
                         "0" * result.difficulty)
Exemple #5
0
 def setUp(self):
     self.previous_block = Block.genesis()
     self.block = Block.mine(self.previous_block, "SHUcoin")