Exemple #1
0
class PaymentIdTestSuite(unittest.TestCase):
    """Payment Id test cases."""

    def setUp(self):
        self.payment_id1 = PaymentId("3")
        self.payment_id2 = PaymentId("4")

    def test_init(self):
        """
        Test the initialization of a quantity
        """
        with self.assertRaises(ValueError):
            PaymentId(1)

    def test_str(self):
        """
        Test the string representation of a payment id
        """
        self.assertEqual(str(self.payment_id1), "3")

    def test_equality(self):
        """
        Test equality between payment ids
        """
        self.assertEqual(self.payment_id1, PaymentId("3"))
        self.assertNotEqual(self.payment_id1, self.payment_id2)
        self.assertEqual(NotImplemented, self.payment_id1.__eq__("3"))

    def test_hash(self):
        """
        Test the hash creation of a payment id
        """
        self.assertEqual(self.payment_id1.__hash__(), "3".__hash__())
        self.assertNotEqual(self.payment_id1.__hash__(), self.payment_id2.__hash__())
Exemple #2
0
    def test_from_network(self):
        # Test for from network
        data = Payment.from_network(
            type(
                'Data', (object, ), {
                    "trader_id":
                    TraderId(b"0"),
                    "transaction_id":
                    TransactionId(TraderId(b'2'), TransactionNumber(2)),
                    "transferred_assets":
                    AssetAmount(3, 'BTC'),
                    "address_from":
                    WalletAddress('a'),
                    "address_to":
                    WalletAddress('b'),
                    "payment_id":
                    PaymentId('aaa'),
                    "timestamp":
                    Timestamp(4.0),
                    "success":
                    True
                }))

        self.assertEquals(TraderId(b"0"), data.trader_id)
        self.assertEquals(TransactionId(TraderId(b'2'), TransactionNumber(2)),
                          data.transaction_id)
        self.assertEquals(AssetAmount(3, 'BTC'), data.transferred_assets)
        self.assertEquals(Timestamp(4.0), data.timestamp)
        self.assertTrue(data.success)
    def setUp(self, annotate=True):
        yield super(TestDatabase, self).setUp(annotate=annotate)

        path = os.path.join(self.getStateDir(), 'sqlite')
        if not os.path.exists(path):
            os.makedirs(path)

        self.database = MarketDB(self.getStateDir())

        self.order_id1 = OrderId(TraderId('3'), OrderNumber(4))
        self.order_id2 = OrderId(TraderId('4'), OrderNumber(5))
        self.order1 = Order(self.order_id1, Price(5,
                                                  'EUR'), Quantity(6, 'BTC'),
                            Timeout(3600), Timestamp.now(), True)
        self.order2 = Order(self.order_id2, Price(5,
                                                  'EUR'), Quantity(6, 'BTC'),
                            Timeout(3600), Timestamp.now(), False)

        self.transaction_id1 = TransactionId(TraderId("0"),
                                             TransactionNumber(4))
        self.transaction1 = Transaction(self.transaction_id1,
                                        Price(100, 'BTC'), Quantity(30, 'MC'),
                                        OrderId(TraderId("0"), OrderNumber(1)),
                                        OrderId(TraderId("1"), OrderNumber(2)),
                                        Timestamp(20.0))

        self.payment1 = Payment(MessageId(TraderId("0"), MessageNumber("4")),
                                self.transaction_id1, Quantity(5, 'MC'),
                                Price(6, 'BTC'), WalletAddress('abc'),
                                WalletAddress('def'), PaymentId("abc"),
                                Timestamp(20.0), False)

        self.transaction1.add_payment(self.payment1)
Exemple #4
0
 def setUp(self):
     # Object creation
     self.payment = Payment(TraderId("0"),
                            TransactionId(TraderId('2'), TransactionNumber(2)),
                            AssetAmount(3, 'BTC'),
                            WalletAddress('a'), WalletAddress('b'),
                            PaymentId('aaa'), Timestamp(4.0), True)
Exemple #5
0
    def test_from_network(self):
        # Test for from network
        data = Payment.from_network(
            type(
                'Data', (object, ), {
                    "message_id":
                    MessageId(TraderId("0"), MessageNumber(1)),
                    "transaction_id":
                    TransactionId(TraderId('2'), TransactionNumber(2)),
                    "transferee_quantity":
                    Quantity(3, 'MC'),
                    "transferee_price":
                    Price(2, 'BTC'),
                    "address_from":
                    WalletAddress('a'),
                    "address_to":
                    WalletAddress('b'),
                    "payment_id":
                    PaymentId('aaa'),
                    "timestamp":
                    Timestamp(4.0),
                    "success":
                    True
                }))

        self.assertEquals(MessageId(TraderId("0"), MessageNumber(1)),
                          data.message_id)
        self.assertEquals(TransactionId(TraderId('2'), TransactionNumber(2)),
                          data.transaction_id)
        self.assertEquals(Quantity(3, 'MC'), data.transferee_quantity)
        self.assertEquals(Price(2, 'BTC'), data.transferee_price)
        self.assertEquals(Timestamp(4.0), data.timestamp)
        self.assertTrue(data.success)
