Ejemplo n.º 1
0
    def addressdb_tester(self, wallet_type, the_address_limit,
                         correct_mnemonic, **kwds):
        assert the_address_limit > 1

        addressdb = AddressSet.fromfile(open(btcrseed.ADDRESSDB_DEF_FILENAME,
                                             "rb"),
                                        preload=False)
        wallet = wallet_type.create_from_params(
            hash160s=addressdb, address_limit=the_address_limit)

        # Convert the mnemonic string into a mnemonic_ids_guess
        wallet.config_mnemonic(correct_mnemonic, **kwds)
        correct_mnemonic_ids = btcrseed.mnemonic_ids_guess

        # Creates wrong mnemonic id guesses
        wrong_mnemonic_iter = wallet.performance_iterator()

        self.assertEqual(
            wallet.return_verified_password_or_false(
                (wrong_mnemonic_iter.next(), wrong_mnemonic_iter.next())),
            (False, 2))
        self.assertEqual(
            wallet.return_verified_password_or_false(
                (wrong_mnemonic_iter.next(), correct_mnemonic_ids,
                 wrong_mnemonic_iter.next())), (correct_mnemonic_ids, 2))

        # Make sure the address_limit is respected (note the "the_address_limit-1" below)
        wallet = wallet_type.create_from_params(
            hash160s=addressdb, address_limit=the_address_limit - 1)
        wallet.config_mnemonic(correct_mnemonic, **kwds)
        self.assertEqual(
            wallet.return_verified_password_or_false((correct_mnemonic_ids, )),
            (False, 1))
Ejemplo n.º 2
0
    def addressdb_tester(self, wallet_type, the_address_limit, correct_mnemonic, test_path, test_address_db, **kwds):
        assert the_address_limit > 1

        #Check to see if the AddressDB exists (and if not, skip)
        if not os.path.isfile("./btcrecover/test/test-addressdbs/" + test_address_db):
            raise unittest.SkipTest("requires ./btcrecover/test/test-addressdbs/" + test_address_db)

        # Test Basic BIP44 AddressDB Search
        addressdb = AddressSet.fromfile(open("./btcrecover/test/test-addressdbs/" + test_address_db, "rb"), preload=False)
        wallet = wallet_type.create_from_params(hash160s=addressdb, address_limit=the_address_limit, path=test_path)

        # Convert the mnemonic string into a mnemonic_ids_guess
        wallet.config_mnemonic(correct_mnemonic, **kwds)
        correct_mnemonic_ids = btcrseed.mnemonic_ids_guess

        # Creates wrong mnemonic id guesses
        wrong_mnemonic_iter = wallet.performance_iterator()

        self.assertEqual(wallet.return_verified_password_or_false(
            (wrong_mnemonic_iter.next(), wrong_mnemonic_iter.next())), (False, 2))
        self.assertEqual(wallet.return_verified_password_or_false(
            (wrong_mnemonic_iter.next(), correct_mnemonic_ids, wrong_mnemonic_iter.next())), (correct_mnemonic_ids, 2))

        # Make sure the address_limit is respected (note the "the_address_limit-1" below)
        wallet = wallet_type.create_from_params(hash160s=addressdb, address_limit=the_address_limit-1, path=test_path)
        wallet.config_mnemonic(correct_mnemonic, **kwds)
        self.assertEqual(wallet.return_verified_password_or_false(
            (correct_mnemonic_ids,)), (False, 1))
Ejemplo n.º 3
0
 def test_file_update(self):
     aset = AddressSet(self.TABLE_LEN)
     dbfile = tempfile.NamedTemporaryFile(delete=False)
     try:
         aset.tofile(dbfile)
         dbfile.seek(0)
         aset = AddressSet.fromfile(dbfile, mmap_access=mmap.ACCESS_WRITE)
         addr = "".join(chr(b) for b in xrange(20))
         aset.add(addr)
         aset.close()
         self.assertTrue(dbfile.closed)
         dbfile = open(dbfile.name, "rb")
         aset = AddressSet.fromfile(dbfile)
         self.assertIn(addr, aset)
         self.assertEqual(len(aset), 1)
     finally:
         aset.close()
         dbfile.close()
         os.remove(dbfile.name)
Ejemplo n.º 4
0
 def test_file(self):
     aset = AddressSet(self.TABLE_LEN)
     addr = "".join(chr(b) for b in xrange(20))
     aset.add(addr)
     dbfile = tempfile.TemporaryFile()
     aset.tofile(dbfile)
     dbfile.seek(0)
     aset = AddressSet.fromfile(dbfile)
     self.assertTrue(dbfile.closed)  # should be closed by AddressSet in read-only mode
     self.assertIn(addr, aset)
     self.assertEqual(len(aset), 1)
Ejemplo n.º 5
0
 def test_pickle_mmap(self):
     aset = AddressSet(self.TABLE_LEN)
     addr = "".join(chr(b) for b in xrange(20))
     aset.add(addr)
     dbfile = tempfile.NamedTemporaryFile(delete=False)
     try:
         aset.tofile(dbfile)
         dbfile.seek(0)
         aset = AddressSet.fromfile(dbfile)  # now it's an mmap
         pickled = pickle.dumps(aset, protocol=pickle.HIGHEST_PROTOCOL)
         aset.close()  # also closes the file
         aset = pickle.loads(pickled)
         self.assertIn(addr, aset)
         self.assertEqual(len(aset), 1)
     finally:
         aset.close()
         dbfile.close()
         os.remove(dbfile.name)