A Python port of the Invisible Internet Project (I2P)
1"""Tests for GarlicConfig and CloveConfig."""
2
3from i2p_data.garlic_config import GarlicConfig, CloveConfig, NULL_CERT
4
5
6def test_garlic_config_add_cloves():
7 gc = GarlicConfig(recipient_public_key=b"\x01" * 32, message_id=1, expiration=999)
8 c1 = CloveConfig.for_local(message_data=b"hello", clove_id=1, expiration=999)
9 c2 = CloveConfig.for_local(message_data=b"world", clove_id=2, expiration=999)
10 gc.add_clove(c1)
11 gc.add_clove(c2)
12 assert gc.clove_count() == 2
13 assert gc.cloves[0] is c1
14 assert gc.cloves[1] is c2
15
16
17def test_clove_config_for_destination():
18 cc = CloveConfig.for_destination(
19 dest_hash=b"\x02" * 32, message_data=b"data", clove_id=1, expiration=100
20 )
21 assert cc.delivery_type == 1 # DESTINATION
22 assert cc.dest_hash == b"\x02" * 32
23
24
25def test_clove_config_for_local():
26 cc = CloveConfig.for_local(message_data=b"data", clove_id=1, expiration=100)
27 assert cc.delivery_type == 0 # LOCAL
28
29
30def test_clove_config_for_tunnel():
31 cc = CloveConfig.for_tunnel(
32 router_hash=b"\x03" * 32, tunnel_id=42,
33 message_data=b"data", clove_id=1, expiration=100,
34 )
35 assert cc.delivery_type == 3 # TUNNEL
36 assert cc.router_hash == b"\x03" * 32
37 assert cc.tunnel_id == 42
38
39
40def test_clove_config_default_certificate():
41 cc = CloveConfig.for_local(message_data=b"x", clove_id=1, expiration=1)
42 assert cc.certificate == NULL_CERT