Skip to content

Commit 2fadccc

Browse files
committed
Run the formatter
Run `cargo +nightly fmt`, no other manual changes.
1 parent 41a7c6e commit 2fadccc

39 files changed

+671
-1907
lines changed

bitcoind-tests/tests/setup/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ pub fn setup() -> BitcoinD {
1818
}
1919
}
2020

21-
let bitcoind_path = root_path
22-
.join("bitcoind-tests")
23-
.join("bin")
24-
.join("bitcoind");
21+
let bitcoind_path = root_path.join("bitcoind-tests").join("bin").join("bitcoind");
2522
std::env::set_var(key, bitcoind_path);
2623
}
2724

bitcoind-tests/tests/setup/test_util.rs

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,7 @@ impl TestData {
108108
let ripemd160_pre = [0x78 as u8; 32];
109109
let ripemd160 = ripemd160::Hash::hash(&ripemd160_pre);
110110

111-
let pubdata = PubData {
112-
pks,
113-
sha256,
114-
hash256,
115-
ripemd160,
116-
hash160,
117-
x_only_pks,
118-
};
111+
let pubdata = PubData { pks, sha256, hash256, ripemd160, hash160, x_only_pks };
119112
let secretdata = SecretData {
120113
sks,
121114
sha256_pre,
@@ -124,10 +117,7 @@ impl TestData {
124117
hash160_pre,
125118
x_only_keypairs,
126119
};
127-
Self {
128-
pubdata,
129-
secretdata,
130-
}
120+
Self { pubdata, secretdata }
131121
}
132122
}
133123

@@ -279,51 +269,26 @@ pub fn parse_test_desc(
279269
let desc = subs_hash_frag(desc, pubdata);
280270
let desc = Descriptor::<String>::from_str(&desc)?;
281271
let mut translator = StrDescPubKeyTranslator(0, pubdata);
282-
let desc = desc
283-
.translate_pk(&mut translator)
284-
.expect("Translation failed");
272+
let desc = desc.translate_pk(&mut translator).expect("Translation failed");
285273
Ok(desc)
286274
}
287275

288276
// substitute hash fragments in the string as the per rules
289277
fn subs_hash_frag(ms: &str, pubdata: &PubData) -> String {
290-
let ms = ms.replace(
291-
"sha256(H)",
292-
&format!("sha256({})", &pubdata.sha256.to_string()),
293-
);
294-
let ms = ms.replace(
295-
"hash256(H)",
296-
&format!("hash256({})", &pubdata.hash256.to_string()),
297-
);
298-
let ms = ms.replace(
299-
"ripemd160(H)",
300-
&format!("ripemd160({})", &pubdata.ripemd160.to_string()),
301-
);
302-
let ms = ms.replace(
303-
"hash160(H)",
304-
&format!("hash160({})", &pubdata.hash160.to_string()),
305-
);
278+
let ms = ms.replace("sha256(H)", &format!("sha256({})", &pubdata.sha256.to_string()));
279+
let ms = ms.replace("hash256(H)", &format!("hash256({})", &pubdata.hash256.to_string()));
280+
let ms = ms.replace("ripemd160(H)", &format!("ripemd160({})", &pubdata.ripemd160.to_string()));
281+
let ms = ms.replace("hash160(H)", &format!("hash160({})", &pubdata.hash160.to_string()));
306282

307283
let mut rand_hash32 = [0u8; 32];
308284
rand::thread_rng().fill_bytes(&mut rand_hash32);
309285

310286
let mut rand_hash20 = [0u8; 20];
311287
rand::thread_rng().fill_bytes(&mut rand_hash20);
312-
let ms = ms.replace(
313-
"sha256(H!)",
314-
&format!("sha256({})", rand_hash32.to_lower_hex_string()),
315-
);
316-
let ms = ms.replace(
317-
"hash256(H!)",
318-
&format!("hash256({})", rand_hash32.to_lower_hex_string()),
319-
);
320-
let ms = ms.replace(
321-
"ripemd160(H!)",
322-
&format!("ripemd160({})", rand_hash20.to_lower_hex_string()),
323-
);
324-
let ms = ms.replace(
325-
"hash160(H!)",
326-
&format!("hash160({})", rand_hash20.to_lower_hex_string()),
327-
);
288+
let ms = ms.replace("sha256(H!)", &format!("sha256({})", rand_hash32.to_lower_hex_string()));
289+
let ms = ms.replace("hash256(H!)", &format!("hash256({})", rand_hash32.to_lower_hex_string()));
290+
let ms =
291+
ms.replace("ripemd160(H!)", &format!("ripemd160({})", rand_hash20.to_lower_hex_string()));
292+
let ms = ms.replace("hash160(H!)", &format!("hash160({})", rand_hash20.to_lower_hex_string()));
328293
ms
329294
}