Exemple #6
0
 def setUp(self):
     # Object creation
     self.payment = Payment(
         MessageId(TraderId("0"), MessageNumber(1)),
         TransactionId(TraderId('2'), TransactionNumber(2)),
         Quantity(3, 'MC'), Price(2, 'BTC'), WalletAddress('a'),
         WalletAddress('b'), PaymentId('aaa'), Timestamp(4.0), True)
Exemple #7
0
 def test_equality(self):
     """
     Test equality between payment ids
     """
     self.assertEqual(self.payment_id1, PaymentId("3"))
     self.assertNotEqual(self.payment_id1, self.payment_id2)
     self.assertEqual(NotImplemented, self.payment_id1.__eq__("3"))
Exemple #8
0
 def setUp(self):
     # Object creation
     self.payment_payload = PaymentPayload.Implementation(
         MetaObject(), TraderId('0'), MessageNumber('1'), TraderId('2'),
         TransactionNumber(2), Quantity(20, 'MC'), Price(10, 'BTC'),
         WalletAddress('a'), WalletAddress('b'), PaymentId('3'),
         Timestamp(0.0), True)
Exemple #9
0
    def setUp(self):
        yield super(TestDatabase, self).setUp()

        path = os.path.join(self.getStateDir(), 'sqlite')
        if not os.path.exists(path):
            os.makedirs(path)

        self.database = MarketDB(self.getStateDir(), 'market')

        self.order_id1 = OrderId(TraderId(b'3'), OrderNumber(4))
        self.order_id2 = OrderId(TraderId(b'4'), OrderNumber(5))
        self.order1 = Order(self.order_id1, AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
                            Timeout(3600), Timestamp.now(), True)
        self.order2 = Order(self.order_id2, AssetPair(AssetAmount(5, 'BTC'), AssetAmount(6, 'EUR')),
                            Timeout(3600), Timestamp.now(), False)
        self.order2.reserve_quantity_for_tick(OrderId(TraderId(b'3'), OrderNumber(4)), 3)

        self.transaction_id1 = TransactionId(TraderId(b"0"), TransactionNumber(4))
        self.transaction1 = Transaction(self.transaction_id1, AssetPair(AssetAmount(100, 'BTC'), AssetAmount(30, 'MB')),
                                        OrderId(TraderId(b"0"), OrderNumber(1)),
                                        OrderId(TraderId(b"1"), OrderNumber(2)), Timestamp(20.0))

        self.payment1 = Payment(TraderId(b"0"), self.transaction_id1, AssetAmount(5, 'BTC'),
                                WalletAddress('abc'), WalletAddress('def'), PaymentId("abc"), Timestamp(20.0), False)

        self.transaction1.add_payment(self.payment1)
Exemple #10
0
 def from_unpack_list(cls, trader_id, timestamp, transaction_trader_id,
                      transaction_number, transferred_amount,
                      transferred_type, address_from, address_to,
                      payment_id, success):
     return PaymentPayload(
         TraderId(trader_id), Timestamp(timestamp),
         TransactionId(TraderId(transaction_trader_id),
                       TransactionNumber(transaction_number)),
         AssetAmount(transferred_amount, transferred_type),
         WalletAddress(address_from), WalletAddress(address_to),
         PaymentId(payment_id), success)
Exemple #11
0
    def test_to_network(self):
        # Test for to network
        data = self.payment.to_network()

        self.assertEquals(data[0], TraderId("0"))
        self.assertEquals(data[1], Timestamp(4.0))
        self.assertEquals(data[2], TransactionId(TraderId("2"), TransactionNumber(2)))
        self.assertEquals(data[3], AssetAmount(3, 'BTC'))
        self.assertEquals(data[4], WalletAddress('a'))
        self.assertEquals(data[5], WalletAddress('b'))
        self.assertEquals(data[6], PaymentId('aaa'))
        self.assertEquals(data[7], True)
 def test_create_payment_message(self):
     """
     Test the creation of a payment message
     """
     self.transaction.incoming_address = WalletAddress('abc')
     self.transaction.outgoing_address = WalletAddress('def')
     self.transaction.partner_incoming_address = WalletAddress('ghi')
     self.transaction.partner_outgoing_address = WalletAddress('jkl')
     payment_msg = self.transaction_manager.create_payment_message(
         MessageId(TraderId("0"), MessageNumber('3')), PaymentId('abc'),
         self.transaction, (Quantity(3, 'MC'), Price(4, 'BTC')), True)
     self.assertIsInstance(payment_msg, Payment)
