def setUp(self):
        self.tx1 = Transaction(
            timestamp=datetime(2018, 1, 29, 15, 0, 25),
            height=1087606,
            hash='a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14',
            fee=Decimal('0.00352891'))
        self.pm1 = IncomingPayment(
            amount=Decimal('1'),
            local_address=address('Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV'),
            payment_id=PaymentID('0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d'),
            transaction=self.tx1)

        # setup for one-time output tests
        self.json1 = { # Actual as_json response from TX ee5bcb6430c39757ff27f8d607287572f3956a0ee16bb1d2378891f93746c8f9
            'version': 2, 'unlock_time': 0, 'vin': [{'key': {'amount': 0, 'key_offsets': 
            [25471133, 261981, 36602, 18967, 13096, 16260, 54279, 3105, 5403, 786, 555],
            'k_image': '4b48346e954a74be9a334b03cadf8aa020542d201fb6ae7416246d19fd04fdb7'}}],
            'vout': [{'amount': 0, 'target': {'key': 'c55e793b4d673dcf73587e5141b777ef24e255d48826c75ce110ffc23ff762b9'}},
            {'amount': 0, 'target': {'key': '93b263454cd3cc349245ad60c9c248332b885a1f2d7b5792cfc24fd87434d62a'}}],
            'extra': [1, 209, 170, 43, 245, 190, 68, 82, 131, 116, 79, 134, 175, 104, 216, 127, 99, 49, 127, 141, 255, 65, 204, 101,
            81, 244, 111, 253, 155, 75, 111, 14, 159, 2, 9, 1, 24, 56, 108, 94, 20, 88, 150, 94], 'rct_signatures': {'type': 5,
            'txnFee': 58560000, 'ecdhInfo': [{'amount': '6c13cf459cb9ed96'}, {'amount': '373bc40c7f600bf4'}], 'outPk':
            ['80521a77ebe954a5daa6f14b13cc74337f999bc68177a58e76f768c18f2fa421',
            '5997e64b90d59f7f810ddbc801f747c4fa43e2de593e4ea48531e16d776c00fd']}}
        self.outind1 = [25884175, 25884176]
        self.tx2 = Transaction(json=self.json1, output_indices=self.outind1)
        self.oto1 = Output(index=25973289, amount=Decimal('0.000000000000'))
        self.oto2 = Output(pubkey='0faff18f7149a0db5aa0dc3c9116887740ccbb5dc4d1eeff87895288e55e5052')
 def test_coinbase_own_output(self):
     txdata = self._read("test_coinbase_own_output-dc0861.json")
     tx = Transaction(
         hash=
         "dc08610685b8a55dc7d64454ecbe12868e4e73c766e2d19ee092885a06fc092d",
         height=518147,
         json=txdata,
     )
     self.assertTrue(tx.is_coinbase)
     wallet = Wallet(
         OfflineWallet(
             address=
             "56eDKfprZtQGfB4y6gVLZx5naKVHw6KEKLDoq2WWtLng9ANuBvsw67wfqyhQECoLmjQN4cKAdvMp2WsC5fnw9seKLcCSfjj",
             view_key=
             "e507923516f52389eae889b6edc182ada82bb9354fb405abedbe0772a15aea0a",
         ))
     outs = tx.outputs(wallet=wallet)
     self.assertEqual(len(outs), 1)
     self.assertIsNotNone(outs[0].payment)
     self.assertEqual(
         outs[0].payment.local_address,
         "56eDKfprZtQGfB4y6gVLZx5naKVHw6KEKLDoq2WWtLng9ANuBvsw67wfqyhQECoLmjQN4cKAdvMp2WsC5fnw9seKLcCSfjj",
     )
     self.assertEqual(outs[0].amount, outs[0].payment.amount)
     self.assertEqual(outs[0].payment.amount, Decimal("13.515927959357"))
