def test_parsing_invoice_request(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) pki_type = "x509+sha256" memo = "Stan LOONA" notification_url = "http://loonatheworld.com" serialized_invoice_request = transact.create_invoice_request( amount=24000, pki_type=pki_type, memo=memo, notification_url=notification_url) transact2 = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) transact2.verify_invoice_request(serialized_invoice_request) verified_data = transact2.get_verified_invoice_request() self.assertEqual(pki_type, verified_data["pki_type"]) self.assertEqual(memo, verified_data["memo"]) self.assertEqual(notification_url, verified_data["notification_url"]) self.assertEqual(transact.certificate_pem, verified_data["pki_data"])
def test_parsing_payment(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem) memo = "Lion" transactions = [b"Lovelyz"] merchant_data = b"Kei" output_amount = 2400 output_script = b"https://www.youtube.com/watch?v=2G84zeRDXX8" outputs = [(output_amount, output_script)] serialized_payment = transact.create_payment( transactions=transactions, refund_to=outputs, memo=memo, merchant_data=merchant_data, ) transact2 = transactid.TransactID(private_key_pem=self.private_key_pem) transact2.verify_payment(serialized_payment) verified_data = transact2.get_verified_payment() self.assertEqual(transactions, verified_data["transactions"]) self.assertEqual(memo, verified_data["memo"]) self.assertEqual(merchant_data, verified_data["merchant_data"])
def test_parsing_payment_request(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) pki_type = "x509+sha256" memo = "Guerilla" payment_url = "https://www.youtube.com/watch?v=wVMeNl4UfIE" merchant_data = b"It's a miracle." output_amount = 2400 output_script = b"Seunghee" outputs = [(output_amount, output_script)] serialized_payment_request = transact.create_payment_request( time_stamp=datetime.datetime.now(), outputs=outputs, memo=memo, payment_url=payment_url, merchant_data=merchant_data, pki_type=pki_type) transact2 = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) transact2.verify_payment_request(serialized_payment_request) verified_data = transact2.get_verified_payment_request() self.assertEqual(pki_type, verified_data["pki_type"]) self.assertEqual(memo, verified_data["payment_details"]["memo"]) self.assertEqual(payment_url, verified_data["payment_details"]["payment_url"]) self.assertEqual(transact.certificate_pem, verified_data["pki_data"])
def test_parsing_invalid_signature(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) pki_type = "x509+sha256" memo = "Stan LOONA" notification_url = "http://loonatheworld.com" serialized_invoice_request = transact.create_invoice_request( amount=24000, pki_type=pki_type, memo=memo, notification_url=notification_url) proto_request = paymentrequest_pb2.InvoiceRequest() proto_request.ParseFromString(serialized_invoice_request) proto_request.memo = "Mamamoo is cool too." serialized_proto_request = proto_request.SerializeToString( deterministic=True) with self.assertRaises(InvalidSignatureException) as context: transact.verify_invoice_request(serialized_proto_request) self.assertTrue( "Unable to verify signature." in str(context.exception))
def test_create_payment(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem) memo = "Lion" transactions = [b"Lovelyz"] merchant_data = b"Mijoo" output_amount = 2400 output_script = b"https://www.youtube.com/watch?v=OlI8Ly3sxvI" outputs = [(output_amount, output_script)] serialized_payment = transact.create_payment( transactions=transactions, refund_to=outputs, memo=memo, merchant_data=merchant_data, ) self.assertEqual(transact.created_payment.memo, memo) self.assertEqual(transact.created_payment.transactions[0], transactions[0]) self.assertEqual(transact.created_payment.merchant_data, merchant_data) self.assertEqual(transact.created_payment.refund_to[0].amount, output_amount) self.assertEqual(transact.created_payment.refund_to[0].script, output_script)
def test_create_payment_ack(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem) payment_memo = "HIP" transactions = [b"Mamamoo"] merchant_data = b"Solar is queen" output_amount = 2400 output_script = b"https://www.youtube.com/watch?v=KhTeiaCezwM" outputs = [(output_amount, output_script)] serialized_payment = transact.create_payment( transactions=transactions, refund_to=outputs, memo=payment_memo, merchant_data=merchant_data, ) transact.verify_payment(serialized_payment) payment_ack_memo = "Wheein wrecks biases though" serialized_payment_ack = transact.create_payment_ack( memo=payment_ack_memo) self.assertEqual(transact.created_payment_ack.memo, payment_ack_memo) self.assertEqual(transact.created_payment_ack.payment, transact.created_payment)
def test_create_payment_request_without_signature(self): transact = transactid.TransactID( private_key_pem=self.private_key_pem, ) pki_type = "none" memo = "Not Sorry" payment_url = "https://www.youtube.com/watch?v=FwsUHHiPcRA" merchant_data = b"They too are queens." output_amount = 2600 output_script = b"ace" outputs = [(output_amount, output_script)] serialized_payment_request = transact.create_payment_request( time_stamp=datetime.datetime.now(), outputs=outputs, memo=memo, payment_url=payment_url, merchant_data=merchant_data, pki_type=pki_type) self.assertEqual(transact.created_payment_details.memo, memo) self.assertEqual(transact.created_payment_details.payment_url, payment_url) self.assertEqual(transact.created_payment_details.merchant_data, merchant_data) self.assertEqual(transact.created_payment_details.outputs[0].amount, output_amount) self.assertEqual(transact.created_payment_details.outputs[0].script, output_script) self.assertEqual(transact.created_payment_request.pki_type, pki_type) self.assertEqual(transact.created_payment_request.pki_data, b"")
def test_create_payment_request_with_signature(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) pki_type = "x509+sha256" memo = "Lion" payment_url = "https://www.youtube.com/watch?v=6oanIo_2Z4Q" merchant_data = b"They are queens." output_amount = 2400 output_script = b"rawr" outputs = [(output_amount, output_script)] serialized_payment_request = transact.create_payment_request( time_stamp=datetime.datetime.now(), outputs=outputs, memo=memo, payment_url=payment_url, merchant_data=merchant_data, pki_type=pki_type) self.assertEqual(transact.created_payment_details.memo, memo) self.assertEqual(transact.created_payment_details.payment_url, payment_url) self.assertEqual(transact.created_payment_details.merchant_data, merchant_data) self.assertEqual(transact.created_payment_details.outputs[0].amount, output_amount) self.assertEqual(transact.created_payment_details.outputs[0].script, output_script) self.assertEqual(transact.created_payment_request.pki_type, pki_type)
def test_parsing_invalid_signature(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) pki_type = "x509+sha256" memo = "Moonlight" payment_url = "https://www.youtube.com/watch?v=OlI8Ly3sxvI" merchant_data = b"LTC" output_amount = 2400 output_script = b"Lovelinus" outputs = [(output_amount, output_script)] serialized_payment_request = transact.create_payment_request( time_stamp=datetime.datetime.now(), outputs=outputs, memo=memo, payment_url=payment_url, merchant_data=merchant_data, pki_type=pki_type) proto_request = paymentrequest_pb2.PaymentRequest() proto_request.ParseFromString(serialized_payment_request) proto_request.pki_type = "Oh Mijoo" serialized_proto_request = proto_request.SerializeToString( deterministic=True) with self.assertRaises(InvalidSignatureException) as context: transact.verify_payment_request(serialized_proto_request) self.assertTrue( "Unable to verify signature." in str(context.exception))
def test_parsing_invalid_protobuf(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem, certificate_pem=self.certificate_pem) with self.assertRaises(DecodeException) as context: transact.verify_invoice_request(b"attack my heart") self.assertTrue( "Unable decode protobuf object." in str(context.exception))
def test_creating_invoice_request_without_signature(self): transact = transactid.TransactID( private_key_pem=self.private_key_pem, ) memo = "Stan LOONA" notification_url = "http://loonatheworld.com" serialized_invoice_request = transact.create_invoice_request( amount=24000, memo=memo, notification_url=notification_url) self.assertIsNotNone(transact.created_invoice_request) self.assertEqual(transact.created_invoice_request.pki_type, "none") self.assertEqual(transact.created_invoice_request.pki_data, b"") self.assertEqual(transact.created_invoice_request.memo, memo) self.assertEqual(transact.created_invoice_request.notification_url, notification_url)
def test_parsing_payment_ack(self): transact = transactid.TransactID(private_key_pem=self.private_key_pem) memo = "Eraser" transactions = [b"Dreamcatcher"] merchant_data = b"Siyeon" output_amount = 2400 output_script = b"https://www.youtube.com/watch?v=Q5ozyxgEcws" outputs = [(output_amount, output_script)] serialized_payment = transact.create_payment( transactions=transactions, refund_to=outputs, memo=memo, merchant_data=merchant_data, ) transact.verify_payment(serialized_payment) payment_ack_memo = "We really need a full cover of this song." serialized_payment_ack = transact.create_payment_ack( memo=payment_ack_memo) transact2 = transactid.TransactID(private_key_pem=self.private_key_pem) transact2.verify_payment_ack(serialized_payment_ack) verified_data = transact2.get_verified_payment_ack() self.assertEqual(transactions, verified_data["payment"]["transactions"]) self.assertEqual(memo, verified_data["payment"]["memo"]) self.assertEqual(merchant_data, verified_data["payment"]["merchant_data"]) self.assertEqual(outputs, [(verified_data["payment"]["refund_to"]["amount"], verified_data["payment"]["refund_to"]["script"])]) self.assertEqual(payment_ack_memo, verified_data["memo"])