From b76c7913a92e98bec880edacb20cec932a50c870 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Thu, 11 Mar 2021 10:20:01 +0800 Subject: [PATCH] refactor: Clean up code --- contracts/info-type/src/entry.rs | 9 ++---- tests/src/index_state_tests.rs | 48 ++++++++++++++++---------------- tests/src/info_tests.rs | 36 ++++++++++++------------ tests/src/lib.rs | 20 ++++++------- 4 files changed, 54 insertions(+), 59 deletions(-) diff --git a/contracts/info-type/src/entry.rs b/contracts/info-type/src/entry.rs index f44d8ae..5795f51 100644 --- a/contracts/info-type/src/entry.rs +++ b/contracts/info-type/src/entry.rs @@ -3,10 +3,7 @@ use alloc::vec::Vec; use ckb_std::{ ckb_constants::Source, ckb_types::{bytes::Bytes, packed::*, prelude::*}, - high_level::{ - load_cell_data, load_cell_type, load_input_since, load_script, - QueryIter, - }, + high_level::{load_cell_data, load_cell_type, load_input_since, load_script, QueryIter}, }; use core::result::Result; @@ -77,8 +74,8 @@ fn check_info_cell_data() -> Result<(), Error> { return Err(Error::TimeInfoDataLenError); } Ok(()) - }, - Err(_) => Err(Error::TimeInfoTypeNotExist) + } + Err(_) => Err(Error::TimeInfoTypeNotExist), } } diff --git a/tests/src/index_state_tests.rs b/tests/src/index_state_tests.rs index a4e9a1f..d24275f 100644 --- a/tests/src/index_state_tests.rs +++ b/tests/src/index_state_tests.rs @@ -218,9 +218,9 @@ fn test_create_index_state_cells_success() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -251,9 +251,9 @@ fn test_update_index_state_cells_success() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -284,9 +284,9 @@ fn test_update_full_index_state_cells_success() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -315,9 +315,9 @@ fn test_error_index_state_len() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -346,9 +346,9 @@ fn test_error_info_amount() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -380,9 +380,9 @@ fn test_error_index_out_of_bound() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -413,9 +413,9 @@ fn test_error_args_invalid() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( @@ -468,9 +468,9 @@ fn test_error_index_not_increase() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 0, + is_lock_script: false, + is_output: true, + script_index: 0, native_binaries: HashMap::default(), }; write_native_setup( diff --git a/tests/src/info_tests.rs b/tests/src/info_tests.rs index 30ff59f..9ea3508 100644 --- a/tests/src/info_tests.rs +++ b/tests/src/info_tests.rs @@ -436,9 +436,9 @@ fn test_error_create_info_cell_data_len() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: true, - script_index: 1, + is_lock_script: false, + is_output: true, + script_index: 1, native_binaries: HashMap::default(), }; write_native_setup( @@ -478,9 +478,9 @@ fn test_error_index_state_cell_data_len() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: false, - script_index: 1, + is_lock_script: false, + is_output: false, + script_index: 1, native_binaries: HashMap::default(), }; write_native_setup( @@ -602,9 +602,9 @@ fn test_error_output_block_number_not_bigger() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: false, - script_index: 1, + is_lock_script: false, + is_output: false, + script_index: 1, native_binaries: HashMap::default(), }; write_native_setup( @@ -656,9 +656,9 @@ fn test_error_output_block_number_since() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: false, - script_index: 1, + is_lock_script: false, + is_output: false, + script_index: 1, native_binaries: HashMap::default(), }; write_native_setup( @@ -710,9 +710,9 @@ fn test_error_output_timestamp_not_bigger() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: false, - script_index: 1, + is_lock_script: false, + is_output: false, + script_index: 1, native_binaries: HashMap::default(), }; write_native_setup( @@ -764,9 +764,9 @@ fn test_error_output_timestamp_since() { // dump raw test tx files let setup = RunningSetup { - is_lock_script: false, - is_output: false, - script_index: 1, + is_lock_script: false, + is_output: false, + script_index: 1, native_binaries: HashMap::default(), }; write_native_setup( diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 75c1741..a205eb7 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -1,23 +1,21 @@ #[macro_use] extern crate lazy_static; +use ckb_standalone_debugger::transaction::{ + MockCellDep, MockInfo, MockInput, MockTransaction, ReprMockTransaction, +}; +use ckb_testtool::context::Context; use ckb_tool::ckb_error::Error; use ckb_tool::ckb_script::ScriptError; use ckb_tool::ckb_types::bytes::Bytes; +use ckb_x64_simulator::RunningSetup; +use serde_json::to_string_pretty; use std::env; use std::fs; use std::path::{Path, PathBuf}; use std::str::FromStr; -use ckb_testtool::context::Context; -use ckb_standalone_debugger::transaction::{ - MockCellDep, MockInfo, MockInput, MockTransaction, ReprMockTransaction, -}; -use ckb_x64_simulator::RunningSetup; -use serde_json::to_string_pretty; -use ckb_tool::ckb_types::{ - core::{DepType, TransactionView}, -}; +use ckb_tool::ckb_types::core::{DepType, TransactionView}; #[cfg(test)] mod info_tests; @@ -150,8 +148,8 @@ fn build_mock_transaction(tx: &TransactionView, context: &Context) -> MockTransa }) .collect(); let mock_info = MockInfo { - inputs: mock_inputs, - cell_deps: mock_cell_deps, + inputs: mock_inputs, + cell_deps: mock_cell_deps, header_deps: vec![], }; MockTransaction {