diff --git a/bitcoinlib/wallets.py b/bitcoinlib/wallets.py index bc94a02d..23c43ec6 100644 --- a/bitcoinlib/wallets.py +++ b/bitcoinlib/wallets.py @@ -2508,16 +2508,17 @@ def account(self, account_id): key_id = qr.id return self.key(key_id) - def accounts(self, network=DEFAULT_NETWORK): + def accounts(self, network=None): """ Get list of accounts for this wallet - :param network: Network name filter. Default filter is DEFAULT_NETWORK + :param network: Network name filter. Default filter is network of first main key :type network: str :return list of integers: List of accounts IDs """ + network, _, _ = self._get_account_defaults(network) if self.multisig and self.cosigner: if self.cosigner_id is None: raise WalletError("Missing Cosigner ID value for this wallet, cannot fetch account ID") diff --git a/tests/test_wallets.py b/tests/test_wallets.py index f0833b28..dcc1fb5b 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -2617,6 +2617,13 @@ def test_wallet_normalize_path(self): self.assertRaisesRegexp(WalletError, 'Could not parse path. Index is empty.', normalize_path, "m/44h/0p/100H//1201") + def test_wallet_accounts(self): + w = Wallet.create('test_litecoin_accounts', network='litecoin', account_id=1111, db_uri=self.DATABASE_URI) + w.new_account(account_id=2222) + w.new_account(account_id=5555, network='testnet') + self.assertListEqual(w.accounts(), [1111, 2222]) + self.assertListEqual(w.accounts(network='testnet'), [5555]) + @parameterized_class(*params) class TestWalletReadonlyAddress(TestWalletMixin, unittest.TestCase):