|
| 1 | +// Copyright 2018-2020 Kodebox, Inc. |
| 2 | +// This file is part of CodeChain. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as |
| 6 | +// published by the Free Software Foundation, either version 3 of the |
| 7 | +// License, or (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +// You should run `cargo test` with `--test-threads=1`, if you use `integration-test` feature. |
| 18 | +#![cfg(feature = "integration-test")] |
| 19 | + |
| 20 | +extern crate foundry_integration_test as test_common; |
| 21 | + |
| 22 | +use std::time::Duration; |
| 23 | +use test_common::*; |
| 24 | +use tokio::time::delay_for; |
| 25 | + |
| 26 | +fn run_node_override(arg: FoundryArgs) -> FoundryNode { |
| 27 | + run_node( |
| 28 | + RunNodeArgs { |
| 29 | + foundry_path: "../target/debug/foundry".to_string(), |
| 30 | + rust_log: "warn".to_string(), |
| 31 | + app_desc_path: "../demo/app-desc.toml".to_string(), |
| 32 | + link_desc_path: "../demo/link-desc.toml".to_string(), |
| 33 | + config_path: "config.tendermint-solo.ini".to_string(), |
| 34 | + }, |
| 35 | + arg, |
| 36 | + ) |
| 37 | +} |
| 38 | + |
| 39 | +const GRAPHQL_PORT_BASE: u16 = 5000; |
| 40 | + |
| 41 | +fn simple_multi_node(index: usize) -> FoundryArgs { |
| 42 | + let signers = [ |
| 43 | + "rjmxg19kCmkCxROEoV0QYsrDpOYsjQwusCtN5_oKMEzk-I6kgtAtc0", |
| 44 | + "szff1322BHP3gsOuwFPDf-K8zvqSmNz4rj3CJirlQKFKWA_3c-Ytc0", |
| 45 | + "qwfj0xwkJQLV5iEGeaGeRfPA-TJX56Mnuq9fQD9coasmhanhck4tc0", |
| 46 | + "dbqtds3w6QnzEf0RXuQS7c_N6IzFBzcBAfdjWme5y0U5DxzLS14tc0", |
| 47 | + ]; |
| 48 | + |
| 49 | + let mut bootstrap_addresses = Vec::new(); |
| 50 | + for i in 0..4 { |
| 51 | + if i == index { |
| 52 | + continue |
| 53 | + } |
| 54 | + bootstrap_addresses.push(format!("127.0.0.1:{}", 3000 + i as u16)); |
| 55 | + } |
| 56 | + |
| 57 | + FoundryArgs { |
| 58 | + graphql_port: GRAPHQL_PORT_BASE + index as u16, |
| 59 | + mem_pool_size: 32768, |
| 60 | + engine_signer: signers[index].to_owned(), |
| 61 | + port: 3000 + index as u16, |
| 62 | + bootstrap_addresses, |
| 63 | + password_path: "../demo/password.json".to_owned(), |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +#[actix_rt::test] |
| 68 | +async fn ping() { |
| 69 | + let _node: Vec<FoundryNode> = (0..4).into_iter().map(|i| run_node_override(simple_multi_node(i))).collect(); |
| 70 | + delay_for(Duration::from_secs(3)).await; |
| 71 | + |
| 72 | + for i in 0..4 { |
| 73 | + let x = request_query(GRAPHQL_PORT_BASE + i, "ping", "aaaa", "aaaa").await; |
| 74 | + assert_eq!(x, "Module not found: ping"); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +#[actix_rt::test] |
| 79 | +async fn track_blocks() { |
| 80 | + let _node: Vec<FoundryNode> = (0..4).into_iter().map(|i| run_node_override(simple_multi_node(i))).collect(); |
| 81 | + delay_for(Duration::from_secs(3)).await; |
| 82 | + |
| 83 | + let start_block = get_latest_block(GRAPHQL_PORT_BASE).await; |
| 84 | + while get_latest_block(GRAPHQL_PORT_BASE).await < start_block + 8 { |
| 85 | + delay_for(Duration::from_secs(1)).await; |
| 86 | + } |
| 87 | + |
| 88 | + for i in 0..4 { |
| 89 | + assert!(get_latest_block(GRAPHQL_PORT_BASE + i).await >= start_block + 8) |
| 90 | + } |
| 91 | +} |
0 commit comments