tests: wizard: imported addrs: validate each addr with "is_address()"
This was already done *in the GUIs*, but the backend should definitely do at least sanity-check-level validation like this.
This commit is contained in:
@@ -679,6 +679,11 @@ class NewWalletWizard(KeystoreWizard):
|
|||||||
addresses[addr] = {'type': txin_type, 'pubkey': pubkey}
|
addresses[addr] = {'type': txin_type, 'pubkey': pubkey}
|
||||||
elif 'address_list' in data:
|
elif 'address_list' in data:
|
||||||
for addr in data['address_list'].split():
|
for addr in data['address_list'].split():
|
||||||
|
assert isinstance(addr, str)
|
||||||
|
assert bitcoin.is_address(addr), f"expected bitcoin addr. got {addr[:5] + '..' + addr[-2:]}"
|
||||||
|
# note: we do not normalize addresses. :/
|
||||||
|
# In particular, bech32 addresses can be either all-lowercase or all-uppercase.
|
||||||
|
# TODO we should normalize them, but it only makes sense if we also do a walletDB-upgrade.
|
||||||
addresses[addr] = {}
|
addresses[addr] = {}
|
||||||
elif data['keystore_type'] in ['createseed', 'haveseed']:
|
elif data['keystore_type'] in ['createseed', 'haveseed']:
|
||||||
seed_extension = data['seed_extra_words'] if data['seed_extend'] else ''
|
seed_extension = data['seed_extra_words'] if data['seed_extend'] else ''
|
||||||
|
|||||||
@@ -789,11 +789,27 @@ class WalletWizardTestCase(WizardTestCase):
|
|||||||
{
|
{
|
||||||
"14gcRovpkCoGkCNBivQBvw7eso7eiNAbxG",
|
"14gcRovpkCoGkCNBivQBvw7eso7eiNAbxG",
|
||||||
"35ZqQJcBQMZ1rsv8aSuJ2wkC7ohUCQMJbT",
|
"35ZqQJcBQMZ1rsv8aSuJ2wkC7ohUCQMJbT",
|
||||||
"BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4",
|
"BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4", # TODO normalize to lowercase?
|
||||||
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y",
|
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def test_create_imported_wallet_from_addresses__invalid_input(self):
|
||||||
|
w = self._wizard_for(wallet_type='imported')
|
||||||
|
v = w._current
|
||||||
|
d = v.wizard_data
|
||||||
|
self.assertEqual('imported', v.view)
|
||||||
|
|
||||||
|
d.update({
|
||||||
|
'address_list':
|
||||||
|
'garbagegarbage\n'
|
||||||
|
'35ZqQJcBQMZ1rsv8aSuJ2wkC7ohUCQMJbT\n'
|
||||||
|
})
|
||||||
|
v = w.resolve_next(v.view, d)
|
||||||
|
with self.assertRaises(AssertionError) as ctx:
|
||||||
|
wallet = self._set_password_and_check_address(v=v, w=w, recv_addr=None)
|
||||||
|
self.assertTrue("expected bitcoin addr" in ctx.exception.args[0])
|
||||||
|
|
||||||
async def test_create_imported_wallet_from_wif_keys(self):
|
async def test_create_imported_wallet_from_wif_keys(self):
|
||||||
w = self._wizard_for(wallet_type='imported')
|
w = self._wizard_for(wallet_type='imported')
|
||||||
v = w._current
|
v = w._current
|
||||||
|
|||||||
Reference in New Issue
Block a user