Add tests, use Base58Check, not Base58
This commit is contained in:
parent
f11821fcc8
commit
5602ed66a9
|
|
@ -196,6 +196,9 @@ name = "bs58"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae"
|
checksum = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae"
|
||||||
|
dependencies = [
|
||||||
|
"sha2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byte-tools"
|
name = "byte-tools"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bs58 = "0.3.0"
|
bs58 = { version = "0.3", features = ["check"] }
|
||||||
byteorder = "1.3"
|
byteorder = "1.3"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ impl fmt::Debug for TransparentAddress {
|
||||||
let _ = self.zcash_serialize(&mut bytes);
|
let _ = self.zcash_serialize(&mut bytes);
|
||||||
|
|
||||||
f.debug_tuple("TransparentAddress")
|
f.debug_tuple("TransparentAddress")
|
||||||
.field(&bs58::encode(bytes.get_ref()).into_string())
|
.field(&bs58::encode(bytes.get_ref()).with_check().into_string())
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -146,6 +146,7 @@ impl ZcashSerialize for TransparentAddress {
|
||||||
writer.write_all(&pub_key_hash.0)?
|
writer.write_all(&pub_key_hash.0)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -181,3 +182,41 @@ impl ZcashDeserialize for TransparentAddress {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
use secp256k1::PublicKey;
|
||||||
|
|
||||||
|
use crate::types::Script;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pubkey() {
|
||||||
|
let pub_key = PublicKey::from_slice(&[
|
||||||
|
3, 23, 183, 225, 206, 31, 159, 148, 195, 42, 67, 115, 146, 41, 248, 140, 11, 3, 51, 41,
|
||||||
|
111, 180, 110, 143, 114, 134, 88, 73, 198, 174, 52, 184, 78,
|
||||||
|
])
|
||||||
|
.expect("A PublicKey from slice");
|
||||||
|
|
||||||
|
let t_addr = TransparentAddress::from(pub_key);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", t_addr),
|
||||||
|
"TransparentAddress(\"t1bmMa1wJDFdbc2TiURQP5BbBz6jHjUBuHq\")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_script() {
|
||||||
|
let script = Script(vec![0; 20]);
|
||||||
|
|
||||||
|
let t_addr = TransparentAddress::from(script);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
format!("{:?}", t_addr),
|
||||||
|
"TransparentAddress(\"t3Y5pHwfgHbS6pDjj1HLuMFxhFFip1fcJ6g\")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue