-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·104 lines (84 loc) · 4.06 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
"""
OpenAlias.py - A Python tool for easily querying OpenAlias records
Copyright (c) 2023 Privex Inc. ( https://www.privex.io )
Copyright::
+===================================================+
| © 2023 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| OpenAlias.py - A python OpenAlias Client |
| License: X11/MIT |
| |
| https://github.com/Privex/openalias-py |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
"""
import unittest
from os.path import abspath, dirname, join
from openalias import CoinResult, doh_lookup, dns_lookup
from openalias import openalias
BASE_DIR = dirname(abspath(__file__))
RECORD_1 = 'oa1:ltc recipient_address=MDRRb9pdLs6nXQ91VNfJEN68ohHSwWvscv; recipient_name=Privex Donations;'
RECORD_2 = 'oa1:bch recipient_address=bitcoincash:qr6ss5pnnx9wad32j7lhulwp6k6we60gyuzsqc6pyj; recipient_name=Privex Donations;'
class TestConvertRecord(unittest.TestCase):
def test_record_1(self):
"""Test converting a simple OA record into a :class:`.CoinResult`"""
c = CoinResult.read_record(RECORD_1)
self.assertEqual(c.coin, 'ltc')
self.assertEqual(c.recipient_address, 'MDRRb9pdLs6nXQ91VNfJEN68ohHSwWvscv')
self.assertEqual(c.recipient_name, 'Privex Donations')
def test_record_2(self):
"""Test converting an OA record with a BCH formatted address"""
c = CoinResult.read_record(RECORD_2)
self.assertEqual(c.coin, 'bch')
self.assertEqual(c.recipient_address, 'bitcoincash:qr6ss5pnnx9wad32j7lhulwp6k6we60gyuzsqc6pyj')
self.assertEqual(c.recipient_name, 'Privex Donations')
def test_multi_record(self):
"""Test converting multiple OA records at once using read_records"""
cs = CoinResult.read_records(RECORD_1, RECORD_2)
self.assertEqual(len(cs), 2)
self.assertIsInstance(cs, list)
self.assertEqual(cs[0].coin, 'ltc')
self.assertEqual(cs[0].recipient_address, 'MDRRb9pdLs6nXQ91VNfJEN68ohHSwWvscv')
self.assertEqual(cs[0].recipient_name, 'Privex Donations')
self.assertEqual(cs[1].coin, 'bch')
self.assertEqual(cs[1].recipient_address, 'bitcoincash:qr6ss5pnnx9wad32j7lhulwp6k6we60gyuzsqc6pyj')
self.assertEqual(cs[1].recipient_name, 'Privex Donations')
class TestDNSLookup(unittest.TestCase):
def test_doh_lookup(self):
"""Test a simple DoH lookup"""
l = doh_lookup('privex.io')
self.assertGreater(len(l), 0)
self.assertIsInstance(l, list)
self.assertIsInstance(l[0], str)
def test_dns_lookup_udp(self):
"""Test a simple UDP DNS lookup"""
l = dns_lookup('privex.io', proto='udp')
self.assertGreater(len(l), 0)
self.assertIsInstance(l, list)
self.assertIsInstance(l[0], str)
def test_dns_lookup_tcp(self):
"""Test a simple TCP DNS lookup"""
l = dns_lookup('privex.io', proto='tcp')
self.assertGreater(len(l), 0)
self.assertIsInstance(l, list)
self.assertIsInstance(l[0], str)
class TestOACore(unittest.TestCase):
def test_coin_lookup_dns(self):
l = dns_lookup('privex.io')
res = openalias.lookup_coin(l, 'xmr')
self.assertIsInstance(res, CoinResult)
self.assertEqual(res.coin, 'xmr')
def test_coin_lookup_doh(self):
l = doh_lookup('privex.io')
res = openalias.lookup_coin(l, 'xmr')
self.assertIsInstance(res, CoinResult)
self.assertEqual(res.coin, 'xmr')
if __name__ == '__main__':
unittest.main()