Skip to content

Commit a24f048

Browse files
committed
test: onion connections with local Tor DA
1 parent 5906257 commit a24f048

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
- logging_test.py
4343
- ln_basic_test.py
4444
- ln_test.py
45+
- onion_test.py
4546
- plugin_test.py
4647
- rpc_test.py
4748
- services_test.py

test/data/onion/network.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
caddy:
2+
enabled: false
3+
fork_observer:
4+
configQueryInterval: 20
5+
enabled: false
6+
nodes:
7+
- image:
8+
tag: '29.0'
9+
name: tank-0000
10+
- image:
11+
tag: '29.0'
12+
name: tank-0001
13+
- image:
14+
tag: '29.0'
15+
name: tank-0002
16+
- image:
17+
tag: '29.0'
18+
name: tank-0003
19+
20+
plugins:
21+
preDeploy:
22+
tor:
23+
entrypoint: "../../../resources/plugins/tor"

test/data/onion/node-defaults.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
chain: regtest
2+
image:
3+
repository: bitcoindevproject/bitcoin
4+
pullPolicy: IfNotPresent
5+
defaultConfig: |
6+
debug=net
7+
debug=tor
8+
proxy=127.0.0.1:9050
9+
listen=1
10+
onlynet=onion
11+
torcontrol=127.0.0.1:9051
12+
13+
collectLogs: false
14+
metricsExport: false
15+
16+
extraContainers:
17+
- name: tor
18+
image: bitcoindevproject/tor-relay:latest
19+
ports:
20+
- name: toror
21+
containerPort: 9001
22+
protocol: TCP

test/onion_test.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import os
5+
from pathlib import Path
6+
7+
from test_base import TestBase
8+
from warnet.k8s import pod_log
9+
10+
11+
class OnionTest(TestBase):
12+
def __init__(self):
13+
super().__init__()
14+
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "onion"
15+
16+
def run_test(self):
17+
try:
18+
self.setup_network()
19+
self.check_tor()
20+
finally:
21+
self.cleanup()
22+
23+
def setup_network(self):
24+
self.log.info("Setting up network")
25+
self.log.info(self.warnet(f"deploy {self.network_dir}"))
26+
self.wait_for_all_tanks_status(target="running")
27+
28+
def check_tor(self):
29+
onions = {
30+
"tank-0001": None,
31+
"tank-0002": None
32+
}
33+
34+
def get_onions():
35+
peers = ["tank-0001", "tank-0002"]
36+
for tank in peers:
37+
if not onions[tank]:
38+
self.log.info(f"Getting local onion address from {tank}...")
39+
info = json.loads(self.warnet(f"bitcoin rpc {tank} getnetworkinfo"))
40+
for addr in info["localaddresses"]:
41+
if "onion" in addr["address"]:
42+
onions[tank] = addr["address"]
43+
self.log.info(f" ... got: {addr['address']}")
44+
for tank in peers:
45+
if not onions[tank]:
46+
return False
47+
return True
48+
self.wait_for_predicate(get_onions)
49+
50+
self.log.info("Adding 1 block")
51+
self.warnet("bitcoin rpc tank-0001 createwallet miner")
52+
self.warnet("bitcoin rpc tank-0001 -generate 1")
53+
54+
self.log.info("Adding connections via onion: 0000->0001->0002")
55+
self.warnet(f"bitcoin rpc tank-0000 addnode {onions['tank-0001']} add")
56+
self.warnet(f"bitcoin rpc tank-0001 addnode {onions['tank-0002']} add")
57+
58+
def onion_connect():
59+
peers = json.loads(self.warnet("bitcoin rpc tank-0001 getpeerinfo"))
60+
self.log.info("\n")
61+
self.log.info("Waiting for tank-0001 to have at least two onion peers:")
62+
self.log.info(json.dumps(peers, indent=2))
63+
if len(peers) >= 2:
64+
for peer in peers:
65+
assert peer["network"] == "onion"
66+
return True
67+
else:
68+
self.log.info("tank-0001 tor log tail:")
69+
stream = pod_log(
70+
pod_name="tank-0001", container_name="tor", namespace="default", follow=False, tail_lines=5
71+
)
72+
for line in stream:
73+
msg = line.decode("utf-8").rstrip()
74+
msg = msg.split("]")
75+
self.log.info(msg[-1])
76+
77+
self.wait_for_predicate(onion_connect, timeout=20*60)
78+
79+
80+
81+
if __name__ == "__main__":
82+
test = OnionTest()
83+
test.run_test()

0 commit comments

Comments
 (0)