Skip to content

Commit 0903413

Browse files
authored
Merge pull request #104 from crisdut/fix/convert-merkle-proof
Fix merkle proof conversion
2 parents 53d02df + 7bde826 commit 0903413

6 files changed

Lines changed: 43 additions & 43 deletions

File tree

commit_verify/src/lnpbp4.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl CommitConceal for MerkleBlock {
538538
fn commit_conceal(&self) -> Self::ConcealedCommitment {
539539
let mut concealed = self.clone();
540540
concealed
541-
.conceal_except(&[])
541+
.conceal_except([])
542542
.expect("broken internal MerkleBlock structure");
543543
debug_assert_eq!(concealed.cross_section.len(), 1);
544544
concealed.cross_section[0].merkle_node_with(0)
@@ -843,8 +843,9 @@ impl MerkleBlock {
843843
for node in &self.cross_section {
844844
match node {
845845
TreeNode::ConcealedNode { depth, hash } => {
846+
let inserted = map.insert(*depth, *hash).is_none();
846847
debug_assert!(
847-
map.insert(*depth, *hash).is_none(),
848+
inserted,
848849
"MerkleBlock conceal procedure is broken"
849850
);
850851
}

strict_encoding/derive/tests/basics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn bytes() -> Result {
8080
&Vect {
8181
data: data[2..].to_vec(),
8282
},
83-
&data,
83+
data,
8484
)?;
8585

8686
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -102,7 +102,7 @@ fn bytes() -> Result {
102102
#[derive(Clone, PartialEq, Eq, Debug)]
103103
#[derive(StrictEncode, StrictDecode)]
104104
struct Heap(Box<[u8]>);
105-
test_encoding_roundtrip(&Heap(Box::from(&data[2..])), &data)
105+
test_encoding_roundtrip(&Heap(Box::from(&data[2..])), data)
106106
.map_err(Error::from)
107107
}
108108

@@ -124,7 +124,7 @@ fn skipping() -> Result {
124124
data: s!("String"),
125125
ephemeral: false,
126126
},
127-
&[0x06, 0x00, b'S', b't', b'r', b'i', b'n', b'g'],
127+
[0x06, 0x00, b'S', b't', b'r', b'i', b'n', b'g'],
128128
)
129129
.map_err(Error::from)
130130
}

strict_encoding/derive/tests/tlv.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn tlv_optional() -> Result {
187187
fixed: 0xDD,
188188
tlv: None,
189189
},
190-
&[0xDD],
190+
[0xDD],
191191
)?;
192192
test_encoding_roundtrip(
193193
&Tlv {
@@ -210,7 +210,7 @@ fn tlv_newtype() -> Result {
210210
#[network_encoding(use_tlv)]
211211
struct Tlv(#[network_encoding(tlv = 0xBEEF)] Option<u32>);
212212

213-
test_encoding_roundtrip(&Tlv(None), &[])?;
213+
test_encoding_roundtrip(&Tlv(None), [])?;
214214
// println!("{:02x?}", Tlv::strict_deserialize(tlv_u32!())?);
215215
test_encoding_roundtrip(&Tlv(Some(TLV_U32)), tlv_u32!())
216216
.map_err(Error::from)
@@ -228,7 +228,7 @@ fn tlv_default() -> Result {
228228
tlv: Vec<u8>,
229229
}
230230

231-
test_encoding_roundtrip(&TlvDefault::default(), &[0x00])?;
231+
test_encoding_roundtrip(&TlvDefault::default(), [0x00])?;
232232

233233
test_encoding_roundtrip(
234234
&TlvDefault {
@@ -271,19 +271,19 @@ fn tlv_ordering() -> Result {
271271
0x01, 0x00, // length
272272
0xA2, // value
273273
];
274-
let _: Tlv = strict_deserialize(&data).unwrap();
274+
let _: Tlv = strict_deserialize(data).unwrap();
275275

276-
test_encoding_roundtrip(&Tlv::default(), &[])?;
276+
test_encoding_roundtrip(&Tlv::default(), [])?;
277277
test_encoding_roundtrip(
278278
&Tlv {
279279
second: Some(0xA2),
280280
first: Some(0xA1),
281281
},
282-
&data,
282+
data,
283283
)?;
284284

285285
// Now lets switch ordering
286-
Tlv::strict_deserialize(&[
286+
Tlv::strict_deserialize([
287287
// Count of TLV fields
288288
0x02, 0x00, //
289289
// Second goes first
@@ -318,16 +318,16 @@ fn pseudo_tlv() -> Result {
318318
];
319319

320320
// Checking that the data are entirely consumed
321-
let _: Tlv = strict_deserialize(&data1).unwrap();
322-
let _: Tlv = strict_deserialize(&data2).unwrap();
321+
let _: Tlv = strict_deserialize(data1).unwrap();
322+
let _: Tlv = strict_deserialize(data2).unwrap();
323323

324-
test_encoding_roundtrip(&Tlv::default(), &data1)?;
324+
test_encoding_roundtrip(&Tlv::default(), data1)?;
325325
test_encoding_roundtrip(
326326
&Tlv {
327327
vec: vec![0xB1, 0xB2, 0xB3],
328328
unknown_tlvs: bmap! {},
329329
},
330-
&data2,
330+
data2,
331331
)
332332
.map_err(Error::from)
333333
}
@@ -345,13 +345,13 @@ fn tlv_collection() -> Result {
345345
vec: Vec<u8>,
346346
}
347347

348-
test_encoding_roundtrip(&Tlv::default(), &[])?;
348+
test_encoding_roundtrip(&Tlv::default(), [])?;
349349
test_encoding_roundtrip(
350350
&Tlv {
351351
map: bmap! { 0xA1u8 => s!("First"), 0xA2u8 => s!("Second") },
352352
vec: vec![0xB1, 0xB2, 0xB3],
353353
},
354-
&[
354+
[
355355
// Count of TLV fields
356356
0x02, 0x00, //
357357
// First goes first
@@ -389,7 +389,7 @@ fn tlv_unknown() -> Result {
389389
rest_of_tlvs: tlv::Stream,
390390
}
391391

392-
test_encoding_roundtrip(&TlvStream::default(), &[0x00; 2])
392+
test_encoding_roundtrip(&TlvStream::default(), [0x00; 2])
393393
.map_err(Error::from)
394394
}
395395

strict_encoding/src/bitcoin.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ pub(crate) mod test {
923923
test_encoding_roundtrip(&secp_pk_03, PK_BYTES_03).unwrap();
924924
test_encoding_roundtrip(&secp_pk_one, PK_BYTES_ONEKEY).unwrap();
925925
assert_eq!(
926-
secp256k1::PublicKey::strict_deserialize(&PK_BYTES_04),
926+
secp256k1::PublicKey::strict_deserialize(PK_BYTES_04),
927927
Err(Error::DataIntegrityError(s!("invalid public key data: \
928928
uncompressed Secp256k1 \
929929
public key format is not \
@@ -1026,21 +1026,21 @@ pub(crate) mod test {
10261026
let msg = Message::from_slice(&[1u8; 32]).unwrap();
10271027

10281028
let ecdsa = secp.sign_ecdsa(&msg, &sk_ecdsa);
1029-
test_encoding_roundtrip(&ecdsa, &ECDSA_BYTES).unwrap();
1029+
test_encoding_roundtrip(&ecdsa, ECDSA_BYTES).unwrap();
10301030
assert!(secp.verify_ecdsa(&msg, &ecdsa, &pk_ecdsa).is_ok());
10311031

10321032
let schnorr =
10331033
secp.sign_schnorr_with_aux_rand(&msg, &sk_schnorr, &[0u8; 32]);
1034-
test_encoding_roundtrip(&schnorr, &SCHNORR_BYTES).unwrap();
1034+
test_encoding_roundtrip(&schnorr, SCHNORR_BYTES).unwrap();
10351035
assert!(secp.verify_schnorr(&schnorr, &msg, &pk_schnorr).is_ok());
10361036

10371037
// Schnorr signature can be deserialized as ECDSA and vice verse,
10381038
// (since there is no encoding-level way of verifying its type)
10391039
// but MUST be invalid upon signature validation
10401040
let schnorr_as_ecdsa: ecdsa::Signature =
1041-
test_vec_decoding_roundtrip(&SCHNORR_BYTES).unwrap();
1041+
test_vec_decoding_roundtrip(SCHNORR_BYTES).unwrap();
10421042
let ecdsa_as_schnorr: schnorr::Signature =
1043-
test_vec_decoding_roundtrip(&ECDSA_BYTES).unwrap();
1043+
test_vec_decoding_roundtrip(ECDSA_BYTES).unwrap();
10441044
assert_eq!(
10451045
secp.verify_ecdsa(&msg, &schnorr_as_ecdsa, &pk_ecdsa),
10461046
Err(secp256k1::Error::IncorrectSignature)
@@ -1066,16 +1066,16 @@ pub(crate) mod test {
10661066
#[test]
10671067
fn test_encoding_network(
10681068
) -> Result<(), DataEncodingTestFailure<bitcoin::Network>> {
1069-
test_encoding_roundtrip(&bitcoin::Network::Bitcoin, &[
1069+
test_encoding_roundtrip(&bitcoin::Network::Bitcoin, [
10701070
0xF9, 0xBE, 0xB4, 0xD9,
10711071
])?;
1072-
test_encoding_roundtrip(&bitcoin::Network::Testnet, &[
1072+
test_encoding_roundtrip(&bitcoin::Network::Testnet, [
10731073
0x0B, 0x11, 0x09, 0x07,
10741074
])?;
1075-
test_encoding_roundtrip(&bitcoin::Network::Signet, &[
1075+
test_encoding_roundtrip(&bitcoin::Network::Signet, [
10761076
0x0A, 0x03, 0xCF, 0x40,
10771077
])?;
1078-
test_encoding_roundtrip(&bitcoin::Network::Regtest, &[
1078+
test_encoding_roundtrip(&bitcoin::Network::Regtest, [
10791079
0xFA, 0xBF, 0xB5, 0xDA,
10801080
])
10811081
}
@@ -1224,9 +1224,9 @@ pub(crate) mod test {
12241224

12251225
// test random and null outpoints
12261226
let outpoint = OutPoint::new(txid, vout);
1227-
test_encoding_roundtrip(&outpoint, &OUTPOINT).unwrap();
1227+
test_encoding_roundtrip(&outpoint, OUTPOINT).unwrap();
12281228
let null = OutPoint::null();
1229-
test_encoding_roundtrip(&null, &OUTPOINT_NULL).unwrap();
1229+
test_encoding_roundtrip(&null, OUTPOINT_NULL).unwrap();
12301230
}
12311231

12321232
#[test]
@@ -1342,14 +1342,14 @@ pub(crate) mod test {
13421342
9ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
13431343
)
13441344
.unwrap();
1345-
test_encoding_roundtrip(&ext_pubkey1, &EXT_PUBKEY1).unwrap();
1345+
test_encoding_roundtrip(&ext_pubkey1, EXT_PUBKEY1).unwrap();
13461346

13471347
let ext_pubkey2 = bip32::ExtendedPubKey::from_str(
13481348
"xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJP\
13491349
MM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5",
13501350
)
13511351
.unwrap();
1352-
test_encoding_roundtrip(&ext_pubkey2, &EXT_PUBKEY2).unwrap();
1352+
test_encoding_roundtrip(&ext_pubkey2, EXT_PUBKEY2).unwrap();
13531353
}
13541354

13551355
#[test]
@@ -1390,28 +1390,27 @@ pub(crate) mod test {
13901390
];
13911391

13921392
// OP_RETURN
1393-
let op_return: Script =
1394-
test_vec_decoding_roundtrip(&OP_RETURN).unwrap();
1393+
let op_return: Script = test_vec_decoding_roundtrip(OP_RETURN).unwrap();
13951394
assert!(op_return.is_op_return());
13961395

13971396
// P2PK
1398-
let p2pk: Script = test_vec_decoding_roundtrip(&P2PK).unwrap();
1397+
let p2pk: Script = test_vec_decoding_roundtrip(P2PK).unwrap();
13991398
assert!(p2pk.is_p2pk());
14001399

14011400
//P2PKH
1402-
let p2pkh: Script = test_vec_decoding_roundtrip(&P2PKH).unwrap();
1401+
let p2pkh: Script = test_vec_decoding_roundtrip(P2PKH).unwrap();
14031402
assert!(p2pkh.is_p2pkh());
14041403

14051404
//P2SH
1406-
let p2sh: Script = test_vec_decoding_roundtrip(&P2SH).unwrap();
1405+
let p2sh: Script = test_vec_decoding_roundtrip(P2SH).unwrap();
14071406
assert!(p2sh.is_p2sh());
14081407

14091408
//P2WPKH
1410-
let p2wpkh: Script = test_vec_decoding_roundtrip(&P2WPKH).unwrap();
1409+
let p2wpkh: Script = test_vec_decoding_roundtrip(P2WPKH).unwrap();
14111410
assert!(p2wpkh.is_v0_p2wpkh());
14121411

14131412
//P2WSH
1414-
let p2wsh: Script = test_vec_decoding_roundtrip(&P2WSH).unwrap();
1413+
let p2wsh: Script = test_vec_decoding_roundtrip(P2WSH).unwrap();
14151414
assert!(p2wsh.is_v0_p2wsh());
14161415
}
14171416
}

strict_encoding/src/miniscript.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,15 +1207,15 @@ mod test {
12071207

12081208
#[test]
12091209
#[should_panic]
1210-
fn test_bare_ctx() { BareCtx::strict_deserialize(&[0u8]).unwrap(); }
1210+
fn test_bare_ctx() { BareCtx::strict_deserialize([0u8]).unwrap(); }
12111211

12121212
#[test]
12131213
#[should_panic]
1214-
fn test_legacy_ctx() { Legacy::strict_deserialize(&[0u8]).unwrap(); }
1214+
fn test_legacy_ctx() { Legacy::strict_deserialize([0u8]).unwrap(); }
12151215

12161216
#[test]
12171217
#[should_panic]
1218-
fn test_segwitv0_ctx() { Segwitv0::strict_deserialize(&[0u8]).unwrap(); }
1218+
fn test_segwitv0_ctx() { Segwitv0::strict_deserialize([0u8]).unwrap(); }
12191219

12201220
#[test]
12211221
fn test_policy() {

strict_encoding/src/slice32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod test {
5858
assert_eq!(&ser, &data);
5959
assert_eq!(Slice32::strict_deserialize(&ser), Ok(slice32));
6060

61-
assert_eq!(Slice32::from_slice(&data), Some(slice32));
61+
assert_eq!(Slice32::from_slice(data), Some(slice32));
6262
assert_eq!(Slice32::from_slice(&data[..30]), None);
6363
assert_eq!(&slice32.to_vec(), &data);
6464
assert_eq!(&slice32.as_inner()[..], &data);

0 commit comments

Comments
 (0)