commit e87aeea1da2941cdcaa7f19b46a9ed83a832846f
parent 957e2ad643f4e8fcf178bd35ccd7543a637c114e
Author: Jared Tobin <jared@jtobin.io>
Date: Thu, 27 Feb 2025 09:39:12 +0400
test: support ct wordlist
Diffstat:
2 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/test/Main.hs b/test/Main.hs
@@ -11,6 +11,10 @@ import Test.Tasty
import Test.Tasty.HUnit
import qualified Vectors as V
+data Wordlist =
+ English
+ | ChineseTraditional
+
main :: IO ()
main = do
vectors_bip39 <- TIO.readFile "etc/vectors.json"
@@ -24,23 +28,31 @@ main = do
bip39_tests :: V.Vectors -> TestTree
bip39_tests V.Vectors {..} =
- testGroup "bip39 vectors" $
- fmap execute v_wordlist
-
-execute :: V.Bip39Test -> TestTree
-execute V.Bip39Test {..} = do
- let entr = bt_entropy
- mnem = bt_mnemonic
- seed = bt_seed
- xprv = bt_xprv
- BIP39.Mnemonic out_mnem = BIP39.mnemonic entr
- out_seed = BIP39.seed out_mnem "TREZOR"
- out_xprv = case BIP32.master out_seed of
- Just hd -> BIP32.xprv hd
- Nothing -> error "bang (bip32)"
- t_msg = "mnemonic " <> show mnem
- testGroup t_msg [
- testCase "mnemonic" $ assertEqual mempty mnem out_mnem
- , testCase "seed" $ assertEqual mempty seed out_seed
- , testCase "xprv" $ assertEqual mempty xprv out_xprv
+ testGroup "bip39 vectors" [
+ testGroup "english"
+ (fmap (execute English) v_english)
+ , testGroup "chinese_traditional"
+ (fmap (execute ChineseTraditional) v_chinese_traditional)
]
+
+execute :: Wordlist -> V.Bip39Test -> TestTree
+execute wlist V.Bip39Test {..} = do
+ let entr = bt_entropy
+ mnem = bt_mnemonic
+ seed = bt_seed
+ xprv = bt_xprv
+ BIP39.Mnemonic out_mnem = BIP39._mnemonic wl entr
+ out_seed = BIP39.seed out_mnem "TREZOR"
+ out_xprv = case BIP32.master out_seed of
+ Just hd -> BIP32.xprv hd
+ Nothing -> error "bang (bip32)"
+ t_msg = "mnemonic " <> show mnem
+ testGroup t_msg [
+ testCase "mnemonic" $ assertEqual mempty mnem out_mnem
+ , testCase "seed" $ assertEqual mempty seed out_seed
+ , testCase "xprv" $ assertEqual mempty xprv out_xprv
+ ]
+ where
+ wl = case wlist of
+ English -> BIP39.english
+ ChineseTraditional -> BIP39.chinese_traditional
diff --git a/test/Vectors.hs b/test/Vectors.hs
@@ -15,12 +15,14 @@ import qualified Data.Text.Encoding as TE
import qualified Data.Vector as V
data Vectors = Vectors {
- v_wordlist :: ![Bip39Test]
+ v_english :: ![Bip39Test]
+ , v_chinese_traditional :: ![Bip39Test]
} deriving Show
instance A.FromJSON Vectors where
parseJSON = A.withObject "Vectors" $ \m -> Vectors
<$> m .: "english"
+ <*> m .: "chinese_traditional"
data Bip39Test = Bip39Test {
bt_entropy :: !BS.ByteString