Merge branch 'split_hash' into move_hash
This commit is contained in:
commit
df29fcff1a
@ -1393,7 +1393,7 @@ fn alter_balance() {
|
||||
let mut state_result = get_temp_state();
|
||||
let mut state = state_result.reference_mut();
|
||||
let a = Address::zero();
|
||||
let b = address_from_u64(1u64);
|
||||
let b = 1u64.into();
|
||||
state.add_balance(&a, &U256::from(69u64));
|
||||
assert_eq!(state.balance(&a), U256::from(69u64));
|
||||
state.commit().unwrap();
|
||||
|
@ -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!(H64, 8);
|
||||
impl_hash!(H128, 16);
|
||||
|
@ -232,11 +232,12 @@ fn fax_raw_dyn() {
|
||||
#[test]
|
||||
fn populate_big_types() {
|
||||
use hash::*;
|
||||
let a = address_from_hex("ffffffffffffffffffffffffffffffffffffffff");
|
||||
let mut h = h256_from_u64(0x69);
|
||||
let a: Address = "ffffffffffffffffffffffffffffffffffffffff".into();
|
||||
let mut h: H256 = 0x69.into();
|
||||
h.populate_raw_from(&a);
|
||||
assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000000"));
|
||||
let mut h = h256_from_u64(0x69);
|
||||
assert_eq!(h, "ffffffffffffffffffffffffffffffffffffffff000000000000000000000000".into());
|
||||
|
||||
let mut h: H256 = 0x69.into();
|
||||
h.copy_raw_from(&a);
|
||||
assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000069"));
|
||||
assert_eq!(h, "ffffffffffffffffffffffffffffffffffffffff000000000000000000000069".into());
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ pub mod ec {
|
||||
|
||||
/// Check if this is a "low" signature.
|
||||
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.
|
||||
@ -246,10 +246,10 @@ pub mod ec {
|
||||
/// Check if each component of the signature is in range.
|
||||
pub fn is_valid(sig: &Signature) -> bool {
|
||||
sig[64] <= 1 &&
|
||||
H256::from_slice(&sig[0..32]) < h256_from_hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141") &&
|
||||
H256::from_slice(&sig[32..64]) < h256_from_hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141") &&
|
||||
H256::from_slice(&sig[32..64]) >= h256_from_u64(1) &&
|
||||
H256::from_slice(&sig[0..32]) >= h256_from_u64(1)
|
||||
H256::from_slice(&sig[0..32]) < "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into() &&
|
||||
H256::from_slice(&sig[32..64]) < "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into() &&
|
||||
H256::from_slice(&sig[32..64]) >= 1.into() &&
|
||||
H256::from_slice(&sig[0..32]) >= 1.into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,14 +432,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_invalid_key() {
|
||||
assert!(KeyPair::from_secret(h256_from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).is_err());
|
||||
assert!(KeyPair::from_secret(h256_from_hex("0000000000000000000000000000000000000000000000000000000000000000")).is_err());
|
||||
assert!(KeyPair::from_secret(h256_from_hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141")).is_err());
|
||||
assert!(KeyPair::from_secret("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".into()).is_err());
|
||||
assert!(KeyPair::from_secret("0000000000000000000000000000000000000000000000000000000000000000".into()).is_err());
|
||||
assert!(KeyPair::from_secret("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -1151,7 +1151,7 @@ fn key_save_load() {
|
||||
#[test]
|
||||
fn host_client_url() {
|
||||
let mut config = NetworkConfiguration::new();
|
||||
let key = h256_from_hex("6f7b0d801bc7b5ce7bbd930b84fd0369b3eb25d09be58d64ba811091046f3aa2");
|
||||
let key = "6f7b0d801bc7b5ce7bbd930b84fd0369b3eb25d09be58d64ba811091046f3aa2".into();
|
||||
config.use_secret = Some(key);
|
||||
let host: Host = Host::new(config, Arc::new(NetworkStats::new())).unwrap();
|
||||
assert!(host.local_url().starts_with("enode://101b3ef5a4ea7a1c7928e24c4c75fd053c235d7b80c22ae5c03d145d0ac7396e2a4ffff9adee3133a7b05044a5cee08115fd65145e5165d646bde371010d803c@"));
|
||||
|
Loading…
Reference in New Issue
Block a user