Skip to content

Commit 3914e47

Browse files
committed
test: add a test that -i2pacceptincoming=0 creates a transient session
The test is a bit primitive as it checks the Bitcoin Core log and assumes that if it logs that it creates a transient session, then it does that indeed. A more thorough test would be to check that it indeed sends the `SESSION CREATE ... DESTINATION=TRANSIENT` command and that it uses the returned I2P address for connecting, even for repeated connections to the same I2P peer. That would require a mocked SAM server (proxy) implementation in Python.
1 parent ae1e97c commit 3914e47

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/functional/p2p_i2p_sessions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022-2022 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""
6+
Test whether persistent or transient I2P sessions are being used, based on `-i2pacceptincoming`.
7+
"""
8+
9+
from test_framework.test_framework import BitcoinTestFramework
10+
11+
12+
class I2PSessions(BitcoinTestFramework):
13+
def set_test_params(self):
14+
self.num_nodes = 2
15+
# The test assumes that an I2P SAM proxy is not listening here.
16+
self.extra_args = [
17+
["-i2psam=127.0.0.1:60000", "-i2pacceptincoming=1"],
18+
["-i2psam=127.0.0.1:60000", "-i2pacceptincoming=0"],
19+
]
20+
21+
def run_test(self):
22+
addr = "zsxwyo6qcn3chqzwxnseusqgsnuw3maqnztkiypyfxtya4snkoka.b32.i2p"
23+
24+
self.log.info("Ensure we create a persistent session when -i2pacceptincoming=1")
25+
node0 = self.nodes[0]
26+
with node0.assert_debug_log(expected_msgs=[f"Creating persistent SAM session"]):
27+
node0.addnode(node=addr, command="onetry")
28+
29+
self.log.info("Ensure we create a transient session when -i2pacceptincoming=0")
30+
node1 = self.nodes[1]
31+
with node1.assert_debug_log(expected_msgs=[f"Creating transient SAM session"]):
32+
node1.addnode(node=addr, command="onetry")
33+
34+
35+
if __name__ == '__main__':
36+
I2PSessions().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
'feature_blocksdir.py',
329329
'wallet_startup.py',
330330
'p2p_i2p_ports.py',
331+
'p2p_i2p_sessions.py',
331332
'feature_config_args.py',
332333
'feature_presegwit_node_upgrade.py',
333334
'feature_settings.py',

0 commit comments

Comments
 (0)