Skip to content

Commit 7d78977

Browse files
committed
Add simple test ensuring we can restart from a VSS backend
This is close to the backwards compatibility test we just added for v0, now just making sure we can actually read the data we persisted with our current (V1+) code. Co-authored by Claude AI
1 parent b202e2e commit 7d78977

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/integration_tests_vss.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,69 @@ async fn vss_v0_schema_backwards_compatibility() {
130130

131131
node_new.stop().unwrap();
132132
}
133+
134+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
135+
async fn vss_node_restart() {
136+
let (bitcoind, electrsd) = common::setup_bitcoind_and_electrsd();
137+
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
138+
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
139+
140+
let rand_suffix: String =
141+
(0..7).map(|_| rng().sample(rand::distr::Alphanumeric) as char).collect();
142+
let store_id = format!("restart_test_{}", rand_suffix);
143+
let storage_path = common::random_storage_path().to_str().unwrap().to_owned();
144+
let seed_bytes = [42u8; 64];
145+
146+
// Setup initial node and fund it.
147+
let (expected_balance_sats, expected_node_id) = {
148+
let mut builder = Builder::new();
149+
builder.set_network(bitcoin::Network::Regtest);
150+
builder.set_storage_dir_path(storage_path.clone());
151+
builder.set_entropy_seed_bytes(seed_bytes);
152+
builder.set_chain_source_esplora(esplora_url.clone(), None);
153+
let node = builder
154+
.build_with_vss_store_and_fixed_headers(
155+
vss_base_url.clone(),
156+
store_id.clone(),
157+
HashMap::new(),
158+
)
159+
.unwrap();
160+
161+
node.start().unwrap();
162+
let addr = node.onchain_payment().new_address().unwrap();
163+
common::premine_and_distribute_funds(
164+
&bitcoind.client,
165+
&electrsd.client,
166+
vec![addr],
167+
bitcoin::Amount::from_sat(100_000),
168+
)
169+
.await;
170+
node.sync_wallets().unwrap();
171+
172+
let balance = node.list_balances().spendable_onchain_balance_sats;
173+
assert!(balance > 0);
174+
let node_id = node.node_id();
175+
176+
node.stop().unwrap();
177+
(balance, node_id)
178+
};
179+
180+
// Verify node can be restarted from VSS backend.
181+
let mut builder = Builder::new();
182+
builder.set_network(bitcoin::Network::Regtest);
183+
builder.set_storage_dir_path(storage_path);
184+
builder.set_entropy_seed_bytes(seed_bytes);
185+
builder.set_chain_source_esplora(esplora_url, None);
186+
187+
let node = builder
188+
.build_with_vss_store_and_fixed_headers(vss_base_url, store_id, HashMap::new())
189+
.unwrap();
190+
191+
node.start().unwrap();
192+
node.sync_wallets().unwrap();
193+
194+
assert_eq!(expected_node_id, node.node_id());
195+
assert_eq!(expected_balance_sats, node.list_balances().spendable_onchain_balance_sats);
196+
197+
node.stop().unwrap();
198+
}

0 commit comments

Comments
 (0)