Example #3
0
    async def test_get_payments(self):
        """
        Get all payments (incoming and outgoing) corresponding to the wallet.
        """
        w = self.new_wallet()
        succeed_backend()
        await w.create_wallet()

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda *_: None

        p1 = Payment(amount=30.3, payment_id=TEST_PID)
        p1.transaction = Transaction(hash=TEST_HASH, height=120909)

        p2 = Payment(amount=12.7, payment_id=TEST_PID)
        p2.transaction = Transaction(has=TEST_HASH, height=118909)

        mock_wallet.incoming = lambda **_: [p1]
        mock_wallet.outgoing = lambda **_: [p2]

        w.wallet = mock_wallet

        payments = await w._get_payments()
        self.assertEqual(2, len(payments))
        w.cancel_all_pending_tasks()
Example #4
0
    async def test_get_transactions_wallet(self):
        """
        Test retrieval of transactions from Monero wallet in case wallet does exist.
        """
        w = self.new_wallet()

        timestamp = datetime.now()

        p1 = IncomingPayment(amount=30.3, payment_id=TEST_PID, local_address=TEST_ADDRESS)
        p1.transaction = Transaction(hash=TEST_HASH, height=120909, fee=1, timestamp=timestamp,
                                     confirmations=21)

        p2 = IncomingPayment(amount=12.7, payment_id=TEST_PID, local_address=TEST_ADDRESS)
        p2.transaction = Transaction(hash=TEST_HASH, height=118909, fee=1, timestamp=timestamp,
                                     confirmations=17)

        ts = mktime(timestamp.timetuple())

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda: None
        mock_wallet.incoming = lambda **_: [p1]
        mock_wallet.outgoing = lambda **_: [p2]
        w.wallet = mock_wallet

        transactions = await w.get_transactions()

        self.assertDictEqual({
            'id': TEST_HASH,
            'outgoing': False,
            'from': '',
            'to': TEST_ADDRESS,
            'amount': 30.3,
            'fee_amount': 1,
            'currency': self.identifier,
            'timestamp': ts,
            'description': 'Confirmations: 21'
        }, transactions.result()[0])

        self.assertDictEqual({
            'id': TEST_HASH,
            'outgoing': False,
            'from': '',
            'to': TEST_ADDRESS,
            'amount': 12.7,
            'fee_amount': 1,
            'currency': self.identifier,
            'timestamp': ts,
            'description': 'Confirmations: 17'
        }, transactions.result()[1])
        w.cancel_all_pending_tasks()
Example #5
0
 def setUp(self):
     self.tx1 = Transaction(
         timestamp=datetime(2018, 1, 29, 15, 0, 25),
         height=1087606,
         hash='a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14',
         fee=Decimal('0.00352891'))
     self.pm1 = IncomingPayment(
         amount=Decimal('1'),
         local_address=address('Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV'),
         payment_id=PaymentID('0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d'),
         transaction=self.tx1)
 def setUp(self):
     self.tx1 = Transaction(
         hash=
         "7e5fea8470c5771315bab4b3c77493d2ff534f5201c7c6b2bab069cb7d21ce7b")
     self.tx2 = Transaction(
         hash=
         "3a2f859dea9d2ad5ecec167719302d4e14e21beef9b74f9583183d8e965d9106")
     self.tx3 = Transaction(
         hash=
         "bde2b5344b63cbe58ce1a724d0a2276aaa4266be5235d5e5fde969446c3e8de1")
     self.tx4 = Transaction(
         hash=
         "24fb42f9f324082658524b29b4cf946a9f5fcfa82194070e2f17c1875e15d5d0")
     self.block1 = Block(
         hash=
         "423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89",
         height=451992,
         difficulty=3590,
         version=(11, 12),
         nonce=140046906,
         orphan=False,
         prev_hash=
         "51f6816891b6a7adedd0f1ad57a846eada1baac476421aa9d32d0630ce3dce41",
         reward=from_atomic(15331952645334),
         timestamp=datetime.fromtimestamp(1573646422),
         transactions=[self.tx1, self.tx2, self.tx3, self.tx4],
     )
     self.block1_duplicate = Block(
         hash=
         "423cd4d170c53729cf25b4243ea576d1e901d86e26c06d6a7f79815f3fcb9a89",
         height=451992,
         difficulty=3590,
         version=(11, 12),
         nonce=140046906,
         orphan=False,
         prev_hash=
         "51f6816891b6a7adedd0f1ad57a846eada1baac476421aa9d32d0630ce3dce41",
         reward=from_atomic(15331952645334),
         timestamp=datetime.fromtimestamp(1573646422),
         transactions=[self.tx1, self.tx2, self.tx3, self.tx4],
     )