Exemple #13
0
    def test_encode_decode_payment(self):
        """
        Test encoding and decoding of a payment
        """
        message = MockObject()
        meta_msg = self.market_community.get_meta_message(u"payment")

        payment_payload = PaymentPayload.Implementation(meta_msg, TraderId('abc'), MessageNumber('3'),
                                                        TraderId('def'), TransactionNumber(5), Quantity(5, 'MC'),
                                                        Price(6, 'BTC'), WalletAddress('a'),
                                                        WalletAddress('b'), PaymentId('abc'), Timestamp.now(), False)
        message.payload = payment_payload
        packet, = self.conversion._encode_payment(message)
        self.assertTrue(packet)

        _, decoded = self.conversion._decode_payment(self.get_placeholder_msg(u"payment"), 0, packet)

        self.assertTrue(decoded)
        self.assertEqual(decoded.trader_id, TraderId('abc'))
        self.assertEqual(decoded.transaction_trader_id, TraderId('def'))
        self.assertEqual(decoded.payment_id, PaymentId('abc'))
        self.assertEqual(decoded.success, False)
Exemple #14
0
    def from_database(cls, data):
        """
        Create a Payment object based on information in the database.
        """
        trader_id, message_number, transaction_trader_id, transaction_number, payment_id, transferee_quantity,\
        quantity_type, transferee_price, price_type, address_from, address_to, timestamp, success = data

        message_id = MessageId(TraderId(str(trader_id)), MessageNumber(str(message_number)))
        transaction_id = TransactionId(TraderId(str(transaction_trader_id)), TransactionNumber(transaction_number))
        return cls(message_id, transaction_id, Quantity(transferee_quantity, str(quantity_type)),
                   Price(transferee_price, str(price_type)), WalletAddress(str(address_from)),
                   WalletAddress(str(address_to)), PaymentId(str(payment_id)), Timestamp(float(timestamp)),
                   bool(success))
 def test_create_payment_message(self):
     """
     Test the creation of a payment message
     """
     self.transaction.incoming_address = WalletAddress('abc')
     self.transaction.outgoing_address = WalletAddress('def')
     self.transaction.partner_incoming_address = WalletAddress('ghi')
     self.transaction.partner_outgoing_address = WalletAddress('jkl')
     payment_msg = self.transaction_manager.create_payment_message(TraderId(b"0"),
                                                                   PaymentId('abc'), self.transaction,
                                                                   AssetAmount(1, 'BTC'),
                                                                   True)
     self.assertIsInstance(payment_msg, Payment)
Exemple #16
0
    def test_to_network(self):
        # Test for to network
        data = self.payment.to_network()

        self.assertEquals(data[0], MessageId(TraderId("0"), MessageNumber(1)))
        self.assertEquals(data[1], Timestamp(4.0))
        self.assertEquals(data[2],
                          TransactionId(TraderId("2"), TransactionNumber(2)))
        self.assertEquals(data[3], Quantity(3, 'MC'))
        self.assertEquals(data[4], Price(2, 'BTC'))
        self.assertEquals(data[5], WalletAddress('a'))
        self.assertEquals(data[6], WalletAddress('b'))
        self.assertEquals(data[7], PaymentId('aaa'))
        self.assertEquals(data[8], True)
Exemple #17
0
    def from_database(cls, data):
        """
        Create a Payment object based on information in the database.
        """
        trader_id, transaction_trader_id, transaction_number, payment_id, transferred_amount, transferred_id,\
        address_from, address_to, timestamp, success = data

        transaction_id = TransactionId(TraderId(str(transaction_trader_id)),
                                       TransactionNumber(transaction_number))
        return cls(TraderId(str(trader_id)), transaction_id,
                   AssetAmount(transferred_amount, str(transferred_id)),
                   WalletAddress(str(address_from)),
                   WalletAddress(str(address_to)), PaymentId(str(payment_id)),
                   Timestamp(float(timestamp)), bool(success))
