def setUp(self): # Object creation self.start_transaction = StartTransaction( TraderId('0'), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(1)), 1234, AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), Timestamp(0.0))
def setUp(self): # Object creation self.start_transaction = StartTransaction( MessageId(TraderId('0'), MessageNumber('1')), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(1)), 1234, Price(30, 'BTC'), Quantity(40, 'MC'), Timestamp(0.0))
def test_from_network(self): # Test for from network data = StartTransaction.from_network( type( 'Data', (object, ), { "trader_id": TraderId('0'), "message_number": MessageNumber("1"), "transaction_trader_id": TraderId('0'), "transaction_number": TransactionNumber(1), "order_trader_id": TraderId('0'), "order_number": OrderNumber(1), "recipient_trader_id": TraderId('1'), "recipient_order_number": OrderNumber(2), "proposal_id": 1235, "price": Price(300, 'BTC'), "quantity": Quantity(20, 'MC'), "timestamp": Timestamp(0.0) })) self.assertEquals(MessageId(TraderId("0"), MessageNumber("1")), data.message_id) self.assertEquals(TransactionId(TraderId("0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId('0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId('1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp)
def test_from_network(self): # Test for from network data = StartTransaction.from_network( type( 'Data', (object, ), { "trader_id": TraderId('0'), "transaction_id": TransactionId(TraderId('0'), TransactionNumber(1)), "order_id": OrderId(TraderId('0'), OrderNumber(1)), "recipient_order_id": OrderId(TraderId('1'), OrderNumber(2)), "proposal_id": 1235, "assets": AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), "timestamp": Timestamp(0.0) })) self.assertEquals(TraderId("0"), data.trader_id) self.assertEquals(TransactionId(TraderId("0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId('0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId('1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp)
def setUp(self): # Object creation self.start_transaction = StartTransaction(TraderId('0'), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(1)), 1234, AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), Timestamp(0.0))
def get_start_transaction_msg(self): transaction = self.market_community.transaction_manager.create_from_proposed_trade( self.proposed_trade, 'abcd') start_transaction = StartTransaction( self.market_community.message_repository.next_identity(), transaction.transaction_id, transaction.order_id, self.proposed_trade.order_id, self.proposed_trade.proposal_id, self.proposed_trade.price, self.proposed_trade.quantity, Timestamp.now()) meta = self.market_community.get_meta_message(u"start-transaction") candidate = Candidate( self.market_community.lookup_ip(TraderId( self.market_community.mid)), False) return meta.impl( authentication=(self.market_community.my_member, ), distribution=(self.market_community.claim_global_time(), ), destination=(candidate, ), payload=start_transaction.to_network())
class StartTransactionTestSuite(unittest.TestCase): """Start transaction test cases.""" def setUp(self): # Object creation self.start_transaction = StartTransaction( MessageId(TraderId('0'), MessageNumber('1')), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(1)), 1234, Price(30, 'BTC'), Quantity(40, 'MC'), Timestamp(0.0)) def test_from_network(self): # Test for from network data = StartTransaction.from_network( type( 'Data', (object, ), { "trader_id": TraderId('0'), "message_number": MessageNumber("1"), "transaction_trader_id": TraderId('0'), "transaction_number": TransactionNumber(1), "order_trader_id": TraderId('0'), "order_number": OrderNumber(1), "recipient_trader_id": TraderId('1'), "recipient_order_number": OrderNumber(2), "proposal_id": 1235, "price": Price(300, 'BTC'), "quantity": Quantity(20, 'MC'), "timestamp": Timestamp(0.0) })) self.assertEquals(MessageId(TraderId("0"), MessageNumber("1")), data.message_id) self.assertEquals(TransactionId(TraderId("0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId('0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId('1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp) def test_to_network(self): """ Test the conversion of a StartTransaction object to the network """ data = self.start_transaction.to_network() self.assertEqual(data[0], self.start_transaction.message_id.trader_id) self.assertEqual(data[1], self.start_transaction.message_id.message_number) self.assertEqual(data[2], self.start_transaction.transaction_id.trader_id) self.assertEqual( data[3], self.start_transaction.transaction_id.transaction_number)
class StartTransactionTestSuite(unittest.TestCase): """Start transaction test cases.""" def setUp(self): # Object creation self.start_transaction = StartTransaction( TraderId('0'), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(1)), 1234, AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), Timestamp(0.0)) def test_from_network(self): # Test for from network data = StartTransaction.from_network( type( 'Data', (object, ), { "trader_id": TraderId('0'), "transaction_id": TransactionId(TraderId('0'), TransactionNumber(1)), "order_id": OrderId(TraderId('0'), OrderNumber(1)), "recipient_order_id": OrderId(TraderId('1'), OrderNumber(2)), "proposal_id": 1235, "assets": AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), "timestamp": Timestamp(0.0) })) self.assertEquals(TraderId("0"), data.trader_id) self.assertEquals(TransactionId(TraderId("0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId('0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId('1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp) def test_to_network(self): """ Test the conversion of a StartTransaction object to the network """ data = self.start_transaction.to_network() self.assertEqual(data[0], self.start_transaction.trader_id)
def test_from_network(self): # Test for from network data = StartTransaction.from_network( type('Data', (object,), {"trader_id": TraderId('0'), "transaction_id": TransactionId(TraderId('0'), TransactionNumber(1)), "order_id": OrderId(TraderId('0'), OrderNumber(1)), "recipient_order_id": OrderId(TraderId('1'), OrderNumber(2)), "proposal_id": 1235, "assets": AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), "timestamp": Timestamp(0.0)})) self.assertEquals(TraderId("0"), data.trader_id) self.assertEquals(TransactionId(TraderId("0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId('0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId('1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp)
def setUp(self): # Object creation self.memory_transaction_repository = MemoryTransactionRepository("0") self.transaction_manager = TransactionManager(self.memory_transaction_repository) self.transaction_id = TransactionId(TraderId(b"0"), TransactionNumber(1)) self.transaction = Transaction(self.transaction_id, AssetPair(AssetAmount(100, 'BTC'), AssetAmount(30, 'MB')), OrderId(TraderId(b'3'), OrderNumber(2)), OrderId(TraderId(b'2'), OrderNumber(1)), Timestamp(0.0)) self.proposed_trade = Trade.propose(TraderId(b'0'), OrderId(TraderId(b'0'), OrderNumber(1)), OrderId(TraderId(b'1'), OrderNumber(2)), AssetPair(AssetAmount(30, 'BTC'), AssetAmount(30, 'MB')), Timestamp(1462224447.117)) self.start_transaction = StartTransaction(TraderId(b'0'), TransactionId(TraderId(b"0"), TransactionNumber(1)), OrderId(TraderId(b'0'), OrderNumber(1)), OrderId(TraderId(b'1'), OrderNumber(2)), 1235, AssetPair(AssetAmount(20, 'BTC'), AssetAmount(20, 'MB')), Timestamp(0.0))
def setUp(self): # Object creation self.memory_transaction_repository = MemoryTransactionRepository("0") self.transaction_manager = TransactionManager( self.memory_transaction_repository) 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('message_number')), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(2)), Price(63400, 'BTC'), Quantity(30, 'MC'), Timestamp(1462224447.117)) self.start_transaction = StartTransaction( MessageId(TraderId('0'), MessageNumber('1')), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(2)), 1235, Price(3600, 'BTC'), Quantity(20, 'MC'), Timestamp(0.0))
class StartTransactionTestSuite(unittest.TestCase): """Start transaction test cases.""" def setUp(self): # Object creation self.start_transaction = StartTransaction(TraderId('0'), TransactionId(TraderId("0"), TransactionNumber(1)), OrderId(TraderId('0'), OrderNumber(1)), OrderId(TraderId('1'), OrderNumber(1)), 1234, AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), Timestamp(0.0)) def test_from_network(self): # Test for from network data = StartTransaction.from_network( type('Data', (object,), {"trader_id": TraderId('0'), "transaction_id": TransactionId(TraderId('0'), TransactionNumber(1)), "order_id": OrderId(TraderId('0'), OrderNumber(1)), "recipient_order_id": OrderId(TraderId('1'), OrderNumber(2)), "proposal_id": 1235, "assets": AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), "timestamp": Timestamp(0.0)})) self.assertEquals(TraderId("0"), data.trader_id) self.assertEquals(TransactionId(TraderId("0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId('0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId('1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp) def test_to_network(self): """ Test the conversion of a StartTransaction object to the network """ data = self.start_transaction.to_network() self.assertEqual(data[0], self.start_transaction.trader_id)
class StartTransactionTestSuite(unittest.TestCase): """Start transaction test cases.""" def setUp(self): # Object creation self.start_transaction = StartTransaction( TraderId(b'0'), TransactionId(TraderId(b"0"), TransactionNumber(1)), OrderId(TraderId(b'0'), OrderNumber(1)), OrderId(TraderId(b'1'), OrderNumber(1)), 1234, AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), Timestamp(0.0)) def test_from_network(self): # Test for from network data = StartTransaction.from_network( type( 'Data', (object, ), { "trader_id": TraderId(b'0'), "transaction_id": TransactionId(TraderId(b'0'), TransactionNumber(1)), "order_id": OrderId(TraderId(b'0'), OrderNumber(1)), "recipient_order_id": OrderId(TraderId(b'1'), OrderNumber(2)), "proposal_id": 1235, "assets": AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), "timestamp": Timestamp(0.0) })) self.assertEquals(TraderId(b"0"), data.trader_id) self.assertEquals(TransactionId(TraderId(b"0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId(b'0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId(b'1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp) def test_to_network(self): """ Test the conversion of a StartTransaction object to the network """ data = self.start_transaction.to_network() self.assertEqual(data[0], self.start_transaction.trader_id) def test_from_block(self): """ Test the from block method of a transaction """ block = { 'tx': { 'payment_complete': False, 'status': 'pending', 'partner_trader_id': '1111111111111111111111111111111111111111', 'trader_id': '0000000000000000000000000000000000000000', 'timestamp': 0.0, 'transferred': { 'second': { 'amount': 0, 'type': 'MB' }, 'first': { 'amount': 0, 'type': 'BTC' } }, 'partner_order_number': 1, 'order_number': 1, 'transaction_number': 1, 'assets': { 'second': { 'amount': 30, 'type': 'MB' }, 'first': { 'amount': 30, 'type': 'BTC' } } } } transaction = Transaction.from_block(block) self.assertEqual(block['tx']['trader_id'], six.text_type(transaction.transaction_id.trader_id)) self.assertEqual(block['tx']['transaction_number'], int(transaction.transaction_id.transaction_number)) self.assertEqual(block['tx']['trader_id'], six.text_type(transaction.order_id.trader_id)) self.assertEqual(block['tx']['transaction_number'], int(transaction.order_id.order_number)) self.assertEqual(block['tx']['partner_trader_id'], six.text_type(transaction.partner_order_id.trader_id)) self.assertEqual(block['tx']['partner_order_number'], int(transaction.partner_order_id.order_number)) self.assertEqual(block['tx']['timestamp'], float(transaction.timestamp)) self.assertEqual(block['tx']['assets']['first']['amount'], transaction.assets.first.amount) self.assertEqual(block['tx']['assets']['first']['type'], transaction.assets.first.asset_id) self.assertEqual(block['tx']['assets']['second']['amount'], transaction.assets.second.amount) self.assertEqual(block['tx']['assets']['second']['type'], transaction.assets.second.asset_id) self.assertEqual(block['tx']['transferred']['first']['amount'], transaction.transferred_assets.first.amount) self.assertEqual(block['tx']['transferred']['first']['type'], transaction.transferred_assets.first.asset_id) self.assertEqual(block['tx']['transferred']['second']['amount'], transaction.transferred_assets.second.amount) self.assertEqual(block['tx']['transferred']['second']['type'], transaction.transferred_assets.second.asset_id)
class StartTransactionTestSuite(unittest.TestCase): """Start transaction test cases.""" def setUp(self): # Object creation self.start_transaction = StartTransaction(TraderId(b'0'), TransactionId(TraderId(b"0"), TransactionNumber(1)), OrderId(TraderId(b'0'), OrderNumber(1)), OrderId(TraderId(b'1'), OrderNumber(1)), 1234, AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), Timestamp(0.0)) def test_from_network(self): # Test for from network data = StartTransaction.from_network( type('Data', (object,), {"trader_id": TraderId(b'0'), "transaction_id": TransactionId(TraderId(b'0'), TransactionNumber(1)), "order_id": OrderId(TraderId(b'0'), OrderNumber(1)), "recipient_order_id": OrderId(TraderId(b'1'), OrderNumber(2)), "proposal_id": 1235, "assets": AssetPair(AssetAmount(30, 'BTC'), AssetAmount(40, 'MC')), "timestamp": Timestamp(0.0)})) self.assertEquals(TraderId(b"0"), data.trader_id) self.assertEquals(TransactionId(TraderId(b"0"), TransactionNumber(1)), data.transaction_id) self.assertEquals(OrderId(TraderId(b'0'), OrderNumber(1)), data.order_id) self.assertEquals(OrderId(TraderId(b'1'), OrderNumber(2)), data.recipient_order_id) self.assertEquals(1235, data.proposal_id) self.assertEquals(Timestamp(0.0), data.timestamp) def test_to_network(self): """ Test the conversion of a StartTransaction object to the network """ data = self.start_transaction.to_network() self.assertEqual(data[0], self.start_transaction.trader_id) def test_from_block(self): """ Test the from block method of a transaction """ block = { 'tx': { 'payment_complete': False, 'status': 'pending', 'partner_trader_id': '1111111111111111111111111111111111111111', 'trader_id': '0000000000000000000000000000000000000000', 'timestamp': 0.0, 'transferred': { 'second': { 'amount': 0, 'type': 'MB' }, 'first': { 'amount': 0, 'type': 'BTC' } }, 'partner_order_number': 1, 'order_number': 1, 'transaction_number': 1, 'assets': { 'second': { 'amount': 30, 'type': 'MB' }, 'first': { 'amount': 30, 'type': 'BTC' } } } } transaction = Transaction.from_block(block) self.assertEqual(block['tx']['trader_id'], six.text_type(transaction.transaction_id.trader_id)) self.assertEqual(block['tx']['transaction_number'], int(transaction.transaction_id.transaction_number)) self.assertEqual(block['tx']['trader_id'], six.text_type(transaction.order_id.trader_id)) self.assertEqual(block['tx']['transaction_number'], int(transaction.order_id.order_number)) self.assertEqual(block['tx']['partner_trader_id'], six.text_type(transaction.partner_order_id.trader_id)) self.assertEqual(block['tx']['partner_order_number'], int(transaction.partner_order_id.order_number)) self.assertEqual(block['tx']['timestamp'], float(transaction.timestamp)) self.assertEqual(block['tx']['assets']['first']['amount'], transaction.assets.first.amount) self.assertEqual(block['tx']['assets']['first']['type'], transaction.assets.first.asset_id) self.assertEqual(block['tx']['assets']['second']['amount'], transaction.assets.second.amount) self.assertEqual(block['tx']['assets']['second']['type'], transaction.assets.second.asset_id) self.assertEqual(block['tx']['transferred']['first']['amount'], transaction.transferred_assets.first.amount) self.assertEqual(block['tx']['transferred']['first']['type'], transaction.transferred_assets.first.asset_id) self.assertEqual(block['tx']['transferred']['second']['amount'], transaction.transferred_assets.second.amount) self.assertEqual(block['tx']['transferred']['second']['type'], transaction.transferred_assets.second.asset_id)