From f81fb2de51dcd710e7dc6ec9757eb810d939604e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 8 Jan 2016 12:02:26 +0100 Subject: [PATCH] Fix and some tests for opaque types in populatable. --- src/bytes.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bytes.rs b/src/bytes.rs index 7eae51a44..133de416b 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -334,14 +334,6 @@ pub trait Populatable { self.as_slice_mut().write(&d).unwrap(); } - /// Copies a bunch of bytes `d` to `self`, overwriting as necessary. - /// - /// If `d` is smaller, will leave some bytes untouched. - fn fax_right_raw(&mut self, d: &[u8]) { - use std::io::Write; - self.as_slice_mut().write(&d).unwrap(); - } - /// Copies the raw representation of an object `d` to `self`, overwriting as necessary. /// /// If `d` is smaller, zero-out the remaining bytes. @@ -350,7 +342,7 @@ pub trait Populatable { /// Copies the raw representation of an object `d` to `self`, overwriting as necessary. /// /// If `d` is smaller, will leave some bytes untouched. - fn fax_raw_from(&mut self, d: &BytesConvertable) { self.populate_raw(d.as_slice()); } + fn fax_raw_from(&mut self, d: &BytesConvertable) { self.fax_raw(d.as_slice()); } /// Get the raw slice for this object. fn as_slice_mut(&mut self) -> &mut [u8]; @@ -412,4 +404,16 @@ fn fax_raw_dyn() { let mut x = [255u8; 4]; x.fax_raw(&[1u8; 6][..]); assert_eq!(&x[..], [1u8, 1, 1, 1]); +} + +#[test] +fn populate_big_types() { + use hash::*; + let a = address_from_hex("ffffffffffffffffffffffffffffffffffffffff"); + let mut h = h256_from_u64(0x69); + h.populate_raw_from(&a); + assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000000")); + let mut h = h256_from_u64(0x69); + h.fax_raw_from(&a); + assert_eq!(h, h256_from_hex("ffffffffffffffffffffffffffffffffffffffff000000000000000000000069")); } \ No newline at end of file