From ec6bcf166032d0820716189308020c2b2d1faa67 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 00:17:18 +0300 Subject: Add new test --- tests/route_tests.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/route_tests.rs b/tests/route_tests.rs index d24bbfb..d88b0da 100644 --- a/tests/route_tests.rs +++ b/tests/route_tests.rs @@ -234,6 +234,7 @@ sQIDAQAB let res = warp::test::request() .method("POST") + .header("Authorization", "Bearer foo.bar.baz") .json(&Block { transaction_list: vec!["foobarbaz".to_owned(), "dazsaz".to_owned()], nonce: 1000, // not valid @@ -247,6 +248,32 @@ sQIDAQAB assert_eq!(res.status(), StatusCode::BAD_REQUEST); } + /// Test a POST request to /block, an endpoint that exists + /// + /// https://tools.ietf.org/html/rfc7231#section-6.3.2 + /// + /// Should reject the block because transaction list is empty + #[tokio::test] + async fn post_block_with_empty_transaction_list() { + let db = mocked_db(); + let filter = consensus_routes(db.clone()); + + let res = warp::test::request() + .method("POST") + .header("Authorization", "Bearer foo.bar.baz") + .json(&Block { + transaction_list: vec![], + nonce: 1000, // not valid + timestamp: chrono::NaiveDate::from_ymd(2021, 04, 12).and_hms(05, 29, 30), + hash: "thisisnotavalidhash".to_owned(), + }) + .path("/block") + .reply(&filter) + .await; + + assert_eq!(res.status(), StatusCode::BAD_REQUEST); + } + /// Test a POST request to /block, an endpoint that exists /// /// https://tools.ietf.org/html/rfc7231#section-6.3.2 -- cgit v1.2.3-70-g09d2