1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

trezor.config: add wipe method

tests: add tests for config, debug, utils
This commit is contained in:
Pavol Rusnak 2016-11-06 12:38:33 +01:00
parent 998fb9fce6
commit 6891c3c463
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 82 additions and 1 deletions

View File

@ -74,9 +74,20 @@ STATIC mp_obj_t mod_TrezorConfig_Config_set(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorConfig_Config_set_obj, 4, 4, mod_TrezorConfig_Config_set);
/// def trezor.config.wipe() -> None:
/// '''
/// Erases the whole config (use with caution!)
/// '''
STATIC mp_obj_t mod_TrezorConfig_Config_wipe(mp_obj_t self) {
// TODO
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorConfig_Config_wipe_obj, mod_TrezorConfig_Config_wipe);
STATIC const mp_rom_map_elem_t mod_TrezorConfig_Config_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&mod_TrezorConfig_Config_get_obj) },
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&mod_TrezorConfig_Config_set_obj) },
{ MP_ROM_QSTR(MP_QSTR_wipe), MP_ROM_PTR(&mod_TrezorConfig_Config_wipe_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorConfig_Config_locals_dict, mod_TrezorConfig_Config_locals_dict_table);

View File

@ -0,0 +1,29 @@
import sys
sys.path.append('..')
sys.path.append('../lib')
import unittest
from trezor import config
from trezor.crypto import random
class TestConfig(unittest.TestCase):
def test_set_get(self):
config.wipe()
for _ in range(128):
appid, key = random.uniform(256), random.uniform(256)
value = random.bytes(128)
config.set(appid, key, value)
value2 = config.get(appid, key)
self.assertEqual(value, value2)
def test_get_default(self):
config.wipe()
for _ in range(128):
appid, key = random.uniform(256), random.uniform(256)
value = random.bytes(128)
value2 = config.get(appid, key, value)
self.assertEqual(value, value2)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,16 @@
import sys
sys.path.append('..')
sys.path.append('../lib')
import unittest
from trezor import debug
class TestDebug(unittest.TestCase):
def test_memaccess(self):
data = debug.memaccess(0, 1024)
# don't access contents (will segfault), just the length of the returned data
self.assertEqual(len(data), 1024)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,19 @@
import sys
sys.path.append('..')
sys.path.append('../lib')
import unittest
from trezor import utils
class TestUtils(unittest.TestCase):
def test_chunks(self):
c = list(utils.chunks(range(100), 7))
for i in range(15):
# need to check start, stop, step attrs until https://github.com/micropython/micropython/issues/2600 is resolved
self.assertEqual(c[i].start, i * 7)
self.assertEqual(c[i].stop, 100 if (i == 14) else (i + 1) * 7)
self.assertEqual(c[i].step, 1)
if __name__ == '__main__':
unittest.main()

View File

@ -41,4 +41,7 @@ def get(app_id, key, default=None):
def set(app_id, key, value):
_mock[(app_id << 8) | key] = value
_save()
return True
def wipe():
_mock = {}
_save()

View File

@ -8,3 +8,6 @@ def get(app, key, default=None):
def set(app, key, value):
return _config.set(app, key, value)
def wipe():
return _config.wipe()