bitcoind-tests/tests/test_cpp.rs

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount { Amount::from_btc(btc.into()).unwrap() }
5454
// Ideally, we should find by scriptPubkey, but this
5555
// works for temp test case
5656
fn get_vout(cl: &Client, txid: Txid, value: u64) -> (OutPoint, TxOut) {
57-
let tx = cl
58-
.get_transaction(&txid, None)
59-
.unwrap()
60-
.transaction()
61-
.unwrap();
57+
let tx = cl.get_transaction(&txid, None).unwrap().transaction().unwrap();
6258
for (i, txout) in tx.output.into_iter().enumerate() {
6359
if txout.value == value {
6460
return (OutPoint::new(txid, i as u32), txout);
@@ -74,10 +70,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
7470
let pks = &testdata.pubdata.pks;
7571
// Generate some blocks
7672
let blocks = cl
77-
.generate_to_address(
78-
500,
79-
&cl.get_new_address(None, None).unwrap().assume_checked(),
80-
)
73+
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
8174
.unwrap();
8275
assert_eq!(blocks.len(), 500);
8376

@@ -100,10 +93,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
10093
}
10194
// Wait for the funds to mature.
10295
let blocks = cl
103-
.generate_to_address(
104-
50,
105-
&cl.get_new_address(None, None).unwrap().assume_checked(),
106-
)
96+
.generate_to_address(50, &cl.get_new_address(None, None).unwrap().assume_checked())
10797
.unwrap();
10898
assert_eq!(blocks.len(), 50);
10999
// Create a PSBT for each transaction.
@@ -138,14 +128,11 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
138128
// Get a new script pubkey from the node so that
139129
// the node wallet tracks the receiving transaction
140130
// and we can check it by gettransaction RPC.
141-
let addr = cl
142-
.get_new_address(None, Some(json::AddressType::Bech32))
143-
.unwrap()
144-
.assume_checked();
145-
psbt.unsigned_tx.output.push(TxOut {
146-
value: 99_999_000,
147-
script_pubkey: addr.script_pubkey(),
148-
});
131+
let addr =
132+
cl.get_new_address(None, Some(json::AddressType::Bech32)).unwrap().assume_checked();
133+
psbt.unsigned_tx
134+
.output
135+
.push(TxOut { value: 99_999_000, script_pubkey: addr.script_pubkey() });
149136
let mut input = psbt::Input::default();
150137
input.witness_utxo = Some(witness_utxo);
151138
input.witness_script = Some(desc.explicit_script().unwrap());
@@ -167,17 +154,14 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
167154
unreachable!("Only Wsh descriptors are supported");
168155
};
169156

170-
let sks_reqd: Vec<_> = ms
171-
.iter_pk()
172-
.map(|pk| sks[pks.iter().position(|&x| x == pk).unwrap()])
173-
.collect();
157+
let sks_reqd: Vec<_> =
158+
ms.iter_pk().map(|pk| sks[pks.iter().position(|&x| x == pk).unwrap()]).collect();
174159
// Get the required sighash message
175160
let amt = btc(1).to_sat();
176161
let mut sighash_cache = bitcoin::sighash::SighashCache::new(&psbts[i].unsigned_tx);
177162
let sighash_ty = bitcoin::sighash::EcdsaSighashType::All;
178-
let sighash = sighash_cache
179-
.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty)
180-
.unwrap();
163+
let sighash =
164+
sighash_cache.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty).unwrap();
181165

182166
// requires both signing and verification because we check the tx
183167
// after we psbt extract it
@@ -187,32 +171,25 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
187171
for sk in sks_reqd {
188172
let sig = secp.sign_ecdsa(&msg, &sk);
189173
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
190-
psbts[i].inputs[0].partial_sigs.insert(
191-
pk,
192-
bitcoin::ecdsa::Signature {
193-
sig,
194-
hash_ty: sighash_ty,
195-
},
196-
);
174+
psbts[i].inputs[0]
175+
.partial_sigs
176+
.insert(pk, bitcoin::ecdsa::Signature { sig, hash_ty: sighash_ty });
197177
}
198178
// Add the hash preimages to the psbt
199-
psbts[i].inputs[0].sha256_preimages.insert(
200-
testdata.pubdata.sha256,
201-
testdata.secretdata.sha256_pre.to_vec(),
202-
);
179+
psbts[i].inputs[0]
180+
.sha256_preimages
181+
.insert(testdata.pubdata.sha256, testdata.secretdata.sha256_pre.to_vec());
203182
psbts[i].inputs[0].hash256_preimages.insert(
204183
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
205184
testdata.secretdata.hash256_pre.to_vec(),
206185
);
207186
println!("{}", ms);
208-
psbts[i].inputs[0].hash160_preimages.insert(
209-
testdata.pubdata.hash160,
210-
testdata.secretdata.hash160_pre.to_vec(),
211-
);
212-
psbts[i].inputs[0].ripemd160_preimages.insert(
213-
testdata.pubdata.ripemd160,
214-
testdata.secretdata.ripemd160_pre.to_vec(),
215-
);
187+
psbts[i].inputs[0]
188+
.hash160_preimages
189+
.insert(testdata.pubdata.hash160, testdata.secretdata.hash160_pre.to_vec());
190+
psbts[i].inputs[0]
191+
.ripemd160_preimages
192+
.insert(testdata.pubdata.ripemd160, testdata.secretdata.ripemd160_pre.to_vec());
216193
// Finalize the transaction using psbt
217194
// Let miniscript do it's magic!
218195
if let Err(e) = psbts[i].finalize_mall_mut(&secp) {
@@ -224,18 +201,14 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
224201
// Send the transactions to bitcoin node for mining.
225202
// Regtest mode has standardness checks
226203
// Check whether the node accepts the transactions
227-
let txid = cl
228-
.send_raw_transaction(&tx)
229-
.expect(&format!("{} send tx failed for ms {}", i, ms));
204+
let txid =
205+
cl.send_raw_transaction(&tx).expect(&format!("{} send tx failed for ms {}", i, ms));
230206
spend_txids.push(txid);
231207
}
232208
}
233209
// Finally mine the blocks and await confirmations
234210
let _blocks = cl
235-
.generate_to_address(
236-
10,
237-
&cl.get_new_address(None, None).unwrap().assume_checked(),
238-
)
211+
.generate_to_address(10, &cl.get_new_address(None, None).unwrap().assume_checked())
239212
.unwrap();
240213
// Get the required transactions from the node mined in the blocks.
241214
for txid in spend_txids {

0 commit comments

Comments
 (0)