Exemple #18
0
    def add_transaction_and_payment(self):
        """
        Add a transaction and a payment to the market
        """
        proposed_trade = Trade.propose(MessageId(TraderId('0'), MessageNumber('message_number')),
                                       OrderId(TraderId('0'), OrderNumber(1)),
                                       OrderId(TraderId('1'), OrderNumber(2)),
                                       Price(63400, 'BTC'), Quantity(30, 'MC'), Timestamp(1462224447.117))
        transaction = self.session.lm.market_community.transaction_manager.create_from_proposed_trade(proposed_trade)

        payment = Payment(MessageId(TraderId("0"), MessageNumber("1")), transaction.transaction_id,
                          Quantity(0, 'MC'), Price(20, 'BTC'), WalletAddress('a'), WalletAddress('b'),
                          PaymentId('aaa'), Timestamp(4.0), True)
        transaction.add_payment(payment)
        self.session.lm.market_community.transaction_manager.transaction_repository.update(transaction)

        return transaction
Exemple #19
0
 def setUp(self):
     # Object creation
     self.transaction_id = TransactionId(TraderId("0"),
                                         TransactionNumber(1))
     self.transaction = Transaction(
         self.transaction_id,
         AssetPair(AssetAmount(100, 'BTC'), AssetAmount(100, 'MB')),
         OrderId(TraderId('3'), OrderNumber(2)),
         OrderId(TraderId('2'), OrderNumber(1)), Timestamp(0.0))
     self.proposed_trade = Trade.propose(
         TraderId('0'), OrderId(TraderId('0'), OrderNumber(2)),
         OrderId(TraderId('1'), OrderNumber(3)),
         AssetPair(AssetAmount(100, 'BTC'), AssetAmount(100, 'MB')),
         Timestamp(0.0))
     self.payment = Payment(
         TraderId("0"), TransactionId(TraderId('2'), TransactionNumber(2)),
         AssetAmount(3, 'MB'), WalletAddress('a'), WalletAddress('b'),
         PaymentId('aaa'), Timestamp(4.0), True)
 def setUp(self):
     # Object creation
     self.transaction_id = TransactionId(TraderId("0"),
                                         TransactionNumber(1))
     self.transaction = Transaction(self.transaction_id, Price(100, 'BTC'),
                                    Quantity(30, 'MC'),
                                    OrderId(TraderId('3'), OrderNumber(2)),
                                    OrderId(TraderId('2'), OrderNumber(1)),
                                    Timestamp(0.0))
     self.proposed_trade = Trade.propose(
         MessageId(TraderId('0'), MessageNumber('1')),
         OrderId(TraderId('0'), OrderNumber(2)),
         OrderId(TraderId('1'), OrderNumber(3)), Price(100, 'BTC'),
         Quantity(30, 'MC'), Timestamp(0.0))
     self.payment = Payment(
         MessageId(TraderId("0"), MessageNumber("1")),
         TransactionId(TraderId('2'), TransactionNumber(2)),
         Quantity(3, 'MC'), Price(2, 'BTC'), WalletAddress('a'),
         WalletAddress('b'), PaymentId('aaa'), Timestamp(4.0), True)
Exemple #21
0
    def add_transaction_and_payment(self):
        """
        Add a transaction and a payment to the market
        """
        proposed_trade = Trade.propose(
            TraderId('0'), OrderId(TraderId('0'), OrderNumber(1)),
            OrderId(TraderId('1'), OrderNumber(2)),
            AssetPair(AssetAmount(30, 'BTC'), AssetAmount(60, 'MB')),
            Timestamp(1462224447.117))
        transaction = self.session.lm.market_community.transaction_manager.create_from_proposed_trade(
            proposed_trade, 'abcd')

        payment = Payment(TraderId("0"), transaction.transaction_id,
                          AssetAmount(20, 'BTC'), WalletAddress('a'),
                          WalletAddress('b'), PaymentId('aaa'), Timestamp(4.0),
                          True)
        transaction.add_payment(payment)
        self.session.lm.market_community.transaction_manager.transaction_repository.update(
            transaction)

        return transaction
Exemple #22
0
 def setUp(self):
     self.payment_id1 = PaymentId("3")
     self.payment_id2 = PaymentId("4")
Exemple #23
0
 def test_init(self):
     """
     Test the initialization of a quantity
     """
     with self.assertRaises(ValueError):
         PaymentId(1)
Exemple #24
0
 def from_unpack_list(cls, trader_id, message_number, timestamp, transaction_trader_id, transaction_number,
                      transferee_quantity, transferee_quantity_type, transferee_price, transferee_price_type,
                      address_from, address_to, payment_id, success):
     return PaymentPayload(MessageId(TraderId(trader_id), MessageNumber(message_number)), Timestamp(timestamp),
                           TransactionId(TraderId(transaction_trader_id), TransactionNumber(transaction_number)),
                           Quantity(transferee_quantity, transferee_quantity_type),
                           Price(transferee_price, transferee_price_type),
                           WalletAddress(address_from), WalletAddress(address_to), PaymentId(payment_id),
                           success)