Esempio n. 1
0
    def test_contains_valid_transactions_duplicate_transaction(self):
        transaction = Transaction(Wallet(), "recipient", 1).serialize()

        self.blockchain.add_block([transaction, transaction])

        with self.assertRaises(ContainsInvalidTransactionError):
            Blockchain.contains_valid_transactions(self.blockchain.chain)
Esempio n. 2
0
 def test_contains_valid_transactions_duplicate_rewards(self):
     self.blockchain.add_block([
         Transaction.reward(Wallet()).serialize(),
         Transaction.reward(Wallet()).serialize(),
     ])
     # Block contains multiple reward transactions so we expect an exception
     with self.assertRaises(ContainsInvalidTransactionError):
         Blockchain.contains_valid_transactions(self.blockchain.chain)
Esempio n. 3
0
    def test_contains_valid_transactions_bad_transaction(self):
        bad_transaction = Transaction(Wallet(), "recipient", 1)
        # Use same transaction output but signed by wrong wallet
        bad_transaction.input["signature"] = Wallet().sign(
            bad_transaction.output)

        self.blockchain.add_block([bad_transaction.serialize()])

        with self.assertRaises(TransactionSignatureError):
            Blockchain.contains_valid_transactions(self.blockchain.chain)
Esempio n. 4
0
    def test_contains_valid_transactions_bad_historic_balance(self):
        wallet = Wallet()
        bad_transaction = Transaction(wallet, "recipient", 1)

        # Tamper with transaction, giving wallet a high amount
        bad_transaction.output[wallet.address] = 1000

        # Ensure input amount and transaction amount are still correct so validation doesn't fail at that point
        bad_transaction.input["amount"] = 1001

        # Re-sign
        wallet.sign(bad_transaction.output)

        self.blockchain.add_block([bad_transaction.serialize()])

        with self.assertRaises(ContainsInvalidTransactionError):
            Blockchain.contains_valid_transactions(self.blockchain.chain)
Esempio n. 5
0
 def test_contains_valid_transactions(self):
     Blockchain.contains_valid_transactions(self.blockchain.chain)