aboutsummaryrefslogtreecommitdiffstats
path: root/tests/route_tests.rs
diff options
context:
space:
mode:
authoralpaylan2021-04-16 03:54:29 +0300
committeralpaylan2021-04-16 03:54:29 +0300
commit4ad38fe7b8936245102ca9acbeea031f11640533 (patch)
treec7926a63472482cbeef7484ef881283deec74c88 /tests/route_tests.rs
parent752b05888c3309538a9a8fd3b87b8dd6b510e37e (diff)
downloadgradecoin-4ad38fe7b8936245102ca9acbeea031f11640533.tar.gz
gradecoin-4ad38fe7b8936245102ca9acbeea031f11640533.tar.bz2
gradecoin-4ad38fe7b8936245102ca9acbeea031f11640533.zip
work on post auth transaction 201 test
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 59483d3..ce7d704 100644
--- a/tests/route_tests.rs
+++ b/tests/route_tests.rs
@@ -27,33 +27,51 @@ FQIDAQAB
27 }, 27 },
28 ); 28 );
29 29
30 // -----BEGIN RSA PRIVATE KEY----- 30 db.users.write().insert(
31 // MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t 31 "mock_transaction_source2".to_owned(),
32 // ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt 32 User {
33 // dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1 33 user_id: MetuId::new("e254275".to_owned(), "DtNX1qk4YF4saRH".to_owned()).unwrap(),
34 // l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/ 34 public_key: "-----BEGIN PUBLIC KEY-----
35 // uqu9jyWQL6qh6gtwQHgN+A9wGvzVvltJ9h8sshSHWWtBD0M19ilbXhKyBsHSSZkp 35MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC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Nm4OX1j+mbL9lEDLf7tRVWQ
70 lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3
71 iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2
72 VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1
73 MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
74 -----END RSA PRIVATE KEY-----*/
57 75
58 db.pending_transactions.write().insert( 76 db.pending_transactions.write().insert(
59 "mock_transaction_source".to_owned(), 77 "mock_transaction_source".to_owned(),
@@ -109,6 +127,16 @@ FQIDAQAB
109 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00), 127 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00),
110 } 128 }
111 } 129 }
130 fn mocked_transaction2() -> Transaction {
131 Transaction {
132 by: "mock_transaction_source".to_owned(),
133 source: "mock_transaction_source".to_owned(),
134 target: "mock_transaction_target".to_owned(),
135 amount: 25,
136 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 09).and_hms(14, 30, 00),
137 }
138 }
139 // r#"{"by":"mock_transaction_source","source":"mock_transaction_source","target":"mock_transaction_target","amount":25,"timestamp":"2021-04-09T14:30:00"}"#
112 140
113 /// Test simple GET request to /transaction, an endpoint that exists 141 /// Test simple GET request to /transaction, an endpoint that exists
114 /// https://tools.ietf.org/html/rfc7231#section-6.3.1 142 /// https://tools.ietf.org/html/rfc7231#section-6.3.1
@@ -185,13 +213,16 @@ FQIDAQAB
185 let res = warp::test::request() 213 let res = warp::test::request()
186 .method("POST") 214 .method("POST")
187 .json(&mocked_transaction()) 215 .json(&mocked_transaction())
188 .header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiI2NjkyZTc3NGViYTdmYjkyZGMwZmU2Y2Y3MzQ3NTkxZSIsImlhdCI6MTYxODI2MDY0MSwiZXhwIjoxNzE4MjYwNjQxfQ.M_FVVE5F_aYcDsprkcqV8n2DAhnM6jImAUEXChI9qYn55meE_0Pmp6AaJlTzclYUT1ZUQfFuehYTYu5UkigQ_AimDhqM5VWxPdnyfTQscV916arbNn4qXW6-3oHGUR93xK7-mX6mxeXyDZLxr1SD_JEvVzGWTU4Xo9SMYSIcaHjROAg_ChxJdD4WLe5T4He7O443jpXdAeeVVYfKoJyBfINx_bxiF58-ni1vur9q6-nrjnMw6sMMbtWD3qvzKZHN7HzfwNXM-90D-9VX1KiaJN05jIxLzCYacLeBUH595I4--XfgpLmqrV_P3Sucmny0yvagbZtjYjswmf0DjR99ug") 216 .header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aGEiOiJmODRmNTBjNjZkNDdhZTAzNzcwZjY0ZjUwMDgzMTAwMSIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoyMDE2MjM5MDIyfQ.APOAH0nOqxnW5FoRjM-T9Mm0VThLrDZspKeTGXioKZJNkAMc6ZbQ_wqdvRXG-GRzivyVAW8849kbnQ-smWFHQjftKEF-aiKxWeO17vsQ4j5I9UdwwPJpGDbxU5vBgLAPXYG8wEndvC4bgy_a0P3FAlD8gIHebMh1YsbyfyEc6DFD4nvZwHzRFJtR43xRfCVgFAjSF_pB5YPAccB0DmYz_uKaGj69-9eNQYKr6giwXaiYIcF-G561kKLmTFPjCuACYNLMHONjwg8i0pT-tdiZgS7SiiWAOAo_98X54W0bCvn6i5tUPpzWKv61QXCWDdHi831YA8kMNJ2az_baRMtmhg")
189 .path("/transaction") 217 .path("/transaction")
190 .reply(&filter) 218 .reply(&filter)
191 .await; 219 .await;
192 220
193 println!("{:?}", res.body()); 221 println!("{:?}", res.body());
194 assert_eq!(res.status(), StatusCode::CREATED); 222 assert_eq!(res.status(), StatusCode::CREATED);
223 for i in db.pending_transactions.read().iter() {
224 println!("{:?}", i);
225 }
195 assert_eq!(db.pending_transactions.read().len(), 2); 226 assert_eq!(db.pending_transactions.read().len(), 2);
196 } 227 }
197 228
@@ -229,9 +260,12 @@ FQIDAQAB
229 /// the block 260 /// the block
230 #[tokio::test] 261 #[tokio::test]
231 async fn post_block_auth_201() { 262 async fn post_block_auth_201() {
263 println!("Wtf");
232 let db = mocked_db(); 264 let db = mocked_db();
233 let filter = consensus_routes(db.clone()); 265 let filter = consensus_routes(db.clone());
234 266
267
268
235 let res = warp::test::request() 269 let res = warp::test::request()
236 .method("POST") 270 .method("POST")
237 .json(&Block { 271 .json(&Block {