()
| 1 | import assert from 'assert'; |
| 2 | import ccxt from '../../../ccxt.js'; |
| 3 | function testBinaryToBase16() { |
| 4 | const exchange = new ccxt.Exchange({ |
| 5 | 'id': 'sampleexchange', |
| 6 | }); |
| 7 | assert(exchange.parseNumber(undefined) === undefined, "GO_WORKAROUND"); |
| 8 | // @SKIP_START_GO |
| 9 | // Test 1: simple known bytes |
| 10 | // 'ff' => [255] |
| 11 | const binary1 = exchange.base16ToBinary('ff'); |
| 12 | assert(exchange.binaryToBase16(binary1) === 'ff'); |
| 13 | // Test 2: all zeros |
| 14 | // '0000' => [0, 0] |
| 15 | const binary2 = exchange.base16ToBinary('0000'); |
| 16 | assert(exchange.binaryToBase16(binary2) === '0000'); |
| 17 | // Test 3: ascending bytes 01 02 03 04 |
| 18 | const binary3 = exchange.base16ToBinary('01020304'); |
| 19 | assert(exchange.binaryToBase16(binary3) === '01020304'); |
| 20 | // Test 4: single byte zero |
| 21 | const binary4 = exchange.base16ToBinary('00'); |
| 22 | assert(exchange.binaryToBase16(binary4) === '00'); |
| 23 | // Test 5: single byte max |
| 24 | const binary5 = exchange.base16ToBinary('ff'); |
| 25 | assert(exchange.binaryLength(binary5) === 1); |
| 26 | assert(exchange.isBinaryMessage(binary5)); |
| 27 | // Test 6: 8 bytes (like a timestamp encoding) |
| 28 | // 00 00 00 00 49 96 02 d2 = 1234567890 |
| 29 | const binary6 = exchange.base16ToBinary('00000000499602d2'); |
| 30 | assert(exchange.binaryToBase16(binary6) === '00000000499602d2'); |
| 31 | assert(exchange.binaryLength(binary6) === 8); |
| 32 | // Test 7: roundtrip with deadbeef |
| 33 | const binary7 = exchange.base16ToBinary('deadbeef'); |
| 34 | assert(exchange.binaryToBase16(binary7) === 'deadbeef'); |
| 35 | assert(exchange.binaryLength(binary7) === 4); |
| 36 | // Test 8: roundtrip binaryToBase16 -> base16ToBinary |
| 37 | const hex8 = 'cafebabe'; |
| 38 | const binary8 = exchange.base16ToBinary(hex8); |
| 39 | assert(exchange.binaryToBase16(binary8) === hex8); |
| 40 | // @SKIP_END_GO |
| 41 | } |
| 42 | export default testBinaryToBase16; |
no test coverage detected
searching dependent graphs…