Fix H256 encoding, remove U256 encoding

Addresses #20
This commit is contained in:
Paul Hauner 2018-09-21 18:57:33 +10:00
parent e88686e4f4
commit 8439094a8d
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -4,7 +4,7 @@ use super::{
Encodable, Encodable,
SszStream SszStream
}; };
use super::ethereum_types::{ H256, U256 }; use super::ethereum_types::H256;
use self::bytes::{ BytesMut, BufMut }; use self::bytes::{ BytesMut, BufMut };
/* /*
@ -49,15 +49,7 @@ impl_encodable_for_uint!(usize, 64);
impl Encodable for H256 { impl Encodable for H256 {
fn ssz_append(&self, s: &mut SszStream) { fn ssz_append(&self, s: &mut SszStream) {
s.append_encoded_val(&self.to_vec()); s.append_encoded_raw(&self.to_vec());
}
}
impl Encodable for U256 {
fn ssz_append(&self, s: &mut SszStream) {
let mut a = [0; 32];
self.to_big_endian(&mut a);
s.append_encoded_val(&a.to_vec());
} }
} }
@ -66,6 +58,14 @@ impl Encodable for U256 {
mod tests { mod tests {
use super::*; use super::*;
#[test]
fn test_ssz_encode_h256() {
let h = H256::zero();
let mut ssz = SszStream::new();
ssz.append(&h);
assert_eq!(ssz.drain(), vec![0; 32]);
}
#[test] #[test]
fn test_ssz_encode_u8() { fn test_ssz_encode_u8() {
let x: u8 = 0; let x: u8 = 0;