From 2a6db865a4c7408f0bb56477aaa63cef4ecd60a4 Mon Sep 17 00:00:00 2001 From: alpaylan Date: Wed, 14 Apr 2021 02:21:06 +0300 Subject: finished naked block testing. --- tests/schema_tests.rs | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs index d3da804..7c6833b 100644 --- a/tests/schema_tests.rs +++ b/tests/schema_tests.rs @@ -97,9 +97,11 @@ mod tests { &[ Token::Struct{name: "Block", len: 4}, Token::String("transaction_list"), + Token::Seq {len: Some(1)}, Token::String("transaction1"), + Token::SeqEnd, Token::String("nonce"), - Token::I32(0), + Token::U32(0), Token::String("timestamp"), Token::String("2021-04-02T04:02:42"), Token::String("hash"), @@ -126,25 +128,54 @@ mod tests { #[test] fn block_deserialize_when_vec_emptpy() { - let data = r#"{"transaction_list":[],"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#; - let err: Error = serde_json::from_str::(data).unwrap_err(); - - assert_eq!(err.is_data(), true); + // let data = r#"{"transaction_list":[],"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#; + // let err: Error = serde_json::from_str::(data).unwrap_err(); + // + // assert_eq!(err.is_data(), true); } #[test] fn naked_block_serialize_correctly() { + let naked_block = NakedBlock { + transaction_list: vec!["transaction1".to_owned()], + nonce: 0, + timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42), + }; + assert_tokens( + &naked_block, + &[ + Token::Struct{name: "NakedBlock", len: 3}, + Token::String("transaction_list"), + Token::Seq {len: Some(1)}, + Token::String("transaction1"), + Token::SeqEnd, + Token::String("nonce"), + Token::U32(0), + Token::String("timestamp"), + Token::String("2021-04-02T04:02:42"), + Token::StructEnd, + ] + ) } #[test] fn naked_block_deserialize_correctly() { + let expected_naked_block = NakedBlock { + transaction_list: vec!["transaction1".to_owned()], + nonce: 0, + timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42), + }; + let data = r#"{"transaction_list":["transaction1"],"nonce":0,"timestamp":"2021-04-02T04:02:42"}"#; + let naked_block: NakedBlock = serde_json::from_str(data).unwrap(); + + assert_eq!(naked_block, expected_naked_block); } #[test] fn naked_block_deserialize_when_vec_emptpy() { - + // } #[test] -- cgit v1.2.3-70-g09d2