Exemple #1
0
 def test_block_create_invalid_schema(self, mock_is_valid_schema):
     err_message = 'Validation error'
     mock_is_valid_schema.side_effect = Mock(side_effect=BlockError(err_message))
     with self.assertRaises(BlockError) as err:
         Block.create(**self.block_info)
         self.assertTrue(mock_is_valid_schema.called)
         self.assertIsInstance(err, BlockError)
         self.assertIn(err_message, err.message)
Exemple #2
0
 def test_block_create_valid_schema(self, mock_is_valid_schema):
     mock_is_valid_schema.return_value = True
     block = Block.create(**self.block_info)
     self.assertTrue(mock_is_valid_schema.called)
     self.assertIsInstance(block, Block)
     self.assertTrue(all([attr in block.info.keys() for attr in self.block_info.keys()]))
     self.assertTrue(all([value in block.info.values() for value in self.block_info.values()]))
Exemple #3
0
 def test_api_get_mine_block_route(self, mock_clear_pool,
                                   mock_broadcast_chain):
     mock_broadcast_chain.return_value = asyncio.Future()
     mock_broadcast_chain.return_value.set_result(None)
     mock_clear_pool.return_value = True
     response = self.client.get("/mine")
     self.assertTrue(mock_broadcast_chain.called)
     self.assertTrue(mock_clear_pool.called)
     self.assertEqual(response.status_code, 200)
     self.assertIn('block', response.json())
     block_info = response.json().get('block')
     self.assertEqual(Block.create(**block_info), app.blockchain.last_block)