def test_generate_partial_mnemonic(): r = rng.LCG() for length in mnemonic.allowed_mnemonic_lengths: for _ in range(100): partial_mnemonic = mnemonic.generate_partial_mnemonic(length - 1, rng=r) assert len(partial_mnemonic) == length - 1 for word in partial_mnemonic: assert word in english2039.word_dict.values()
def test_generate_mnemonic(): r = rng.LCG() for length in mnemonic.allowed_mnemonic_lengths: for _ in range(100): test_mnemonic = mnemonic.generate_mnemonic(length, rng=r) assert len(test_mnemonic) == length for word in test_mnemonic: assert word in english2039.word_dict.values() assert checksum.check_mnemonic_checksum(test_mnemonic)
def test_secret_to_points(): r = rng.LCG() prime = 2039 for _ in range(100): secret = r.random_int() % prime points = shamir.secret_to_points(prime, secret, rng=r) assert secret == shamir.points_to_secret(prime, points[0], points[1]) assert secret == shamir.points_to_secret(prime, points[0], points[2]) assert secret == shamir.points_to_secret(prime, points[1], points[2])
def test_mnemonic_to_bits(): r = rng.LCG() for length in mnemonic.allowed_mnemonic_lengths: for _ in range(100): test_mnemonic = mnemonic.generate_mnemonic(length, rng=r) bitstring = checksum.mnemonic_to_bits(test_mnemonic) assert len(bitstring) == length * 11 assert int(bitstring, 2) > -1 for u, v in zip(test_mnemonic, checksum.bits_to_mnemonic(bitstring)): assert u == v
def test_api(): r = rng.LCG() for length in mnemonic.allowed_mnemonic_lengths: for _ in range(100): test_mnemonic = mnemonic.generate_mnemonic(length, rng=r) shares = api.mnemonic_to_shares(test_mnemonic, rng=r) for u, v in zip( test_mnemonic, api.shares_to_mnemonic(share1=shares['share1'], share2=shares['share2'])): assert u == v for u, v in zip( test_mnemonic, api.shares_to_mnemonic(share1=shares['share1'], share3=shares['share3'])): assert u == v for u, v in zip( test_mnemonic, api.shares_to_mnemonic(share2=shares['share2'], share3=shares['share3'])): assert u == v
def test_lcg(): r = rng.LCG() for _ in range(100): assert r.random_int() % 1 == 0