Repository navigation
Expand file tree
/
Copy pathtest_dingo_wallet.py
More file actions
60 lines (50 loc) · 2.72 KB
/
Copy pathtest_dingo_wallet.py
File metadata and controls
60 lines (50 loc) · 2.72 KB
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
import unittest
from embit.transaction import Transaction, TransactionOutput
from dingo_wallet import address, create_phrase, key_path, payment_script, restore, sign_payment
class WalletTests(unittest.TestCase):
# Public BIP39 test mnemonic. Addresses cross-checked with an independent
# HMAC-SHA512 / OpenSSL secp256k1 / Base58Check implementation.
words = "abandon " * 11 + "about"
def test_address_vectors(self):
root = restore(self.words)
vectors = [
("mainnet", 0, False, "DBus3bamQjgJULBJtYXpEzDWQRwF5iwxgC"),
("mainnet", 1, False, "DAcDAtJRztxBHyA6D6h8du1HguyTR43Mas"),
("mainnet", 0, True, "D7ReBLrRv12mi9pYh5HtfFLTt1PSoeAa7e"),
("testnet", 0, False, "nZVmfmUtKPmskB9Ds4P9GUJy9eYFqPKHqH"),
("regtest", 0, False, "mkpZhYtJu2r87Js3pDiWJDmPte2NRZ8bJV"),
]
for network, index, change, expected in vectors:
with self.subTest(network=network, index=index, change=change):
self.assertEqual(address(root, network, index, change), expected)
def test_fresh_phrase_and_restoration(self):
first, second = create_phrase(), create_phrase()
self.assertEqual(len(first.split()), 12)
self.assertNotEqual(first, second)
self.assertEqual(address(restore(first), "mainnet"),
address(restore(" ".join(first.split())), "mainnet"))
def test_passphrase_normalization(self):
a = address(restore(self.words, "caf\u00e9"), "mainnet")
b = address(restore(self.words, "cafe\u0301"), "mainnet")
self.assertEqual(a, b)
self.assertNotEqual(a, address(restore(self.words), "mainnet"))
def test_invalid_checksum_and_index(self):
with self.assertRaises(ValueError):
restore("abandon " * 12)
for index in (-1, 2**31):
with self.assertRaises(ValueError):
key_path("mainnet", index)
def test_signing_checks(self):
root = restore(self.words)
sender = address(root, "regtest")
utxo = Transaction(vout=[TransactionOutput(10000, payment_script(sender, "regtest"))])
with self.assertRaisesRegex(ValueError, "selected network"):
sign_payment(root, "regtest", utxo, 0, address(root, "mainnet"), 500, 20)
with self.assertRaisesRegex(ValueError, "Insufficient funds"):
sign_payment(root, "regtest", utxo, 0, sender, 10000, 20)
with self.assertRaisesRegex(ValueError, "selected key"):
sign_payment(root, "regtest", utxo, 0, sender, 500, 20, receive_index=1)
tx = sign_payment(root, "regtest", utxo, 0, sender, 9980, 20)
self.assertEqual([o.value for o in tx.vout], [9980])
if __name__ == "__main__":
unittest.main()