From 6ed263bbb0991376d315748d64e5d53a40a859e1 Mon Sep 17 00:00:00 2001 From: mohanson Date: Mon, 8 Jul 2024 15:07:01 +0800 Subject: [PATCH] Merge ckb-debugger-api into ckb-debugger --- .github/workflows/release.yml | 1 - Cargo.lock | 18 -- Cargo.toml | 1 - README.md | 1 - ckb-debugger-api/Cargo.toml | 28 --- ckb-debugger-api/README.md | 3 - ckb-debugger-api/src/embed.rs | 110 --------- ckb-debugger-api/src/lib.rs | 208 ------------------ ckb-debugger-api/tests/programs/bench | Bin 4056 -> 0 bytes ckb-debugger-api/tests/programs/bench.c | 47 ---- ckb-debugger-api/tests/programs/sample.c | 27 --- ckb-debugger-api/tests/programs/sample.json | 94 -------- .../tests/programs/sample_data1.json | 94 -------- ckb-debugger-api/tests/test_json.rs | 18 -- ckb-debugger-api/tests/test_rust.rs | 74 ------- ckb-debugger/Cargo.toml | 2 + ckb-debugger/src/api.rs | 76 +++++++ ckb-debugger/src/lib.rs | 2 + ckb-debugger/src/main.rs | 10 +- ckb-debugger/tests/test_api.rs | 12 + 20 files changed, 96 insertions(+), 730 deletions(-) delete mode 100644 ckb-debugger-api/Cargo.toml delete mode 100644 ckb-debugger-api/README.md delete mode 100644 ckb-debugger-api/src/embed.rs delete mode 100644 ckb-debugger-api/src/lib.rs delete mode 100755 ckb-debugger-api/tests/programs/bench delete mode 100644 ckb-debugger-api/tests/programs/bench.c delete mode 100644 ckb-debugger-api/tests/programs/sample.c delete mode 100644 ckb-debugger-api/tests/programs/sample.json delete mode 100644 ckb-debugger-api/tests/programs/sample_data1.json delete mode 100644 ckb-debugger-api/tests/test_json.rs delete mode 100644 ckb-debugger-api/tests/test_rust.rs create mode 100644 ckb-debugger/src/api.rs create mode 100644 ckb-debugger/tests/test_api.rs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 87f817f..9c9c508 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -84,7 +84,6 @@ jobs: cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }} cd ckb-mock-tx-types && cargo publish && cd .. cd ckb-vm-pprof && cargo publish && cd .. - cd ckb-debugger-api && cargo publish && cd .. cd ckb-vm-debug-utils && cargo publish && cd .. cd ckb-debugger && cargo publish && cd .. cd ckb-vm-pprof-protos && cargo publish --no-verify && cd .. diff --git a/Cargo.lock b/Cargo.lock index 2fa49f2..825a74d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,24 +344,6 @@ dependencies = [ "probe", "rand 0.8.5", "regex 1.10.5", - "serde_json", - "serde_plain", -] - -[[package]] -name = "ckb-debugger-api" -version = "0.116.1" -dependencies = [ - "byteorder", - "ckb-chain-spec", - "ckb-hash", - "ckb-jsonrpc-types", - "ckb-mock-tx-types", - "ckb-script", - "ckb-types", - "ckb-vm", - "hex", - "regex 1.10.5", "serde", "serde_json", "serde_plain", diff --git a/Cargo.toml b/Cargo.toml index 4ed963f..d7e7826 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ resolver = "2" members = [ "ckb-debugger", - "ckb-debugger-api", "ckb-mock-tx-types", "ckb-vm-debug-utils", "ckb-vm-pprof", diff --git a/README.md b/README.md index de9babf..b416a64 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ CKB standalone debugger is a collection of debugging tools. - [ckb-debugger](./ckb-debugger) -- [ckb-debugger-api](./ckb-debugger-api) - [ckb-mock-tx-types](./ckb-mock-tx-types) - [ckb-vm-debug-utils](./ckb-vm-debug-utils) - [ckb-vm-pprof](./ckb-vm-pprof) diff --git a/ckb-debugger-api/Cargo.toml b/ckb-debugger-api/Cargo.toml deleted file mode 100644 index cbb734e..0000000 --- a/ckb-debugger-api/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "ckb-debugger-api" -description = "Standalone debugger for Nervos CKB" -version = "0.116.1" -license = "MIT" -authors = ["Nervos Core Dev "] -edition = "2021" - -[lib] -crate-type = ["cdylib", "rlib"] - -[dependencies] -ckb-hash = { git = "https://github.com/libraries/ckb", branch = "new_spawn" } -ckb-chain-spec = { git = "https://github.com/libraries/ckb", branch = "new_spawn" } -ckb-jsonrpc-types = { git = "https://github.com/libraries/ckb", branch = "new_spawn" } -ckb-mock-tx-types = { path = "../ckb-mock-tx-types", version = "=0.116.1" } -ckb-script = { git = "https://github.com/libraries/ckb", branch = "new_spawn", default-features = false, features = ["flatmemory"] } -ckb-types = { git = "https://github.com/libraries/ckb", branch = "new_spawn" } -ckb-vm = { version = "= 0.24.12", default-features = false } -hex = "0.4" -regex = "1" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -serde_plain = "1.0" -wasm-bindgen = "=0.2.50" - -[dev-dependencies] -byteorder = "1.3.2" diff --git a/ckb-debugger-api/README.md b/ckb-debugger-api/README.md deleted file mode 100644 index 08b8796..0000000 --- a/ckb-debugger-api/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# CKB Debugger API - -The api of ckb debugger, supports compiling to wasm. diff --git a/ckb-debugger-api/src/embed.rs b/ckb-debugger-api/src/embed.rs deleted file mode 100644 index 45f84a4..0000000 --- a/ckb-debugger-api/src/embed.rs +++ /dev/null @@ -1,110 +0,0 @@ -use ckb_chain_spec::consensus::TYPE_ID_CODE_HASH; -use ckb_hash::blake2b_256; -use ckb_types::core::ScriptHashType; -use ckb_types::packed::Script; -use ckb_types::prelude::{Builder, Entity, Pack}; -use ckb_vm::Bytes; -use regex::{Captures, Regex}; -use std::collections::HashMap; -use std::path::{Path, PathBuf}; - -pub struct Embed { - pub data: String, - pub path: PathBuf, - pub type_id_dict: HashMap, -} - -impl Embed { - pub fn new(path: PathBuf, data: String) -> Self { - Self { data, path, type_id_dict: HashMap::new() } - } - - pub fn replace_data(&mut self) -> &mut Self { - let regex = Regex::new(r"\{\{ ?data (.+?) ?\}\}").unwrap(); - self.data = regex - .replace_all(&self.data, |caps: &Captures| -> String { - let cap1 = &caps[1]; - let path = if !Path::new(cap1).is_absolute() { - let root = self.path.parent().unwrap(); - root.join(cap1) - } else { - Path::new(cap1).to_path_buf() - }; - let data = std::fs::read(&path); - if data.is_err() { - panic!("Read {:?} failed : {:?}", path, data); - } - let data = data.unwrap(); - hex::encode(data) - }) - .to_string(); - self - } - - pub fn replace_hash(&mut self) -> &mut Self { - let regex = Regex::new(r"\{\{ ?hash (.+?) ?\}\}").unwrap(); - self.data = regex - .replace_all(&self.data, |caps: &Captures| -> String { - let cap1 = &caps[1]; - let path = if !Path::new(cap1).is_absolute() { - let root = self.path.parent().unwrap(); - root.join(cap1) - } else { - Path::new(cap1).to_path_buf() - }; - let data = std::fs::read(path).unwrap(); - hex::encode(blake2b_256(data)) - }) - .to_string(); - self - } - - pub fn prelude_type_id(&mut self) -> &mut Self { - let rule = Regex::new(r"\{\{ ?def_type (.+?) ?\}\}").unwrap(); - for caps in rule.captures_iter(&self.data) { - let type_id_name = &caps[1]; - assert!(!self.type_id_dict.contains_key(type_id_name)); - let type_id_script = Script::new_builder() - .args(Bytes::from(type_id_name.to_string()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) - .build(); - let type_id_script_hash = type_id_script.calc_script_hash(); - let type_id_script_hash = format!("{:x}", type_id_script_hash); - self.type_id_dict.insert(type_id_name.to_string(), type_id_script_hash); - } - self - } - - pub fn replace_def_type(&mut self) -> &mut Self { - let regex = Regex::new(r#""?\{\{ ?def_type (.+?) ?\}\}"?"#).unwrap(); - self.data = regex - .replace_all(&self.data, |caps: &Captures| -> String { - let cap1 = &caps[1]; - let type_id_script_json = ckb_jsonrpc_types::Script { - code_hash: TYPE_ID_CODE_HASH, - hash_type: ckb_jsonrpc_types::ScriptHashType::Type, - args: ckb_jsonrpc_types::JsonBytes::from_vec(cap1.as_bytes().to_vec()), - }; - return serde_json::to_string_pretty(&type_id_script_json).unwrap(); - }) - .to_string(); - self - } - - pub fn replace_ref_type(&mut self) -> &mut Self { - let regex = Regex::new(r"\{\{ ?ref_type (.+?) ?\}\}").unwrap(); - self.data = regex - .replace_all(&self.data, |caps: &Captures| -> String { - let cap1 = &caps[1]; - return self.type_id_dict[&cap1.to_string()].clone(); - }) - .to_string(); - self - } - - pub fn replace_all(&mut self) -> String { - self.replace_data().replace_hash().prelude_type_id().replace_def_type().replace_ref_type(); - self.data.clone() - } -} diff --git a/ckb-debugger-api/src/lib.rs b/ckb-debugger-api/src/lib.rs deleted file mode 100644 index d690ede..0000000 --- a/ckb-debugger-api/src/lib.rs +++ /dev/null @@ -1,208 +0,0 @@ -use ckb_chain_spec::consensus::ConsensusBuilder; -use ckb_jsonrpc_types::{CellDep, CellInput, DepType}; -use ckb_mock_tx_types::{MockInput, MockResourceLoader, MockTransaction, ReprMockTransaction, Resource}; -use ckb_script::{ScriptGroupType, TransactionScriptsVerifier, TxVerifyEnv}; -use ckb_types::{ - bytes::Bytes, - core::cell::resolve_transaction, - core::hardfork::{HardForks, CKB2021, CKB2023}, - core::{Cycle, EpochNumberWithFraction, HeaderView}, - packed::{self, Byte32, CellOutput, OutPoint, OutPointVec}, - prelude::*, - H256, -}; -use serde::{Deserialize, Serialize}; -use serde_json::{from_str as from_json_str, to_string as to_json_string}; -use serde_plain::from_str as from_plain_str; -use std::collections::HashSet; -use std::sync::Arc; -use wasm_bindgen::prelude::*; -pub mod embed; - -pub struct DummyResourceLoader {} - -impl MockResourceLoader for DummyResourceLoader { - fn get_header(&mut self, hash: H256) -> Result, String> { - return Err(format!("Header {:x} is missing!", hash)); - } - - fn get_live_cell(&mut self, out_point: OutPoint) -> Result)>, String> { - return Err(format!("Cell: {:?} is missing!", out_point)); - } -} - -pub fn run( - mock_tx: &MockTransaction, - script_group_type: &ScriptGroupType, - script_hash: &Byte32, - max_cycle: Cycle, - debug_printer: Option>, -) -> Result { - let resource = Resource::from_both(mock_tx, DummyResourceLoader {})?; - let tx = mock_tx.core_transaction(); - let rtx = { - let mut seen_inputs = HashSet::new(); - resolve_transaction(tx, &mut seen_inputs, &resource, &resource) - .map_err(|err| format!("Resolve transaction error: {:?}", err))? - }; - let hardfork_switch = HardForks { - ckb2021: CKB2021::new_mirana(), - ckb2023: CKB2023::new_mirana().as_builder().rfc_0049(2023).build().unwrap(), - }; - let consensus = Arc::new(ConsensusBuilder::default().hardfork_switch(hardfork_switch).build()); - let epoch = EpochNumberWithFraction::new(2023, 0, 1); - let header = HeaderView::new_advanced_builder().epoch(epoch.pack()).build(); - let tx_env = Arc::new(TxVerifyEnv::new_commit(&header)); - let mut verifier = - TransactionScriptsVerifier::new(Arc::new(rtx), resource.clone(), consensus.clone(), tx_env.clone()); - if let Some(debug_printer) = debug_printer { - verifier.set_debug_printer(debug_printer); - } - verifier - .verify_single(*script_group_type, script_hash, max_cycle) - .map_err(|err| format!("Verify script error: {:?}", err)) -} - -#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] -struct JsonResult { - cycle: Option, - error: Option, -} - -impl From> for JsonResult { - fn from(result: Result) -> JsonResult { - match result { - Ok(cycle) => JsonResult { cycle: Some(cycle), error: None }, - Err(error) => JsonResult { cycle: None, error: Some(error) }, - } - } -} - -fn internal_run_json( - mock_tx: &str, - script_group_type: &str, - hex_script_hash: &str, - max_cycle: &str, - debug_printer: Option>, -) -> Result { - let repr_mock_tx: ReprMockTransaction = from_json_str(mock_tx).map_err(|e| e.to_string())?; - let mock_tx: MockTransaction = repr_mock_tx.into(); - let script_group_type: ScriptGroupType = from_plain_str(script_group_type).map_err(|e| e.to_string())?; - if hex_script_hash.len() != 66 || (!hex_script_hash.starts_with("0x")) { - return Err("Invalid script hash format!".to_string()); - } - let b = hex::decode(&hex_script_hash.as_bytes()[2..]).map_err(|e| e.to_string())?; - let script_hash = Byte32::from_slice(b.as_slice()).map_err(|e| e.to_string())?; - let max_cycle: Cycle = max_cycle.parse().map_err(|_| "Invalid max cycle!".to_string())?; - run(&mock_tx, &script_group_type, &script_hash, max_cycle, debug_printer) -} - -#[wasm_bindgen] -pub fn run_json(mock_tx: &str, script_group_type: &str, hex_script_hash: &str, max_cycle: &str) -> String { - let json_result: JsonResult = - internal_run_json(mock_tx, script_group_type, hex_script_hash, max_cycle, None).into(); - to_json_string(&json_result).expect("JSON serialization should not fail!") -} - -fn parse_dep_group_data(slice: &[u8]) -> Result { - if slice.is_empty() { - Err("data is empty".to_owned()) - } else { - match OutPointVec::from_slice(slice) { - Ok(v) => { - if v.is_empty() { - Err("dep group is empty".to_owned()) - } else { - Ok(v) - } - } - Err(err) => Err(err.to_string()), - } - } -} - -pub fn check(tx: &ReprMockTransaction) -> Result<(), String> { - let mut mock_cell_deps: Vec = - tx.mock_info.cell_deps.iter().map(|c| c.cell_dep.clone()).collect::>(); - let mut cell_deps = tx.tx.cell_deps.iter().map(|c| c.clone()).collect::>(); - - for dep in &tx.mock_info.cell_deps { - if dep.cell_dep.dep_type == DepType::DepGroup { - let sub_outpoints = parse_dep_group_data(dep.data.as_bytes())?; - let outpoints: Vec = sub_outpoints.into_iter().collect::>(); - let resolved_cell_deps: Vec = outpoints - .into_iter() - .map(|o| CellDep { out_point: o.into(), dep_type: DepType::Code }) - .collect::>(); - cell_deps.extend(resolved_cell_deps); - } - } - let compare = |a: &CellDep, b: &CellDep| { - let left = serde_json::to_string(a).unwrap(); - let right = serde_json::to_string(b).unwrap(); - left.cmp(&right) - }; - mock_cell_deps.sort_by(compare); - cell_deps.sort_by(compare); - - if mock_cell_deps.len() != cell_deps.len() { - return Err(format!( - "mock_cell_deps.len() != cell_deps.len(), {} != {}", - mock_cell_deps.len(), - cell_deps.len() - )); - } else { - for (a, b) in mock_cell_deps.into_iter().zip(cell_deps.into_iter()) { - if a != b { - return Err(format!("CellDeps {:?} != {:?}", a, b)); - } - } - } - - if tx.mock_info.inputs.len() != tx.tx.inputs.len() { - return Err(format!("tx.mock_info.inputs.len() != tx.tx.inputs.len() ")); - } else { - for i in 0..tx.mock_info.inputs.len() { - let mock_input: MockInput = tx.mock_info.inputs[i].clone().into(); - let input: CellInput = tx.tx.inputs[i].clone(); - let input: packed::CellInput = input.into(); - if mock_input.input != input { - return Err(format!("inputs at index {} is mismatched", i)); - } - } - } - if tx.mock_info.header_deps.len() != tx.tx.header_deps.len() { - return Err(format!("tx.mock_info.header_deps.len() != tx.tx.header_deps.len() ")); - } - Ok(()) -} - -// Get script hash by give group type, cell type and cell index. -// Note cell_type should be a string, in the range ["input", "output"]. -pub fn get_script_hash_by_index( - mock_tx: &MockTransaction, - script_group_type: &ScriptGroupType, - cell_type: &str, - cell_index: usize, -) -> Byte32 { - match (&script_group_type, cell_type) { - (ScriptGroupType::Lock, "input") => mock_tx.mock_info.inputs[cell_index].output.calc_lock_hash(), - (ScriptGroupType::Type, "input") => mock_tx.mock_info.inputs[cell_index] - .output - .type_() - .to_opt() - .expect("cell should have type script") - .calc_script_hash(), - (ScriptGroupType::Type, "output") => mock_tx - .tx - .raw() - .outputs() - .get(cell_index) - .expect("index out of bound") - .type_() - .to_opt() - .expect("cell should have type script") - .calc_script_hash(), - _ => panic!("Invalid specified script: {:?} {} {}", script_group_type, cell_type, cell_index), - } -} diff --git a/ckb-debugger-api/tests/programs/bench b/ckb-debugger-api/tests/programs/bench deleted file mode 100755 index 1650213c7f14a17f2dc06f7858ff216371d261bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4056 zcmeHKYfKbZ6h3!mXCGP@=G;Hsk zSeRc(35$$q$TdcYiRK3j?CKbu-4KgwGdP3P%wl_B@KkU~lSFZ(Js?*~l{N^{$?Lo| z?|!I3l(*)(?7|32r_7t@1croy-ihX4p3wQpkV}DMeF&8}LNqn-Xj?Fd`zEy- zpe^jEq^a~G?mX`cY{WLsF-VKt9NmH*nND%8X*iddgs%ZjxzbWbHE9|w8?nbsxLyO~ zo}T$L(%esmxjE`zM_k%?fnUz9pOo`+Ke%vysw{wedKVue(^qcoxHn5wI1umSeOeuz zI8GALyd0ZE0#xBx-q-8tWH>ju$pGChHs&F5pyQEKUT=OqAiX%&XqQ< zpUm>(voexH-0be!&TsfYnm7&D)}gr3sgJh7K%{nRATQ{`b#dp8Oy8FQ^z08x6=Kbuq5gohANYDv(DCoB4kH!l9 zh8)VhEAb8tMy`XkKPktW|C^=F%_fb3aDmC$f696(oP9>01SW&o&=npIbW9)@@8eug zpK{}`l>Ef72k>Ko@7OHAesY)2SBS4Zz}M&;I!6wnIo^juR2oy?cjbig9?DX==6^d? zu^ZPa{7aQ<{{K5y&I-Vs`_tvTmuv4#{XyaP`wFdeV5I{q9a!nWN(Wx70~YnaUgJzr z(N4=IrgZ;i%MROCTQ)ed@CJ1?^=tzm3l?>;R9(aNyqc}Yvk%qEi$`8qya3qhtLwdW zUe95$c`F;eV5_V?bfnHxTM4$BV>RAGp1L|u6WESmMUyK$UJu48>~MWO*x2`LYb%do z@Y1F>kJnpQbNB;qrTpLU;v|1N7^Wr%FshQqGqD~Mg-=%T$tqrp(-LU9#&fYFx_<4t zTU2}ro*<%0!)dl1Sct|~uah-^>X(+7HV!HZUYFwwRhxGHjViuT#pgdoD#CKS3!CK~ z@!j?uX?XeiM3YjTf|2c|_`rJ~kB*V$Hg*3k%N!bBGt0VGyJnO56%}6|ZN&0&{C|7n B;Hv-t diff --git a/ckb-debugger-api/tests/programs/bench.c b/ckb-debugger-api/tests/programs/bench.c deleted file mode 100644 index c7655b1..0000000 --- a/ckb-debugger-api/tests/programs/bench.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "ckb_syscalls.h" -#include "protocol.h" - -int main() { - char script[1024]; - char buffer[1024 * 1024]; - - uint64_t len = 1024; - uint64_t ret = ckb_load_script(script, &len, 0); - if (ret != 0) { - return ret; - } - mol_seg_t script_seg; - script_seg.ptr = (uint8_t*)script; - script_seg.size = len; - mol_seg_t args_seg = MolReader_Script_get_args(&script_seg); - mol_seg_t args_bytes_seg = MolReader_Bytes_raw_bytes(&args_seg); - if (args_bytes_seg.size != 32) { - return -101; - } - uint64_t adds = *((const uint64_t *) (&args_bytes_seg.ptr[0])); - uint64_t muls = *((const uint64_t *) (&args_bytes_seg.ptr[8])); - uint64_t loads = *((const uint64_t *) (&args_bytes_seg.ptr[16])); - uint64_t load_bytes = *((const uint64_t *) (&args_bytes_seg.ptr[24])); - - uint64_t result = 0; - for (uint64_t i = 1; i <= adds; i++) { - result += adds; - } - for (uint64_t i = 1; i <= muls; i++) { - result *= muls; - } - for (uint64_t i = 1; i <= loads; i++) { - len = load_bytes; - ret = ckb_load_cell_data(buffer, &len, 0, 0, CKB_SOURCE_CELL_DEP); - if (ret != 0) { - return ret; - } - result += buffer[0]; - } - - if (result == 0) { - return -1; - } - - return 0; -} diff --git a/ckb-debugger-api/tests/programs/sample.c b/ckb-debugger-api/tests/programs/sample.c deleted file mode 100644 index c669196..0000000 --- a/ckb-debugger-api/tests/programs/sample.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "ckb_syscalls.h" -#include "protocol.h" - -int main() -{ - ckb_debug("I'm in main now!"); - - char script[1024]; - uint64_t len = 1024; - uint64_t ret = ckb_load_script(script, &len, 0); - if (ret != 0) { - return ret; - } - mol_seg_t script_seg; - script_seg.ptr = (uint8_t*)script; - script_seg.size = len; - mol_seg_t args_seg = MolReader_Script_get_args(&script_seg); - mol_seg_t args_bytes_seg = MolReader_Bytes_raw_bytes(&args_seg); - - if (args_bytes_seg.size == 3) { - return -2; - } else if (args_bytes_seg.size == 5 ) { - return -3; - } else { - return 0; - } -} diff --git a/ckb-debugger-api/tests/programs/sample.json b/ckb-debugger-api/tests/programs/sample.json deleted file mode 100644 index 273d82f..0000000 --- a/ckb-debugger-api/tests/programs/sample.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "mock_info": { - "inputs": [ - { - "input": { - "previous_output": { - "tx_hash": "0xa98c57135830e1b91345948df6c4b8870828199a786b26f09f7dec4bc27a73da", - "index": "0x0" - }, - "since": "0x0" - }, - "output": { - "capacity": "0x4b9f96b00", - "lock": { - "args": "0x", - "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "hash_type": "data" - }, - "type": null - }, - "data": "0x616263" - } - ], - "cell_deps": [ - { - "cell_dep": { - "out_point": { - "tx_hash": "0xfcd1b3ddcca92b1e49783769e9bf606112b3f8cf36b96cac05bf44edcf5377e6", - "index": "0x0" - }, - "dep_type": "code" - }, - "output": { - "capacity": "0x702198d000", - "lock": { - "args": "0x", - "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "hash_type": "data" - }, - "type": null - }, - "data": "0x7f454c460201010000000000000000000200f3000100000044010100000000004000000000000000900c0000000000000100000040003800020040000c000b00010000000500000000000000000000000000010000000000000001000000000070040000000000007004000000000000001000000000000001000000060000007004000000000000701401000000000070140100000000007807000000000000b0070000000000000010000000000000130101bc05684165233c114223388142130585458145014681460147814793081888730000000f00f00f930500402ee008188a8593084880730000000f00f00f82671b04050009c883308143228503340143130101448280181809462c0028083ae43ec8ef00200c82770d479c436387e7001547e39ae7fc7554f9b77954e9b7b70700009387070089c741651305a53881a48280972100009381c1b4138581f5138601f9098e8145ef00a016170500001305452219c51705000013054522ef002021ef00a00e02452c000146eff05ff37da803c781f505eb411122e03e84b707000006e49387070081cb45651305054797000000e70000008547a260238cf1f40264410182808280b70700009387070091cb4565938501f61305054717030000670000008280986191478146032807009545630ff8025c439bd72700fd376379f60205269b152600939605028192ba9694429398060293d80802ba986300f6029125821581912e971c438145bb86d7402300b5002334150114c98280bb06d84081452300b5002334150114c982804111814522e006e42a84ef00a00803b581f43c6d91c382972285ef00c01c0111c56722e845641387474713044447198c26e44ae006ec0d8481441389474763958402c56745641387874713048448198c0d84814413898747639f8400e2604264a26402690561828093973400ca979c6385048297e9b793973400ca979c6385048297d9bf2a8311c62300b3007d16050365fe82805d7156ec83ba81f44ef452f05ae886e4a2e026fc4af85ee42a8aae89054b83b48a1f81c880441b09f4ff0e042694635d0900a6600664e2744279a279027ae26a426ba26b616182806389090083378420638537017d396114d9bf9c441464fd376397270323a42401f5d603a704313b162b0183ab8400718f012709ef8296984483b78a1fe31d77f9e386f4fc49bf23340400d9bf83a7443183358410f18f812781e752858296e1bf2e858296c9bfaa8581460146014525a80111c56722e845641387874813040449198c26e406ec0d849384874811e4e2604264a264056182807d1493173400a6979c638297e5b703b781f42a888337871f89e793070720233cf71e9847fd487d5563c4e804630a0802131537003e952338c51083a8073105463b16e600b3e8c80023a817312338d52089466317d80083a64731558e23aac7309b06170009070e0794c7ba978ce301458280814501468146014781479308d00573000000635c0500411122e02a8406e43b048040ef00a00000c101a001a003b501f58280000049276d20696e206d61696e206e6f7721000000000000000000000000000000003001010000000000b80101000000000082010100000000000000000000000000c819010000000000781a010000000000281b010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000e33cdab34126de6ecde05000b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000901401000000000090140100000000004743433a2028474e552920392e322e3000412a000000726973637600012000000004100572763634693270305f6d3270305f613270305f6332703000002e7368737472746162002e74657874002e726f64617461002e65685f6672616d65002e696e69745f6172726179002e66696e695f6172726179002e64617461002e7364617461002e627373002e636f6d6d656e74002e72697363762e617474726962757465730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000b000010000000000b000000000000000a6030000000000000000000000000000020000000000000000000000000000001100000001000000320000000000000058040100000000005804000000000000180000000000000000000000000000000800000000000000010000000000000019000000010000000300000000000000701401000000000070040000000000000400000000000000000000000000000004000000000000000000000000000000230000000e00000003000000000000007814010000000000780400000000000010000000000000000000000000000000080000000000000008000000000000002f0000000f00000003000000000000008814010000000000880400000000000008000000000000000000000000000000080000000000000008000000000000003b00000001000000030000000000000090140100000000009004000000000000480700000000000000000000000000000800000000000000000000000000000041000000010000000300000000000000d81b010000000000d80b000000000000100000000000000000000000000000000800000000000000000000000000000048000000080000000300000000000000e81b010000000000e80b00000000000038000000000000000000000000000000080000000000000000000000000000004d0000000100000030000000000000000000000000000000e80b0000000000001100000000000000000000000000000001000000000000000100000000000000560000000300007000000000000000000000000000000000f90b0000000000002b00000000000000000000000000000001000000000000000000000000000000010000000300000000000000000000000000000000000000240c0000000000006800000000000000000000000000000001000000000000000000000000000000" - } - ], - "header_deps": [ - - ] - }, - "tx": { - "version": "0x0", - "cell_deps": [ - { - "out_point": { - "tx_hash": "0xfcd1b3ddcca92b1e49783769e9bf606112b3f8cf36b96cac05bf44edcf5377e6", - "index": "0x0" - }, - "dep_type": "code" - } - ], - "header_deps": [ - - ], - "inputs": [ - { - "previous_output": { - "tx_hash": "0xa98c57135830e1b91345948df6c4b8870828199a786b26f09f7dec4bc27a73da", - "index": "0x0" - }, - "since": "0x0" - } - ], - "outputs": [ - { - "capacity": "0x0", - "lock": { - "args": "0x", - "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "hash_type": "data" - }, - "type": { - "args": "0x666f6f626172", - "code_hash": "0xfa93982d582a0f3302a96ac34944d14b41d53549b9fb2ab284eafc1d021588ad", - "hash_type": "data" - } - } - ], - "witnesses": [ - "0x7769746e657373666f6f626172" - ], - "outputs_data": [ - "0x" - ] - } -} \ No newline at end of file diff --git a/ckb-debugger-api/tests/programs/sample_data1.json b/ckb-debugger-api/tests/programs/sample_data1.json deleted file mode 100644 index 2d83f32..0000000 --- a/ckb-debugger-api/tests/programs/sample_data1.json +++ /dev/null @@ -1,94 +0,0 @@ -{ - "mock_info": { - "inputs": [ - { - "input": { - "previous_output": { - "tx_hash": "0xa98c57135830e1b91345948df6c4b8870828199a786b26f09f7dec4bc27a73da", - "index": "0x0" - }, - "since": "0x0" - }, - "output": { - "capacity": "0x4b9f96b00", - "lock": { - "args": "0x", - "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "hash_type": "data1" - }, - "type": null - }, - "data": "0x616263" - } - ], - "cell_deps": [ - { - "cell_dep": { - "out_point": { - "tx_hash": "0xfcd1b3ddcca92b1e49783769e9bf606112b3f8cf36b96cac05bf44edcf5377e6", - "index": "0x0" - }, - "dep_type": "code" - }, - "output": { - "capacity": "0x702198d000", - "lock": { - "args": "0x", - "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "hash_type": "data1" - }, - "type": null - }, - "data": "0x7f454c460201010000000000000000000200f3000100000044010100000000004000000000000000900c0000000000000100000040003800020040000c000b00010000000500000000000000000000000000010000000000000001000000000070040000000000007004000000000000001000000000000001000000060000007004000000000000701401000000000070140100000000007807000000000000b0070000000000000010000000000000130101bc05684165233c114223388142130585458145014681460147814793081888730000000f00f00f930500402ee008188a8593084880730000000f00f00f82671b04050009c883308143228503340143130101448280181809462c0028083ae43ec8ef00200c82770d479c436387e7001547e39ae7fc7554f9b77954e9b7b70700009387070089c741651305a53881a48280972100009381c1b4138581f5138601f9098e8145ef00a016170500001305452219c51705000013054522ef002021ef00a00e02452c000146eff05ff37da803c781f505eb411122e03e84b707000006e49387070081cb45651305054797000000e70000008547a260238cf1f40264410182808280b70700009387070091cb4565938501f61305054717030000670000008280986191478146032807009545630ff8025c439bd72700fd376379f60205269b152600939605028192ba9694429398060293d80802ba986300f6029125821581912e971c438145bb86d7402300b5002334150114c98280bb06d84081452300b5002334150114c982804111814522e006e42a84ef00a00803b581f43c6d91c382972285ef00c01c0111c56722e845641387474713044447198c26e44ae006ec0d8481441389474763958402c56745641387874713048448198c0d84814413898747639f8400e2604264a26402690561828093973400ca979c6385048297e9b793973400ca979c6385048297d9bf2a8311c62300b3007d16050365fe82805d7156ec83ba81f44ef452f05ae886e4a2e026fc4af85ee42a8aae89054b83b48a1f81c880441b09f4ff0e042694635d0900a6600664e2744279a279027ae26a426ba26b616182806389090083378420638537017d396114d9bf9c441464fd376397270323a42401f5d603a704313b162b0183ab8400718f012709ef8296984483b78a1fe31d77f9e386f4fc49bf23340400d9bf83a7443183358410f18f812781e752858296e1bf2e858296c9bfaa8581460146014525a80111c56722e845641387874813040449198c26e406ec0d849384874811e4e2604264a264056182807d1493173400a6979c638297e5b703b781f42a888337871f89e793070720233cf71e9847fd487d5563c4e804630a0802131537003e952338c51083a8073105463b16e600b3e8c80023a817312338d52089466317d80083a64731558e23aac7309b06170009070e0794c7ba978ce301458280814501468146014781479308d00573000000635c0500411122e02a8406e43b048040ef00a00000c101a001a003b501f58280000049276d20696e206d61696e206e6f7721000000000000000000000000000000003001010000000000b80101000000000082010100000000000000000000000000c819010000000000781a010000000000281b010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000e33cdab34126de6ecde05000b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000901401000000000090140100000000004743433a2028474e552920392e322e3000412a000000726973637600012000000004100572763634693270305f6d3270305f613270305f6332703000002e7368737472746162002e74657874002e726f64617461002e65685f6672616d65002e696e69745f6172726179002e66696e695f6172726179002e64617461002e7364617461002e627373002e636f6d6d656e74002e72697363762e617474726962757465730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b000000010000000600000000000000b000010000000000b000000000000000a6030000000000000000000000000000020000000000000000000000000000001100000001000000320000000000000058040100000000005804000000000000180000000000000000000000000000000800000000000000010000000000000019000000010000000300000000000000701401000000000070040000000000000400000000000000000000000000000004000000000000000000000000000000230000000e00000003000000000000007814010000000000780400000000000010000000000000000000000000000000080000000000000008000000000000002f0000000f00000003000000000000008814010000000000880400000000000008000000000000000000000000000000080000000000000008000000000000003b00000001000000030000000000000090140100000000009004000000000000480700000000000000000000000000000800000000000000000000000000000041000000010000000300000000000000d81b010000000000d80b000000000000100000000000000000000000000000000800000000000000000000000000000048000000080000000300000000000000e81b010000000000e80b00000000000038000000000000000000000000000000080000000000000000000000000000004d0000000100000030000000000000000000000000000000e80b0000000000001100000000000000000000000000000001000000000000000100000000000000560000000300007000000000000000000000000000000000f90b0000000000002b00000000000000000000000000000001000000000000000000000000000000010000000300000000000000000000000000000000000000240c0000000000006800000000000000000000000000000001000000000000000000000000000000" - } - ], - "header_deps": [ - - ] - }, - "tx": { - "version": "0x0", - "cell_deps": [ - { - "out_point": { - "tx_hash": "0xfcd1b3ddcca92b1e49783769e9bf606112b3f8cf36b96cac05bf44edcf5377e6", - "index": "0x0" - }, - "dep_type": "code" - } - ], - "header_deps": [ - - ], - "inputs": [ - { - "previous_output": { - "tx_hash": "0xa98c57135830e1b91345948df6c4b8870828199a786b26f09f7dec4bc27a73da", - "index": "0x0" - }, - "since": "0x0" - } - ], - "outputs": [ - { - "capacity": "0x0", - "lock": { - "args": "0x", - "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "hash_type": "data1" - }, - "type": { - "args": "0x666f6f626172", - "code_hash": "0xfa93982d582a0f3302a96ac34944d14b41d53549b9fb2ab284eafc1d021588ad", - "hash_type": "data1" - } - } - ], - "witnesses": [ - "0x7769746e657373666f6f626172" - ], - "outputs_data": [ - "0x" - ] - } -} diff --git a/ckb-debugger-api/tests/test_json.rs b/ckb-debugger-api/tests/test_json.rs deleted file mode 100644 index 782e76f..0000000 --- a/ckb-debugger-api/tests/test_json.rs +++ /dev/null @@ -1,18 +0,0 @@ -use ckb_debugger_api::run_json; -use std::fs::read_to_string; - -#[test] -pub fn test_sample_json() { - let mock_tx = read_to_string("tests/programs/sample.json").unwrap(); - let result = - run_json(&mock_tx, "type", "0xee75995da2e55e6c4938533d341597bc10add3837cfe57174f2ee755da82555c", "4000"); - assert_eq!(result, "{\"cycle\":3217,\"error\":null}"); -} - -#[test] -pub fn test_sample_json_version1() { - let mock_tx = read_to_string("tests/programs/sample_data1.json").unwrap(); - let result = - run_json(&mock_tx, "type", "0xca505bee92c34ac4522d15da2c91f0e4060e4540f90a28d7202df8fe8ce930ba", "4000"); - assert_eq!(result, "{\"cycle\":3219,\"error\":null}"); -} diff --git a/ckb-debugger-api/tests/test_rust.rs b/ckb-debugger-api/tests/test_rust.rs deleted file mode 100644 index f0936e4..0000000 --- a/ckb-debugger-api/tests/test_rust.rs +++ /dev/null @@ -1,74 +0,0 @@ -use byteorder::{ByteOrder, LittleEndian}; -use ckb_debugger_api::run; -use ckb_mock_tx_types::{MockCellDep, MockInfo, MockInput, MockTransaction}; -use ckb_script::ScriptGroupType; -use ckb_types::{ - bytes::Bytes, - core::{Capacity, DepType, ScriptHashType, TransactionBuilder}, - packed::{self, Byte32, CellDep, CellInput, CellOutput, OutPoint, Script}, - prelude::*, -}; -use std::fs::File; -use std::io::Read; - -fn read_file(name: &str) -> Bytes { - let mut file = File::open(name).unwrap(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - buffer.into() -} - -fn create_mock_cell_dep(data: Bytes, lock: Option