Ejemplo n.º 1
0
 def test_sendrawtransaction(self):
     num_outputs = 5
     given_transaction = CMutableTransaction(
         [], [make_txout() for x in range(0, num_outputs)])
     expected_txid = b2lx(given_transaction.GetHash())
     given_transaction_hex = b2x(given_transaction.serialize())
     proxy = FakeRavencoinProxy()
     resulting_txid = proxy.sendrawtransaction(given_transaction_hex)
     self.assertEqual(resulting_txid, expected_txid)
Ejemplo n.º 2
0
    def test_fundrawtransaction_adds_output(self):
        num_outputs = 5
        unfunded_transaction = CMutableTransaction(
            [], [make_txout() for x in range(0, num_outputs)])
        proxy = FakeRavencoinProxy()

        funded_transaction_hex = proxy.fundrawtransaction(
            b2x(unfunded_transaction.serialize()))["hex"]
        funded_transaction = CMutableTransaction.deserialize(
            x(funded_transaction_hex))

        self.assertTrue(len(funded_transaction.vout) > num_outputs)
        self.assertEqual(len(funded_transaction.vout), num_outputs + 1)
    def fundrawtransaction(self, given_transaction, *args, **kwargs):
        """
        Make up some inputs for the given transaction.
        """
        # just use any txid here
        vintxid = lx("99264749804159db1e342a0c8aa3279f6ef4031872051a1e52fb302e51061bef")

        if isinstance(given_transaction, str):
            given_bytes = x(given_transaction)
        elif isinstance(given_transaction, CMutableTransaction):
            given_bytes = given_transaction.serialize()
        else:
            raise FakeRavencoinProxyException("Wrong type passed to fundrawtransaction.")

        # this is also a clever way to not cause a side-effect in this function
        transaction = CMutableTransaction.deserialize(given_bytes)

        for vout_counter in range(0, self._num_fundrawtransaction_inputs):
            txin = CMutableTxIn(COutPoint(vintxid, vout_counter))
            transaction.vin.append(txin)

        # also allocate a single output (for change)
        txout = make_txout()
        transaction.vout.append(txout)

        transaction_hex = b2x(transaction.serialize())

        return {"hex": transaction_hex, "fee": 5000000}
Ejemplo n.º 4
0
    def test_fundrawtransaction_hex_hash(self):
        unfunded_transaction = CMutableTransaction(
            [], [make_txout() for x in range(0, 5)])
        proxy = FakeRavencoinProxy()

        funded_transaction_hex = proxy.fundrawtransaction(
            b2x(unfunded_transaction.serialize()))["hex"]
        funded_transaction = CMutableTransaction.deserialize(
            x(funded_transaction_hex))

        self.assertTrue(unfunded_transaction is not funded_transaction)
        self.assertEqual(type(funded_transaction), type(unfunded_transaction))
        self.assertNotEqual(len(funded_transaction.vin), 0)
        self.assertTrue(
            len(funded_transaction.vin) > len(unfunded_transaction.vin))
        self.assertEqual(type(funded_transaction.vin[0]), CTxIn)
 def sendrawtransaction(self, given_transaction):
     """
     Pretend to broadcast and relay the transaction. Return the txid of the
     given transaction.
     """
     if isinstance(given_transaction, str):
         given_bytes = x(given_transaction)
     elif isinstance(given_transaction, CMutableTransaction):
         given_bytes = given_transaction.serialize()
     else:
         raise FakeRavencoinProxyException("Wrong type passed to sendrawtransaction.")
     transaction = CMutableTransaction.deserialize(given_bytes)
     return b2lx(transaction.GetHash())
Ejemplo n.º 6
0
    def test_signrawtransaction(self):
        num_outputs = 5
        given_transaction = CMutableTransaction(
            [], [make_txout() for x in range(0, num_outputs)])
        proxy = FakeRavencoinProxy()

        result = proxy.signrawtransaction(given_transaction)

        self.assertEqual(type(result), dict)
        self.assertTrue("hex" in result.keys())

        result_transaction_hex = result["hex"]
        result_transaction = CMutableTransaction.deserialize(
            x(result_transaction_hex))

        self.assertTrue(result_transaction is not given_transaction)
        self.assertTrue(result_transaction.vin is not given_transaction.vin)
        self.assertTrue(result_transaction.vout is not given_transaction.vout)
        self.assertEqual(len(result_transaction.vout),
                         len(given_transaction.vout))
        self.assertEqual(result_transaction.vout[0].scriptPubKey,
                         given_transaction.vout[0].scriptPubKey)
    def signrawtransaction(self, given_transaction):
        """
        This method does not actually sign the transaction, but it does return
        a transaction based on the given transaction.
        """
        if isinstance(given_transaction, str):
            given_bytes = x(given_transaction)
        elif isinstance(given_transaction, CMutableTransaction):
            given_bytes = given_transaction.serialize()
        else:
            raise FakeRavencoinProxyException("Wrong type passed to signrawtransaction.")

        transaction = CMutableTransaction.deserialize(given_bytes)
        transaction_hex = b2x(transaction.serialize())
        return {"hex": transaction_hex}