Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for sequential /set_data requests with random data in src/tests/mod.rs #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,39 @@ async fn test_set_data() {
"{\"status\":\"Success\",\"reason\":\"Data set successfully\",\"route\":\"set_data\",\"content\":\"0x123\"}"
);
}

#[tokio::test(flavor = "current_thread")]
async fn test_sequential_set_data_requests() {
// Arrange
let db_stub = Arc::new(Mutex::new(DbStub::init("").await.unwrap()));
let cache_stub = Arc::new(Mutex::new(DbStub::init("").await.unwrap()));
let cfilter = Arc::new(Mutex::new(cuckoofilter::CuckooFilter::new()));
let filter = routes::set_data(db_stub.clone(), cache_stub.clone(), cfilter.clone(), 1000, 600).recover(handle_rejection);

for i in 0..3 {
let data_id = format!("test_id_{}", i);
let data = format!("{{\"value\": \"test_{}\"}}", i);
let req_body = format!(
"{{\"address\":\"0x123\",\"data\":\"{}\", \"data_id\":\"{}\"}}",
data, data_id
);

// Act
let request = warp::test::request()
.method("POST")
.header("public_key", TEST_VALID_PUB_KEY)
.header("address", TEST_VALID_ADDRESS)
.header("signature", TEST_VALID_SIG)
.body(&req_body)
.path("/set_data");

let res = request.reply(&filter).await;

// Assert
assert_eq!(res.status(), 200);
assert_eq!(
res.body(),
"{\"status\":\"Success\",\"reason\":\"Data set successfully\",\"route\":\"set_data\",\"content\":\"0x123\"}"
);
}
}
Loading