diff --git a/extmod/modtrezorconfig/modtrezorconfig.c b/extmod/modtrezorconfig/modtrezorconfig.c index 85aad476d..17fb0b5df 100644 --- a/extmod/modtrezorconfig/modtrezorconfig.c +++ b/extmod/modtrezorconfig/modtrezorconfig.c @@ -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); diff --git a/src/tests/test_trezor.config.py b/src/tests/test_trezor.config.py new file mode 100644 index 000000000..d019b2a23 --- /dev/null +++ b/src/tests/test_trezor.config.py @@ -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() diff --git a/src/tests/test_trezor.debug.py b/src/tests/test_trezor.debug.py new file mode 100644 index 000000000..d1253ff6b --- /dev/null +++ b/src/tests/test_trezor.debug.py @@ -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() diff --git a/src/tests/test_trezor.utils.py b/src/tests/test_trezor.utils.py new file mode 100644 index 000000000..8a2e5b81c --- /dev/null +++ b/src/tests/test_trezor.utils.py @@ -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() diff --git a/src/trezor/config.py b/src/trezor/config.py index 1c09959f4..a342d040b 100644 --- a/src/trezor/config.py +++ b/src/trezor/config.py @@ -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() diff --git a/src/trezor/config.py.real b/src/trezor/config.py.real index 641ce9ce5..471f64435 100644 --- a/src/trezor/config.py.real +++ b/src/trezor/config.py.real @@ -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()