| 15 | import ccxt.async_support as ccxt # noqa: F402 |
| 16 | |
| 17 | def test_uuid(): |
| 18 | exchange = ccxt.Exchange({ |
| 19 | 'id': 'sampleexchange', |
| 20 | }) |
| 21 | # uuid() - standard UUID v4: xxxxxxxx-xxxx-4xxx-[89ab]xxx-xxxxxxxxxxxx |
| 22 | id1 = exchange.uuid() # need type for .length understanding |
| 23 | id2 = exchange.uuid() |
| 24 | assert id1 is not None, 'uuid 1 must return a value' |
| 25 | assert id2 is not None, 'uuid 2 must return a value' |
| 26 | assert id1 != id2, 'uuid() must return unique values on each call' |
| 27 | assert str(id1) == id1, 'uuid() must return a string' |
| 28 | assert str(id2) == id2, 'uuid() must return a string' |
| 29 | assert len(id1) == 36, 'uuid() must return a 36-character string, returned id1: ' + id1 |
| 30 | assert len(id2) == 36, 'uuid() must return a 36-character string, returned id2: ' + id2 |
| 31 | assert id1.find('-') == 8, 'uuid() must have dash, returned id1: ' + id1 |
| 32 | # uuid16() - 16-char hex string |
| 33 | id16a = exchange.uuid16() |
| 34 | id16b = exchange.uuid16() |
| 35 | assert id16a is not None, 'uuid16 1 must return a value' |
| 36 | assert id16b is not None, 'uuid16 2 must return a value' |
| 37 | assert id16a != id16b, 'uuid16() must return unique values on each call, returned id16a: ' + id16a + ', id16b: ' + id16b |
| 38 | assert str(id16a) == id16a, 'uuid16() must return a string, returned id16a: ' + id16a |
| 39 | assert str(id16b) == id16b, 'uuid16() must return a string, returned id16b: ' + id16b |
| 40 | assert len(id16a) == 16, 'uuid16() must return a 16-character string, returned id16a: ' + id16a |
| 41 | assert len(id16b) == 16, 'uuid16() must return a 16-character string, returned id16b: ' + id16b |
| 42 | # uuid22() - 22-char hex string |
| 43 | id22a = exchange.uuid22() |
| 44 | id22b = exchange.uuid22() |
| 45 | assert id22a is not None, 'uuid22 1 must return a value' |
| 46 | assert id22b is not None, 'uuid22 2 must return a value' |
| 47 | assert id22a != id22b, 'uuid22() must return unique values on each call' |
| 48 | assert str(id22a) == id22a, 'uuid22() must return a string, returned id22a: ' + id22a |
| 49 | assert str(id22b) == id22b, 'uuid22() must return a string, returned id22b: ' + id22b |
| 50 | assert len(id22a) == 22, 'uuid22() must return a 22-character string, returned id22a: ' + id22a |
| 51 | assert len(id22b) == 22, 'uuid22() must return a 22-character string, returned id22b: ' + id22b |