forked from matja/bitcoin-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.sh
executable file
·292 lines (283 loc) · 11.1 KB
/
tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env bash
BITCOIN_TOOL="./bitcoin-tool"
check () {
if [ "$2" != "$3" ] ; then
echo "failed test $1"
echo "output : [$2]"
echo "expected : [$3]"
return 1
else
echo "pass $1"
fi
}
checkfail () {
if [ $? -eq 0 ] ; then
echo "failed test $1"
echo "expected to return >0 (error) but it returned 0 (success)"
return 1
else
echo "pass $1"
fi
}
# -----------------------------------------------------------------------------
TEST="1 - convert Casascius mini private key format to address"
NOTE="from example at https://en.bitcoin.it/wiki/Mini_private_key_format"
EXPECTED="1CciesT23BNionJeXrbxmjc7ywfiyM4oLW"
INPUT="S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy"
OUTPUT=$($BITCOIN_TOOL \
--input-type mini-private-key \
--input-format raw \
--input "${INPUT}" \
--output-type address \
--output-format base58check )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="2 - hex private key to compressed address"
EXPECTED="1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key \
--input-format hex \
--output-type address \
--output-format base58check \
--public-key-compression compressed \
--network bitcoin \
--input 0000000000000000000000000000000000000000000000000000000000000001 )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="3 - hex private key to uncompressed address"
EXPECTED="1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key \
--input-format hex \
--output-type address \
--output-format base58check \
--public-key-compression uncompressed \
--network bitcoin \
--input 0000000000000000000000000000000000000000000000000000000000000001 )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="4 - WIF uncompressed private key to address"
EXPECTED="16SK7HnxBMRxSpLhhdf8RYcqv8MPJiSF6Q"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input 5J1LYLWqNxJBTwdGAmzYnpkqqSuFu48fsHv8jgojFMV2Z8exk9L )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="6 - raw private key file, to uncompressed base58check WIF private key"
EXPECTED="5JZjfs5wJv1gNkJXCmYpyj6VxciqPkwmK4yHW8zMmPN1PW7Hk7F"
INPUT="62A87AD3272B41E67108FEA10C57BA6ED609F2F7A2264A83B690CD45707090D1"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key \
--input-format raw \
--input-file <(echo "${INPUT}"|xxd -r -p) \
--output-type private-key-wif \
--output-format base58check \
--public-key-compression uncompressed \
--network bitcoin \
)
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="7 - raw private key file, to compressed base58check WIF private key"
EXPECTED="KzXVLY4ni4yznz8LJwdUmNoGpUfebSxiakXRqcGAeuhihzaVe3Rz"
INPUT="62A87AD3272B41E67108FEA10C57BA6ED609F2F7A2264A83B690CD45707090D1"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key \
--input-format raw \
--input-file <(echo "${INPUT}"|xxd -r -p) \
--output-type private-key-wif \
--output-format base58check \
--public-key-compression compressed \
--network bitcoin \
)
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="8 - hex ripemd160 hash of public key, to base58check address"
EXPECTED="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
INPUT="62E907B15CBF27D5425399EBF6F0FB50EBB88F18"
OUTPUT=$($BITCOIN_TOOL \
--input-type public-key-rmd \
--input-format hex \
--input "${INPUT}" \
--output-type address \
--output-format base58check \
--network bitcoin \
)
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="9 - base58check address, to hex ripemd160 hash of public key"
EXPECTED="62e907b15cbf27d5425399ebf6f0fb50ebb88f18"
INPUT="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
OUTPUT=$($BITCOIN_TOOL \
--input-type address \
--input-format base58check \
--input "${INPUT}" \
--output-type public-key-rmd \
--output-format hex )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="10 - fix base58check address, by changing 1 character"
EXPECTED="1NaqSiNC4tfbyX42NGca24pBWvJ5L4Bd5J"
INPUT="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input 5J5sKGFLpZ4bQXEHiEmDp9Fuf7k36FqF3WoaNKHKDHnLfJYnkUR \
--fix-base58check )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="11 - convert 'Hash 160' to address"
EXPECTED="12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX"
INPUT="119b098e2e980a229e139a9ed01a469e518e6f26"
OUTPUT=$($BITCOIN_TOOL \
--input-type public-key-rmd \
--output-type address \
--input-format hex \
--network bitcoin \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="12 - convert 'SHA256' to address"
EXPECTED="1JNC98D5LZbrGHFR8shDwiqLPGfpg15BUM"
INPUT="904b8a01c68095a9e825d28082c04b75b1f56277648256985717620e8913b79b"
OUTPUT=$($BITCOIN_TOOL \
--input-type public-key-sha \
--output-type address \
--input-format hex \
--network bitcoin \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="13 - convert WIF private key to address bech32"
EXPECTED="bc1qhmc0vk4xzr37ayv7tlyhns7x4dk04tyvflk8ey"
INPUT="L3GzRAGwCqfSNFr6g1NQm7edn29DgAKZJ6owUBqYELpP6Kbim5kM"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--output-type address \
--input-format base58check \
--network bitcoin \
--output-format bech32 \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="14 - bech32 address, to hex ripemd160 hash of public key"
EXPECTED="bef0f65aa610e3ee919e5fc979c3c6ab6cfaac8c"
INPUT="bc1qhmc0vk4xzr37ayv7tlyhns7x4dk04tyvflk8ey"
OUTPUT=$($BITCOIN_TOOL \
--input-type address \
--input-format bech32 \
--input "${INPUT}" \
--output-type public-key-rmd \
--output-format hex )
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="15 - convert WIF private key to ripemd160 hash of public key"
EXPECTED="bef0f65aa610e3ee919e5fc979c3c6ab6cfaac8c"
INPUT="L3GzRAGwCqfSNFr6g1NQm7edn29DgAKZJ6owUBqYELpP6Kbim5kM"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--output-type public-key-rmd \
--input-format base58check \
--network bitcoin \
--output-format hex \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="16 - private key to uncompressed public key to bech32 should fail"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key \
--input-format hex \
--input 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff \
--public-key-compression uncompressed \
--network bitcoin \
--output-type address \
--output-format bech32)
checkfail "${TEST}" || exit 1
# -----------------------------------------------------------------------------
# Test various different network prefixes
# -----------------------------------------------------------------------------
TEST="prefix1 - WIF compressed private key to address (bitcoin)"
EXPECTED="1NFeCVtA3zuCUAmYheRvfyABnSZCHfrR3j"
INPUT="Kx4VFK8gXu4qBv73x9b1KFnWYqKekkprYyfX9QhFUMQhrTUooXKc"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="prefix2 - WIF compressed private key to address (bitcoin-testnet)"
EXPECTED="mxToLbBqPcSNnqPCSnrYjFv172TFPLjVNf"
INPUT="92Wn1EBgiwDNT8SC7WMZfcSk2y3mQkLUPAQtwMNYZQGAzCFUTdu"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="prefix3 - WIF compressed private key to address (litecoin)"
EXPECTED="LMzBLYQG2opHvMBihMQgJBboxunoj5pssC"
INPUT="6vVAeKejJRV5wgrAqtqi7eQsS4Zf79nkw8xuYntU3JwHCiexYaJ"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="prefix4 - WIF compressed private key to address (dogecoin)"
EXPECTED="DHEPGdnS46dHT79tkfm5DyhGAbQj4Xi8Ni"
INPUT="6KayMYAEQfFACQhZUzbBpFhvGzDWSmRtaY9NrPQGig9qVzRCzQf"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="prefix5 - WIF compressed private key to address (feathercoin)"
EXPECTED="6ggpjHf7iq2vdvq8HNfZo9XQSLeVfxezzX"
INPUT="5nU4VfsTK8B4ra3ytR4YqSWH8txuGxZUCuVSyKKtU9pdENQkpTi"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="prefix6 - WIF compressed private key to address (quarkcoin)"
EXPECTED="QUARKbonge6S9FyPKSa5HgxAsUercoU8CL"
INPUT="7EoLLiHnKZnbvsgfS91NHBS5r11N1G2RxGaepGNH4gRVeDYRgWB"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
TEST="prefix7 - WIF compressed private key to address (namecoin)"
EXPECTED="MyMfA2KMf1ppNGhvYKEqfSohKwGFyK1P5e"
INPUT="5KhxuVoUB2AUpyqKb9bgpp1468vpTaKc1Pcd48qNzgtdpWwknBE"
OUTPUT=$($BITCOIN_TOOL \
--input-type private-key-wif \
--input-format base58check \
--output-type address \
--output-format base58check \
--network namecoin \
--input "${INPUT}")
check "${TEST}" "${OUTPUT}" "${EXPECTED}" || exit 1
# -----------------------------------------------------------------------------
echo "all tests passed"