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)
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)
class PaymentTestSuite(unittest.TestCase): """Payment test cases.""" 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) def test_from_network(self): # Test for from network data = Payment.from_network( type('Data', (object,), {"trader_id": TraderId("0"), "transaction_id": TransactionId(TraderId('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("0"), data.trader_id) self.assertEquals(TransactionId(TraderId('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 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_to_dictionary(self): """ Test the dictionary representation of a payment """ self.assertDictEqual(self.payment.to_dictionary(), { "trader_id": '2', "transaction_number": 2, "transferred": { "amount": 3, "type": "BTC" }, "payment_id": 'aaa', "address_from": 'a', "address_to": 'b', "timestamp": 4.0, "success": True })
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)
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)
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)
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 get_payments(self, transaction_id): """ Return all payment tied to a specific transaction. """ db_result = self.execute(u"SELECT * FROM payments WHERE transaction_trader_id = ? AND transaction_number = ?" u"ORDER BY timestamp ASC", (unicode(transaction_id.trader_id), unicode(transaction_id.transaction_number))) return [Payment.from_database(db_item) for db_item in db_result]
def get_payments(self, transaction_id): """ Return all payment tied to a specific transaction. """ db_result = self.execute( u"SELECT * FROM payments WHERE transaction_trader_id = ? AND transaction_number = ?" u"ORDER BY timestamp ASC", (unicode(transaction_id.trader_id), unicode(transaction_id.transaction_number))) return [Payment.from_database(db_item) for db_item in db_result]
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
def test_from_network(self): # Test for from network data = Payment.from_network( type('Data', (object,), {"trader_id": TraderId("0"), "transaction_id": TransactionId(TraderId('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("0"), data.trader_id) self.assertEquals(TransactionId(TraderId('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 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
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)
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
class PaymentTestSuite(unittest.TestCase): """Payment test cases.""" 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) 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) 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) def test_to_dictionary(self): """ Test the dictionary representation of a payment """ self.assertDictEqual( self.payment.to_dictionary(), { "trader_id": '2', "transaction_number": 2, "price": 2.0, "price_type": 'BTC', "quantity": 3.0, "quantity_type": 'MC', "payment_id": 'aaa', "address_from": 'a', "address_to": 'b', "timestamp": 4.0, "success": True })