Skip to content

Commit 802c006

Browse files
committed
upgrade bitcoin 0.31 -> 0.32, fix test env vars
avoid setting {BITCOIND,ELEMENTSD}_EXE in setup The logic of setting the env var inside the setup prevents user of other OS like nixos to run the tests (because the included binary are not working on nixos). Setting those env vars is meant to be done in the dev environment not in the code. With this users with `bitcoind` and `elementsd` in their PATH will work too. The CI script will set the variables only if they are not already set. (Allowing Nixos users to override and run it locally)
1 parent ea70b14 commit 802c006

File tree

12 files changed

+52
-86
lines changed

12 files changed

+52
-86
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ json-contract = ["serde_json"]
2222
base64 = ["bitcoin/base64"]
2323

2424
[dependencies]
25-
bitcoin = "0.31.0"
26-
secp256k1-zkp = { version = "0.10.0", features = ["global-context", "hashes"] }
25+
bech32 = "0.11.0"
26+
bitcoin = "0.32.2"
27+
secp256k1-zkp = { version = "0.11.0", features = ["global-context", "hashes"] }
2728

2829
# Used for ContractHash::from_json_contract.
2930
serde_json = { version = "1.0", optional = true }

contrib/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ fi
6666
if [ "$DO_INTEGRATION" = true ]
6767
then
6868
(
69+
BITCOIND_EXE_DEFAULT="$(git rev-parse --show-toplevel)/elementsd-tests/bin/bitcoind"
70+
ELEMENTSD_EXE_DEFAULT="$(git rev-parse --show-toplevel)/elementsd-tests/bin/elementsd"
71+
6972
cd elementsd-tests
73+
BITCOIND_EXE=${BITCOIND_EXE:=${BITCOIND_EXE_DEFAULT}} \
74+
ELEMENTSD_EXE=${ELEMENTSD_EXE:=${ELEMENTSD_EXE_DEFAULT}} \
7075
cargo test
7176
cd ..
7277
)

elementsd-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
bitcoin = "0.31.0"
10+
bitcoin = "0.32.2"
1111
elements = {path = "../", features = ["base64"]}
12-
elementsd = "0.9.0"
12+
elementsd = "0.11.0"
1313
rand = "0.8"
1414

elementsd-tests/src/lib.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
21
#[cfg(test)]
32
mod pset;
43
#[cfg(test)]
54
mod taproot;
65

7-
use elementsd::bitcoincore_rpc::RpcApi;
86
use elementsd::bitcoincore_rpc::jsonrpc::serde_json::{json, Value};
7+
use elementsd::bitcoincore_rpc::RpcApi;
98
#[cfg(test)]
109
use elementsd::bitcoind::{self, BitcoinD};
1110
use elementsd::ElementsD;
@@ -132,45 +131,10 @@ impl Call for ElementsD {
132131
.unwrap()
133132
.to_string()
134133
}
135-
136134
}
137135

