aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYigit Sever2022-04-16 18:05:37 +0300
committerYigit Sever2022-04-16 18:05:37 +0300
commit43ad693490d3c2770bdcad7f59be50d6f1aa79dc (patch)
treebc4f75101941bf369a82ab62e756c91ecbbbfd44 /tests
parent96d34952c1fb2cf096b6c907feada60b0db27a8f (diff)
downloadgradecoin-43ad693490d3c2770bdcad7f59be50d6f1aa79dc.tar.gz
gradecoin-43ad693490d3c2770bdcad7f59be50d6f1aa79dc.tar.bz2
gradecoin-43ad693490d3c2770bdcad7f59be50d6f1aa79dc.zip
temporarily remove tests
Diffstat (limited to 'tests')
-rw-r--r--tests/route_tests.rs435
-rw-r--r--tests/schema_tests.rs310
2 files changed, 0 insertions, 745 deletions
diff --git a/tests/route_tests.rs b/tests/route_tests.rs
deleted file mode 100644
index a449b0b..0000000
--- a/tests/route_tests.rs
+++ /dev/null
@@ -1,435 +0,0 @@
1#[cfg(test)]
2mod tests {
3 use gradecoin::schema::{Block, Db, InitialAuthRequest, MetuId, Transaction, User};
4 use pretty_assertions::assert_eq;
5
6 use gradecoin::routes::consensus_routes;
7 use warp::http::StatusCode;
8
9 /// Create a mock database to be used in tests
10 fn mocked_db() -> Db {
11 let db = Db::new();
12
13 db.users.write().insert(
14 "fingerprint_of_some_guy".to_owned(),
15 User {
16 user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
17 public_key: "-----BEGIN PUBLIC KEY-----
18MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5yWTMeFqr2nvOC9oR5Wq
19/nzcNlwCIaziojt7rJ4BBvuwkT0tERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXG
20ekrGzvC8jHQMKHyNoWzUlpQJ9UMtdQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2
21/ef6abkdj+XWg/slYtrFeOf3ktc1l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH
228LFPX4bO9lJ9mAoMZFec6XVwumn/uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8s
23shSHWWtBD0M19ilbXhKyBsHSSZkpx+TAvFhfQ8JURw7KqahUPVlCwJ5OIKccJ/6F
24FQIDAQAB
25-----END PUBLIC KEY-----"
26 .to_owned(),
27 balance: 30,
28 is_bot: false,
29 },
30 );
31
32 db.users.write().insert(
33 "fingerprint_of_foo".to_owned(),
34 User {
35 user_id: MetuId::new("e223715".to_owned(), "1H5QuOYI1b2r9ET".to_owned()).unwrap(),
36 public_key: "NOT_USED_FOR_THIS_USER".to_owned(),
37 balance: 0,
38 is_bot: false,
39 },
40 );
41
42 /*
43 -----BEGIN RSA PRIVATE KEY-----
44 MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t
45 ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt
46 dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1
47 l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/
48 uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8sshSHWWtBD0M19ilbXhKyBsHSSZkp
49 x+TAvFhfQ8JURw7KqahUPVlCwJ5OIKccJ/6FFQIDAQABAoIBADTZGnZlG4dPqSon
50 bKgxSA83bQHgt3wLkyWUhApLdeCq2wvZ+NvWDG/s7yT11IZ991ZJIJGfjTtoIALz
51 J3rAX8jGH/5gfDuArOb000z9HP3wivZQjawa9gqlNC7s5INkQ9iHdsaIqeoYtpMX
52 qg8uLPiQeWiCsoeb/Rff7ARWEKA7udoZ2uZcZFMHTKx+mBpk8IiepQAJPBRVwmXk
53 x/3LTaezi6Tkvp/k/gf4IeSICiRGFRmm2Vxciduj11/CrdTHPQLz/Rh5/IN8Bkry
54 xdQdQxxhwxF/ap6OJIJyguq7gximn2uK0jbHY3nRmrF8SsEtIT+Gd7I46L/goR8c
55 jQOQRmECgYEA9RJSOBUkZMLoUcC2LGJBZOAnJZ7WToCVdu3LrPceRYtQHwcznW4O
56 NAHF+blQRzqvbMi11ap8NVpkDDu0ki/Yi2VdSVjQmlaOcpAXjN6T5ZrKoz61xj4g
57 2T2/K6d6ypkZRKPhKCC1iI419rq/APVEZHYCl7jZp4iD2izHiegZYccCgYEA8XRK
58 rfVuPiYsaB07eJrRKKjuoM1Jcr19jZyXY8sbALRcExaTX2CRaPA7binVeDBXayQ1
59 I0+kA1nV1EI+ROegV+b6gs2YaUmMJzI1yLqMqGDgHFxFvhkDsZaI+/V+G9eOLEt4
60 5ic5tImfZITLE/GSC8b+C16gxMGUN4t9gHq2okMCgYAKyNedaDDFzl3y2wwpP9mo
61 2sReP3Mm2Tm6lhRUdDt8y/impOZ8kw9E8p8HskP6HncBzoNR98KnhmbIswfrNvfM
62 ipVkWOg1IoH6QKUIqfLQM9OfA290Xd+ML89t2Fzq9XnLL3sFDQtwCvIM/YLSQ/jS
63 gu7yRkwttzA2NapCQ1h6mQKBgQClwBwn8Qyd01y2mCKkNzsP+2/cqTAbeSNAXFe8
64 pMfDowx1+hBu7/7CF+/kPwmQuTa5kSB9PgWsWzYjwNm4OX1j+mbL9lEDLf7tRVWQ
65 lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3
66 iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2
67 VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1
68 MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
69 -----END RSA PRIVATE KEY-----
70 */
71
72 db.pending_transactions.write().insert(
73 "fingerprint_of_foo".to_owned(),
74 Transaction {
75 source: "fingerprint_of_foo".to_owned(),
76 target: "fingerprint_of_foo".to_owned(),
77 amount: 2,
78 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30),
79 },
80 );
81
82 *db.blockchain.write() = Block {
83 transaction_list: vec![
84 "foo_public_key_signature".to_owned(),
85 "bar_public_key_signature".to_owned(),
86 "baz_public_key_signature".to_owned(),
87 ],
88 nonce: 6920405,
89 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 00),
90 hash: "0000009745f2f09c968c095af75e8ab87eba9be90a93e5df464f83ea7ec08537".to_owned(),
91 };
92
93 db
94 }
95
96 /// Test simple GET request to /transaction, an endpoint that exists
97 /// https://tools.ietf.org/html/rfc7231#section-6.3.1
98 /// We should get the only pending transaction available in the database as json
99 #[tokio::test]
100 async fn get_pending_transactions() {
101 let db = mocked_db();
102
103 let reply = consensus_routes(db);
104
105 let res = warp::test::request()
106 .method("GET")
107 .path("/transaction")
108 .reply(&reply)
109 .await;
110
111 assert_eq!(res.status(), StatusCode::OK);
112
113 let expected_json_body = r#"{"fingerprint_of_foo":{"source":"fingerprint_of_foo","target":"fingerprint_of_foo","amount":2,"timestamp":"2021-04-13T20:55:30"}}"#;
114
115 assert_eq!(res.body(), expected_json_body);
116 }
117
118 /// Test simple GET request to /block, an enpoint that exists
119 ///
120 /// https://tools.ietf.org/html/rfc7231#section-6.3.1
121 ///
122 /// Should return the single block available in the database as json
123 #[tokio::test]
124 async fn get_blockchain() {
125 let db = mocked_db();
126 let filter = consensus_routes(db);
127
128 let res = warp::test::request()
129 .method("GET")
130 .path("/block")
131 .reply(&filter)
132 .await;
133
134 assert_eq!(res.status(), StatusCode::OK);
135
136 let expected_json_body = r#"{"transaction_list":["foo_public_key_signature","bar_public_key_signature","baz_public_key_signature"],"nonce":6920405,"timestamp":"2021-04-13T20:55:00","hash":"0000009745f2f09c968c095af75e8ab87eba9be90a93e5df464f83ea7ec08537"}"#;
137 assert_eq!(res.body(), expected_json_body);
138 }
139
140 /// Test a simple GET request to a nonexisting path
141 /// https://tools.ietf.org/html/rfc7231#section-6.5.4
142 /// Should respond with 404 and stop
143 #[tokio::test]
144 async fn get_nonexisting_path_404() {
145 let db = mocked_db();
146 let filter = consensus_routes(db);
147
148 let res = warp::test::request()
149 .method("GET")
150 .path("/this_path_does_not_exist")
151 .reply(&filter)
152 .await;
153
154 assert_eq!(res.status(), StatusCode::NOT_FOUND);
155 }
156
157 /// Test a POST request to /transaction, an endpoint that exists
158 ///
159 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
160 ///
161 /// Should accept the json request, create
162 /// the transaction and add it to pending transactions in the db
163 #[tokio::test]
164 async fn post_auth_json_201() {
165 let db = mocked_db();
166 let filter = consensus_routes(db.clone());
167
168 let res = warp::test::request()
169 .method("POST")
170 .json(&Transaction {
171 source: "fingerprint_of_some_guy".to_owned(),
172 target: "31415926535897932384626433832795028841971693993751058209749445923".to_owned(),
173 amount: 2,
174 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30),
175 })
176 .header("Authorization", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiJiODI4ZmYwNzM5NjFmMDA2YjU3ZmNkZWMwNmEwZTY1YSIsImV4cCI6MjAwMDAwMDAwMCwiaWF0IjoyNTE2MjM5MDIyfQ.Zwr2BPYzxvdAy8ZjCWSA3dp96KKVHjRDu9imHKCJ0NUeD5fM4D678B6pRZk9ev8PvbEI88MgYVW9akj_IsFwrsho7Tpsh7ym593ZOMwtSWSxxzxuKuGhAuKHDiQlXMFfv6kl8-eXIxa7xbV_0m81vAz6_vYQnVnlhjRQ26LogJRixWpUKV7-mPdRHhrK6dUxi9CwVuc9fdYhd6n2FMKT2AlAnk472fDa3G1oPsFLkp56eJ6_rKWrALHFWItfNvY4zFvwXXyNjMu-0EYJiaQIXFVNnipsy5Sy2HckdY3UiYS2lFUwHIczNrdrLM7NQhJQmbJLD6XRAMifH6bA1ZxH8A")
177 .path("/transaction")
178 .reply(&filter)
179 .await;
180
181 println!("{:?}", res.body());
182 assert_eq!(res.status(), StatusCode::CREATED);
183 for i in db.pending_transactions.read().iter() {
184 println!("{:?}", i);
185 }
186 assert_eq!(db.pending_transactions.read().len(), 2);
187 }
188
189 /// Test a POST request to /transaction, an endpoint that exists with an incorrect JWT in the
190 /// Authorization header
191 ///
192 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
193 ///
194 /// Should reject the request
195 #[tokio::test]
196 async fn post_auth_json_400() {
197 let db = mocked_db();
198 let filter = consensus_routes(db.clone());
199
200 let res = warp::test::request()
201 .method("POST")
202 .json(&Transaction {
203 source: "some_fingerprint".to_owned(),
204 target: "some_other_fingerprint".to_owned(),
205 amount: 2,
206 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00),
207 })
208 .header(
209 "Authorization",
210 "Bearer aaaaaaaasdlkjaldkasljdaskjlaaaaaaaaaaaaaa",
211 )
212 .path("/transaction")
213 .reply(&filter)
214 .await;
215
216 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
217 assert_eq!(db.pending_transactions.read().len(), 1);
218 }
219
220 /// Test a POST request to /block, an endpoint that exists
221 ///
222 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
223 ///
224 /// Should accept the json request, create
225 /// the block
226 #[tokio::test]
227 async fn post_block_auth_201() {
228 let db = mocked_db();
229 let filter = consensus_routes(db.clone());
230
231 db.pending_transactions.write().insert(
232 "fingerprint_of_some_guy".to_owned(),
233 Transaction {
234 source: "fingerprint_of_some_guy".to_owned(),
235 target: "31415926535897932384626433832795028841971693993751058209749445923"
236 .to_owned(),
237 amount: 2,
238 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30),
239 },
240 );
241
242 let res = warp::test::request()
243 .method("POST")
244 .json(&Block {
245 transaction_list: vec!["fingerprint_of_some_guy".to_owned()],
246 nonce: 3222170950,
247 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(23, 38, 00),
248 hash: "0000002149b72e0b348c32ac442a50ced4efbd1df7d48b377733d55dfe4f3577".to_owned(),
249 } )
250 .header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiIwMDAwMDAyMTQ5YjcyZTBiMzQ4YzMyYWM0NDJhNTBjZWQ0ZWZiZDFkZjdkNDhiMzc3NzMzZDU1ZGZlNGYzNTc3IiwiZXhwIjoxMDAwMDAwMDAwMCwiaWF0IjoxNTE2MjM5MDAyMn0.2hZkIZiOJ9DpHwzL_rTCHGkTxs0S_-KD58a2bXuICogjrW6Z3o9LaJ95d8kpXSrAUCaFWN_-TNbk26LczDFSAhtTxpPh6ELXyLN82wAOCjsp8qLgXJQCnqNY7VFZdRUW0HDwHBLY2PVH40wprPkF7mLLonUPKcJUg9TLnmqHGriSECgv2-XZt2mD9XdTkofqIR-JRR3qoErb4G4xemMNYlWMuJK8I66Vj8kNytSt4wSCzkrWfmk5yyi7q1N3beo4nkP0DKzVstXZzWjn_qMZNZulfOdrNiKwHpwqX_bL66LB0rVpKcI5f6N6w5GZBKsdeUly7dCtKbxwYX3mV-7I_g")
251 .path("/block")
252 .reply(&filter)
253 .await;
254
255 println!("RESPONSE: {:?}", res.body());
256
257 // should be reflectled on the db as well
258 assert_eq!(
259 db.blockchain.read().hash,
260 "0000002149b72e0b348c32ac442a50ced4efbd1df7d48b377733d55dfe4f3577".to_owned()
261 );
262 assert_eq!(res.status(), StatusCode::CREATED);
263 }
264
265 /// Test a POST request to /block, an endpoint that exists
266 ///
267 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
268 ///
269 /// Should reject the block because there aren't enough zeroes in the hash
270 #[tokio::test]
271 async fn post_block_wrong_hash() {
272 let db = mocked_db();
273 let filter = consensus_routes(db.clone());
274
275 let res = warp::test::request()
276 .method("POST")
277 .header("Authorization", "Bearer foo.bar.baz")
278 .json(&Block {
279 transaction_list: vec!["foobarbaz".to_owned(), "dazsaz".to_owned()],
280 nonce: 1000, // not valid
281 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 12).and_hms(05, 29, 30),
282 hash: "tnarstnarsuthnarsthlarjstk".to_owned(),
283 })
284 .path("/block")
285 .reply(&filter)
286 .await;
287
288 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
289 }
290
291 /// Test a POST request to /block, an endpoint that exists
292 ///
293 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
294 ///
295 /// Should reject the block because transaction list is empty
296 #[tokio::test]
297 async fn post_block_with_empty_transaction_list() {
298 let db = mocked_db();
299 let filter = consensus_routes(db.clone());
300
301 let res = warp::test::request()
302 .method("POST")
303 .header("Authorization", "Bearer foo.bar.baz")
304 .json(&Block {
305 transaction_list: vec![],
306 nonce: 1000, // not valid
307 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 12).and_hms(05, 29, 30),
308 hash: "thisisnotavalidhash".to_owned(),
309 })
310 .path("/block")
311 .reply(&filter)
312 .await;
313
314 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
315 }
316
317 /// Test a POST request to /block, an endpoint that exists
318 ///
319 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
320 ///
321 /// Should reject the block because hash has enough zeroes but is not the actual hash of the
322 /// block
323 #[tokio::test]
324 async fn post_block_incorrect_hash() {
325 let db = mocked_db();
326 let filter = consensus_routes(db.clone());
327
328 let res = warp::test::request()
329 .method("POST")
330 .json(&Block {
331 transaction_list: vec![],
332 nonce: 12314,
333 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 00),
334 hash: "0000001111111111111111111111111111111111111111111111111111111111".to_owned(),
335 })
336 .path("/block")
337 .reply(&filter)
338 .await;
339
340 println!("{:?}", res.body());
341 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
342 assert_eq!(
343 db.blockchain.read().hash,
344 "0000009745f2f09c968c095af75e8ab87eba9be90a93e5df464f83ea7ec08537"
345 );
346 }
347
348 /// Test a POST request to /register, an endpoint that exists
349 ///
350 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
351 ///
352 /// Should accept the json request, create a new user and
353 /// add it to the user hashmap in the db
354 // #[tokio::test]
355 // async fn post_register_priviliged_user() {
356 // let db = mocked_db();
357 // let filter = consensus_routes(db.clone());
358
359 // let res = warp::test::request()
360 // .method("POST")
361 // .json(&priviliged_mocked_user())
362 // .path("/register")
363 // .reply(&filter)
364 // .await;
365
366 // println!("{:?}", res.body());
367 // assert_eq!(res.status(), StatusCode::CREATED);
368 // assert_eq!(db.users.read().len(), 2);
369 // }
370
371 /// Test a POST request to /transaction, an endpoint that exists
372 /// https://tools.ietf.org/html/rfc7231#section-6.3.2
373 /// Should NOT accept the json request as the user is unpriviliged
374 // #[tokio::test]
375 // async fn post_register_unpriviliged_user() {
376 // let db = mocked_db();
377 // let filter = consensus_routes(db.clone());
378
379 // let res = warp::test::request()
380 // .method("POST")
381 // .json(&unpriviliged_mocked_user())
382 // .path("/register")
383 // .reply(&filter)
384 // .await;
385
386 // println!("{:?}", res.body());
387 // assert_eq!(res.status(), StatusCode::BAD_REQUEST);
388 // assert_eq!(db.users.read().len(), 1);
389 // }
390
391 /// Test a POST request to /transaction, an endpoint that exists with a longer than expected
392 /// payload
393 ///
394 /// https://tools.ietf.org/html/rfc7231#section-6.5.11
395 ///
396 /// Should return 413 to user
397 #[tokio::test]
398 async fn post_too_long_content_413() {
399 let db = mocked_db();
400 let filter = consensus_routes(db);
401
402 let res = warp::test::request()
403 .method("POST")
404 .header("content-length", 1024 * 36)
405 .path("/transaction")
406 .reply(&filter)
407 .await;
408
409 assert_eq!(res.status(), StatusCode::PAYLOAD_TOO_LARGE);
410 }
411
412 /// Test the User Authentication Process
413 #[tokio::test]
414 async fn user_authentication() {
415 let db = mocked_db();
416 let filter = consensus_routes(db);
417
418 let res = warp::test::request()
419 .method("POST")
420 .json(&InitialAuthRequest {
421 c: "D9OKSp4XD+niltqhoiTEyz3pTxGm5ZKYVNFPofW40M6Km7wE7FgIpfTkurBZ6tQsG/rYPRsd6C/Qo+o3HrgOYC8BDprwpnYb7UnJdL2pe44ZMEsPAmDAdwTP9WozY0lr+bjEjtTM1mVQnIdfknychFek/FNi3l8MrapeFTxFaTMGxWuS1+wEuAkcz4AR4+jooaXVAEpKrPiSXqbywF9OQ41tk0kRiXn234dj40ndND+GlfMgghITuBJrJx6tzLppAZNIIGwUjQDt5Oib5dEGrPOe+rran1D26YNhZOtrfYEGyUSN+/58HbItQlLrgFhL6zRT7ojw/Eg4jYXndK0xNgYGyhAn5UI/qnI2NPpZU7Wd3sJKlWc7HfrjNnKVKlcrhHtYy3FXfN/hLg7SFmuSfXqqvVbNVT6pEDU6Y5NahOYaE/vkL0no7F7lz0UjAlgQCmn5yN7mKs3yLSnlx6hmsK/fVoqGBcOIbYY5gzYMlAQ3E+lq0p2MPEoWC8NYxStSeo9M8uLYT6Jl3hYVf8aLgd1l0HEiCyT+kWxvcR5hw42I7gqaoUcnr53Zm1mYK30/fvZ6lxsrb4FphldgQC5fx6nwEgjaLUeB4n0oZTSRLbrd9ZXCjUG4FNmM+sOklhIXyTYUj4VcBSwZuAvJZEFf2em68e7ySJs/ysz+TGu3eVeRc+voAvI9mGLxWnSEjWx64po7PO61uG6ikadHZH+wIw==".to_owned(),
422 iv: "bmV2ZXJtaW5kdGhlbmZ1aw==".to_owned(),
423 key: "Xd6/VSuFKqayNHspcFJSm+PAHNoTmcR4SsMijSyuyEh6PS5rdvO4W98AhxW4VBrRO1ljfEMeFq835NEDame511D2pim00Xv0HPIYSDW6pIJA1hy+Np/WyC7PCxvKy0hPzTmHMpFmM+aF43BknJdYlPUhY4cww/xScU6WxuKIsEQNORRhQds8CHOO0EGcOjHVvR2xqnOda1g/rI7mfNMATHj9ZRsB9GH6QG5WTUbo9/71cDAILF+28TG40jSKvY2KzO9vr668tgqoMV2vLnXQa1AD9ZWmdHHdjiXuiH3X0uXxHrfjH7HeXi/HOj/pgCX12jKsEsRwkBTGL4koObH6pQ==".to_owned(),
424 })
425 .path("/register")
426 .reply(&filter)
427 .await;
428
429 println!("{:?}", res);
430 assert_eq!(res.status(), StatusCode::CREATED);
431 }
432}
433
434// TODO: POST block without correct transactions test <09-04-21, yigit> //
435// TODO: POST transaction while that source has pending transaction test <09-04-21, yigit> //
diff --git a/tests/schema_tests.rs b/tests/schema_tests.rs
deleted file mode 100644
index 072cb2b..0000000
--- a/tests/schema_tests.rs
+++ /dev/null
@@ -1,310 +0,0 @@
1// #[cfg(test)]
2// mod tests {
3// use gradecoin::schema::*;
4// use serde_test::{assert_tokens, Token};
5// use chrono::NaiveDate;
6
7// #[test]
8// fn claims_serialize_correctly() {
9// let claims = Claims {
10// tha: "hashed_string".to_owned(),
11// iat: 0,
12// exp: 100,
13// };
14// assert_tokens(
15// &claims,
16// &[
17// Token::Struct{name: "Claims", len: 3},
18// Token::String("tha"),
19// Token::String("hashed_string"),
20// Token::String("iat"),
21// Token::U64(0),
22// Token::String("exp"),
23// Token::U64(100),
24// Token::StructEnd,
25// ]
26// )
27// }
28
29// #[test]
30// fn claims_deserialize_correctly() {
31// let data = r#"{"tha":"hashed_string","iat":0,"exp":100}"#;
32// let claims: Claims = serde_json::from_str(data).unwrap();
33// let expected_claims = Claims {
34// tha: "hashed_string".to_owned(),
35// iat: 0,
36// exp: 100,
37// };
38// assert_eq!(claims, expected_claims);
39// }
40
41// #[test]
42// fn transaction_serialize_correctly() {
43// let transaction = Transaction {
44// by: "source".to_owned(),
45// source: "source".to_owned(),
46// target: "target".to_owned(),
47// amount: 0,
48// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
49// };
50
51// assert_tokens(
52// &transaction,
53// &[
54// Token::Struct{name: "Transaction", len: 5},
55// Token::String("by"),
56// Token::String("source"),
57// Token::String("source"),
58// Token::String("source"),
59// Token::String("target"),
60// Token::String("target"),
61// Token::String("amount"),
62// Token::I32(0),
63// Token::String("timestamp"),
64// Token::String("2021-04-02T04:02:42"),
65// Token::StructEnd,
66// ]
67// )
68// }
69
70// #[test]
71// fn transaction_deserialize_correctly() {
72// let data = r#"{"by":"source","source":"source","target":"target","amount":0,"timestamp":"2021-04-02T04:02:42"}"#;
73// let transaction: Transaction = serde_json::from_str(data).unwrap();
74// let expected_transaction = Transaction {
75// by: "source".to_owned(),
76// source: "source".to_owned(),
77// target: "target".to_owned(),
78// amount: 0,
79// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
80// };
81
82// assert_eq!(transaction, expected_transaction);
83// }
84
85// #[test]
86// fn block_serialize_correctly() {
87// let block = Block {
88// transaction_list: vec!["transaction1".to_owned()],
89// nonce: 0,
90// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
91// hash: "hash".to_owned()
92// };
93
94// assert_tokens(
95// &block,
96// &[
97// Token::Struct{name: "Block", len: 4},
98// Token::String("transaction_list"),
99// Token::Seq {len: Some(1)},
100// Token::String("transaction1"),
101// Token::SeqEnd,
102// Token::String("nonce"),
103// Token::U32(0),
104// Token::String("timestamp"),
105// Token::String("2021-04-02T04:02:42"),
106// Token::String("hash"),
107// Token::String("hash"),
108// Token::StructEnd,
109// ]
110// )
111// }
112
113// #[test]
114// fn block_deserialize_correctly() {
115// let expected_block = Block {
116// transaction_list: vec!["transaction1".to_owned()],
117// nonce: 0,
118// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
119// hash: "hash".to_owned()
120// };
121// let data = r#"{"transaction_list":["transaction1"],"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#;
122// let block: Block = serde_json::from_str(data).unwrap();
123
124// assert_eq!(block, expected_block);
125
126// }
127
128// #[test]
129// fn block_serialize_when_vec_emptpy() {
130// let block = Block {
131// transaction_list: vec![],
132// nonce: 0,
133// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
134// hash: "hash".to_owned()
135// };
136
137// let json = serde_json::to_string(&block).unwrap();
138// assert_eq!(json, r#"{"nonce":0,"timestamp":"2021-04-02T04:02:42","hash":"hash"}"#)
139// }
140
141// #[test]
142// fn naked_block_serialize_correctly() {
143// let naked_block = NakedBlock {
144// transaction_list: vec!["transaction1".to_owned()],
145// nonce: 0,
146// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
147// };
148
149// assert_tokens(
150// &naked_block,
151// &[
152// Token::Struct{name: "NakedBlock", len: 3},
153// Token::String("transaction_list"),
154// Token::Seq {len: Some(1)},
155// Token::String("transaction1"),
156// Token::SeqEnd,
157// Token::String("nonce"),
158// Token::U32(0),
159// Token::String("timestamp"),
160// Token::String("2021-04-02T04:02:42"),
161// Token::StructEnd,
162// ]
163// )
164// }
165
166// #[test]
167// fn naked_block_deserialize_correctly() {
168// let expected_naked_block = NakedBlock {
169// transaction_list: vec!["transaction1".to_owned()],
170// nonce: 0,
171// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
172// };
173// let data = r#"{"transaction_list":["transaction1"],"nonce":0,"timestamp":"2021-04-02T04:02:42"}"#;
174// let naked_block: NakedBlock = serde_json::from_str(data).unwrap();
175
176// assert_eq!(naked_block, expected_naked_block);
177
178// }
179
180// #[test]
181// fn naked_block_serialize_when_vec_emptpy() {
182// let naked_block = NakedBlock {
183// transaction_list: vec![],
184// nonce: 0,
185// timestamp: NaiveDate::from_ymd(2021, 4, 2).and_hms(4, 2, 42),
186// };
187
188// let json = serde_json::to_string(&naked_block).unwrap();
189// assert_eq!(json, r#"{"nonce":0,"timestamp":"2021-04-02T04:02:42"}"#)
190// }
191
192// #[test]
193// fn user_serialize_correctly() {
194// let user = User {
195// user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
196// public_key: "public_key".to_owned(),
197// balance: 0
198// };
199
200// assert_tokens(
201// &user,
202// &[
203// Token::Struct{name: "User", len: 3},
204// Token::String("user_id"),
205// Token::Struct {name: "MetuId", len: 2},
206// Token::String("id"),
207// Token::String("e254275"),
208// Token::String("passwd"),
209// Token::String("DtNX1qk4YF4saRH"),
210// Token::StructEnd,
211// Token::String("public_key"),
212// Token::String("public_key"),
213// Token::String("balance"),
214// Token::I32(0),
215// Token::StructEnd,
216// ]
217// )
218// }
219
220// #[test]
221// fn user_deserialize_correctly() {
222// let expected_user = User {
223// user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
224// public_key: "public_key".to_owned(),
225// balance: 0
226// };
227// let data = r#"{"user_id":{"id":"e254275","passwd":"DtNX1qk4YF4saRH"},"public_key":"public_key","balance":0}"#;
228// let user: User = serde_json::from_str(data).unwrap();
229
230// assert_eq!(user, expected_user);
231
232// }
233
234// #[test]
235// fn metu_id_serialize_correctly() {
236// let metu_id = MetuId::new ("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap();
237
238// assert_tokens(
239// &metu_id,
240// &[
241// Token::Struct{name: "MetuId", len: 2},
242// Token::String("id"),
243// Token::String("e254275"),
244// Token::String("passwd"),
245// Token::String("DtNX1qk4YF4saRH"),
246// Token::StructEnd,
247// ]
248// )
249// }
250
251// #[test]
252// fn metu_id_deserialize_correctly() {
253// let expected_metu_id = MetuId::new ("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap();
254// let data = r#"{"id":"e254275","passwd":"DtNX1qk4YF4saRH"}"#;
255// let metu_id: MetuId = serde_json::from_str(data).unwrap();
256
257// assert_eq!(metu_id, expected_metu_id);
258// }
259
260// #[test]
261// fn auth_request_serialize_correctly() {
262// let auth_request = AuthRequest {
263// student_id: "e254275".to_owned(),
264// passwd: "DtNX1qk4YF4saRH".to_owned(),
265// public_key: "public_key".to_owned()
266// };
267
268// assert_tokens(
269// &auth_request,
270// &[
271// Token::Struct{name: "AuthRequest", len: 3},
272// Token::String("student_id"),
273// Token::String("e254275"),
274// Token::String("passwd"),
275// Token::String("DtNX1qk4YF4saRH"),
276// Token::String("public_key"),
277// Token::String("public_key"),
278// Token::StructEnd,
279// ]
280// )
281// }
282
283// #[test]
284// fn auth_request_deserialize_correctly() {
285// let expected_auth_request = AuthRequest {
286// student_id: "e254275".to_owned(),
287// passwd: "DtNX1qk4YF4saRH".to_owned(),
288// public_key: "public_key".to_owned()
289// };
290// let data = r#"{"student_id":"e254275","passwd":"DtNX1qk4YF4saRH","public_key":"public_key"}"#;
291// let auth_request: AuthRequest = serde_json::from_str(data).unwrap();
292
293// assert_eq!(auth_request, expected_auth_request);
294
295// }
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310// }