Skip to content

Commit

Permalink
Test progress
Browse files Browse the repository at this point in the history
  • Loading branch information
zmanian committed May 6, 2018
1 parent a31c9a9 commit 95d9a3b
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 60 deletions.
87 changes: 38 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/types/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ impl Amino for Heartbeat{
println!("{:x?}",length_buf );
length_buf
}
}

pub fn deserialize_heartbeat(data: &[u8]) -> Result<Heartbeat,DecodeError> {


fn deserialize(data: &[u8]) -> Result<Heartbeat,DecodeError> {
let mut buf = Cursor::new(data);

{
Expand Down Expand Up @@ -218,6 +215,7 @@ pub fn deserialize_heartbeat(data: &[u8]) -> Result<Heartbeat,DecodeError> {
signature:sig
})
}
}

#[cfg(test)]
mod tests {
Expand All @@ -242,7 +240,7 @@ mod tests {

let data = vec![0x2c, 0xbf, 0x58, 0xca, 0xeb, 0xb, 0xa, 0x14, 0xa3, 0xb2, 0xcc, 0xdd, 0x71, 0x86, 0xf1, 0x68, 0x5f, 0x21, 0xf2, 0x48, 0x2a, 0xf4, 0xfb, 0x34, 0x46, 0xa8, 0x4b, 0x35, 0x10, 0x2, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1e, 0x20, 0x14, 0x28, 0x1e, 0x4, 0x4];

match deserialize_heartbeat(&data){
match Heartbeat::deserialize(&data){
Err(err) => assert!(false,err.description().to_string()),
Ok(have) => assert_eq!(have,want)
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ValidatorAddress(pub [u8;20]);


#[derive(PartialEq, Debug)]
struct PartsSetHeader{
pub struct PartsSetHeader{
total: i64,
hash: Vec<u8>
}
Expand Down
43 changes: 43 additions & 0 deletions src/types/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use chrono::{DateTime,Utc};
use signatory::ed25519::{Signature, SIGNATURE_SIZE};
use super::{TendermintSign, BlockID, PartsSetHeader};
use hex::encode_upper;
use amino::*;



Expand Down Expand Up @@ -41,3 +42,45 @@ impl TendermintSign for Proposal{
value.to_string()
}
}

impl Amino for Proposal{
fn serialize(self)->Vec<u8>{
unimplemented!()
}
fn deserialize(data: &[u8])->Result<Proposal,DecodeError>{
unimplemented!()
}
}

// #[cfg(test)]
// mod tests {
// use super::*;

// #[test]
// fn test_serialization() {
// let addr:[u8;20] =[0xa3, 0xb2, 0xcc, 0xdd, 0x71, 0x86, 0xf1, 0x68, 0x5f, 0x21, 0xf2, 0x48, 0x2a, 0xf4, 0xfb, 0x34, 0x46, 0xa8, 0x4b, 0x35];
// let proposal = Proposal{ validator_address:ValidatorAddress(addr), validator_index:1, height: 15, round: 10, sequence: 30, signature:None };


// let have = proposal.serialize();

// let want = vec![0x2c, 0xbf, 0x58, 0xca, 0xeb, 0xb, 0xa, 0x14, 0xa3, 0xb2, 0xcc, 0xdd, 0x71, 0x86, 0xf1, 0x68, 0x5f, 0x21, 0xf2, 0x48, 0x2a, 0xf4, 0xfb, 0x34, 0x46, 0xa8, 0x4b, 0x35, 0x10, 0x2, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1e, 0x20, 0x14, 0x28, 0x1e, 0x4, 0x4];

// assert_eq!(have, want)
// }
// #[test]
// fn test_derialization(){
// let addr:[u8;20] =[0xa3, 0xb2, 0xcc, 0xdd, 0x71, 0x86, 0xf1, 0x68, 0x5f, 0x21, 0xf2, 0x48, 0x2a, 0xf4, 0xfb, 0x34, 0x46, 0xa8, 0x4b, 0x35];
// let want = Proposal{ validator_address:ValidatorAddress(addr), validator_index:1, height: 15, round: 10, sequence: 30, signature:None };

// let data = vec![0x2c, 0xbf, 0x58, 0xca, 0xeb, 0xb, 0xa, 0x14, 0xa3, 0xb2, 0xcc, 0xdd, 0x71, 0x86, 0xf1, 0x68, 0x5f, 0x21, 0xf2, 0x48, 0x2a, 0xf4, 0xfb, 0x34, 0x46, 0xa8, 0x4b, 0x35, 0x10, 0x2, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1e, 0x20, 0x14, 0x28, 0x1e, 0x4, 0x4];

// match Proposal::deserialize(&data){
// Err(err) => assert!(false,err.description().to_string()),
// Ok(have) => assert_eq!(have,want)
// }


// }
// //ToDo Serialization with Signature
// }
Loading

0 comments on commit 95d9a3b

Please sign in to comment.