11import time
2+
23import bittensor_drand as btcr
34
45
@@ -28,33 +29,35 @@ def test_encrypt_and_decrypt():
2829 assert decrypted is not None
2930 assert decrypted == data
3031
32+
3133def test_encrypt_at_round_and_decrypt ():
3234 data = b"test data for specific round"
33-
35+
3436 # Get a round that's already revealed (in the past)
3537 current_round = btcr .get_latest_round ()
3638 past_round = current_round - 100 # Use a round from the past
37-
39+
3840 # Encrypt at specific round
3941 encrypted , returned_round = btcr .encrypt_at_round (data , past_round )
4042 assert isinstance (encrypted , bytes )
4143 assert returned_round == past_round
42-
44+
4345 # Should be able to decrypt immediately since the round is in the past
4446 decrypted = btcr .decrypt (encrypted )
4547 assert decrypted is not None
4648 assert decrypted == data
47-
49+
4850 # Test with future round
4951 future_round = current_round + 1000
5052 encrypted_future , returned_future_round = btcr .encrypt_at_round (data , future_round )
5153 assert isinstance (encrypted_future , bytes )
5254 assert returned_future_round == future_round
53-
55+
5456 # Attempting to decrypt future round should fail or return None
5557 decrypted_future = btcr .decrypt (encrypted_future , no_errors = True )
5658 assert decrypted_future is None # Can't decrypt yet
5759
60+
5861def test_get_signature_for_round ():
5962 # Get a past round that's already revealed
6063 current_round = btcr .get_latest_round ()
@@ -65,7 +68,7 @@ def test_get_signature_for_round():
6568 assert isinstance (signature , str )
6669 assert len (signature ) > 0
6770 # Drand signatures are hex-encoded, so should only contain hex characters
68- assert all (c in ' 0123456789abcdef' for c in signature .lower ())
71+ assert all (c in " 0123456789abcdef" for c in signature .lower ())
6972
7073
7174def test_decrypt_with_signature ():
@@ -104,9 +107,7 @@ def test_batch_decryption_optimization():
104107 past_round = current_round - 100
105108
106109 # Encrypt all messages at the same round
107- encrypted_messages = [
108- btcr .encrypt_at_round (msg , past_round )[0 ] for msg in messages
109- ]
110+ encrypted_messages = [btcr .encrypt_at_round (msg , past_round )[0 ] for msg in messages ]
110111
111112 # Fetch signature once
112113 signature = btcr .get_signature_for_round (past_round )
@@ -118,8 +119,11 @@ def test_batch_decryption_optimization():
118119
119120 # Verify all messages decrypted correctly
120121 assert decrypted_messages == messages
121- print (f"Successfully decrypted { len (messages )} messages with a single signature fetch!" )
122-
122+ print (
123+ f"Successfully decrypted { len (messages )} messages with a single signature fetch!"
124+ )
125+
126+
123127def test_get_encrypted_commitment ():
124128 encrypted , round_ = btcr .get_encrypted_commitment ("my_commitment" , 1 )
125129 assert isinstance (encrypted , bytes )
@@ -146,7 +150,7 @@ def test_get_encrypted_commit():
146150 netuid ,
147151 subnet_reveal_period_epochs ,
148152 block_time ,
149- hotkey
153+ hotkey ,
150154 )
151155 assert isinstance (encrypted , bytes )
152156 assert isinstance (round_ , int )
0 commit comments