aboutsummaryrefslogtreecommitdiffstats
path: root/tests/route_tests.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-16 03:55:38 +0300
committerYigit Sever2021-04-16 03:55:38 +0300
commitf98766d8d989c18b2150b91463fba1f9de812658 (patch)
treece20af5f0e9e57b5b66f20eb30c15ece18236a4e /tests/route_tests.rs
parent90525af1b50219801a019842bc635ea08f9f93d9 (diff)
parentf759c6b4da459ae2544c6cb5b0e19e4367fef57f (diff)
downloadgradecoin-f98766d8d989c18b2150b91463fba1f9de812658.tar.gz
gradecoin-f98766d8d989c18b2150b91463fba1f9de812658.tar.bz2
gradecoin-f98766d8d989c18b2150b91463fba1f9de812658.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to 'tests/route_tests.rs')
-rw-r--r--tests/route_tests.rs90
1 files changed, 62 insertions, 28 deletions
diff --git a/tests/route_tests.rs b/tests/route_tests.rs
index a1531bb..bae58ee 100644
--- a/tests/route_tests.rs
+++ b/tests/route_tests.rs
@@ -29,33 +29,51 @@ FQIDAQAB
29 }, 29 },
30 ); 30 );
31 31
32 // -----BEGIN RSA PRIVATE KEY----- 32 db.users.write().insert(
33 // MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t 33 "mock_transaction_source2".to_owned(),
34 // ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt 34 User {
35 // dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1 35 user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
36 // l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/ 36 public_key: "-----BEGIN PUBLIC KEY-----
37 // uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8sshSHWWtBD0M19ilbXhKyBsHSSZkp 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 pMfDowx1+hBu7/7CF+/kPwmQuTa5kSB9PgWsWzYjwNm4OX1j+mbL9lEDLf7tRVWQ
72 lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3
73 iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2
74 VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1
75 MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
76 -----END RSA PRIVATE KEY-----*/
59 77
60 db.pending_transactions.write().insert( 78 db.pending_transactions.write().insert(
61 "mock_transaction_source".to_owned(), 79 "mock_transaction_source".to_owned(),
@@ -111,6 +129,16 @@ FQIDAQAB
111 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00), 129 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00),
112 } 130 }
113 } 131 }
132 fn mocked_transaction2() -> Transaction {
133 Transaction {
134 by: "mock_transaction_source".to_owned(),
135 source: "mock_transaction_source".to_owned(),
136 target: "mock_transaction_target".to_owned(),
137 amount: 25,
138 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00),
139 }
140 }
141 // r#"{"by":"mock_transaction_source","source":"mock_transaction_source","target":"mock_transaction_target","amount":25,"timestamp":"2021-04-09T14:30:00"}"#
114 142
115 /// Test simple GET request to /transaction, an endpoint that exists 143 /// Test simple GET request to /transaction, an endpoint that exists
116 /// https://tools.ietf.org/html/rfc7231#section-6.3.1 144 /// https://tools.ietf.org/html/rfc7231#section-6.3.1
@@ -187,13 +215,16 @@ FQIDAQAB
187 let res = warp::test::request() 215 let res = warp::test::request()
188 .method("POST") 216 .method("POST")
189 .json(&mocked_transaction()) 217 .json(&mocked_transaction())
190 .header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiI2NjkyZTc3NGViYTdmYjkyZGMwZmU2Y2Y3MzQ3NTkxZSIsImlhdCI6MTYxODI2MDY0MSwiZXhwIjoxNzE4MjYwNjQxfQ.M_FVVE5F_aYcDsprkcqV8n2DAhnM6jImAUEXChI9qYn55meE_0Pmp6AaJlTzclYUT1ZUQfFuehYTYu5UkigQ_AimDhqM5VWxPdnyfTQscV916arbNn4qXW6-3oHGUR93xK7-mX6mxeXyDZLxr1SD_JEvVzGWTU4Xo9SMYSIcaHjROAg_ChxJdD4WLe5T4He7O443jpXdAeeVVYfKoJyBfINx_bxiF58-ni1vur9q6-nrjnMw6sMMbtWD3qvzKZHN7HzfwNXM-90D-9VX1KiaJN05jIxLzCYacLeBUH595I4--XfgpLmqrV_P3Sucmny0yvagbZtjYjswmf0DjR99ug") 218 .header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiJmODRmNTBjNjZkNDdhZTAzNzcwZjY0ZjUwMDgzMTAwMSIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoyMDE2MjM5MDIyfQ.APOAH0nOqxnW5FoRjM-T9Mm0VThLrDZspKeTGXioKZJNkAMc6ZbQ_wqdvRXG-GRzivyVAW8849kbnQ-smWFHQjftKEF-aiKxWeO17vsQ4j5I9UdwwPJpGDbxU5vBgLAPXYG8wEndvC4bgy_a0P3FAlD8gIHebMh1YsbyfyEc6DFD4nvZwHzRFJtR43xRfCVgFAjSF_pB5YPAccB0DmYz_uKaGj69-9eNQYKr6giwXaiYIcF-G561kKLmTFPjCuACYNLMHONjwg8i0pT-tdiZgS7SiiWAOAo_98X54W0bCvn6i5tUPpzWKv61QXCWDdHi831YA8kMNJ2az_baRMtmhg")
191 .path("/transaction") 219 .path("/transaction")
192 .reply(&filter) 220 .reply(&filter)
193 .await; 221 .await;
194 222
195 println!("{:?}", res.body()); 223 println!("{:?}", res.body());
196 assert_eq!(res.status(), StatusCode::CREATED); 224 assert_eq!(res.status(), StatusCode::CREATED);
225 for i in db.pending_transactions.read().iter() {
226 println!("{:?}", i);
227 }
197 assert_eq!(db.pending_transactions.read().len(), 2); 228 assert_eq!(db.pending_transactions.read().len(), 2);
198 } 229 }
199 230
@@ -231,9 +262,12 @@ FQIDAQAB
231 /// the block 262 /// the block
232 #[tokio::test] 263 #[tokio::test]
233 async fn post_block_auth_201() { 264 async fn post_block_auth_201() {
265 println!("Wtf");
234 let db = mocked_db(); 266 let db = mocked_db();
235 let filter = consensus_routes(db.clone()); 267 let filter = consensus_routes(db.clone());
236 268
269
270
237 let res = warp::test::request() 271 let res = warp::test::request()
238 .method("POST") 272 .method("POST")
239 .json(&Block { 273 .json(&Block {