diff options
| author | alpaylan | 2021-04-14 02:07:08 +0300 |
|---|---|---|
| committer | alpaylan | 2021-04-14 02:07:08 +0300 |
| commit | 0eda923b0865d4bee57ac54062d2e0140f966eb1 (patch) | |
| tree | 1e6d073e2354c5dd0ffe43e0b794b08f72ea2c9e /tests | |
| parent | 6a27685c253e1ea520dd903cb3db4581f3ab66f6 (diff) | |
| download | gradecoin-0eda923b0865d4bee57ac54062d2e0140f966eb1.tar.gz gradecoin-0eda923b0865d4bee57ac54062d2e0140f966eb1.tar.bz2 gradecoin-0eda923b0865d4bee57ac54062d2e0140f966eb1.zip | |
finished claim testing.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema_tests.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs index c6fae9d..fc06796 100644 --- a/tests/schema_tests.rs +++ b/tests/schema_tests.rs | |||
| @@ -3,6 +3,7 @@ mod tests { | |||
| 3 | use gradecoin::schema::*; | 3 | use gradecoin::schema::*; |
| 4 | use serde_json::error::Error; | 4 | use serde_json::error::Error; |
| 5 | use serde_test::{assert_tokens, Token}; | 5 | use serde_test::{assert_tokens, Token}; |
| 6 | use chrono::{NaiveDate, NaiveTime, NaiveDateTime}; | ||
| 6 | 7 | ||
| 7 | #[test] | 8 | #[test] |
| 8 | fn claims_serialize_correctly() { | 9 | fn claims_serialize_correctly() { |
| @@ -40,12 +41,46 @@ mod tests { | |||
| 40 | 41 | ||
| 41 | #[test] | 42 | #[test] |
| 42 | fn transaction_serialize_correctly() { | 43 | fn transaction_serialize_correctly() { |
| 44 | let transaction = Transaction { | ||
| 45 | by: "source".to_owned(), | ||
| 46 | source: "source".to_owned(), | ||
| 47 | target: "target".to_owned(), | ||
| 48 | amount: 0, | ||
| 49 | timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42), | ||
| 50 | }; | ||
| 43 | 51 | ||
| 52 | assert_tokens( | ||
| 53 | &transaction, | ||
| 54 | &[ | ||
| 55 | Token::Struct{name: "Transaction", len: 5}, | ||
| 56 | Token::String("by"), | ||
| 57 | Token::String("source"), | ||
| 58 | Token::String("source"), | ||
| 59 | Token::String("source"), | ||
| 60 | Token::String("target"), | ||
| 61 | Token::String("target"), | ||
| 62 | Token::String("amount"), | ||
| 63 | Token::I32(0), | ||
| 64 | Token::String("timestamp"), | ||
| 65 | Token::String("2021-04-02T04:02:42"), | ||
| 66 | Token::StructEnd, | ||
| 67 | ] | ||
| 68 | ) | ||
| 44 | } | 69 | } |
| 45 | 70 | ||
| 46 | #[test] | 71 | #[test] |
| 47 | fn transaction_deserialize_correctly() { | 72 | fn transaction_deserialize_correctly() { |
| 73 | let data = r#"{"by":"source","source":"source","target":"target","amount":0,"timestamp":"2021-04-02T04:02:42"}"#; | ||
| 74 | let transaction: Transaction = serde_json::from_str(data).unwrap(); | ||
| 75 | let expected_transaction = Transaction { | ||
| 76 | by: "source".to_owned(), | ||
| 77 | source: "source".to_owned(), | ||
| 78 | target: "target".to_owned(), | ||
| 79 | amount: 0, | ||
| 80 | timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42), | ||
| 81 | }; | ||
| 48 | 82 | ||
| 83 | assert_eq!(transaction, expected_transaction); | ||
| 49 | } | 84 | } |
| 50 | 85 | ||
| 51 | #[test] | 86 | #[test] |
