diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9bfc35fe1..a84bfbab2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,8 +29,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - # test: [scenarios_test.py, rpc_test.py, graph_test.py, ln_test.py, dag_connection_test.py, logging_test.py] - test: [scenarios_test.py, rpc_test.py, dag_connection_test.py, logging_test.py] + test: + - conf_test.py + - dag_connection_test.py + - logging_test.py + - rpc_test.py + - scenarios_test.py steps: - uses: actions/checkout@v4 - uses: azure/setup-helm@v4.2.0 diff --git a/resources/charts/bitcoincore/templates/_helpers.tpl b/resources/charts/bitcoincore/templates/_helpers.tpl index 25622c4e8..f22ca65e4 100644 --- a/resources/charts/bitcoincore/templates/_helpers.tpl +++ b/resources/charts/bitcoincore/templates/_helpers.tpl @@ -55,3 +55,15 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + + +{{/* +Add network section heading in bitcoin.conf after v0.17.0 +*/}} +{{- define "bitcoincore.check_semver.regtest" -}} +{{- $tag := .Values.image.tag | trimPrefix "v" -}} +{{- $version := semverCompare ">=0.17.0" $tag -}} +{{- if $version -}} +[regtest] +{{- end -}} +{{- end -}} diff --git a/resources/charts/bitcoincore/templates/configmap.yaml b/resources/charts/bitcoincore/templates/configmap.yaml index ea21616f0..37952ff48 100644 --- a/resources/charts/bitcoincore/templates/configmap.yaml +++ b/resources/charts/bitcoincore/templates/configmap.yaml @@ -7,6 +7,9 @@ metadata: data: bitcoin.conf: | {{- if eq .Values.chain "regtest" }} + regtest=1 + + {{ template "bitcoincore.check_semver.regtest" . }} {{- tpl .Values.regtestConfig . | nindent 4 }} {{- end }} {{- .Values.baseConfig | nindent 4 }} diff --git a/resources/charts/bitcoincore/values.yaml b/resources/charts/bitcoincore/values.yaml index aac305ec6..275e11cd3 100644 --- a/resources/charts/bitcoincore/values.yaml +++ b/resources/charts/bitcoincore/values.yaml @@ -111,9 +111,6 @@ metricsExport: false prometheusMetricsPort: 9332 regtestConfig: | - regtest=1 - - [regtest] rpcuser=user rpcpassword=password rpcport=18443 diff --git a/test/build_branch_test.py b/test/build_branch_test.py deleted file mode 100755 index bbce564ce..000000000 --- a/test/build_branch_test.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python3 - -import json -import os -from pathlib import Path - -from test_base import TestBase - - -class BuildBranchTest(TestBase): - def __init__(self): - super().__init__() - self.graph_file_path = Path(os.path.dirname(__file__)) / "data" / "build_v24_test.graphml" - - def run_test(self): - self.start_server() - try: - self.setup_network() - self.wait_for_p2p_connections() - self.check_build_flags() - finally: - self.stop_server() - - def setup_network(self): - self.log.info("Setting up network") - self.log.info(self.warcli(f"network start {self.graph_file_path}")) - self.wait_for_all_tanks_status(target="running", timeout=10 * 60) - self.wait_for_all_edges() - - def wait_for_p2p_connections(self): - self.log.info("Waiting for P2P connections") - self.wait_for_predicate(self.check_peers, timeout=5 * 60) - - def check_peers(self): - info0 = json.loads(self.warcli("bitcoin rpc 0 getpeerinfo")) - info1 = json.loads(self.warcli("bitcoin rpc 1 getpeerinfo")) - self.log.debug( - f"Waiting for both nodes to get one peer: node0: {len(info0)}, node1: {len(info1)}" - ) - return len(info0) == 1 and len(info1) == 1 - - def check_build_flags(self): - self.log.info("Checking build flags") - release_help = self.get_tank(0).exec("bitcoind -h") - build_help = self.get_tank(1).exec("bitcoind -h") - - assert "zmqpubhashblock" in release_help, "zmqpubhashblock not found in release help" - assert ( - "zmqpubhashblock" not in build_help - ), "zmqpubhashblock found in build help, but it shouldn't be" - - self.log.info("Build flags check passed") - - -if __name__ == "__main__": - test = BuildBranchTest() - test.run_test() diff --git a/test/conf_test.py b/test/conf_test.py new file mode 100755 index 000000000..97b9b0fcc --- /dev/null +++ b/test/conf_test.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import json +import os +import re +from pathlib import Path + +from test_base import TestBase + +from warnet.k8s import get_mission + + +class ConfTest(TestBase): + def __init__(self): + super().__init__() + self.network_dir = Path(os.path.dirname(__file__)) / "data" / "bitcoin_conf" + + def run_test(self): + try: + self.setup_network() + self.check_uacomment() + finally: + self.stop_server() + + def setup_network(self): + self.log.info("Setting up network") + self.log.info(self.warcli(f"deploy {self.network_dir}")) + self.wait_for_all_tanks_status(target="running") + + def check_uacomment(self): + tanks = get_mission("tank") + + def get_uacomment(): + for tank in tanks[::-1]: + try: + name = tank.metadata.name + info = json.loads(self.warcli(f"bitcoin rpc {name} getnetworkinfo")) + subver = info["subversion"] + + # Regex pattern to match the uacomment inside parentheses + # e.g. /Satoshi:27.0.0(tank-0027)/ + pattern = r"\(([^)]+)\)" + match = re.search(pattern, subver) + if match: + uacomment = match.group(1) + assert uacomment == name + else: + return False + except Exception: + return False + return True + + self.wait_for_predicate(get_uacomment) + + +if __name__ == "__main__": + test = ConfTest() + test.run_test() diff --git a/test/data/bitcoin_conf/network.yaml b/test/data/bitcoin_conf/network.yaml new file mode 100644 index 000000000..0ceb8b059 --- /dev/null +++ b/test/data/bitcoin_conf/network.yaml @@ -0,0 +1,64 @@ +nodes: + - name: tank-0016 + image: + tag: "v0.16.1" + connect: + - tank-0017 + config: + uacomment=tank-0016 + - name: tank-0017 + image: + tag: "v0.17.0" + connect: + - tank-0019 + config: + uacomment=tank-0017 + - name: tank-0019 + image: + tag: "v0.19.2" + connect: + - tank-0020 + config: + uacomment=tank-0019 + - name: tank-0020 + image: + tag: "v0.20.0" + connect: + - tank-0021 + config: + uacomment=tank-0020 + - name: tank-0021 + image: + tag: "v0.21.1" + connect: + - tank-0024 + config: + uacomment=tank-0021 + - name: tank-0024 + image: + tag: "24.2" + connect: + - tank-0025 + config: + uacomment=tank-0024 + - name: tank-0025 + image: + tag: "25.1" + connect: + - tank-0026 + config: + uacomment=tank-0025 + - name: tank-0026 + image: + tag: "26.0" + connect: + - tank-0027 + config: + uacomment=tank-0026 + - name: tank-0027 + image: + tag: "27.0" + connect: + - tank-0016 + config: + uacomment=tank-0027 \ No newline at end of file diff --git a/test/data/bitcoin_conf/node-defaults.yaml b/test/data/bitcoin_conf/node-defaults.yaml new file mode 100644 index 000000000..7e021cad1 --- /dev/null +++ b/test/data/bitcoin_conf/node-defaults.yaml @@ -0,0 +1,4 @@ +image: + repository: bitcoindevproject/bitcoin + pullPolicy: IfNotPresent + tag: "27.0" diff --git a/test/data/build_v24_test.graphml b/test/data/build_v24_test.graphml deleted file mode 100644 index d55c3611c..000000000 --- a/test/data/build_v24_test.graphml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - 27.0 - - - bitcoin/bitcoin#24.x - --disable-zmq - - - - diff --git a/test/data/permutations.graphml b/test/data/permutations.graphml deleted file mode 100644 index 0c4686f61..000000000 --- a/test/data/permutations.graphml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - 27.0 - - - - False - False - - - bitcoindevproject/bitcoin:26.0 - - - - False - False - - - 27.0 - - - - False - False - - - 27.0 - - - - False - False - - - 27.0 - - - - False - False - - - 27.0 - - - - False - False - - - 27.0 - - - - False - False - - - 27.0 - - - - False - False - - - - - - - - - - - - \ No newline at end of file diff --git a/test/data/services.graphml b/test/data/services.graphml deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/graph_test.py b/test/graph_test.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/onion_test.py b/test/onion_test.py deleted file mode 100755 index 7f7454b60..000000000 --- a/test/onion_test.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 - -import json -import os -from pathlib import Path - -from test_base import TestBase - - -class OnionTest(TestBase): - def __init__(self): - super().__init__() - self.graph_file_path = Path(os.path.dirname(__file__)) / "data" / "12_node_ring.graphml" - self.onion_addr = None - - def run_test(self): - self.start_server() - try: - self.setup_network() - self.test_reachability() - self.test_onion_peer_connection() - finally: - self.stop_server() - - def setup_network(self): - self.log.info("Setting up network") - self.log.info(self.warcli(f"network start {self.graph_file_path}")) - self.wait_for_all_tanks_status(target="running") - self.wait_for_all_edges() - - def test_reachability(self): - self.log.info("Checking IPv4 and onion reachability") - self.wait_for_predicate(self.check_reachability, timeout=10 * 60) - - def check_reachability(self): - try: - info = json.loads(self.warcli("bitcoin rpc 0 getnetworkinfo")) - for net in info["networks"]: - if net["name"] == "ipv4" and not net["reachable"]: - return False - if net["name"] == "onion" and not net["reachable"]: - return False - if len(info["localaddresses"]) != 2: - return False - for addr in info["localaddresses"]: - assert "100." in addr["address"] or ".onion" in addr["address"] - if ".onion" in addr["address"]: - self.onion_addr = addr["address"] - return True - except Exception as e: - self.log.error(f"Error checking reachability: {e}") - return False - - def test_onion_peer_connection(self): - self.log.info("Attempting addnode to onion peer") - self.warcli(f"bitcoin rpc 1 addnode {self.onion_addr} add") - # Might take up to 10 minutes - self.wait_for_predicate(self.check_onion_peer, timeout=10 * 60) - - def check_onion_peer(self): - peers = json.loads(self.warcli("bitcoin rpc 0 getpeerinfo")) - for peer in peers: - self.log.debug(f"Checking peer: {peer['network']} {peer['addr']}") - if peer["network"] == "onion": - return True - return False - - -if __name__ == "__main__": - test = OnionTest() - test.run_test()