Skip to content

Commit 4ca3464

Browse files
authored
Merge pull request #621 from pinheadmz/testframework-cp
Make test_framework available for users when creating scenarios
2 parents 9b7a5c9 + 5ee0c8b commit 4ca3464

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+197
-222
lines changed

.github/workflows/deploy.yml

-61
This file was deleted.

.github/workflows/test.yml

+1-38
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,8 @@ jobs:
3030
enable-cache: true
3131
- run: uvx ruff format . --check
3232

33-
build-image:
34-
needs: [ruff, ruff-format]
35-
runs-on: ubuntu-latest
36-
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v4
39-
40-
- name: Set up Docker Buildx
41-
uses: docker/setup-buildx-action@v3
42-
43-
- name: Build and export
44-
uses: docker/build-push-action@v5
45-
with:
46-
file: resources/images/commander/Dockerfile
47-
context: .
48-
tags: bitcoindevproject/warnet-commander:latest
49-
cache-from: type=gha
50-
cache-to: type=gha,mode=max
51-
outputs: type=docker,dest=/tmp/commander.tar
52-
53-
- name: Upload artifact
54-
uses: actions/upload-artifact@v4
55-
with:
56-
name: commander
57-
path: /tmp/commander.tar
58-
5933
test:
60-
needs: [build-image]
34+
needs: [ruff, ruff-format]
6135
runs-on: ubuntu-latest
6236
strategy:
6337
matrix:
@@ -80,11 +54,6 @@ jobs:
8054
memory: 4000m
8155
- name: Start minikube's loadbalancer tunnel
8256
run: minikube tunnel &> /dev/null &
83-
- name: Download commander artifact
84-
uses: actions/download-artifact@v4
85-
with:
86-
name: commander
87-
path: /tmp
8857
- name: Install the latest version of uv
8958
uses: astral-sh/setup-uv@v2
9059
with:
@@ -94,12 +63,6 @@ jobs:
9463
run: uv python install $PYTHON_VERSION
9564
- name: Install project
9665
run: uv sync --all-extras --dev
97-
- name: Install commander image
98-
run: |
99-
echo loading commander image into minikube docker
100-
eval $(minikube -p minikube docker-env)
101-
docker load --input /tmp/commander.tar
102-
docker image ls -a
10366
- name: Run tests
10467
run: |
10568
source .venv/bin/activate

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ build-backend = "setuptools.build_meta"
5151
include-package-data = true
5252

5353
[tool.setuptools.packages.find]
54-
where = ["src", "."]
54+
where = ["src", ".", "resources/scenarios"]
5555
include = ["warnet*", "test_framework*", "resources*"]
5656

5757
[tool.setuptools.package-data]

resources/charts/commander/templates/configmap.yaml

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
apiVersion: v1
22
kind: ConfigMap
3-
metadata:
4-
name: {{ include "commander.fullname" . }}-scenario
5-
labels:
6-
{{- include "commander.labels" . | nindent 4 }}
7-
binaryData:
8-
scenario.py: {{ .Values.scenario }}
9-
---
10-
apiVersion: v1
11-
kind: ConfigMap
123
metadata:
134
name: {{ include "commander.fullname" . }}-warnet
145
labels:

resources/charts/commander/templates/pod.yaml

+20-15
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,30 @@ metadata:
88
mission: commander
99
spec:
1010
restartPolicy: {{ .Values.restartPolicy }}
11+
initContainers:
12+
- name: init
13+
image: busybox
14+
command: ["/bin/sh", "-c"]
15+
args:
16+
- |
17+
while [ ! -f /shared/archive.pyz ]; do
18+
echo "Waiting for /shared/archive.pyz to exist..."
19+
sleep 2
20+
done
21+
volumeMounts:
22+
- name: shared-volume
23+
mountPath: /shared
1124
containers:
1225
- name: {{ .Chart.Name }}
13-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
14-
imagePullPolicy: {{ .Values.image.pullPolicy }}
26+
image: python:3.12-slim
27+
imagePullPolicy: IfNotPresent
1528
command: ["/bin/sh", "-c"]
1629
args:
1730
- |
18-
python3 /scenario.py {{ .Values.args }}
31+
python3 /shared/archive.pyz {{ .Values.args }}
1932
volumeMounts:
20-
- name: scenario
21-
mountPath: /scenario.py
22-
subPath: scenario.py
23-
- name: warnet
24-
mountPath: /warnet.json
25-
subPath: warnet.json
33+
- name: shared-volume
34+
mountPath: /shared
2635
volumes:
27-
- name: scenario
28-
configMap:
29-
name: {{ include "commander.fullname" . }}-scenario
30-
- name: warnet
31-
configMap:
32-
name: {{ include "commander.fullname" . }}-warnet
36+
- name: shared-volume
37+
emptyDir: {}

resources/charts/commander/values.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ namespace: warnet
55

66
restartPolicy: Never
77