138136
#[cfg(test)]
139137
fn setup(validate_pegin: bool) -> (ElementsD, Option<BitcoinD>) {
140-
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
141-
let key = "BITCOIND_EXE";
142-
if std::env::var(key).is_err() {
143-
let mut root_path = std::env::current_dir().unwrap();
144-
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
145-
if !root_path.pop() {
146-
panic!("Could not find LICENSE file; do not know where repo root is.");
147-
}
148-
}
149-
150-
let bitcoind_path = root_path
151-
.join("elementsd-tests")
152-
.join("bin")
153-
.join("bitcoind");
154-
std::env::set_var(key, bitcoind_path);
155-
}
156-
157-
// Create env var BITCOIND_EXE_PATH to point to the ../bitcoind/bin/bitcoind binary
158-
let key = "ELEMENTSD_EXE";
159-
if std::env::var(key).is_err() {
160-
let mut root_path = std::env::current_dir().unwrap();
161-
while std::fs::metadata(root_path.join("LICENSE")).is_err() {
162-
if !root_path.pop() {
163-
panic!("Could not find LICENSE file; do not know where repo root is.");
164-
}
165-
}
166-
167-
let bitcoind_path = root_path
168-
.join("elementsd-tests")
169-
.join("bin")
170-
.join("elementsd");
171-
std::env::set_var(key, bitcoind_path);
172-
}
173-
174138
let mut bitcoind = None;
175139
if validate_pegin {
176140
let bitcoind_exe = bitcoind::exe_path().unwrap();

src/address.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::fmt;
2121
use std::fmt::Write as _;
2222
use std::str::FromStr;
2323

24-
use crate::bech32::{Bech32, Bech32m, ByteIterExt, Fe32, Fe32IterExt, Hrp};
24+
use bech32::{Bech32, Bech32m, ByteIterExt, Fe32, Fe32IterExt, Hrp};
2525
use crate::blech32::{Blech32, Blech32m};
2626
use crate::hashes::Hash;
2727
use bitcoin::base58;
@@ -44,7 +44,7 @@ pub enum AddressError {
4444
/// Base58 encoding error
4545
Base58(base58::Error),
4646
/// Bech32 encoding error
47-
Bech32(crate::bech32::primitives::decode::SegwitHrpstringError),
47+
Bech32(bech32::primitives::decode::SegwitHrpstringError),
4848
/// Blech32 encoding error
4949
Blech32(crate::blech32::decode::SegwitHrpstringError),
5050
/// Was unable to parse the address.
@@ -70,8 +70,8 @@ pub enum AddressError {
7070
InvalidAddressVersion(u8),
7171
}
7272

73-
impl From<crate::bech32::primitives::decode::SegwitHrpstringError> for AddressError {
74-
fn from(e: crate::bech32::primitives::decode::SegwitHrpstringError) -> Self {
73+
impl From<bech32::primitives::decode::SegwitHrpstringError> for AddressError {
74+
fn from(e: bech32::primitives::decode::SegwitHrpstringError) -> Self {
7575
AddressError::Bech32(e)
7676
}
7777
}
@@ -458,7 +458,7 @@ impl Address {
458458
let hs = crate::blech32::decode::SegwitHrpstring::new(s)?;
459459
(hs.witness_version(), hs.byte_iter().collect())
460460
} else {
461-
let hs = crate::bech32::primitives::decode::SegwitHrpstring::new(s)?;
461+
let hs = bech32::primitives::decode::SegwitHrpstring::new(s)?;
462462
(hs.witness_version(), hs.byte_iter().collect())
463463
};
464464

@@ -908,7 +908,7 @@ mod test {
908908
"ert130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqqu2tys".parse();
909909
assert_eq!(
910910
address.err().unwrap().to_string(),
911-
"bech32 error: invalid segwit witness version: 3", // FIXME https://github.com/rust-bitcoin/rust-bech32/issues/162 should be 17
911+
"bech32 error: invalid segwit witness version: 17 (bech32 character: '3')",
912912
);
913913

914914
let address: Result<Address, _> = "el1pq0umk3pez693jrrlxz9ndlkuwne93gdu9g83mhhzuyf46e3mdzfpva0w48gqgzgrklncnm0k5zeyw8my2ypfsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpe9jfn0gypaj".parse();
@@ -920,10 +920,7 @@ mod test {
920920
// "invalid prefix" gives a weird error message because we do
921921
// a dumb prefix check before even attempting bech32 decoding
922922
let address: Result<Address, _> = "rrr1qq0umk3pez693jrrlxz9ndlkuwne93gdu9g83mhhzuyf46e3mdzfpva0w48gqgzgrklncnm0k5zeyw8my2ypfs2d9rp7meq4kg".parse();
923-
assert_eq!(
924-
address.err().unwrap().to_string(),
925-
"base58 error: invalid base58 character 0x30",
926-
);
923+
assert_eq!(address.err().unwrap().to_string(), "base58 error: decode",);
927924
}
928925

929926
#[test]

src/blech32/decode.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666
use core::{fmt, iter, slice, str};
6767

6868
use crate::error::write_err;
69-
use crate::bech32::primitives::checksum::{self, Checksum};
70-
use crate::bech32::primitives::gf32::Fe32;
71-
use crate::bech32::primitives::hrp::{self, Hrp};
72-
use crate::bech32::primitives::iter::{Fe32IterExt, FesToBytes};
73-
use crate::bech32::primitives::segwit::{WitnessLengthError, VERSION_0};
69+
use bech32::primitives::checksum::{self, Checksum};
70+
use bech32::primitives::gf32::Fe32;
71+
use bech32::primitives::hrp::{self, Hrp};
72+
use bech32::primitives::iter::{Fe32IterExt, FesToBytes};
73+
use bech32::primitives::segwit::{WitnessLengthError, VERSION_0};
7474
use super::{Blech32, Blech32m};
7575

7676
/// Separator between the hrp and payload (as defined by BIP-173).
@@ -150,7 +150,7 @@ impl<'s> UncheckedHrpstring<'s> {
150150
}
151151

152152
let mut checksum_eng = checksum::Engine::<Ck>::new();
153-
checksum_eng.input_hrp(&self.hrp());
153+
checksum_eng.input_hrp(self.hrp());
154154

155155
// Unwrap ok since we checked all characters in our constructor.
156156
for fe in self.data.iter().map(|&b| Fe32::from_char(b.into()).unwrap()) {
@@ -881,7 +881,7 @@ mod tests {
881881
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio";
882882

883883
let hrp = Hrp::parse_unchecked(hrps);
884-
let s = crate::bech32::encode::<Blech32>(hrp, &[]).expect("failed to encode empty buffer");
884+
let s = bech32::encode::<Blech32>(hrp, &[]).expect("failed to encode empty buffer");
885885

886886
let unchecked = UncheckedHrpstring::new(&s).expect("failed to parse address");
887887
assert_eq!(unchecked.hrp(), hrp);

src/blech32/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub mod decode;
2626
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2727
pub enum Blech32 {}
2828

29-
impl crate::bech32::Checksum for Blech32 {
29+
impl bech32::Checksum for Blech32 {
3030
type MidstateRepr = u64;
3131
const CHECKSUM_LENGTH: usize = 12;
3232
const GENERATOR_SH: [u64; 5] = [
@@ -37,13 +37,15 @@ impl crate::bech32::Checksum for Blech32 {
3737
0x7093e5a608865b,
3838
];
3939
const TARGET_RESIDUE: u64 = 1;
40+
41+
const CODE_LENGTH: usize = 1024;
4042
}
4143

4244
/// The blech32m checksum algorithm.
4345
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
4446
pub enum Blech32m {}
4547

46-
impl crate::bech32::Checksum for Blech32m {
48+
impl bech32::Checksum for Blech32m {
4749
type MidstateRepr = u64;
4850
const CHECKSUM_LENGTH: usize = 12;
4951
const GENERATOR_SH: [u64; 5] = [
@@ -54,5 +56,6 @@ impl crate::bech32::Checksum for Blech32m {
5456
0x7093e5a608865b,
5557
];
5658
const TARGET_RESIDUE: u64 = 0x455972a3350f7a1;
57-
}
5859

60+
const CODE_LENGTH: usize = 1024;
61+
}

src/blind.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ mod tests {
13751375
use crate::encode::deserialize;
13761376
use crate::hex::FromHex;
13771377
use crate::Script;
1378-
use bitcoin::{Network, PrivateKey, PublicKey};
1378+
use bitcoin::{PrivateKey, PublicKey};
13791379
use rand::thread_rng;
13801380
use secp256k1_zkp::SECP256K1;
13811381
use std::str::FromStr;
@@ -1466,7 +1466,7 @@ mod tests {
14661466
SECP256K1,
14671467
&PrivateKey {
14681468
compressed: true,
1469-
network: Network::Regtest,
1469+
network: bitcoin::NetworkKind::Test,
14701470
inner: sk,
14711471
},
14721472
);
@@ -1475,7 +1475,7 @@ mod tests {
14751475
SECP256K1,
14761476
&PrivateKey {
14771477
compressed: true,
1478-
network: Network::Regtest,
1478+
network: bitcoin::NetworkKind::Test,
14791479
inner: blinding_sk,
14801480
},
14811481
);

src/hash_types.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,39 @@
1616
//! to avoid mixing data of the same hash format (like SHA256d) but of different meaning
1717
//! (transaction id, block hash etc).
1818
19-
use crate:: hashes::{hash_newtype, hash160, sha256, sha256d, Hash};
20-
use bitcoin::secp256k1::ThirtyTwoByteHash;
19+
use crate::hashes::{hash160, hash_newtype, sha256, sha256d, Hash};
2120

2221
macro_rules! impl_hashencode {
2322
($hashtype:ident) => {
2423
impl $crate::encode::Encodable for $hashtype {
25-
fn consensus_encode<W: std::io::Write>(&self, w: W) -> Result<usize, crate::encode::Error> {
24+
fn consensus_encode<W: std::io::Write>(
25+
&self,
26+
w: W,
27+
) -> Result<usize, crate::encode::Error> {
2628
self.0.consensus_encode(w)
2729
}
2830
}
2931

3032
impl $crate::encode::Decodable for $hashtype {
3133
fn consensus_decode<R: std::io::Read>(r: R) -> Result<Self, $crate::encode::Error> {
32-
Ok(Self::from_byte_array(<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?))
34+
Ok(Self::from_byte_array(
35+
<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?,
36+
))
3337
}
3438
}
3539
};
3640
}
3741

3842
hash_newtype! {
3943
/// An elements transaction ID
40-
pub struct Txid(sha256d::Hash);
44+
pub struct Txid(sha256d::Hash);
4145
/// An elements witness transaction ID
42-
pub struct Wtxid(sha256d::Hash);
46+
pub struct Wtxid(sha256d::Hash);
4347
/// An elements blockhash
44-
pub struct BlockHash(sha256d::Hash);
48+
pub struct BlockHash(sha256d::Hash);
4549

4650
/// "Hash of the transaction according to the signature algorithm"
47-
pub struct Sighash(sha256d::Hash);
51+
pub struct Sighash(sha256d::Hash);
4852

4953
/// A hash of a public key.
5054
pub struct PubkeyHash(hash160::Hash);
@@ -59,15 +63,8 @@ hash_newtype! {
5963
pub struct TxMerkleNode(sha256d::Hash);
6064
}
6165

62-
6366
impl_hashencode!(Txid);
6467
impl_hashencode!(Wtxid);
6568
impl_hashencode!(Sighash);
6669
impl_hashencode!(BlockHash);
6770
impl_hashencode!(TxMerkleNode);
68-
69-
impl ThirtyTwoByteHash for Sighash {
70-
fn into_32(self) -> [u8; 32] {
71-
self.0.to_byte_array()
72-
}
73-
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ mod transaction;
7373
// consider making upstream public
7474
mod endian;
7575
// re-export bitcoin deps which we re-use
76-
pub use bitcoin::bech32;
7776
pub use bitcoin::hashes;
7877
// export everything at the top level so it can be used as `elements::Transaction` etc.
7978
pub use crate::address::{Address, AddressError, AddressParams};

0 commit comments

Comments
 (0)