Skip to content

Commit 91056b7

Browse files
authored
test(dash-spv): add masternode integration tests (#740)
* test(dash-spv): add masternode integration tests Adds a `dashd_masternode` integration test suite that runs against a real dashd regtest network with multiple masternodes, plus a new `masternode_network` module in `test_utils` that manages multi-node dashd lifecycles, DKG cycles, mocktime advancement, and ChainLock signing. The new suite complements the existing `dashd_sync` tests by exercising masternode-specific behavior. `tests_sync.rs` covers masternode list sync, restart, new-block extension, quorum rotation, and a full end-to-end scenario. `tests_instantsend.rs` covers InstantSend lock formation, behavior across quorum rotation, and the case where the `islock` arrives before the transaction. * fix(dash-spv): check current state before awaiting in `wait_for_masternode_sync` `watch::Receiver::changed()` only wakes on future updates, so callers entering after masternode sync was already `Synced` would wait until timeout. Inspect the current value via `borrow_and_update()` first and return early when already synced. Addresses CodeRabbit review comment on PR #740 #740 (comment) * test(dash-spv): fail fast when `protx update_service` fails during bootstrap The masternode network setup depends on every node having its real P2P port registered, otherwise dashd can't form quorum connections and downstream DKG/IS sessions fail with hard-to-trace timeouts. Collect any RPC failures during the per-masternode `protx update_service` loop and panic with the affected datadirs once the loop is done so all failures are surfaced together. Addresses CodeRabbit review comment on PR #740 #740 (comment)
1 parent 77824fe commit 91056b7

18 files changed

Lines changed: 2811 additions & 109 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ permissions:
1818
env:
1919
DASHVERSION: "23.1.0"
2020
TEST_DATA_REPO: "dashpay/regtest-blockchain"
21-
TEST_DATA_VERSION: "v0.0.3"
21+
TEST_DATA_VERSION: "v0.0.4"
2222

2323
jobs:
2424
test:

contrib/setup-dashd.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Environment variables:
99
DASHVERSION - Dash Core version (default: 23.1.0)
10-
TEST_DATA_VERSION - Test data release version (default: v0.0.3)
10+
TEST_DATA_VERSION - Test data release version (default: v0.0.4)
1111
TEST_DATA_REPO - GitHub repo for test data (default: dashpay/regtest-blockchain)
1212
CACHE_DIR - Cache directory (default: ~/.rust-dashcore-test)
1313
"""
@@ -22,7 +22,7 @@
2222

2323
# Keep these defaults in sync with .github/workflows/build-and-test.yml
2424
DASHVERSION = os.environ.get("DASHVERSION", "23.1.0")
25-
TEST_DATA_VERSION = os.environ.get("TEST_DATA_VERSION", "v0.0.3")
25+
TEST_DATA_VERSION = os.environ.get("TEST_DATA_VERSION", "v0.0.4")
2626
TEST_DATA_REPO = os.environ.get("TEST_DATA_REPO", "dashpay/regtest-blockchain")
2727

2828

@@ -115,23 +115,26 @@ def setup_dashd(cache_dir):
115115
return dashd_bin
116116

117117

118-
VARIANTS = ["regtest-40000", "regtest-200"]
118+
# Each entry maps a variant directory name to a marker path (relative to that
119+
# directory) used as a cache hit / extraction-success check. Single-node
120+
# variants ship a `regtest/blocks` subdirectory; the masternode network ships a
121+
# top-level `network.json` plus per-node datadirs.
122+
VARIANTS = {
123+
"regtest-40000": "regtest/blocks",
124+
"regtest-200": "regtest/blocks",
125+
"regtest-mn": "network.json",
126+
}
119127

120128

121-
def setup_test_data(cache_dir, variant):
122-
"""Download and extract a single test blockchain variant.
123-
124-
Args:
125-
cache_dir: Root cache directory for all test assets.
126-
variant: Directory name of the test data (e.g. "regtest-40000" or "regtest-200").
127-
"""
129+
def setup_test_data(cache_dir, variant, marker_relpath):
130+
"""Download and extract a single test blockchain variant."""
128131
parent_dir = os.path.join(cache_dir, f"regtest-blockchain-{TEST_DATA_VERSION}")
129132
test_data_dir = os.path.join(parent_dir, variant)
130-
blocks_dir = os.path.join(test_data_dir, "regtest", "blocks")
133+
marker_path = os.path.join(test_data_dir, marker_relpath)
131134

132-
if os.path.isdir(blocks_dir):
135+
if os.path.exists(marker_path):
133136
log(f"Test blockchain data {variant} ({TEST_DATA_VERSION}) already available")
134-
return
137+
return test_data_dir
135138

136139
log(f"Downloading test blockchain data {variant} ({TEST_DATA_VERSION})...")
137140
os.makedirs(parent_dir, exist_ok=True)
@@ -143,26 +146,30 @@ def setup_test_data(cache_dir, variant):
143146
extract(archive_path, parent_dir)
144147
os.remove(archive_path)
145148

146-
if not os.path.isdir(blocks_dir):
147-
sys.exit(f"Expected blocks directory not found after extraction: {blocks_dir}")
149+
if not os.path.exists(marker_path):
150+
sys.exit(f"Expected marker not found after extraction: {marker_path}")
148151

149152
log(f"Downloaded test data to {test_data_dir}")
153+
return test_data_dir
150154

151155

152156
def main():
153157
cache_dir = get_cache_dir()
154158
os.makedirs(cache_dir, exist_ok=True)
155159

156160
dashd_path = setup_dashd(cache_dir)
157-
for variant in VARIANTS:
158-
setup_test_data(cache_dir, variant)
161+
variant_dirs = {
162+
variant: setup_test_data(cache_dir, variant, marker)
163+
for variant, marker in VARIANTS.items()
164+
}
159165

160166
datadir = os.path.join(cache_dir, f"regtest-blockchain-{TEST_DATA_VERSION}")
161167

162168
# GITHUB_ENV expects bare NAME=value; shell `eval` needs `export NAME=value`.
163169
prefix = "" if os.environ.get("GITHUB_ACTIONS") == "true" else "export "
164170
print(f"{prefix}DASHD_PATH={dashd_path}")
165171
print(f"{prefix}DASHD_TEST_DATA={datadir}")
172+
print(f"{prefix}DASHD_MN_DATADIR={variant_dirs['regtest-mn']}")
166173

167174

168175
if __name__ == "__main__":

dash-spv/src/test_utils/event_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ pub struct TestEventHandler {
2323

2424
impl TestEventHandler {
2525
pub fn new() -> Self {
26-
let (sync_tx, _) = broadcast::channel(256);
27-
let (network_tx, _) = broadcast::channel(256);
26+
let (sync_tx, _) = broadcast::channel(10000);
27+
let (network_tx, _) = broadcast::channel(10000);
2828
let (progress_tx, _) = watch::channel(SyncProgress::default());
29-
let (wallet_tx, _) = broadcast::channel(256);
29+
let (wallet_tx, _) = broadcast::channel(10000);
3030
Self {
3131
sync_tx,
3232
network_tx,

0 commit comments

Comments
 (0)