use libsecp256k1 if available. abstract away ecc stuff. move symmetric crypto and hash functions to crypto.py
This commit is contained in:
@@ -13,6 +13,8 @@ from lib.wallet import TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT
|
||||
from plugins.trustedcoin import trustedcoin
|
||||
|
||||
from . import TestCaseForTestnet
|
||||
from . import SequentialTestCase
|
||||
from .test_bitcoin import needs_test_with_all_ecc_implementations
|
||||
|
||||
|
||||
class WalletIntegrityHelper:
|
||||
@@ -57,8 +59,9 @@ class WalletIntegrityHelper:
|
||||
|
||||
|
||||
# TODO passphrase/seed_extension
|
||||
class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
class TestWalletKeystoreAddressIntegrityForMainnet(SequentialTestCase):
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_electrum_seed_standard(self, mock_write):
|
||||
seed_words = 'cycle rocket west magnet parrot shuffle foot correct salt library feed song'
|
||||
@@ -78,6 +81,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '1NNkttn1YvVGdqBW4PR6zvc3Zx3H5owKRf')
|
||||
self.assertEqual(w.get_change_addresses()[0], '1KSezYMhAJMWqFbVFB2JshYg69UpmEXR4D')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_electrum_seed_segwit(self, mock_write):
|
||||
seed_words = 'bitter grass shiver impose acquire brush forget axis eager alone wine silver'
|
||||
@@ -97,6 +101,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], 'bc1q3g5tmkmlvxryhh843v4dz026avatc0zzr6h3af')
|
||||
self.assertEqual(w.get_change_addresses()[0], 'bc1qdy94n2q5qcp0kg7v9yzwe6wvfkhnvyzje7nx2p')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_electrum_seed_old(self, mock_write):
|
||||
seed_words = 'powerful random nobody notice nothing important anyway look away hidden message over'
|
||||
@@ -115,6 +120,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '1FJEEB8ihPMbzs2SkLmr37dHyRFzakqUmo')
|
||||
self.assertEqual(w.get_change_addresses()[0], '1KRW8pH6HFHZh889VDq6fEKvmrsmApwNfe')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_electrum_seed_2fa(self, mock_write):
|
||||
seed_words = 'kiss live scene rude gate step hip quarter bunker oxygen motor glove'
|
||||
@@ -148,6 +154,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '35L8XmCDoEBKeaWRjvmZvoZvhp8BXMMMPV')
|
||||
self.assertEqual(w.get_change_addresses()[0], '3PeZEcumRqHSPNN43hd4yskGEBdzXgY8Cy')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_bip39_seed_bip44_standard(self, mock_write):
|
||||
seed_words = 'treat dwarf wealth gasp brass outside high rent blood crowd make initial'
|
||||
@@ -166,6 +173,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '16j7Dqk3Z9DdTdBtHcCVLaNQy9MTgywUUo')
|
||||
self.assertEqual(w.get_change_addresses()[0], '1GG5bVeWgAp5XW7JLCphse14QaC4qiHyWn')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_bip39_seed_bip49_p2sh_segwit(self, mock_write):
|
||||
seed_words = 'treat dwarf wealth gasp brass outside high rent blood crowd make initial'
|
||||
@@ -184,6 +192,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '35ohQTdNykjkF1Mn9nAVEFjupyAtsPAK1W')
|
||||
self.assertEqual(w.get_change_addresses()[0], '3KaBTcviBLEJajTEMstsA2GWjYoPzPK7Y7')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_bip39_seed_bip84_native_segwit(self, mock_write):
|
||||
# test case from bip84
|
||||
@@ -203,6 +212,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu')
|
||||
self.assertEqual(w.get_change_addresses()[0], 'bc1q8c6fshw2dlwun7ekn9qwf37cu2rn755upcp6el')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_electrum_multisig_seed_standard(self, mock_write):
|
||||
seed_words = 'blast uniform dragon fiscal ensure vast young utility dinosaur abandon rookie sure'
|
||||
@@ -225,6 +235,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '32ji3QkAgXNz6oFoRfakyD3ys1XXiERQYN')
|
||||
self.assertEqual(w.get_change_addresses()[0], '36XWwEHrrVCLnhjK5MrVVGmUHghr9oWTN1')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_electrum_multisig_seed_segwit(self, mock_write):
|
||||
seed_words = 'snow nest raise royal more walk demise rotate smooth spirit canyon gun'
|
||||
@@ -247,6 +258,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], 'bc1qvzezdcv6vs5h45ugkavp896e0nde5c5lg5h0fwe2xyfhnpkxq6gq7pnwlc')
|
||||
self.assertEqual(w.get_change_addresses()[0], 'bc1qxqf840dqswcmu7a8v82fj6ej0msx08flvuy6kngr7axstjcaq6us9hrehd')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_bip39_multisig_seed_bip45_standard(self, mock_write):
|
||||
seed_words = 'treat dwarf wealth gasp brass outside high rent blood crowd make initial'
|
||||
@@ -269,6 +281,7 @@ class TestWalletKeystoreAddressIntegrityForMainnet(unittest.TestCase):
|
||||
self.assertEqual(w.get_receiving_addresses()[0], '3JPTQ2nitVxXBJ1yhMeDwH6q417UifE3bN')
|
||||
self.assertEqual(w.get_change_addresses()[0], '3FGyDuxgUDn2pSZe5xAJH1yUwSdhzDMyEE')
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_bip39_multisig_seed_p2sh_segwit(self, mock_write):
|
||||
# bip39 seed: pulse mixture jazz invite dune enrich minor weapon mosquito flight fly vapor
|
||||
@@ -332,6 +345,7 @@ class TestWalletSending(TestCaseForTestnet):
|
||||
ks = keystore.from_seed(seed_words, '', False)
|
||||
return WalletIntegrityHelper.create_standard_wallet(ks, gap_limit=2)
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_sending_between_p2wpkh_and_compressed_p2pkh(self, mock_write):
|
||||
wallet1 = self.create_standard_wallet_from_seed('bitter grass shiver impose acquire brush forget axis eager alone wine silver')
|
||||
@@ -382,6 +396,7 @@ class TestWalletSending(TestCaseForTestnet):
|
||||
self.assertEqual((0, funding_output_value - 250000 - 5000 + 100000, 0), wallet1.get_balance())
|
||||
self.assertEqual((0, 250000 - 5000 - 100000, 0), wallet2.get_balance())
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_sending_between_p2sh_2of3_and_uncompressed_p2pkh(self, mock_write):
|
||||
wallet1a = WalletIntegrityHelper.create_multisig_wallet(
|
||||
@@ -451,6 +466,7 @@ class TestWalletSending(TestCaseForTestnet):
|
||||
self.assertEqual((0, funding_output_value - 370000 - 5000 + 100000, 0), wallet1a.get_balance())
|
||||
self.assertEqual((0, 370000 - 5000 - 100000, 0), wallet2.get_balance())
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_sending_between_p2wsh_2of3_and_p2wsh_p2sh_2of2(self, mock_write):
|
||||
wallet1a = WalletIntegrityHelper.create_multisig_wallet(
|
||||
@@ -538,6 +554,7 @@ class TestWalletSending(TestCaseForTestnet):
|
||||
self.assertEqual((0, funding_output_value - 165000 - 5000 + 100000, 0), wallet1a.get_balance())
|
||||
self.assertEqual((0, 165000 - 5000 - 100000, 0), wallet2a.get_balance())
|
||||
|
||||
@needs_test_with_all_ecc_implementations
|
||||
@mock.patch.object(storage.WalletStorage, '_write')
|
||||
def test_sending_between_p2sh_1of2_and_p2wpkh_p2sh(self, mock_write):
|
||||
wallet1a = WalletIntegrityHelper.create_multisig_wallet(
|
||||
|
||||
Reference in New Issue
Block a user