예제 #1
0
 def test_block_proof_of_work(self, mock_adjust_difficulty, mock_is_valid_schema):
     mock_is_valid_schema.return_value = True
     mock_adjust_difficulty.return_value = self.first_block.difficulty + 1
     block = Block.mine_block(self.first_block, self.second_block.data)
     self.assertTrue(mock_is_valid_schema.called)
     self.assertTrue(mock_adjust_difficulty.called)
     self.assertIsInstance(block, Block)
예제 #2
0
 def test_block_mine_block(self, mock_proof_of_work, mock_is_valid_schema):
     mock_is_valid_schema.return_value = True
     mock_proof_of_work.return_value = self.block_info
     block = Block.mine_block(self.first_block, self.second_block.data)
     self.assertTrue(mock_is_valid_schema.called)
     self.assertTrue(mock_proof_of_work.called)
     self.assertIsInstance(block, Block)
예제 #3
0
    def add_block(self, data: list):
        """
        Mine new block and add it to the local blockchain. If new block
        is mined the candidate blockchain will be send over the network
        to be validated for the rest of the nodes.

        :param data list: transactions data to be added to the next block.
        :return Block: new mined block.
        """
        block = Block.mine_block(self.last_block, data)
        self.chain.append(block)
        return block
예제 #4
0
 def _generate_block(self, block: Block, mock_is_valid_schema):
     mock_is_valid_schema.return_value = True
     transaction = self._generate_transaction()
     data = [transaction.info]
     return Block.mine_block(block, data)