aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2022-06-09 12:22:24 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-08-16 13:02:19 +0200
commit3914e472f5685c29aa3d1c6dc5af9a758313d6c1 (patch)
tree0b4e1a87d734325fefc46359a5ed5a6e017c9840 /test
parentae1e97ce863609e06be44a2632fb9d1fbb8e5698 (diff)
downloadbitcoin-3914e472f5685c29aa3d1c6dc5af9a758313d6c1.tar.xz
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.
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/p2p_i2p_sessions.py36
-rwxr-xr-xtest/functional/test_runner.py1
2 files changed, 37 insertions, 0 deletions
diff --git a/test/functional/p2p_i2p_sessions.py b/test/functional/p2p_i2p_sessions.py
new file mode 100755
index 0000000000..4e52522b81
--- /dev/null
+++ b/test/functional/p2p_i2p_sessions.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+# Copyright (c) 2022-2022 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+"""
+Test whether persistent or transient I2P sessions are being used, based on `-i2pacceptincoming`.
+"""
+
+from test_framework.test_framework import BitcoinTestFramework
+
+
+class I2PSessions(BitcoinTestFramework):
+ def set_test_params(self):
+ self.num_nodes = 2
+ # The test assumes that an I2P SAM proxy is not listening here.
+ self.extra_args = [
+ ["-i2psam=127.0.0.1:60000", "-i2pacceptincoming=1"],
+ ["-i2psam=127.0.0.1:60000", "-i2pacceptincoming=0"],
+ ]
+
+ def run_test(self):
+ addr = "zsxwyo6qcn3chqzwxnseusqgsnuw3maqnztkiypyfxtya4snkoka.b32.i2p"
+
+ self.log.info("Ensure we create a persistent session when -i2pacceptincoming=1")
+ node0 = self.nodes[0]
+ with node0.assert_debug_log(expected_msgs=[f"Creating persistent SAM session"]):
+ node0.addnode(node=addr, command="onetry")
+
+ self.log.info("Ensure we create a transient session when -i2pacceptincoming=0")
+ node1 = self.nodes[1]
+ with node1.assert_debug_log(expected_msgs=[f"Creating transient SAM session"]):
+ node1.addnode(node=addr, command="onetry")
+
+
+if __name__ == '__main__':
+ I2PSessions().main()
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 2b365d8d10..d542286cfb 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -328,6 +328,7 @@ BASE_SCRIPTS = [
'feature_blocksdir.py',
'wallet_startup.py',
'p2p_i2p_ports.py',
+ 'p2p_i2p_sessions.py',
'feature_config_args.py',
'feature_presegwit_node_upgrade.py',
'feature_settings.py',