summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/schema_tests.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs
index fc06796..d3da804 100644
--- a/tests/schema_tests.rs
+++ b/tests/schema_tests.rs
@@ -85,17 +85,51 @@ mod tests {
85 85
86 #[test] 86 #[test]
87 fn block_serialize_correctly() { 87 fn block_serialize_correctly() {
88 let block = Block {
89 transaction_list: vec!["transaction1".to_owned()],
90 nonce: 0,
91 timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
92 hash: "hash".to_owned()
93 };
88 94
95 assert_tokens(
96 &block,
97 &[
98 Token::Struct{name: "Block", len: 4},
99 Token::String("transaction_list"),
100 Token::String("transaction1"),
101 Token::String("nonce"),
102 Token::I32(0),
103 Token::String("timestamp"),
104 Token::String("2021-04-02T04:02:42"),
105 Token::String("hash"),
106 Token::String("hash"),
107 Token::StructEnd,
108 ]
109 )
89 } 110 }
90 111
91 #[test] 112 #[test]
92 fn block_deserialize_correctly() { 113 fn block_deserialize_correctly() {
114 let expected_block = Block {
115 transaction_list: vec!["transaction1".to_owned()],
116 nonce: 0,
117 timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
118 hash: "hash".to_owned()
119 };
120 let data = r#"{"transaction_list":["transaction1"],"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#;
121 let block: Block = serde_json::from_str(data).unwrap();
122
123 assert_eq!(block, expected_block);
93 124
94 } 125 }
95 126
96 #[test] 127 #[test]
97 fn block_deserialize_when_vec_emptpy() { 128 fn block_deserialize_when_vec_emptpy() {
129 let data = r#"{"transaction_list":[],"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#;
130 let err: Error = serde_json::from_str::<Block>(data).unwrap_err();
98 131
132 assert_eq!(err.is_data(), true);
99 } 133 }
100 134
101 #[test] 135 #[test]