v
Зеркало из https://github.com/vlang/v
1import encoding.base58
2import encoding.hex
3
4fn test_encode() {
5for input, expected in {
6'': ''
7'6263': '2PMCRQ'
8'hello world': 'StV1DL6CwTryKyV'
9'\x00\x00hello world': '11StV1DL6CwTryKyV'
10} {
11output := base58.encode(input)
12println('> input: `${input}` | ${input.bytes().hex()} | => output: `${output}`')
13assert output == expected
14}
15}
16
17fn test_encode_int() {
18for input, expected in {
190x6263: '8VG'
200x61: '2g'
210x626262: 'a3gV'
220x636363: 'aPEr'
23} {
24output := base58.encode_int(input)!
25println('> input: 0x${input:x} | => output: `${output}`')
26assert output == expected
27}
28}
29
30fn test_decode() {
31for 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} {
38input := base58.decode(output)!
39println('> output: `${output}` | decoded input: `${input}` | bytes: ${input.bytes().hex()}')
40assert input.bytes().hex() == expected.bytes().hex()
41}
42}
43