Example #7
0
 def test_send_transaction(self):
     path = os.path.join(
         os.path.dirname(__file__), "data", self.data_subdir,
         "0e8fa9202e0773333360e5b9e8fb8e94272c16a8a58b6fe7cf3b4327158e3a44.tx"
     )
     responses.add(responses.POST,
                   self.sendrawtransaction_url,
                   json=self._read('test_send_transaction.json'),
                   status=200)
     tx = Transaction(blob=open(path, "rb").read())
     rsp = self.daemon.send_transaction(tx)
     self.assertEqual(rsp["status"], "OK")
Example #8
0
 def test_coinbase_no_own_output(self):
     txdata = self._read("test_coinbase_no_own_output-26dcb5.json")
     tx = Transaction(
         hash=
         "26dcb55c3c93a2176949fd9ec4e20a9d97ece7c420408d9353c390a909e9a7c1",
         height=766459,
         output_indices=txdata["output_indices"],
         json=json.loads(txdata["as_json"]))
     self.assertTrue(tx.is_coinbase)
     wallet = Wallet(
         OfflineWallet(
             address=
             "56eDKfprZtQGfB4y6gVLZx5naKVHw6KEKLDoq2WWtLng9ANuBvsw67wfqyhQECoLmjQN4cKAdvMp2WsC5fnw9seKLcCSfjj",
             view_key=
             "e507923516f52389eae889b6edc182ada82bb9354fb405abedbe0772a15aea0a"
         ))
     outs = tx.outputs(wallet=wallet)
     self.assertEqual(len(outs), 1)
     self.assertIsNone(outs[0].payment)
     self.assertEqual(outs[0].amount, Decimal("8.415513145431"))
     self.assertEqual(outs[0].index, 3129279)
Example #9
0
    async def test_transfer_multiple_wallet(self):
        """
        Make multiple transfers at once, enough balance.
        """
        w = self.new_wallet()

        transfers = [
            (TEST_ADDRESS, Decimal('20.2')),
            (TEST_ADDRESS, Decimal('7.8'))
        ]

        mock_wallet = MockObject()
        mock_wallet.refresh = lambda: None
        mock_wallet.balance = lambda **_: 57.3
        mock_wallet.transfer_multiple = \
            lambda *_, **__: succeed([(Transaction(hash=TEST_HASH), Decimal('20.2')),
                                      (Transaction(hash=TEST_HASH), Decimal('7.8'))])

        w.wallet = mock_wallet

        hashes = await w.transfer_multiple(transfers, priority=3)
        self.assertEqual(2, len(hashes.result()))
        w.cancel_all_pending_tasks()
 def test_sorting(self):
     pmts = [
         IncomingPayment(transaction=Transaction(height=10)),
         IncomingPayment(transaction=Transaction(height=12)),
         IncomingPayment(transaction=Transaction(height=13)),
         IncomingPayment(transaction=Transaction(height=None)),
         IncomingPayment(transaction=Transaction(height=100)),
         IncomingPayment(transaction=Transaction(height=None)),
         IncomingPayment(transaction=Transaction(height=1))
     ]
     for i in range(1680):    # 1/3 of possible permutations
         sorted_pmts = sorted(pmts, key=_ByHeight)
         self.assertEqual(
             list(map(attrgetter('height'), map(attrgetter('transaction'), sorted_pmts))),
             [None, None, 100, 13, 12, 10, 1])
         random.shuffle(pmts)
