diff --git a/.github/workflows/cargo-publish-ckb-testtool.yml b/.github/workflows/cargo-publish-ckb-testtool.yml deleted file mode 100644 index ff82579..0000000 --- a/.github/workflows/cargo-publish-ckb-testtool.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Cargo Publish - -on: - push: - tags: - - '*' - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - name: Publish - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - working-directory: ./crates/testtool - run: cargo publish diff --git a/Cargo.lock b/Cargo.lock index 90bf829..eb55aa6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -639,7 +639,9 @@ checksum = "d4dc9b70fa7a9ecb0cf285cadab32139c58be9fee08b94e019b15d6b3f5296ef" [[package]] name = "ckb-testtool" -version = "0.12.0" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b635fc26720bc75d363b3f5159574a09b4cc0cc767b02f315ae3abf7333d41d" dependencies = [ "ckb-always-success-script", "ckb-chain-spec", @@ -653,6 +655,7 @@ dependencies = [ "ckb-traits", "ckb-types", "ckb-verification", + "faster-hex", "lazy_static", "rand 0.8.5", ] diff --git a/Cargo.toml b/Cargo.toml index 2c99899..5005f07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,14 +38,13 @@ chrono = { version = "0.4.24", default-features = false, features = ["std"] } xshell = "=0.2.2" path_macro = "1.0.0" ckb-sdk = "3.1" -ckb-testtool = { version = "0.12.0", path = "crates/testtool" } +ckb-testtool = "0.13" [build-dependencies] includedir_codegen = "0.6" [workspace] members = [ - "crates/testtool", "crates/tests", ] exclude = ["tmp", "tests/test-contract"] diff --git a/README.md b/README.md index 26ce2c6..1f882d0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Capsule consists of: - Capsule CLI - Scaffolding tool. -- [CKB-testtool](https://github.com/nervosnetwork/capsule/tree/develop/crates/testtool) - CKB scripts testing framework. CKB supports several programming languages for writing scripts, and the language supporting libraries are maintained in the following repositories: diff --git a/crates/tests/Cargo.toml b/crates/tests/Cargo.toml index 0975d8a..51a5642 100644 --- a/crates/tests/Cargo.toml +++ b/crates/tests/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" [dependencies] anyhow = "1.0" -ckb-testtool = { path = "../testtool" } +ckb-testtool = "0.13" ckb-system-scripts = "0.5" diff --git a/crates/tests/test-contract/tests/Cargo.toml b/crates/tests/test-contract/tests/Cargo.toml index 68c5ffd..632b2ac 100644 --- a/crates/tests/test-contract/tests/Cargo.toml +++ b/crates/tests/test-contract/tests/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ckb-testtool = { path = "../testtool" } +ckb-testtool = "0.13" diff --git a/crates/testtool/Cargo.toml b/crates/testtool/Cargo.toml deleted file mode 100644 index 686edbf..0000000 --- a/crates/testtool/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "ckb-testtool" -version = "0.12.0" -authors = ["Nervos Network"] -edition = "2021" -license = "MIT" -description = "CKB contract testing tools" -repository = "https://github.com/nervosnetwork/capsule" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -ckb-always-success-script = "0.0.1" -rand = "0.8" -lazy_static = "1.4" -ckb-chain-spec = "0.116.1" -ckb-types = "0.116.1" -ckb-error = "0.116.1" -ckb-script = "0.116.1" -ckb-hash = "0.116.1" -ckb-jsonrpc-types = "0.116.1" -ckb-crypto = "0.116.1" -ckb-resource = "0.116.1" -ckb-verification = "0.116.1" -ckb-traits = "0.116.1" -ckb-mock-tx-types = "0.116.1" diff --git a/crates/testtool/src/builtin.rs b/crates/testtool/src/builtin.rs deleted file mode 100644 index f7c372b..0000000 --- a/crates/testtool/src/builtin.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! This module contains some builtin contracts - -use ckb_types::bytes::Bytes; -use lazy_static::lazy_static; - -lazy_static! { - /// Always return success - pub static ref ALWAYS_SUCCESS: Bytes = - ckb_always_success_script::ALWAYS_SUCCESS.to_vec().into(); -} diff --git a/crates/testtool/src/context.rs b/crates/testtool/src/context.rs deleted file mode 100644 index 26cfce0..0000000 --- a/crates/testtool/src/context.rs +++ /dev/null @@ -1,488 +0,0 @@ -use crate::tx_verifier::OutputsDataVerifier; -use ckb_chain_spec::consensus::{ConsensusBuilder, TYPE_ID_CODE_HASH}; -use ckb_error::Error as CKBError; -use ckb_mock_tx_types::{MockCellDep, MockInfo, MockInput, MockTransaction, ReprMockTransaction}; -use ckb_script::{TransactionScriptsVerifier, TxVerifyEnv}; -use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider}; -use ckb_types::{ - bytes::Bytes, - core::{ - cell::{CellMeta, CellMetaBuilder, ResolvedTransaction}, - hardfork::{HardForks, CKB2021, CKB2023}, - Capacity, Cycle, DepType, EpochExt, HeaderBuilder, HeaderView, ScriptHashType, - TransactionInfo, TransactionView, - }, - packed::{Byte32, CellDep, CellDepBuilder, CellOutput, OutPoint, OutPointVec, Script}, - prelude::*, -}; -use rand::{thread_rng, Rng}; -use std::collections::HashMap; -use std::sync::{Arc, Mutex}; - -/// Return a random hash -pub fn random_hash() -> Byte32 { - let mut rng = thread_rng(); - let mut buf = [0u8; 32]; - rng.fill(&mut buf); - buf.pack() -} - -/// Return a random OutPoint -pub fn random_out_point() -> OutPoint { - OutPoint::new_builder().tx_hash(random_hash()).build() -} - -/// Return a random Type ID Script -pub fn random_type_id_script() -> Script { - let args = random_hash().as_bytes(); - debug_assert_eq!(args.len(), 32); - Script::new_builder() - .code_hash(TYPE_ID_CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) - .args(args.pack()) - .build() -} - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct Message { - pub id: Byte32, - pub message: String, -} - -/// Verification Context -#[derive(Clone, Default)] -pub struct Context { - pub cells: HashMap, - pub transaction_infos: HashMap, - pub headers: HashMap, - pub epoches: HashMap, - pub block_extensions: HashMap, - pub cells_by_data_hash: HashMap, - pub cells_by_type_hash: HashMap, - capture_debug: bool, - captured_messages: Arc>>, -} - -impl Context { - #[deprecated(since = "0.1.1", note = "Please use the deploy_cell function instead")] - pub fn deploy_contract(&mut self, data: Bytes) -> OutPoint { - self.deploy_cell(data) - } - - /// Deploy a cell - /// return the out-point of the cell - pub fn deploy_cell(&mut self, data: Bytes) -> OutPoint { - let data_hash = CellOutput::calc_data_hash(&data); - if let Some(out_point) = self.cells_by_data_hash.get(&data_hash) { - // contract has been deployed - return out_point.to_owned(); - } - let mut rng = thread_rng(); - let tx_hash = { - let mut buf = [0u8; 32]; - rng.fill(&mut buf); - buf.pack() - }; - let out_point = OutPoint::new(tx_hash, 0); - let type_id_script = random_type_id_script(); - let type_id_hash = type_id_script.calc_script_hash(); - let cell = { - let cell = CellOutput::new_builder() - .type_(Some(type_id_script).pack()) - .build(); - let occupied_capacity = cell - .occupied_capacity(Capacity::bytes(data.len()).expect("data occupied capacity")) - .expect("cell capacity"); - cell.as_builder().capacity(occupied_capacity.pack()).build() - }; - self.cells.insert(out_point.clone(), (cell, data)); - self.cells_by_data_hash.insert(data_hash, out_point.clone()); - self.cells_by_type_hash - .insert(type_id_hash, out_point.clone()); - out_point - } - - /// Insert a block header into context - pub fn insert_header(&mut self, header: HeaderView) { - self.headers.insert(header.hash(), header); - } - - /// Link a cell with a block - /// to make the load_header_by_cell syscalls works - pub fn link_cell_with_block( - &mut self, - out_point: OutPoint, - block_hash: Byte32, - tx_index: usize, - ) { - let header = self - .headers - .get(&block_hash) - .expect("can't find the header"); - self.transaction_infos.insert( - out_point, - TransactionInfo::new(header.number(), header.epoch(), block_hash, tx_index), - ); - } - - #[deprecated( - since = "0.1.1", - note = "Please use the get_cell_by_data_hash function instead" - )] - pub fn get_contract_out_point(&self, data_hash: &Byte32) -> Option { - self.get_cell_by_data_hash(data_hash) - } - - /// Get the out-point of a cell by data_hash - /// the cell must has deployed to this context - pub fn get_cell_by_data_hash(&self, data_hash: &Byte32) -> Option { - self.cells_by_data_hash.get(data_hash).cloned() - } - - /// Create a cell with data - /// return the out-point - pub fn create_cell(&mut self, cell: CellOutput, data: Bytes) -> OutPoint { - let out_point = random_out_point(); - self.create_cell_with_out_point(out_point.clone(), cell, data); - out_point - } - - /// Create cell with specified out-point and cell data - pub fn create_cell_with_out_point( - &mut self, - out_point: OutPoint, - cell: CellOutput, - data: Bytes, - ) { - let data_hash = CellOutput::calc_data_hash(&data); - self.cells_by_data_hash.insert(data_hash, out_point.clone()); - if let Some(_type) = cell.type_().to_opt() { - let type_hash = _type.calc_script_hash(); - self.cells_by_type_hash.insert(type_hash, out_point.clone()); - } - self.cells.insert(out_point, (cell, data)); - } - - #[deprecated( - since = "0.1.1", - note = "Please use the create_cell_with_out_point function instead" - )] - pub fn insert_cell(&mut self, out_point: OutPoint, cell: CellOutput, data: Bytes) { - self.create_cell_with_out_point(out_point, cell, data) - } - - /// Get cell output and data by out-point - pub fn get_cell(&self, out_point: &OutPoint) -> Option<(CellOutput, Bytes)> { - self.cells.get(out_point).cloned() - } - - /// Build script with out_point, hash_type, args - /// return none if the out-point is not exist - pub fn build_script_with_hash_type( - &mut self, - out_point: &OutPoint, - hash_type: ScriptHashType, - args: Bytes, - ) -> Option