summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralpaylan2021-04-14 02:21:06 +0300
committeralpaylan2021-04-14 02:21:06 +0300
commit2a6db865a4c7408f0bb56477aaa63cef4ecd60a4 (patch)
treeda103af9e9b6b9a5766e7b4bf0f74b785f65abf8
parentaa0ad3f0810b015953f31f19155343295b0ca0d3 (diff)
downloadgradecoin-2a6db865a4c7408f0bb56477aaa63cef4ecd60a4.tar.gz
gradecoin-2a6db865a4c7408f0bb56477aaa63cef4ecd60a4.tar.bz2
gradecoin-2a6db865a4c7408f0bb56477aaa63cef4ecd60a4.zip
finished naked block testing.
-rw-r--r--src/schema.rs2
-rw-r--r--tests/schema_tests.rs43
2 files changed, 38 insertions, 7 deletions
diff --git a/src/schema.rs b/src/schema.rs
index b67bce4..5546d12 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -100,7 +100,7 @@ pub struct Block {
100} 100}
101 101
102/// For prototyping and letting serde handle everything json 102/// For prototyping and letting serde handle everything json
103#[derive(Serialize, Deserialize, Debug)] 103#[derive(Serialize, Deserialize, Debug, PartialEq)]
104pub struct NakedBlock { 104pub struct NakedBlock {
105 #[serde(skip_serializing_if = "Vec::is_empty", default)] 105 #[serde(skip_serializing_if = "Vec::is_empty", default)]
106 pub transaction_list: Vec<PublicKeySignature>, 106 pub transaction_list: Vec<PublicKeySignature>,
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 {
97 &[ 97 &[
98 Token::Struct{name: "Block", len: 4}, 98 Token::Struct{name: "Block", len: 4},
99 Token::String("transaction_list"), 99 Token::String("transaction_list"),
100 Token::Seq {len: Some(1)},
100 Token::String("transaction1"), 101 Token::String("transaction1"),
102 Token::SeqEnd,
101 Token::String("nonce"), 103 Token::String("nonce"),
102 Token::I32(0), 104 Token::U32(0),
103 Token::String("timestamp"), 105 Token::String("timestamp"),
104 Token::String("2021-04-02T04:02:42"), 106 Token::String("2021-04-02T04:02:42"),
105 Token::String("hash"), 107 Token::String("hash"),
@@ -126,25 +128,54 @@ mod tests {
126 128
127 #[test] 129 #[test]
128 fn block_deserialize_when_vec_emptpy() { 130 fn block_deserialize_when_vec_emptpy() {
129 let data = r#"{"transaction_list":[],"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#; 131 // 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(); 132 // let err: Error = serde_json::from_str::<Block>(data).unwrap_err();
131 133 //
132 assert_eq!(err.is_data(), true); 134 // assert_eq!(err.is_data(), true);
133 } 135 }
134 136
135 #[test] 137 #[test]
136 fn naked_block_serialize_correctly() { 138 fn naked_block_serialize_correctly() {
139 let naked_block = NakedBlock {
140 transaction_list: vec!["transaction1".to_owned()],
141 nonce: 0,
142 timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
143 };
137 144
145 assert_tokens(
146 &naked_block,
147 &[
148 Token::Struct{name: "NakedBlock", len: 3},
149 Token::String("transaction_list"),
150 Token::Seq {len: Some(1)},
151 Token::String("transaction1"),
152 Token::SeqEnd,
153 Token::String("nonce"),
154 Token::U32(0),
155 Token::String("timestamp"),
156 Token::String("2021-04-02T04:02:42"),
157 Token::StructEnd,
158 ]
159 )
138 } 160 }
139 161
140 #[test] 162 #[test]
141 fn naked_block_deserialize_correctly() { 163 fn naked_block_deserialize_correctly() {
164 let expected_naked_block = NakedBlock {
165 transaction_list: vec!["transaction1".to_owned()],
166 nonce: 0,
167 timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
168 };
169 let data = r#"{"transaction_list":["transaction1"],"nonce":0,"timestamp":"2021-04-02T04:02:42"}"#;
170 let naked_block: NakedBlock = serde_json::from_str(data).unwrap();
171
172 assert_eq!(naked_block, expected_naked_block);
142 173
143 } 174 }
144 175
145 #[test] 176 #[test]
146 fn naked_block_deserialize_when_vec_emptpy() { 177 fn naked_block_deserialize_when_vec_emptpy() {
147 178 //
148 } 179 }
149 180
150 #[test] 181 #[test]