| 28 | |
| 29 | #[tokio::test(flavor = "multi_thread")] |
| 30 | async fn post_simulate_file() { |
| 31 | if config().etherscan_key.is_some() { |
| 32 | eprintln!("etherscan_key is some, skipping test"); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | let filter = filter(config()); |
| 37 | |
| 38 | let file = File::open("tests/body.json").expect("file should open read only"); |
| 39 | let json: SimulationRequest = |
| 40 | serde_json::from_reader(file).expect("file should be proper JSON"); |
| 41 | |
| 42 | let res = warp::test::request() |
| 43 | .method("POST") |
| 44 | .path("/simulate") |
| 45 | .json(&json) |
| 46 | .reply(&filter) |
| 47 | .await; |
| 48 | |
| 49 | assert_eq!(res.status(), 200); |
| 50 | |
| 51 | // Uncomment to create new file, if you've made changes to the expected response |
| 52 | // let mut file = File::create("tests/expected.json").expect("file should open write only"); |
| 53 | // file.write_all(res.body()).expect("file should be written"); |
| 54 | |
| 55 | let body: SimulationResponse = serde_json::from_slice(res.body()).unwrap(); |
| 56 | |
| 57 | let file = File::open("tests/expected.json").expect("file should open read only"); |
| 58 | let expected: SimulationResponse = |
| 59 | serde_json::from_reader(file).expect("file should be proper JSON"); |
| 60 | |
| 61 | assert_eq!(body, expected); |
| 62 | } |
| 63 | |
| 64 | /// The difference between this test and `post_simulate_file` is that this one checks against |
| 65 | /// a file which has the Etherscan decoded traces included. Therefore, the etherscan_key must be set |