Merge branch 'split_hash' into move_hash

This commit is contained in:
debris 2016-08-05 09:56:36 +02:00
commit df29fcff1a
5 changed files with 17 additions and 39 deletions

View File

@ -1393,7 +1393,7 @@ fn alter_balance() {
let mut state_result = get_temp_state(); let mut state_result = get_temp_state();
let mut state = state_result.reference_mut(); let mut state = state_result.reference_mut();
let a = Address::zero(); let a = Address::zero();
let b = address_from_u64(1u64); let b = 1u64.into();
state.add_balance(&a, &U256::from(69u64)); state.add_balance(&a, &U256::from(69u64));
assert_eq!(state.balance(&a), U256::from(69u64)); assert_eq!(state.balance(&a), U256::from(69u64));
state.commit().unwrap(); state.commit().unwrap();

View File

@ -441,29 +441,6 @@ impl<'a> From<&'a Address> for H256 {
} }
} }
/// Convert string `s` to an `H256`. Will panic if `s` is not 64 characters long or if any of
/// those characters are not 0-9, a-z or A-Z.
pub fn h256_from_hex(s: &str) -> H256 {
H256::from_str(s).unwrap()
}
/// Convert `n` to an `H256`, setting the rightmost 8 bytes.
pub fn h256_from_u64(n: u64) -> H256 {
H256::from(&U256::from(n))
}
/// Convert string `s` to an `Address`. Will panic if `s` is not 40 characters long or if any of
/// those characters are not 0-9, a-z or A-Z.
pub fn address_from_hex(s: &str) -> Address {
Address::from_str(s).unwrap()
}
/// Convert `n` to an `Address`, setting the rightmost 8 bytes.
pub fn address_from_u64(n: u64) -> Address {
let h256 = h256_from_u64(n);
From::from(h256)
}
impl_hash!(H32, 4); impl_hash!(H32, 4);
impl_hash!(H64, 8); impl_hash!(H64, 8);
impl_hash!(H128, 16); impl_hash!(H128, 16);

View File

@ -232,11 +232,12 @@ fn fax_raw_dyn() {
#[test] #[test]
fn populate_big_types() { fn populate_big_types() {
use hash::*; use hash::*;
let a = address_from_hex("ffffffffffffffffffffffffffffffffffffffff"); let a: Address = "ffffffffffffffffffffffffffffffffffffffff".into();
let mut h = h256_from_u64(0x69); let mut h: H256 = 0x69.into();
h.populate_raw_from(&a); h.populate_raw_from(&a);
assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000000")); assert_eq!(h, "ffffffffffffffffffffffffffffffffffffffff000000000000000000000000".into());
let mut h = h256_from_u64(0x69);
let mut h: H256 = 0x69.into();
h.copy_raw_from(&a); h.copy_raw_from(&a);
assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000069")); assert_eq!(h, "ffffffffffffffffffffffffffffffffffffffff000000000000000000000069".into());
} }

View File

@ -235,7 +235,7 @@ pub mod ec {
/// Check if this is a "low" signature. /// Check if this is a "low" signature.
pub fn is_low(sig: &Signature) -> bool { pub fn is_low(sig: &Signature) -> bool {
H256::from_slice(&sig[32..64]) <= h256_from_hex("7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0") H256::from_slice(&sig[32..64]) <= "7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0".into()
} }
/// Check if this is a "low" signature. /// Check if this is a "low" signature.
@ -246,10 +246,10 @@ pub mod ec {
/// Check if each component of the signature is in range. /// Check if each component of the signature is in range.
pub fn is_valid(sig: &Signature) -> bool { pub fn is_valid(sig: &Signature) -> bool {
sig[64] <= 1 && sig[64] <= 1 &&
H256::from_slice(&sig[0..32]) < h256_from_hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141") && H256::from_slice(&sig[0..32]) < "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into() &&
H256::from_slice(&sig[32..64]) < h256_from_hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141") && H256::from_slice(&sig[32..64]) < "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into() &&
H256::from_slice(&sig[32..64]) >= h256_from_u64(1) && H256::from_slice(&sig[32..64]) >= 1.into() &&
H256::from_slice(&sig[0..32]) >= h256_from_u64(1) H256::from_slice(&sig[0..32]) >= 1.into()
} }
} }
@ -432,14 +432,14 @@ mod tests {
#[test] #[test]
fn test_invalid_key() { fn test_invalid_key() {
assert!(KeyPair::from_secret(h256_from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).is_err()); assert!(KeyPair::from_secret("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".into()).is_err());
assert!(KeyPair::from_secret(h256_from_hex("0000000000000000000000000000000000000000000000000000000000000000")).is_err()); assert!(KeyPair::from_secret("0000000000000000000000000000000000000000000000000000000000000000".into()).is_err());
assert!(KeyPair::from_secret(h256_from_hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141")).is_err()); assert!(KeyPair::from_secret("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into()).is_err());
} }
#[test] #[test]
fn test_key() { fn test_key() {
let pair = KeyPair::from_secret(h256_from_hex("6f7b0d801bc7b5ce7bbd930b84fd0369b3eb25d09be58d64ba811091046f3aa2")).unwrap(); let pair = KeyPair::from_secret("6f7b0d801bc7b5ce7bbd930b84fd0369b3eb25d09be58d64ba811091046f3aa2".into()).unwrap();
assert_eq!(pair.public().hex(), "101b3ef5a4ea7a1c7928e24c4c75fd053c235d7b80c22ae5c03d145d0ac7396e2a4ffff9adee3133a7b05044a5cee08115fd65145e5165d646bde371010d803c"); assert_eq!(pair.public().hex(), "101b3ef5a4ea7a1c7928e24c4c75fd053c235d7b80c22ae5c03d145d0ac7396e2a4ffff9adee3133a7b05044a5cee08115fd65145e5165d646bde371010d803c");
} }

View File

@ -1151,7 +1151,7 @@ fn key_save_load() {
#[test] #[test]
fn host_client_url() { fn host_client_url() {
let mut config = NetworkConfiguration::new(); let mut config = NetworkConfiguration::new();
let key = h256_from_hex("6f7b0d801bc7b5ce7bbd930b84fd0369b3eb25d09be58d64ba811091046f3aa2"); let key = "6f7b0d801bc7b5ce7bbd930b84fd0369b3eb25d09be58d64ba811091046f3aa2".into();
config.use_secret = Some(key); config.use_secret = Some(key);
let host: Host = Host::new(config, Arc::new(NetworkStats::new())).unwrap(); let host: Host = Host::new(config, Arc::new(NetworkStats::new())).unwrap();
assert!(host.local_url().starts_with("enode://101b3ef5a4ea7a1c7928e24c4c75fd053c235d7b80c22ae5c03d145d0ac7396e2a4ffff9adee3133a7b05044a5cee08115fd65145e5165d646bde371010d803c@")); assert!(host.local_url().starts_with("enode://101b3ef5a4ea7a1c7928e24c4c75fd053c235d7b80c22ae5c03d145d0ac7396e2a4ffff9adee3133a7b05044a5cee08115fd65145e5165d646bde371010d803c@"));