def test_is_valid_transaction_chain_multiple_rewards(blockchain_three_blocks): reward_1 = Transaction.reward_transaction(Wallet()).to_json() reward_2 = Transaction.reward_transaction(Wallet()).to_json() blockchain_three_blocks.add_block([reward_1, reward_2]) with pytest.raises(Exception, match='one mining reward per block'): Blockchain.is_valid_transaction_chain(blockchain_three_blocks.chain)
def route_blockchain_mine(): transaction_data = transaction_pool.transaction_data() transaction_data.append(Transaction.reward_transaction(wallet).to_json()) blockchain.add_block(transaction_data) block = blockchain.chain[-1] pubsub.broadcast_block(block) transaction_pool.clear_blockchain_transactions(blockchain) return jsonify(block.to_json())
def test_valid_reward_transaction(): reward_transaction = Transaction.reward_transaction(Wallet()) Transaction.transaction_is_valid(reward_transaction)
def test_reward_transaction(): miner_wallet = Wallet() transaction = Transaction.reward_transaction(miner_wallet) assert transaction.input == MINING_REWARD_INPUT assert transaction.output[miner_wallet.address] == MINING_REWARD
def test_invalid_reward_transaction_invalid_amount(): miner_wallet = Wallet() reward_transaction = Transaction.reward_transaction(miner_wallet) reward_transaction.output[miner_wallet.address] = 1998 with pytest.raises(Exception, match='Invalid Mining Reward'): Transaction.transaction_is_valid(reward_transaction)
def test_invalid_reward_transaction_extra_reciepient(): reward_transaction = Transaction.reward_transaction(Wallet()) reward_transaction.output['extra_reciepient'] = 60 with pytest.raises(Exception, match='Invalid Mining Reward'): Transaction.transaction_is_valid(reward_transaction)