コード例 #1
0
 def test_blockchain_is_valid_transaction_data_multiple_rewards(self):
     reward_transaction_1 = Transaction.reward_mining(Wallet())
     reward_transaction_2 = Transaction.reward_mining(Wallet())
     self.blockchain.add_block(
         [reward_transaction_1.info, reward_transaction_2.info])
     err_message = 'Multiple mining rewards in the same block'
     with self.assertRaises(BlockchainError) as err:
         Blockchain.is_valid_transaction_data(self.blockchain.chain)
         self.assertIsInstance(err, BlockchainError)
         self.assertIn(err_message, err.message)
コード例 #2
0
async def mine_block():
    logger.info('[API] GET mine. Mining block.')
    transaction_reward = Transaction.reward_mining(router.wallet)
    data = router.transactions_pool.data
    data.append(transaction_reward.info)
    block = router.blockchain.add_block(data)
    logger.info(f'[API] GET mine. Block mined: {block}.')
    await router.p2p_server.broadcast_chain()
    router.transactions_pool.clear_pool(router.blockchain)
    return {'block': block}
コード例 #3
0
 def test_transaction_reward_mining(self):
     transaction = Transaction.reward_mining(self.wallet)
     self.assertEqual(transaction.input, MINING_REWARD_INPUT)
     self.assertEqual(transaction.output[self.wallet.address],
                      MINING_REWARD)
コード例 #4
0
 def test_transaction_is_valid_mining_reward(self, mock_is_valid_schema):
     mock_is_valid_schema.return_value = True
     wallet = Wallet()
     transaction = Transaction.reward_mining(wallet)
     Transaction.is_valid(transaction)
     self.assertTrue(mock_is_valid_schema.called)