Ejemplo n.º 1
0
 def setUp(self):
     # Object creation
     self.payment = Payment(
         TraderId(b'0' * 20),
         TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
         AssetAmount(3, 'BTC'), WalletAddress('a'), WalletAddress('b'),
         PaymentId('aaa'), Timestamp(4000), True)
Ejemplo n.º 2
0
    async def setUp(self):
        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' * 20), OrderNumber(4))
        self.order_id2 = OrderId(TraderId(b'4' * 20), 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' * 20), OrderNumber(4)), 3)

        self.transaction_id1 = TransactionId(b'a' * 32)
        self.transaction1 = Transaction(
            self.transaction_id1,
            AssetPair(AssetAmount(100, 'BTC'), AssetAmount(30, 'MB')),
            OrderId(TraderId(b'0' * 20), OrderNumber(1)),
            OrderId(TraderId(b'1' * 20), OrderNumber(2)), Timestamp(20000))

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

        self.transaction1.add_payment(self.payment1)
Ejemplo n.º 3
0
    def test_from_network(self):
        # Test for from network
        data = Payment.from_network(
            type(
                'Data', (object, ), {
                    "trader_id":
                    TraderId(b'0' * 20),
                    "transaction_id":
                    TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
                    "transferred_assets":
                    AssetAmount(3, 'BTC'),
                    "address_from":
                    WalletAddress('a'),
                    "address_to":
                    WalletAddress('b'),
                    "payment_id":
                    PaymentId('aaa'),
                    "timestamp":
                    Timestamp(4000),
                    "success":
                    True
                }))

        self.assertEquals(TraderId(b'0' * 20), data.trader_id)
        self.assertEquals(
            TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
            data.transaction_id)
        self.assertEquals(AssetAmount(3, 'BTC'), data.transferred_assets)
        self.assertEquals(Timestamp(4000), data.timestamp)
        self.assertTrue(data.success)
Ejemplo n.º 4
0
class PaymentTestSuite(unittest.TestCase):
    """Payment test cases."""
    def setUp(self):
        # Object creation
        self.payment = Payment(TraderId(b'0' * 20), TransactionId(b'a' * 32),
                               AssetAmount(3, 'BTC'), WalletAddress('a'),
                               WalletAddress('b'), PaymentId('aaa'),
                               Timestamp(4000))

    def test_to_dictionary(self):
        """
        Test the dictionary representation of a payment
        """
        self.assertDictEqual(
            self.payment.to_dictionary(), {
                "trader_id": "30" * 20,
                "transaction_id": "61" * 32,
                "transferred": {
                    "amount": 3,
                    "type": "BTC"
                },
                "payment_id": 'aaa',
                "address_from": 'a',
                "address_to": 'b',
                "timestamp": 4000,
            })
Ejemplo n.º 5
0
 def get_payments(self, transaction_id):
     """
     Return all payment tied to a specific transaction.
     """
     db_result = self.execute(
         u"SELECT * FROM payments WHERE transaction_id = ? ORDER BY timestamp ASC",
         (database_blob(bytes(transaction_id)), ))
     return [Payment.from_database(db_item) for db_item in db_result]
Ejemplo n.º 6
0
    def create_payment_message(self, message_id, payment_id, transaction, transferred_assets, success):
        payment_message = Payment(message_id, transaction.transaction_id, transferred_assets,
                                  transaction.outgoing_address, transaction.partner_incoming_address,
                                  payment_id, Timestamp.now(), success)
        transaction.add_payment(payment_message)
        self.transaction_repository.update(transaction)

        return payment_message
Ejemplo n.º 7
0
 def setUp(self):
     # Object creation
     self.maxDiff = None
     self.transaction_id = TransactionId(b'a' * 32)
     self.transaction = Transaction(
         self.transaction_id,
         AssetPair(AssetAmount(100, 'BTC'), AssetAmount(100, 'MB')),
         OrderId(TraderId(b'3' * 20), OrderNumber(2)),
         OrderId(TraderId(b'2' * 20), OrderNumber(1)), Timestamp(0))
     self.proposed_trade = Trade.propose(
         TraderId(b'0' * 20), OrderId(TraderId(b'0' * 20), OrderNumber(2)),
         OrderId(TraderId(b'1' * 20), OrderNumber(3)),
         AssetPair(AssetAmount(100, 'BTC'), AssetAmount(100, 'MB')),
         Timestamp(0))
     self.payment = Payment(TraderId(b'0' * 20), TransactionId(b'a' * 32),
                            AssetAmount(100, 'MB'), WalletAddress('a'),
                            WalletAddress('b'), PaymentId('aaa'),
                            Timestamp(4))
     self.payment2 = Payment(TraderId(b'0' * 20), TransactionId(b'a' * 32),
                             AssetAmount(100, 'BTC'), WalletAddress('a'),
                             WalletAddress('b'), PaymentId('aaa'),
                             Timestamp(4))
Ejemplo n.º 8
0
    def add_transaction_and_payment(self):
        """
        Add a transaction and a payment to the market
        """
        self.accepted_trade = AcceptedTrade(
            TraderId(b'0' * 20), OrderId(TraderId(b'0' * 20), OrderNumber(1)),
            OrderId(TraderId(b'1' * 20), OrderNumber(1)), 1234,
            AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MB')),
            Timestamp(0))
        transaction = Transaction.from_accepted_trade(self.accepted_trade,
                                                      TransactionId(b'a' * 32))

        payment = Payment(TraderId(b'0' * 20), transaction.transaction_id,
                          AssetAmount(20, 'BTC'), WalletAddress('a'),
                          WalletAddress('b'), PaymentId('aaa'),
                          Timestamp(4000))
        transaction.add_payment(payment)
        self.nodes[
            0].overlay.transaction_manager.transaction_repository.update(
                transaction)

        return transaction
Ejemplo n.º 9
0
def payment():
    transaction_id = TransactionId(b'a' * 32)
    payment = Payment(TraderId(b'0' * 20), transaction_id,
                      AssetAmount(5, 'BTC'), WalletAddress('abc'),
                      WalletAddress('def'), PaymentId("abc"), Timestamp(20000))
    return payment
Ejemplo n.º 10
0
class PaymentTestSuite(unittest.TestCase):
    """Payment test cases."""
    def setUp(self):
        # Object creation
        self.payment = Payment(
            TraderId(b'0' * 20),
            TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
            AssetAmount(3, 'BTC'), WalletAddress('a'), WalletAddress('b'),
            PaymentId('aaa'), Timestamp(4000), True)

    def test_from_network(self):
        # Test for from network
        data = Payment.from_network(
            type(
                'Data', (object, ), {
                    "trader_id":
                    TraderId(b'0' * 20),
                    "transaction_id":
                    TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
                    "transferred_assets":
                    AssetAmount(3, 'BTC'),
                    "address_from":
                    WalletAddress('a'),
                    "address_to":
                    WalletAddress('b'),
                    "payment_id":
                    PaymentId('aaa'),
                    "timestamp":
                    Timestamp(4000),
                    "success":
                    True
                }))

        self.assertEquals(TraderId(b'0' * 20), data.trader_id)
        self.assertEquals(
            TransactionId(TraderId(b'2' * 20), TransactionNumber(2)),
            data.transaction_id)
        self.assertEquals(AssetAmount(3, 'BTC'), data.transferred_assets)
        self.assertEquals(Timestamp(4000), data.timestamp)
        self.assertTrue(data.success)

    def test_to_network(self):
        # Test for to network
        data = self.payment.to_network()

        self.assertEquals(data[0], TraderId(b'0' * 20))
        self.assertEquals(data[1], Timestamp(4000))
        self.assertEquals(
            data[2], TransactionId(TraderId(b'2' * 20), 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_to_dictionary(self):
        """
        Test the dictionary representation of a payment
        """
        self.assertDictEqual(
            self.payment.to_dictionary(), {
                "trader_id": "32" * 20,
                "transaction_number": 2,
                "transferred": {
                    "amount": 3,
                    "type": "BTC"
                },
                "payment_id": 'aaa',
                "address_from": 'a',
                "address_to": 'b',
                "timestamp": 4000,
                "success": True
            })