mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 02:58:57 +00:00
trezor.config: add wipe method
tests: add tests for config, debug, utils
This commit is contained in:
parent
998fb9fce6
commit
6891c3c463
@ -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);
|
||||
|
||||
|
29
src/tests/test_trezor.config.py
Normal file
29
src/tests/test_trezor.config.py
Normal 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()
|
16
src/tests/test_trezor.debug.py
Normal file
16
src/tests/test_trezor.debug.py
Normal 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()
|
19
src/tests/test_trezor.utils.py
Normal file
19
src/tests/test_trezor.utils.py
Normal 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()
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user