Example #11
0
 def __init__(self, **kwargs):
     self.transfers = []
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 15, 0, 25),
         height=1087606,
         hash=
         "a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14",
         fee=Decimal("0.00352891"),
         confirmations=3,
     )
     pm = IncomingPayment(
         amount=Decimal("1"),
         local_address=address(
             "Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK"
             "7P6L32RELNzCR6QzNFkmogDjvypyV"),
         payment_id=PaymentID(
             "0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d"
         ),
         transaction=tx,
     )
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087530,
         hash=
         "5c3ab739346e9d98d38dc7b8d36a4b7b1e4b6a16276946485a69797dbf887cd8",
         fee=Decimal("0.000962550000"),
     )
     pm = IncomingPayment(
         amount=Decimal("10.000000000000"),
         local_address=address(
             "9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6"
             "K3fhq3scsyY88tdB1MqucULcKzWZC"),
         payment_id=PaymentID("f75ad90e25d71a12"),
         transaction=tx,
     )
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087608,
         hash=
         "4ea70add5d0c7db33557551b15cd174972fcfc73bf0f6a6b47b7837564b708d3",
         fee=Decimal("0.000962550000"),
         confirmations=1,
     )
     pm = IncomingPayment(
         amount=Decimal("4.000000000000"),
         local_address=address(
             "9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6"
             "K3fhq3scsyY88tdB1MqucULcKzWZC"),
         payment_id=PaymentID("f75ad90e25d71a12"),
         transaction=tx,
     )
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087530,
         hash=
         "e9a71c01875bec20812f71d155bfabf42024fde3ec82475562b817dcc8cbf8dc",
         fee=Decimal("0.000962550000"),
     )
     pm = IncomingPayment(
         amount=Decimal("2.120000000000"),
         local_address=address(
             "9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6"
             "K3fhq3scsyY88tdB1MqucULcKzWZC"),
         payment_id=PaymentID("cb248105ea6a9189"),
         transaction=tx,
     )
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 14, 57, 47),
         height=1087601,
         hash=
         "5ef7ead6a041101ed326568fbb59c128403cba46076c3f353cd110d969dac808",
         fee=Decimal("0.000962430000"),
     )
     pm = IncomingPayment(
         amount=Decimal("1240.0000000"),
         local_address=address(
             "BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejr"
             "MfpHeNXoX8MjY8q8prW1PEALgr1En"),
         payment_id=PaymentID("0000000000000000"),
         transaction=tx,
     )
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087606,
         hash=
         "cc44568337a186c2e1ccc080b43b4ae9db26a07b7afd7edeed60ce2fc4a6477f",
         fee=Decimal("0.000962550000"),
     )
     pm = IncomingPayment(
         amount=Decimal("10.000000000000"),
         local_address=address(
             "9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6"
             "K3fhq3scsyY88tdB1MqucULcKzWZC"),
         payment_id=PaymentID("0000000000000000"),
         transaction=tx,
     )
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 21, 13, 28),
         height=None,
         hash=
         "d29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c",
         fee=Decimal("0.000961950000"),
     )
     pm = IncomingPayment(
         amount=Decimal("3.140000000000"),
         local_address=address(
             "9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6"
             "K3fhq3scsyY88tdB1MqucULcKzWZC"),
         payment_id=PaymentID("03f6649304ea4cb2"),
         transaction=tx,
     )
     self.transfers.append(pm)
 def __init__(self):
     self.transfers = []
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 15, 0, 25),
         height=1087606,
         hash=
         'a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14',
         fee=Decimal('0.00352891'))
     pm = IncomingPayment(
         amount=Decimal('1'),
         local_address=address(
             'Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV'
         ),
         payment_id=PaymentID(
             '0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d'
         ),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 14, 57, 47),
         height=1087601,
         hash=
         'f34b495cec77822a70f829ec8a5a7f1e727128d62e6b1438e9cb7799654d610e',
         fee=Decimal('0.008661870000'))
     pm = IncomingPayment(
         amount=Decimal('3.000000000000'),
         local_address=address(
             'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En'
         ),
         payment_id=PaymentID('f75ad90e25d71a12'),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087530,
         hash=
         '5c3ab739346e9d98d38dc7b8d36a4b7b1e4b6a16276946485a69797dbf887cd8',
         fee=Decimal('0.000962550000'))
     pm = IncomingPayment(
         amount=Decimal('10.000000000000'),
         local_address=address(
             '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC'
         ),
         payment_id=PaymentID('f75ad90e25d71a12'),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087530,
         hash=
         '4ea70add5d0c7db33557551b15cd174972fcfc73bf0f6a6b47b7837564b708d3',
         fee=Decimal('0.000962550000'))
     pm = IncomingPayment(
         amount=Decimal('4.000000000000'),
         local_address=address(
             '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC'
         ),
         payment_id=PaymentID('f75ad90e25d71a12'),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087530,
         hash=
         'e9a71c01875bec20812f71d155bfabf42024fde3ec82475562b817dcc8cbf8dc',
         fee=Decimal('0.000962550000'))
     pm = IncomingPayment(
         amount=Decimal('2.120000000000'),
         local_address=address(
             '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC'
         ),
         payment_id=PaymentID('cb248105ea6a9189'),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 14, 57, 47),
         height=1087601,
         hash=
         '5ef7ead6a041101ed326568fbb59c128403cba46076c3f353cd110d969dac808',
         fee=Decimal('0.000962430000'))
     pm = IncomingPayment(
         amount=Decimal('7.000000000000'),
         local_address=address(
             'BhE3cQvB7VF2uuXcpXp28Wbadez6GgjypdRS1F1Mzqn8Advd6q8VfaX8ZoEDobjejrMfpHeNXoX8MjY8q8prW1PEALgr1En'
         ),
         payment_id=PaymentID('0000000000000000'),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 13, 17, 18),
         height=1087530,
         hash=
         'cc44568337a186c2e1ccc080b43b4ae9db26a07b7afd7edeed60ce2fc4a6477f',
         fee=Decimal('0.000962550000'))
     pm = IncomingPayment(
         amount=Decimal('10.000000000000'),
         local_address=address(
             '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC'
         ),
         payment_id=PaymentID('0000000000000000'),
         transaction=tx)
     self.transfers.append(pm)
     tx = Transaction(
         timestamp=datetime(2018, 1, 29, 21, 13, 28),
         height=None,
         hash=
         'd29264ad317e8fdb55ea04484c00420430c35be7b3fe6dd663f99aebf41a786c',
         fee=Decimal('0.000961950000'))
     pm = IncomingPayment(
         amount=Decimal('3.140000000000'),
         local_address=address(
             '9tQoHWyZ4yXUgbz9nvMcFZUfDy5hxcdZabQCxmNCUukKYicXegsDL7nQpcUa3A1pF6K3fhq3scsyY88tdB1MqucULcKzWZC'
         ),
         payment_id=PaymentID('03f6649304ea4cb2'),
         transaction=tx)
     self.transfers.append(pm)
