summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralpaylan2021-04-14 02:14:09 +0300
committeralpaylan2021-04-14 02:14:09 +0300
commitaa0ad3f0810b015953f31f19155343295b0ca0d3 (patch)
tree92cec814a852688a5b8d21692d704e9b3b388b25
parent0eda923b0865d4bee57ac54062d2e0140f966eb1 (diff)
downloadgradecoin-aa0ad3f0810b015953f31f19155343295b0ca0d3.tar.gz
gradecoin-aa0ad3f0810b015953f31f19155343295b0ca0d3.tar.bz2
gradecoin-aa0ad3f0810b015953f31f19155343295b0ca0d3.zip
finished block testing
-rw-r--r--src/schema.rs2
-rw-r--r--tests/schema_tests.rs34
2 files changed, 35 insertions, 1 deletions
diff --git a/src/schema.rs b/src/schema.rs
index 4d2b442..b67bce4 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -90,7 +90,7 @@ pub struct Transaction {
90/// https://serde.rs/container-attrs.html might be valuable to normalize the serialize/deserialize 90/// https://serde.rs/container-attrs.html might be valuable to normalize the serialize/deserialize
91/// conventions as these will be hashed 91/// conventions as these will be hashed
92/// 92///
93#[derive(Serialize, Deserialize, Debug)] 93#[derive(Serialize, Deserialize, Debug, PartialEq)]
94pub struct Block { 94pub struct Block {
95 #[serde(skip_serializing_if = "Vec::is_empty")] 95 #[serde(skip_serializing_if = "Vec::is_empty")]
96 pub transaction_list: Vec<PublicKeySignature>, 96 pub transaction_list: Vec<PublicKeySignature>,
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]