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__())
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)
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.decode('utf-8')), WalletAddress(address_from.decode('utf-8')), WalletAddress(address_to.decode('utf-8')), PaymentId(payment_id.decode('utf-8')), success)
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 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_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 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))
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 from_database(cls, data): """ Create a Payment object based on information in the database. """ (trader_id, transaction_id, payment_id, transferred_amount, transferred_id, address_from, address_to, timestamp) = data transaction_id = TransactionId(bytes(transaction_id)) return cls(TraderId(bytes(trader_id)), transaction_id, AssetAmount(transferred_amount, str(transferred_id)), WalletAddress(str(address_from)), WalletAddress(str(address_to)), PaymentId(str(payment_id)), Timestamp(timestamp))
def from_block(cls, block): """ Restore a payment from a TrustChain block :param block: TrustChainBlock :return: Restored payment :rtype: Payment """ tx_dict = block.transaction["payment"] return cls( TraderId(unhexlify(tx_dict["trader_id"])), TransactionId(unhexlify(tx_dict["transaction_id"])), AssetAmount(tx_dict["transferred"]["amount"], tx_dict["transferred"]["type"]), WalletAddress(tx_dict["address_from"]), WalletAddress(tx_dict["address_to"]), PaymentId(tx_dict["payment_id"]), Timestamp(tx_dict["timestamp"]))
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
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
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)