|
1 | 1 | use ckb_chain::chain::ChainController; |
2 | 2 | use ckb_chain_spec::consensus::Consensus; |
3 | 3 | use ckb_dao::DaoCalculator; |
4 | | -use ckb_jsonrpc_types::ScriptHashType; |
5 | | -use ckb_network::{Flags, NetworkService, NetworkState}; |
6 | 4 | use ckb_reward_calculator::RewardCalculator; |
7 | | -use ckb_shared::{Shared, SharedBuilder, Snapshot}; |
| 5 | +use ckb_shared::{Shared, Snapshot}; |
8 | 6 | use ckb_store::ChainStore; |
9 | 7 | use ckb_test_chain_utils::{always_success_cell, always_success_cellbase}; |
10 | 8 | use ckb_types::{ |
11 | 9 | core::{ |
12 | 10 | cell::resolve_transaction, BlockBuilder, BlockView, HeaderView, TransactionBuilder, |
13 | 11 | TransactionView, |
14 | 12 | }, |
15 | | - global::DATA_DIR, |
16 | | - h256, |
17 | 13 | packed::{CellInput, OutPoint}, |
18 | 14 | prelude::*, |
19 | 15 | }; |
@@ -221,128 +217,7 @@ fn always_success_transaction() -> TransactionView { |
221 | 217 | .build() |
222 | 218 | } |
223 | 219 |
|
224 | | -// setup a chain with 20 blocks and enable `Chain`, `Miner` and `Pool` rpc modules for unit test |
225 | | -// there is a similar fn `setup_rpc_test_suite` which enables all rpc modules, |
226 | | -// may be refactored into one fn with different paramsters in other PRs |
| 220 | +// setup a chain with 20 blocks and enable `Chain`, `Miner` and `Pool` rpc modules for unit test. |
227 | 221 | fn setup(consensus: Consensus) -> RpcTestSuite { |
228 | 222 | setup_rpc_test_suite(20, Some(consensus)) |
229 | | - /* |
230 | | - let (shared, mut pack) = SharedBuilder::with_temp_db() |
231 | | - .consensus(consensus) |
232 | | - .block_assembler_config(Some(BlockAssemblerConfig { |
233 | | - code_hash: h256!("0x0"), |
234 | | - args: Default::default(), |
235 | | - hash_type: ScriptHashType::Data, |
236 | | - message: Default::default(), |
237 | | - use_binary_version_as_message_prefix: false, |
238 | | - binary_version: "TEST".to_string(), |
239 | | - update_interval_millis: 800, |
240 | | - notify: vec![], |
241 | | - notify_scripts: vec![], |
242 | | - notify_timeout_millis: 800, |
243 | | - })) |
244 | | - .build() |
245 | | - .unwrap(); |
246 | | - let chain_controller = |
247 | | - ChainService::new(shared.clone(), pack.take_proposal_table()).start::<&str>(None); |
248 | | -
|
249 | | - let tmp_dir = tempfile::tempdir().expect("create tmp_dir failed"); |
250 | | - DATA_DIR |
251 | | - .set(tmp_dir.path().join("data")) |
252 | | - .expect("DATA_DIR set only once"); |
253 | | -
|
254 | | - // Start network services |
255 | | - let network_controller = { |
256 | | - let network_config = NetworkConfig { |
257 | | - path: tmp_dir.path().join("network").to_path_buf(), |
258 | | - ping_interval_secs: 1, |
259 | | - ping_timeout_secs: 1, |
260 | | - connect_outbound_interval_secs: 1, |
261 | | - ..Default::default() |
262 | | - }; |
263 | | - let network_state = |
264 | | - Arc::new(NetworkState::from_config(network_config).expect("Init network state failed")); |
265 | | - NetworkService::new( |
266 | | - Arc::clone(&network_state), |
267 | | - Vec::new(), |
268 | | - Vec::new(), |
269 | | - ( |
270 | | - shared.consensus().identify_name(), |
271 | | - "0.1.0".to_string(), |
272 | | - Flags::COMPATIBILITY, |
273 | | - ), |
274 | | - ) |
275 | | - .start(shared.async_handle()) |
276 | | - .expect("Start network service failed") |
277 | | - }; |
278 | | -
|
279 | | - pack.take_tx_pool_builder() |
280 | | - .start(network_controller.clone()); |
281 | | -
|
282 | | - // Build chain, insert 20 blocks |
283 | | - let mut parent = shared.consensus().genesis_block().clone(); |
284 | | -
|
285 | | - for _ in 0..20 { |
286 | | - let block = next_block(&shared, &parent.header()); |
287 | | - chain_controller |
288 | | - .process_block(Arc::new(block.clone())) |
289 | | - .expect("processing new block should be ok"); |
290 | | - parent = block; |
291 | | - } |
292 | | -
|
293 | | - // Start rpc services |
294 | | - let rpc_config = RpcConfig { |
295 | | - listen_address: "127.0.0.1:0".to_owned(), |
296 | | - tcp_listen_address: Some("127.0.0.1:0".to_owned()), |
297 | | - ws_listen_address: None, |
298 | | - max_request_body_size: 20_000_000, |
299 | | - threads: None, |
300 | | - modules: vec![ |
301 | | - RpcModule::Chain, |
302 | | - RpcModule::Miner, |
303 | | - RpcModule::Pool, |
304 | | - RpcModule::IntegrationTest, |
305 | | - ], |
306 | | - reject_ill_transactions: false, |
307 | | - enable_deprecated_rpc: false, |
308 | | - extra_well_known_lock_scripts: vec![], |
309 | | - extra_well_known_type_scripts: vec![], |
310 | | - }; |
311 | | -
|
312 | | - let builder = ServiceBuilder::new(&rpc_config) |
313 | | - .enable_chain(shared.clone()) |
314 | | - .enable_pool(shared.clone(), vec![], vec![]) |
315 | | - .enable_miner( |
316 | | - shared.clone(), |
317 | | - network_controller.clone(), |
318 | | - chain_controller.clone(), |
319 | | - true, |
320 | | - ) |
321 | | - .enable_integration_test(shared.clone(), network_controller, chain_controller.clone()); |
322 | | - let io_handler = builder.build(); |
323 | | -
|
324 | | - let shared_clone = shared.clone(); |
325 | | - let handler = shared_clone.async_handle().clone(); |
326 | | - let rpc_server = handler.block_on(async move { RpcServer::new(rpc_config, io_handler).await }); |
327 | | -
|
328 | | - let rpc_client = Client::new(); |
329 | | - let rpc_uri = format!( |
330 | | - "http://{}:{}/", |
331 | | - rpc_server.http_address.ip(), |
332 | | - rpc_server.http_address.port() |
333 | | - ); |
334 | | - let tcp_uri = rpc_server |
335 | | - .tcp_address |
336 | | - .as_ref() |
337 | | - .map(|addr| format!("{}:{}", addr.ip(), addr.port())); |
338 | | -
|
339 | | - RpcTestSuite { |
340 | | - shared, |
341 | | - chain_controller, |
342 | | - rpc_uri, |
343 | | - tcp_uri, |
344 | | - rpc_client, |
345 | | - _tmp_dir: tmp_dir, |
346 | | - } |
347 | | - */ |
348 | 223 | } |
0 commit comments