You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.7 KiB

import shutil
import tempfile
import sys
import unittest
import os
10 years ago
import json
7 years ago
from io import StringIO
8 years ago
from lib.storage import WalletStorage, FINAL_SEED_VERSION
from . import SequentialTestCase
class FakeSynchronizer(object):
def __init__(self):
self.store = []
def add(self, address):
self.store.append(address)
class WalletTestCase(SequentialTestCase):
def setUp(self):
super(WalletTestCase, self).setUp()
self.user_dir = tempfile.mkdtemp()
self.wallet_path = os.path.join(self.user_dir, "somewallet")
self._saved_stdout = sys.stdout
self._stdout_buffer = StringIO()
sys.stdout = self._stdout_buffer
def tearDown(self):
super(WalletTestCase, self).tearDown()
shutil.rmtree(self.user_dir)
# Restore the "real" stdout
sys.stdout = self._saved_stdout
class TestWalletStorage(WalletTestCase):
7 years ago
def test_read_dictionary_from_file(self):
some_dict = {"a":"b", "c":"d"}
contents = json.dumps(some_dict)
with open(self.wallet_path, "w") as f:
contents = f.write(contents)
7 years ago
storage = WalletStorage(self.wallet_path, manual_upgrades=True)
self.assertEqual("b", storage.get("a"))
self.assertEqual("d", storage.get("c"))
7 years ago
def test_write_dictionary_to_file(self):
storage = WalletStorage(self.wallet_path)
some_dict = {
8 years ago
u"a": u"b",
u"c": u"d",
u"seed_version": FINAL_SEED_VERSION}
9 years ago
for key, value in some_dict.items():
storage.put(key, value)
storage.write()
contents = ""
with open(self.wallet_path, "r") as f:
contents = f.read()
10 years ago
self.assertEqual(some_dict, json.loads(contents))