Merge pull request #82 from popzxc/impl-display-for-uint
Added `impl Display` to `construct_uint` macro
This commit is contained in:
commit
7ffd829e39
|
@ -323,6 +323,12 @@ macro_rules! construct_uint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for $name {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
<fmt::Debug>::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S: ::network::serialize::SimpleEncoder> ::network::encodable::ConsensusEncodable<S> for $name {
|
impl<S: ::network::serialize::SimpleEncoder> ::network::encodable::ConsensusEncodable<S> for $name {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_encode(&self, s: &mut S) -> Result<(), S::Error> {
|
fn consensus_encode(&self, s: &mut S) -> Result<(), S::Error> {
|
||||||
|
@ -401,6 +407,19 @@ mod tests {
|
||||||
assert!(!Uint256::from_u64(10).unwrap().bit(4));
|
assert!(!Uint256::from_u64(10).unwrap().bit(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn uint256_display_test() {
|
||||||
|
assert_eq!(format!("{}", Uint256::from_u64(0xDEADBEEF).unwrap()),
|
||||||
|
"0x00000000000000000000000000000000000000000000000000000000deadbeef");
|
||||||
|
assert_eq!(format!("{}", Uint256::from_u64(u64::max_value()).unwrap()),
|
||||||
|
"0x000000000000000000000000000000000000000000000000ffffffffffffffff");
|
||||||
|
|
||||||
|
let max_val = Uint256([0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
|
||||||
|
0xFFFFFFFFFFFFFFFF]);
|
||||||
|
assert_eq!(format!("{}", max_val),
|
||||||
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn uint256_comp_test() {
|
pub fn uint256_comp_test() {
|
||||||
let small = Uint256([10u64, 0, 0, 0]);
|
let small = Uint256([10u64, 0, 0, 0]);
|
||||||
|
|
Loading…
Reference in New Issue