Example #13
0
    dest='relay',
    action='store_false',
    help=
    "Do not relay the transaction (it will stay at the node unless mined or expired)"
)
args = argsparser.parse_args()
level = logging.WARNING
if args.verbosity == 1:
    level = logging.INFO
elif args.verbosity > 1:
    level = logging.DEBUG
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
if args.tx_filenames:
    blobs = [(f, open(f, 'r').read()) for f in args.tx_filenames]
else:
    blobs = [('transaction', sys.stdin.read())]
d = Daemon(JSONRPCDaemon(**args.daemon_rpc_url))
for name, blob in blobs:
    logging.debug("Sending {}".format(name))
    tx = Transaction(blob=blob)
    try:
        res = d.send_transaction(tx, relay=args.relay)
    except exceptions.TransactionBroadcastError as e:
        print("{} not sent, reason: {}".format(name, e.details['reason']))
        logging.debug(e.details)
        continue
    if res['not_relayed']:
        print("{} not relayed".format(name))
    else:
        print("{} successfully sent".format(name))
Example #14
0
 def test_v1_tx(self):
     tx1 = Transaction(
         hash=
         "2634445086cc48b89f1cd241e89e6f37195008807264684d8fad4a16f479c45a",
         height=2022660,
         json=self._read("test_v1_tx-263444.json"))
     tx2 = Transaction(
         hash=
         "3586a81f051bcb265a45c99f11b19fc4b55bb2abb3332c515a8b88a559cd9f7b",
         height=2022660,
         json=self._read("test_v1_tx-3586a8.json"))
     outs1 = tx1.outputs()
     self.assertEqual(len(outs1), 14)
     self.assertEqual(
         outs1[0].stealth_address,
         "b1ef76960fe245f73131be22e9b548e861f93b727ab8a2a3ff64d86521512382")
     self.assertEqual(outs1[0].amount, Decimal("0.000000000300"))
     self.assertEqual(
         outs1[1].stealth_address,
         "dcd66bbcb6e72602dd876e1dad65a3464a2bd831f09ec7c8131147315152e29b")
     self.assertEqual(outs1[1].amount, Decimal("0.000008000000"))
     self.assertEqual(
         outs1[2].stealth_address,
         "71efdb68dfd33f5c89a5fa8312ec6e346681f6f60fb406e9426231a5f230351a")
     self.assertEqual(outs1[2].amount, Decimal("0.007000000000"))
     self.assertEqual(
         outs1[3].stealth_address,
         "499fb727f61f2ce0fbc3419b309601f2cbf672eeef2cc827aef423b0b70e2529")
     self.assertEqual(outs1[3].amount, Decimal("0.000000010000"))
     self.assertEqual(
         outs1[4].stealth_address,
         "297ef9bb654dd6e26472a4f07f037eddb3f8b458cf4315e2cc40d9fd725e28b9")
     self.assertEqual(outs1[4].amount, Decimal("0.000000500000"))
     self.assertEqual(
         outs1[5].stealth_address,
         "b2bf18a500afe1775305b19d16d0d5afec0f72096b9f15cca6604d7f5ad6e5f8")
     self.assertEqual(outs1[5].amount, Decimal("0.300000000000"))
     self.assertEqual(
         outs1[6].stealth_address,
         "f7a95b33912077e3aca425270f76be13af503919b6230368a591e1053b3c7436")
     self.assertEqual(outs1[6].amount, Decimal("5.000000000000"))
     self.assertEqual(
         outs1[7].stealth_address,
         "1e93e243a865b71e14fe4df6de0902ca634749b48002c52adc7f046053c2b921")
     self.assertEqual(outs1[7].amount, Decimal("0.000200000000"))
     self.assertEqual(
         outs1[8].stealth_address,
         "513822bad9697e8494ff82cb4b58a5a693aa433c16f0aafdaaf4a27b026a32e4")
     self.assertEqual(outs1[8].amount, Decimal("0.000000000009"))
     self.assertEqual(
         outs1[9].stealth_address,
         "6e1ace4cfdf3f5363d72c241382e3b9927af1093b549a62f2902f56137d153bc")
     self.assertEqual(outs1[9].amount, Decimal("0.000000000070"))
     self.assertEqual(
         outs1[10].stealth_address,
         "1df18bd04f42c9da8f6b49afe418aabc8ab973448a941d365534b5d0862a3d46")
     self.assertEqual(outs1[10].amount, Decimal("0.000000002000"))
     self.assertEqual(
         outs1[11].stealth_address,
         "caf3e6c07f8172fc31a56ba7f541ba8d6cc601f2c7da1a135126f8f3455e3ffc")
     self.assertEqual(outs1[11].amount, Decimal("20.000000000000"))
     self.assertEqual(
         outs1[12].stealth_address,
         "1ce506bc1ee041dfe36df3e085156023be26e133fb14f5e529b60a2d769a7c7c")
     self.assertEqual(outs1[12].amount, Decimal("0.000030000000"))
     self.assertEqual(
         outs1[13].stealth_address,
         "ee1a22b1f49db4df0df56161801974326cda4ceacbbf2a17c795ebe945790281")
     self.assertEqual(outs1[13].amount, Decimal("0.030000000000"))
     outs2 = tx2.outputs()
     self.assertEqual(len(outs2), 10)
     self.assertEqual(
         outs2[0].stealth_address,
         "ddd1d47e5d419cf5e2298e4d9e828364b929976912dfc1bbed25fb20cc681f9f")
     self.assertEqual(outs2[0].amount, Decimal("3.000000000000"))
     self.assertEqual(
         outs2[1].stealth_address,
         "a0c0edc478a3448a0d371755bd614854505d2f158499d9881bfffa8b05c5b3e8")
     self.assertEqual(outs2[1].amount, Decimal("0.600000000000"))
     self.assertEqual(
         outs2[2].stealth_address,
         "f9aeb5f16117f363adcd22f6b73d6e35eda64c25fee2f59208bd68d411b6d0c6")
     self.assertEqual(outs2[2].amount, Decimal("0.000000000700"))
     self.assertEqual(
         outs2[3].stealth_address,
         "17e36384cf11a4d85be1320c0e221505818edbb2d6634dd54db24e25570d0f75")
     self.assertEqual(outs2[3].amount, Decimal("0.000000500000"))
     self.assertEqual(
         outs2[4].stealth_address,
         "8b7e5dac3e0e45f9e7213ec3d4a465c5301b20f8ef30a5b2b5baba80867952b3")
     self.assertEqual(outs2[4].amount, Decimal("0.000000000070"))
     self.assertEqual(
         outs2[5].stealth_address,
         "d1e24eeaa62232cb0e4be536fc785e03075416457dd2b704437bced16da52500")
     self.assertEqual(outs2[5].amount, Decimal("0.000000001000"))
     self.assertEqual(
         outs2[6].stealth_address,
         "52c26fcce9d0a41f91ec57074e2cbfe301ca96b556e861deba51cd54e3e5b3e3")
     self.assertEqual(outs2[6].amount, Decimal("0.000010000000"))
     self.assertEqual(
         outs2[7].stealth_address,
         "c5859574278889dede61d5aa341e14d2fb2acf45941486276f61dd286e7f8895")
     self.assertEqual(outs2[7].amount, Decimal("0.000000010000"))
     self.assertEqual(
         outs2[8].stealth_address,
         "a3556072b7c8f77abdd16fe762fe1099c10c5ab071e16075ce0c667a3eacf1cc")
     self.assertEqual(outs2[8].amount, Decimal("0.090000000000"))
     self.assertEqual(
         outs2[9].stealth_address,
         "d72affedd142c6a459c42318169447f22042dba0d93c0f7ade42ddb222de8914")
     self.assertEqual(outs2[9].amount, Decimal("0.009000000000"))
class FiltersTestCase(unittest.TestCase):
    def setUp(self):
        self.tx1 = Transaction(
            timestamp=datetime(2018, 1, 29, 15, 0, 25),
            height=1087606,
            hash=
            "a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14",
            fee=Decimal("0.00352891"),
        )
        self.pm1 = IncomingPayment(
            amount=Decimal("1"),
            local_address=address(
                "Bf6ngv7q2TBWup13nEm9AjZ36gLE6i4QCaZ7XScZUKDUeGbYEHmPRdegKGwLT8tBBK7P6L32RELNzCR6QzNFkmogDjvypyV"
            ),
            payment_id=PaymentID(
                "0166d8da6c0045c51273dd65d6f63734beb8a84e0545a185b2cfd053fced9f5d"
            ),
            transaction=self.tx1,
        )

        # setup for one-time output tests
        self.json1 = {  # Actual as_json response from TX ee5bcb6430c39757ff27f8d607287572f3956a0ee16bb1d2378891f93746c8f9
            "version": 2,
            "unlock_time": 0,
            "vin": [
                {
                    "key": {
                        "amount": 0,
                        "key_offsets": [
                            25471133,
                            261981,
                            36602,
                            18967,
                            13096,
                            16260,
                            54279,
                            3105,
                            5403,
                            786,
                            555,
                        ],
                        "k_image": "4b48346e954a74be9a334b03cadf8aa020542d201fb6ae7416246d19fd04fdb7",
                    }
                }
            ],
            "vout": [
                {
                    "amount": 0,
                    "target": {
                        "key": "c55e793b4d673dcf73587e5141b777ef24e255d48826c75ce110ffc23ff762b9"
                    },
                },
                {
                    "amount": 0,
                    "target": {
                        "key": "93b263454cd3cc349245ad60c9c248332b885a1f2d7b5792cfc24fd87434d62a"
                    },
                },
            ],
            "extra": [
                1,
                209,
                170,
                43,
                245,
                190,
                68,
                82,
                131,
                116,
                79,
                134,
                175,
                104,
                216,
                127,
                99,
                49,
                127,
                141,
                255,
                65,
                204,
                101,
                81,
                244,
                111,
                253,
                155,
                75,
                111,
                14,
                159,
                2,
                9,
                1,
                24,
                56,
                108,
                94,
                20,
                88,
                150,
                94,
            ],
            "rct_signatures": {
                "type": 5,
                "txnFee": 58560000,
                "ecdhInfo": [
                    {"amount": "6c13cf459cb9ed96"},
                    {"amount": "373bc40c7f600bf4"},
                ],
                "outPk": [
                    "80521a77ebe954a5daa6f14b13cc74337f999bc68177a58e76f768c18f2fa421",
                    "5997e64b90d59f7f810ddbc801f747c4fa43e2de593e4ea48531e16d776c00fd",
                ],
            },
        }
        self.outind1 = [25884175, 25884176]
        self.tx2 = Transaction(json=self.json1, output_indices=self.outind1)
        self.oto1 = Output(index=25973289, amount=Decimal("0.000000000000"))
        self.oto2 = Output(
            pubkey=
            "0faff18f7149a0db5aa0dc3c9116887740ccbb5dc4d1eeff87895288e55e5052")

    def test_hash(self):
        self.assertIn(
            "a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14",
            repr(self.tx1),
        )
        self.assertIn(
            "a0b876ebcf7c1d499712d84cedec836f9d50b608bb22d6cb49fd2feae3ffed14",
            repr(self.pm1),
        )

    def test_outputs(self):
        out1, out2 = self.tx2.outputs()
        self.assertEqual(out1.transaction, self.tx2)
        self.assertEqual(out2.transaction, self.tx2)
        self.assertIn(self.json1["vout"][0]["target"]["key"], repr(out1))
        self.assertFalse(out2 != Output(
            stealth_address=self.json1["vout"][1]["target"]["key"]))
        self.assertIn("(index=25973289,amount=0E-12)", repr(self.oto1))
        self.assertEqual(
            self.oto1, Output(index=25973289,
                              amount=Decimal("0.000000000000")))

        with self.assertRaises(exceptions.TransactionWithoutJSON):
            self.tx1.outputs()

        with self.assertRaises(TypeError):
            self.oto1 == self.oto2