v

Зеркало из https://github.com/vlang/v
Форк
0
/
base58_usage_test.v 
42 строки · 1.4 Кб
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.bytes().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.bytes().hex()}')
40
		assert input.bytes().hex() == expected.bytes().hex()
41
	}
42
}
43

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.