From b09f0eaf4e4e6cd1f2c7412a6c65f87536fd20f6 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 15 Nov 2016 11:57:18 +0100 Subject: [PATCH] tests: add test for apps.common.coins --- src/apps/common/coins.py | 6 +++--- tests/test_apps.common.coins.py | 36 ++++++++++++++++++++++++++++++++ tests/test_apps.common.signtx.py | 1 - 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/test_apps.common.coins.py diff --git a/src/apps/common/coins.py b/src/apps/common/coins.py index 95096af3..5b3fd007 100644 --- a/src/apps/common/coins.py +++ b/src/apps/common/coins.py @@ -90,18 +90,18 @@ def by_shortcut(shortcut): for c in COINS: if c.coin_shortcut == shortcut: return c - raise Exception('Unknown coin shortcut "%s"' % shortcut) + raise ValueError('Unknown coin shortcut "%s"' % shortcut) def by_name(name): for c in COINS: if c.coin_name == name: return c - raise Exception('Unknown coin name "%s"' % name) + raise ValueError('Unknown coin name "%s"' % name) def by_address_type(version): for c in COINS: if c.address_type == version: return c - raise Exception('Unknown coin address type %d' % version) + raise ValueError('Unknown coin address type %d' % version) diff --git a/tests/test_apps.common.coins.py b/tests/test_apps.common.coins.py new file mode 100644 index 00000000..fa2cf7a8 --- /dev/null +++ b/tests/test_apps.common.coins.py @@ -0,0 +1,36 @@ +from common import * + +from apps.common import coins + +class TestCoins(unittest.TestCase): + + def test_coins(self): + ref = [ + ('BTC', 'Bitcoin', 0), + ('TEST', 'Testnet', 111), + ('NMC', 'Namecoin', 52), + ('LTC', 'Litecoin', 48), + ('DOGE', 'Dogecoin', 30), + ('DASH', 'Dash', 76), + ('ZEC', 'Zcash', 7352), + ('TAZ', 'Zcash Testnet', 7461), + ] + for s, n, a in ref: + c1 = coins.by_shortcut(s) + c2 = coins.by_name(n) + c3 = coins.by_address_type(a) + self.assertEqual(c1, c2) + self.assertEqual(c1, c3) + self.assertEqual(c2, c3) + + def test_failure(self): + with self.assertRaises(ValueError): + coins.by_shortcut('XXX') + with self.assertRaises(ValueError): + coins.by_name('XXXXX') + with self.assertRaises(ValueError): + coins.by_address_type(1234) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_apps.common.signtx.py b/tests/test_apps.common.signtx.py index 67e0f307..2417945a 100644 --- a/tests/test_apps.common.signtx.py +++ b/tests/test_apps.common.signtx.py @@ -17,7 +17,6 @@ from trezor.messages import OutputScriptType from apps.common import coins from apps.common import signtx - class TestSignTx(unittest.TestCase): # pylint: disable=C0301