浏览代码

Add tests

develop
Silvestr Predko 2 年前
父节点
当前提交
a74a903d47
共有 2 个文件被更改,包括 32 次插入0 次删除
  1. 1
    0
      common-api/Cargo.toml
  2. 31
    0
      common-api/src/api.rs

+ 1
- 0
common-api/Cargo.toml 查看文件

@@ -29,3 +29,4 @@ x25519-dalek = { version = "1", features = ["serde"] }
29 29
 [dev-dependencies]
30 30
 rand = "0.8.5"
31 31
 rand_chacha = "0.3"
32
+serde_json = "1"

+ 31
- 0
common-api/src/api.rs 查看文件

@@ -40,3 +40,34 @@ pub struct NodeInfo {
40 40
     pub bandwidth: Bandwidth,
41 41
     pub account_id: AccountId,
42 42
 }
43
+
44
+#[cfg(test)]
45
+mod tests {
46
+
47
+    use super::*;
48
+    use std::str::FromStr;
49
+
50
+    #[test]
51
+    fn node_info_json() {
52
+        let s1 = serde_json::to_value(&NodeInfo {
53
+            account_id: AccountId::from_str("account.testnet").unwrap(),
54
+            bandwidth: Bandwidth {
55
+                speed: 100,
56
+                units: "mbps".to_owned(),
57
+            },
58
+            region: "us".to_owned(),
59
+        })
60
+        .unwrap();
61
+
62
+        let s2 = serde_json::json!({
63
+            "account_id": "account.testnet",
64
+            "region": "us",
65
+            "bandwidth": {
66
+                "speed": 100,
67
+                "units": "mbps"
68
+            }
69
+        });
70
+
71
+        assert_eq!(s1, s2);
72
+    }
73
+}

正在加载...
取消
保存