Files
pallectrum/lib/tests/test_wallet.py

72 lines
1.7 KiB
Python
Raw Normal View History

import shutil
import tempfile
import sys
import unittest
import os
2014-08-25 15:11:52 +02:00
import json
2017-10-24 14:04:16 +02:00
from io import StringIO
2017-01-22 21:25:24 +03:00
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):
2017-10-13 05:52:58 +02:00
def test_read_dictionary_from_file(self):
some_dict = {"a":"b", "c":"d"}
2017-03-06 08:44:38 +01:00
contents = json.dumps(some_dict)
with open(self.wallet_path, "w") as f:
contents = f.write(contents)
2017-10-13 05:52:58 +02:00
storage = WalletStorage(self.wallet_path, manual_upgrades=True)
self.assertEqual("b", storage.get("a"))
self.assertEqual("d", storage.get("c"))
2017-10-13 05:52:58 +02:00
def test_write_dictionary_to_file(self):
storage = WalletStorage(self.wallet_path)
2016-10-16 13:23:43 +02:00
some_dict = {
2016-10-16 22:17:52 +02:00
u"a": u"b",
u"c": u"d",
u"seed_version": FINAL_SEED_VERSION}
2015-09-11 20:17:20 +09:00
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()
2014-08-25 15:11:52 +02:00
self.assertEqual(some_dict, json.loads(contents))