| 1 | import encoding.base58 |
| 2 | import encoding.hex |
| 3 | |
| 4 | fn test_encode() { |
| 5 | for input, expected in { |
| 6 | '': '' |
| 7 | '6263': '2PMCRQ' |
| 8 | 'hello world': 'StV1DL6CwTryKyV' |
| 9 | '\x00\x00hello world': '11StV1DL6CwTryKyV' |
| 10 | } { |
| 11 | output := base58.encode(input) |
| 12 | println('> input: `${input}` | ${input.hex()} | => output: `${output}`') |
| 13 | assert output == expected |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | fn test_encode_int() { |
| 18 | for input, expected in { |
| 19 | 0x6263: '8VG' |
| 20 | 0x61: '2g' |
| 21 | 0x626262: 'a3gV' |
| 22 | 0x636363: 'aPEr' |
| 23 | } { |
| 24 | output := base58.encode_int(input)! |
| 25 | println('> input: 0x${input:x} | => output: `${output}`') |
| 26 | assert output == expected |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | fn test_decode() { |
| 31 | for output, expected in { |
| 32 | 'USm3fpXnKG5EUBx2ndxBDMPVciP5hGey2Jh4NDv6gmeo1LkMeiKrLJUUBk6Z': 'The quick brown fox jumps over the lazy dog.' |
| 33 | '11StV1DL6CwTryKyV': '\x00\x00hello world' |
| 34 | '2NEpo7TZRRrLZSi2U': 'Hello World!' |
| 35 | '14cxpo3MBCYYWCgF74SWTdcmxipnGUsPw3': hex.decode('0027b5891b01da2db74cde1689a97a2acbe23d5fb1c0205bf6')!.bytestr() |
| 36 | '3vQB7B6MrGQZaxCuFg4oh': hex.decode('68656c6c6f20776f726c64bc62d4b8')!.bytestr() |
| 37 | } { |
| 38 | input := base58.decode(output)! |
| 39 | println('> output: `${output}` | decoded input: `${input}` | bytes: ${input.hex()}') |
| 40 | assert input.hex() == expected.hex() |
| 41 | } |
| 42 | } |
| 43 | |