8-
image:
9-
repository: bitcoindevproject/warnet-commander
10-
pullPolicy: IfNotPresent
11-
# Overrides the image tag whose default is the chart appVersion.
12-
tag: "latest"
13-
148
imagePullSecrets: []
159
nameOverride: ""
1610
fullnameOverride: ""
@@ -71,8 +65,6 @@ volumeMounts: []
7165

7266
port:
7367

74-
scenario: ""
75-
7668
warnet: ""
7769

7870
args: ""

resources/images/commander/Dockerfile

-11
This file was deleted.

resources/networks/6_node_bitcoin/network.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ nodes:
2828
connect:
2929
- tank-0006
3030
- name: tank-0006
31-
fork_observer:
32-
enabled: true
3331
caddy:
3432
enabled: true

resources/scenarios/commander.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import signal
99
import sys
1010
import tempfile
11-
from pathlib import Path
1211
from typing import Dict
1312

1413
from test_framework.authproxy import AuthServiceProxy
@@ -21,7 +20,7 @@
2120
from test_framework.test_node import TestNode
2221
from test_framework.util import PortSeed, get_rpc_proxy
2322

24-
WARNET_FILE = Path(os.path.dirname(__file__)) / "warnet.json"
23+
WARNET_FILE = "/shared/warnet.json"
2524

2625
try:
2726
with open(WARNET_FILE) as file:

resources/scenarios/ln_init.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
from time import sleep
44

5-
# The base class exists inside the commander container
6-
try:
7-
from commander import Commander
8-
except ImportError:
9-
from resources.scenarios.commander import Commander
5+
from commander import Commander
106

117

128
class LNInit(Commander):
@@ -185,5 +181,9 @@ def funded_lnnodes():
185181
)
186182

187183

188-
if __name__ == "__main__":
184+
def main():
189185
LNInit().main()
186+
187+
188+
if __name__ == "__main__":
189+
main()

resources/scenarios/miner_std.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
from time import sleep
44

5-
# The base class exists inside the commander container
6-
try:
7-
from commander import Commander
8-
except ImportError:
9-
from resources.scenarios.commander import Commander
5+
from commander import Commander
106

117

128
class Miner:
@@ -72,5 +68,9 @@ def run_test(self):
7268
sleep(self.options.interval)
7369

7470

75-
if __name__ == "__main__":
71+
def main():
7672
MinerStd().main()
73+
74+
75+
if __name__ == "__main__":
76+
main()

resources/scenarios/reconnaissance.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import socket
44

5-
# The base class exists inside the commander container when deployed,
6-
# but requires a relative path inside the python source code for other functions.
7-
try:
8-
from commander import Commander
9-
except ImportError:
10-
from resources.scenarios.commander import Commander
5+
from commander import Commander
116

127
# The entire Bitcoin Core test_framework directory is available as a library
138
from test_framework.messages import MSG_TX, CInv, hash256, msg_getdata
@@ -85,5 +80,9 @@ def run_test(self):
8580
self.log.info(f"Got notfound message from {dstaddr}:{dstport}")
8681

8782

88-
if __name__ == "__main__":
83+
def main():
8984
Reconnaissance().main()
85+
86+
87+
if __name__ == "__main__":
88+
main()

resources/scenarios/signet_miner.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
# we use the authproxy from the test framework.
1212
###
1313

14-
# The base class exists inside the commander container
15-
try:
16-
from commander import Commander
17-
except ImportError:
18-
from resources.scenarios.commander import Commander
14+
from commander import Commander
1915

2016
import json
2117
import logging
@@ -566,5 +562,8 @@ def get_args(parser):
566562

567563
return args
568564

569-
if __name__ == "__main__":
565+
def main():
570566
SignetMinerScenario().main()
567+
568+
if __name__ == "__main__":
569+
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.

resources/scenarios/test_scenarios/__init__.py

Whitespace-only changes.

test/data/scenario_buggy_failure.py renamed to resources/scenarios/test_scenarios/buggy_failure.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ def run_test(self):
2020
raise Exception("Failed execution!")
2121

2222

23-
if __name__ == "__main__":
23+
def main():
2424
Failure().main()
25+
26+
27+
if __name__ == "__main__":
28+
main()

test/data/scenario_connect_dag.py renamed to resources/scenarios/test_scenarios/connect_dag.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,9 @@ def assert_connection(self, connector, connectee_index, connection_type: Connect
117117
raise ValueError("ConnectionType must be of type DNS or IP")
118118

119119

120-
if __name__ == "__main__":
120+
def main():
121121
ConnectDag().main()
122+
123+
124+
if __name__ == "__main__":
125+
main()

test/data/scenario_p2p_interface.py renamed to resources/scenarios/test_scenarios/p2p_interface.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ def run_test(self):
5252
p2p_block_store.wait_until(lambda: p2p_block_store.blocks[best_block] == 1)
5353

5454

55-
if __name__ == "__main__":
55+
def main():
5656
GetdataTest().main()
57+
58+
59+
if __name__ == "__main__":
60+
main()

0 commit comments

Comments
 (0)