From 3c428dbf096b608e26f059efecf19e6c9673ef90 Mon Sep 17 00:00:00 2001 From: driftluo Date: Fri, 12 Jul 2024 14:04:08 +0800 Subject: [PATCH] feat: change builder funtion to generics --- Cargo.lock | 1 - benches/benches/benchmarks/overall.rs | 10 +- benches/benches/benchmarks/resolve.rs | 13 +- benches/benches/benchmarks/util.rs | 66 +- chain/src/consume_unverified.rs | 4 +- chain/src/init_load_unverified.rs | 4 +- chain/src/lib.rs | 9 +- chain/src/tests/basic.rs | 38 +- chain/src/tests/block_assembler.rs | 20 +- chain/src/tests/cell.rs | 26 +- chain/src/tests/delay_verify.rs | 60 +- chain/src/tests/dep_cell.rs | 50 +- chain/src/tests/find_fork.rs | 40 +- chain/src/tests/load_code_with_snapshot.rs | 32 +- chain/src/tests/load_input_cell_data.rs | 10 +- chain/src/tests/load_input_data_hash_cell.rs | 10 +- .../tests/non_contextual_block_txs_verify.rs | 22 +- chain/src/tests/orphan_block_pool.rs | 21 +- chain/src/tests/reward.rs | 26 +- chain/src/tests/util.rs | 6 +- devtools/ci/ci_main.sh | 2 +- miner/src/miner.rs | 5 +- network/src/protocols/discovery/protocol.rs | 10 +- network/src/protocols/identify/mod.rs | 6 +- network/src/protocols/ping.rs | 16 +- rpc/src/module/miner.rs | 2 +- rpc/src/module/net.rs | 10 +- rpc/src/module/test.rs | 2 +- rpc/src/tests/examples.rs | 6 +- rpc/src/tests/mod.rs | 10 +- rpc/src/tests/module/miner.rs | 8 +- rpc/src/tests/module/pool.rs | 17 +- rpc/src/tests/setup.rs | 20 +- script/fuzz/fuzz_targets/syscall_spawn.rs | 18 +- script/src/syscalls/tests/utils.rs | 2 +- .../syscalls/tests/vm_latest/syscalls_1.rs | 65 +- .../syscalls/tests/vm_latest/syscalls_2.rs | 2 +- script/src/verify.rs | 4 +- .../tests/ckb_latest/features_since_v2019.rs | 205 ++- .../tests/ckb_latest/features_since_v2021.rs | 156 +- .../tests/ckb_latest/features_since_v2023.rs | 471 +----- script/src/verify/tests/utils.rs | 60 +- shared/src/shared.rs | 4 +- shared/src/shared_builder.rs | 3 +- spec/src/consensus.rs | 8 +- spec/src/lib.rs | 44 +- spec/src/tests/consensus.rs | 4 +- spec/src/tests/versionbits.rs | 16 +- store/src/cell.rs | 24 +- store/src/tests/db.rs | 7 +- store/src/transaction.rs | 10 +- store/src/write_batch.rs | 4 +- .../get_block_filter_check_points_process.rs | 4 +- .../filter/get_block_filter_hashes_process.rs | 4 +- sync/src/filter/get_block_filters_process.rs | 6 +- sync/src/net_time_checker.rs | 2 +- .../src/relayer/block_transactions_process.rs | 4 +- sync/src/relayer/compact_block_process.rs | 4 +- .../src/relayer/get_block_proposal_process.rs | 2 +- .../relayer/get_block_transactions_process.rs | 6 +- sync/src/relayer/get_transactions_process.rs | 2 +- sync/src/relayer/mod.rs | 20 +- .../relayer/tests/block_proposal_process.rs | 12 +- .../tests/block_transactions_process.rs | 64 +- .../tests/block_transactions_verifier.rs | 4 +- sync/src/relayer/tests/compact_block.rs | 8 +- .../relayer/tests/compact_block_process.rs | 40 +- .../relayer/tests/compact_block_verifier.rs | 20 +- .../tests/get_block_proposal_process.rs | 2 +- .../relayer/tests/get_transactions_process.rs | 2 +- sync/src/relayer/tests/helper.rs | 42 +- sync/src/relayer/tests/reconstruct_block.rs | 8 +- sync/src/synchronizer/get_headers_process.rs | 3 +- sync/src/synchronizer/mod.rs | 4 +- sync/src/tests/orphan_block_pool.rs | 152 -- sync/src/tests/sync_shared.rs | 12 +- sync/src/tests/synchronizer/basic_sync.rs | 18 +- sync/src/tests/synchronizer/functions.rs | 36 +- sync/src/tests/types.rs | 11 +- sync/src/tests/util.rs | 8 +- sync/src/types/mod.rs | 2 +- test/src/node.rs | 21 +- test/src/specs/alert/alert_propagation.rs | 16 +- .../specs/consensus/insufficient_reward.rs | 5 +- test/src/specs/dao/dao_tx.rs | 5 +- test/src/specs/dao/dao_user.rs | 18 +- test/src/specs/dao/satoshi_dao_occupied.rs | 11 +- test/src/specs/hardfork/v2021/cell_deps.rs | 42 +- .../specs/hardfork/v2021/vm_b_extension.rs | 12 +- test/src/specs/hardfork/v2021/vm_version1.rs | 20 +- test/src/specs/hardfork/v2023/vm_version2.rs | 20 +- test/src/specs/mining/basic.rs | 2 +- test/src/specs/mining/bootstrap.rs | 6 +- test/src/specs/mining/fee.rs | 22 +- test/src/specs/mining/proposal.rs | 2 +- test/src/specs/mining/uncle.rs | 21 +- test/src/specs/relay/block_relay.rs | 2 +- test/src/specs/relay/compact_block.rs | 6 +- .../specs/relay/get_block_proposal_process.rs | 2 +- .../relay/get_block_transactions_process.rs | 11 +- test/src/specs/relay/transaction_relay.rs | 2 +- .../relay/transaction_relay_low_fee_rate.rs | 7 +- test/src/specs/rpc/submit_block.rs | 11 +- test/src/specs/sync/block_filter.rs | 8 +- test/src/specs/sync/block_sync.rs | 12 +- test/src/specs/sync/chain_forks.rs | 12 +- test/src/specs/sync/invalid_locator_size.rs | 2 +- test/src/specs/tx_pool/collision.rs | 7 +- test/src/specs/tx_pool/dead_cell_deps.rs | 6 +- .../tx_pool/different_txs_with_same_input.rs | 2 +- test/src/specs/tx_pool/limit.rs | 2 +- test/src/specs/tx_pool/orphan_tx.rs | 6 +- test/src/specs/tx_pool/pool_reconcile.rs | 2 +- test/src/specs/tx_pool/replace.rs | 38 +- .../src/specs/tx_pool/send_defected_binary.rs | 14 +- .../src/specs/tx_pool/send_large_cycles_tx.rs | 22 +- .../src/specs/tx_pool/send_low_fee_rate_tx.rs | 4 +- .../specs/tx_pool/send_multisig_secp_tx.rs | 19 +- test/src/specs/tx_pool/send_secp_tx.rs | 40 +- test/src/txo.rs | 14 +- test/src/util/cell.rs | 2 +- test/src/util/transaction.rs | 8 +- test/src/utils.rs | 21 +- tx-pool/src/block_assembler/mod.rs | 26 +- tx-pool/src/block_assembler/tests.rs | 10 +- tx-pool/src/component/tests/chunk.rs | 9 +- tx-pool/src/component/tests/proposed.rs | 32 +- tx-pool/src/component/tests/score_key.rs | 16 +- tx-pool/src/component/tests/util.rs | 6 +- util/dao/src/tests.rs | 46 +- util/gen-types/src/extension/calc_hash.rs | 10 +- util/gen-types/src/extension/capacity.rs | 2 +- util/gen-types/src/extension/shortcut.rs | 6 +- .../src/extension/tests/calc_hash.rs | 114 +- .../gen-types/src/extension/tests/capacity.rs | 4 +- .../src/extension/tests/check_data.rs | 30 +- .../src/extension/tests/rust_core_traits.rs | 84 +- .../src/extension/tests/serialized_size.rs | 38 +- util/gen-types/src/generated/blockchain.rs | 1246 ++++++++++----- util/gen-types/src/generated/extensions.rs | 1351 ++++++++++++----- util/gen-types/src/generated/protocols.rs | 224 ++- util/indexer/src/indexer.rs | 556 ++++--- util/indexer/src/service.rs | 192 ++- util/jsonrpc-types/src/alert.rs | 17 +- util/jsonrpc-types/src/block_template.rs | 33 +- util/jsonrpc-types/src/blockchain.rs | 94 +- util/jsonrpc-types/src/tests/blockchain.rs | 10 +- util/launcher/Cargo.toml | 1 - .../src/components/get_last_state_proof.rs | 2 +- .../src/components/get_transactions_proof.rs | 6 +- util/light-client-protocol-server/src/lib.rs | 4 +- .../src/tests/components/get_blocks_proof.rs | 2 +- .../tests/components/get_last_state_proof.rs | 6 +- .../components/get_transactions_proof.rs | 2 +- .../src/tests/prelude.rs | 2 +- .../src/tests/utils/chain.rs | 10 +- util/migrate/src/migrations/cell.rs | 12 +- util/migrate/src/tests.rs | 2 +- .../src/tests/generate_alert_signature.rs | 32 +- util/network-alert/src/tests/test_notifier.rs | 10 +- util/network-alert/src/tests/test_verifier.rs | 4 +- util/reward-calculator/src/tests.rs | 48 +- util/rich-indexer/src/indexer/insert.rs | 12 +- .../async_indexer_handle/get_cells.rs | 22 +- util/rich-indexer/src/tests/insert.rs | 138 +- util/rich-indexer/src/tests/query.rs | 312 ++-- util/test-chain-utils/src/chain.rs | 14 +- util/test-chain-utils/src/median_time.rs | 17 +- util/test-chain-utils/src/mock_chain.rs | 44 +- util/test-chain-utils/src/mock_utils.rs | 16 +- util/types/src/conversion/storage.rs | 50 +- util/types/src/core/advanced_builders.rs | 59 +- util/types/src/core/cell.rs | 24 +- util/types/src/core/extras.rs | 2 +- util/types/src/core/tests/cell.rs | 48 +- util/types/src/core/tests/transaction_meta.rs | 3 +- util/types/src/core/tests/views.rs | 10 +- util/types/src/core/views.rs | 31 +- util/types/src/extension.rs | 18 +- .../src/utilities/merkle_mountain_range.rs | 34 +- util/types/src/utilities/merkle_tree.rs | 2 +- .../src/contextual_block_verifier.rs | 2 +- .../src/tests/contextual_block_verifier.rs | 39 +- .../contextual/src/tests/uncle_verifier.rs | 24 +- verification/src/tests/block_verifier.rs | 38 +- verification/src/tests/genesis_verifier.rs | 6 +- verification/src/tests/header_verifier.rs | 20 +- verification/src/tests/mod.rs | 16 +- .../src/tests/transaction_verifier.rs | 154 +- 189 files changed, 4372 insertions(+), 3778 deletions(-) delete mode 100644 sync/src/tests/orphan_block_pool.rs diff --git a/Cargo.lock b/Cargo.lock index c3ac071e90..5d6ae80e11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1033,7 +1033,6 @@ dependencies = [ "ckb-store", "ckb-sync", "ckb-tx-pool", - "ckb-types", "ckb-verification", "ckb-verification-traits", ] diff --git a/benches/benches/benchmarks/overall.rs b/benches/benches/benchmarks/overall.rs index 10c6876d3e..921bf85804 100644 --- a/benches/benches/benchmarks/overall.rs +++ b/benches/benches/benchmarks/overall.rs @@ -92,21 +92,21 @@ pub fn setup_chain(txs_size: usize) -> (Shared, ChainController) { .map(|i| { let data = Bytes::from(i.to_le_bytes().to_vec()); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(50_000).into()) + .capacity(capacity_bytes!(50_000)) .lock(secp_script.clone()) .build(); TransactionBuilder::default() .input(CellInput::new(OutPoint::null(), 0)) .output(output.clone()) .output(output) - .output_data(data.clone().into()) - .output_data(data.into()) + .output_data(&data) + .output_data(&data) .build() }) .collect(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .dao(dao) .transaction(tx) .transactions(transactions) @@ -207,7 +207,7 @@ fn bench(c: &mut Criterion) { let raw_header = raw_block.header().raw(); let header = Header::new_builder() .raw(raw_header) - .nonce(random::().into()) + .nonce(random::()) .build(); let block = raw_block.as_builder().header(header).build().into_view(); diff --git a/benches/benches/benchmarks/resolve.rs b/benches/benches/benchmarks/resolve.rs index 8fa587210c..a250781623 100644 --- a/benches/benches/benchmarks/resolve.rs +++ b/benches/benches/benchmarks/resolve.rs @@ -33,22 +33,19 @@ const DEFAULT_CODE_HASH: H256 = fn script() -> Script { Script::new_builder() - .code_hash(DEFAULT_CODE_HASH.into()) - .args(Bytes::from(PUBKEY_HASH.as_bytes()).into()) - .hash_type(ScriptHashType::Type.into()) + .code_hash(DEFAULT_CODE_HASH) + .args(Bytes::from(PUBKEY_HASH.as_bytes())) + .hash_type(ScriptHashType::Type) .build() } fn cell_dep(genesis: &BlockView) -> CellDep { let tx_hash = genesis.transaction(1).unwrap().hash(); - let out_point = OutPoint::new_builder() - .tx_hash(tx_hash) - .index(0u32.into()) - .build(); + let out_point = OutPoint::new_builder().tx_hash(tx_hash).index(0u32).build(); CellDep::new_builder() .out_point(out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build() } diff --git a/benches/benches/benchmarks/util.rs b/benches/benches/benchmarks/util.rs index ba93d6c2f2..9a5afc336d 100644 --- a/benches/benches/benchmarks/util.rs +++ b/benches/benches/benchmarks/util.rs @@ -49,18 +49,18 @@ pub fn new_always_success_chain(txs_size: usize, chains_num: usize) -> Chains { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutput::new_builder() - .capacity(capacity_bytes!(50_000).into()) + .capacity(capacity_bytes!(50_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(data.into()) + .output_data(data) .build() }) .collect(); let genesis_block = BlockBuilder::default() .dao(dao) - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .transaction(tx) .transactions(transactions) .build(); @@ -92,7 +92,7 @@ pub fn create_always_success_tx() -> TransactionView { .witness(script.clone().into_witness()) .input(CellInput::new(OutPoint::null(), 0)) .output(always_success_cell.clone()) - .output_data(always_success_cell_data.into()) + .output_data(always_success_cell_data) .build() } @@ -110,11 +110,11 @@ pub fn create_always_success_cellbase(shared: &Shared, parent: &HeaderView) -> T builder .output( CellOutput::new_builder() - .capacity(capacity.into()) + .capacity(capacity) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build() } } @@ -185,11 +185,11 @@ pub fn gen_always_success_block( .transactions(transactions) .proposals(proposals) .parent_hash(p_block.hash()) - .number(number.into()) - .timestamp(timestamp.into()) - .compact_target(epoch.compact_target().into()) - .epoch(epoch.number_with_fraction(number).into()) - .nonce(random::().into()) + .number(number) + .timestamp(timestamp) + .compact_target(epoch.compact_target()) + .epoch(epoch.number_with_fraction(number)) + .nonce(random::()) .dao(dao) .build(); @@ -208,7 +208,7 @@ lazy_static! { let data: Bytes = raw_data.to_vec().into(); let cell = CellOutput::new_builder() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); (cell, data) }; @@ -219,13 +219,13 @@ lazy_static! { let data: Bytes = raw_data.to_vec().into(); let cell = CellOutput::new_builder() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); let script = Script::new_builder() .code_hash(CellOutput::calc_data_hash(&data)) - .args(Bytes::from(PUBKEY_HASH.as_bytes()).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(PUBKEY_HASH.as_bytes())) + .hash_type(ScriptHashType::Data) .build(); (cell, data, script) @@ -263,21 +263,21 @@ pub fn new_secp_chain(txs_size: usize, chains_num: usize) -> Chains { .map(|i| { let data = Bytes::from(i.to_le_bytes().to_vec()); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(50_000).into()) + .capacity(capacity_bytes!(50_000)) .lock(secp_script.clone()) .build(); TransactionBuilder::default() .input(CellInput::new(OutPoint::null(), 0)) .output(output.clone()) .output(output) - .output_data((&data).into()) - .output_data(data.into()) + .output_data(&data) + .output_data(&data) .build() }) .collect(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .dao(dao) .transaction(tx) .transactions(transactions) @@ -318,11 +318,11 @@ pub fn create_secp_cellbase(shared: &Shared, parent: &HeaderView) -> Transaction builder .output( CellOutput::new_builder() - .capacity(capacity.into()) + .capacity(capacity) .lock(secp_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build() } } @@ -395,11 +395,11 @@ pub fn gen_secp_block( .transactions(transactions) .proposals(proposals) .parent_hash(p_block.hash()) - .number(number.into()) - .timestamp(timestamp.into()) - .compact_target(epoch.compact_target().into()) - .epoch(epoch.number_with_fraction(number).into()) - .nonce(random::().into()) + .number(number) + .timestamp(timestamp) + .compact_target(epoch.compact_target()) + .epoch(epoch.number_with_fraction(number)) + .nonce(random::()) .dao(dao) .build(); @@ -412,11 +412,11 @@ fn create_transaction(parent_hash: &Byte32, lock: Script, dep: OutPoint) -> Tran TransactionBuilder::default() .output( CellOutput::new_builder() - .capacity(capacity_bytes!(50_000).into()) + .capacity(capacity_bytes!(50_000)) .lock(lock) .build(), ) - .output_data(data.into()) + .output_data(data) .input(CellInput::new(OutPoint::new(parent_hash.to_owned(), 0), 0)) .cell_dep(CellDep::new_builder().out_point(dep).build()) .build() @@ -431,7 +431,7 @@ pub fn create_2out_transaction( let cell_inputs = inputs.into_iter().map(|pts| CellInput::new(pts, 0)); let cell_output = CellOutput::new_builder() - .capacity(capacity_bytes!(50_000).into()) + .capacity(capacity_bytes!(50_000)) .lock(lock) .build(); @@ -440,15 +440,15 @@ pub fn create_2out_transaction( let raw = TransactionBuilder::default() .output(cell_output.clone()) .output(cell_output) - .output_data((&data).into()) - .output_data(data.into()) + .output_data(&data) + .output_data(&data) .inputs(cell_inputs) .cell_deps(cell_deps) .build(); let privkey: Privkey = PRIVKEY.into(); let witness: WitnessArgs = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build(); let witness_len: u64 = witness.as_bytes().len() as u64; let non_sig_witnesses = vec![Bytes::new(); inputs_count - 1]; @@ -470,7 +470,7 @@ pub fn create_2out_transaction( .expect("sign tx") .serialize() .into(); - let witness = witness.as_builder().lock(Some(sig).into()).build(); + let witness = witness.as_builder().lock(Some(sig)).build(); let mut witnesses = vec![witness.as_bytes().into()]; witnesses.extend(non_sig_witnesses.into_iter().map(|w| w.into())); diff --git a/chain/src/consume_unverified.rs b/chain/src/consume_unverified.rs index cf09abdaba..31d2c811f3 100644 --- a/chain/src/consume_unverified.rs +++ b/chain/src/consume_unverified.rs @@ -203,9 +203,7 @@ impl ConsumeUnverifiedBlockProcessor { match *assume_valid_target { Some(ref target) => { // if the target has been reached, delete it - if target - == &ckb_types::prelude::Unpack::::unpack(&BlockView::hash(block)) - { + if target == &Into::::into(&BlockView::hash(block)) { assume_valid_target.take(); Switch::NONE } else { diff --git a/chain/src/init_load_unverified.rs b/chain/src/init_load_unverified.rs index e2c4ebae00..3aab89a6fc 100644 --- a/chain/src/init_load_unverified.rs +++ b/chain/src/init_load_unverified.rs @@ -9,7 +9,7 @@ use ckb_stop_handler::has_received_stop_signal; use ckb_store::ChainStore; use ckb_types::core::{BlockNumber, BlockView}; use ckb_types::packed; -use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Pack, Reader}; +use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Reader}; use std::cmp; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -34,7 +34,7 @@ impl InitLoadUnverified { } fn find_unverified_block_hashes(&self, check_unverified_number: u64) -> Vec { - let pack_number: packed::Uint64 = check_unverified_number.pack(); + let pack_number: packed::Uint64 = check_unverified_number.into(); let prefix = pack_number.as_slice(); // If a block has `COLUMN_NUMBER_HASH` but not `BlockExt`, diff --git a/chain/src/lib.rs b/chain/src/lib.rs index 5ffd268222..33b4a8d25e 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -28,7 +28,6 @@ mod utils; pub use chain_controller::ChainController; use ckb_logger::{error, info}; use ckb_store::{ChainDB, ChainStore}; -use ckb_types::prelude::{Pack, Unpack}; use ckb_types::{BlockNumberAndHash, H256}; pub use init::start_chain_services; @@ -89,11 +88,11 @@ impl From for LonelyBlockHash { switch, verify_callback, } = val; - let block_hash_h256: H256 = block.hash().unpack(); + let block_hash_h256: H256 = block.hash().into(); let block_number: BlockNumber = block.number(); - let parent_hash_h256: H256 = block.parent_hash().unpack(); - let block_hash = block_hash_h256.pack(); - let parent_hash = parent_hash_h256.pack(); + let parent_hash_h256: H256 = block.parent_hash().into(); + let block_hash = block_hash_h256.into(); + let parent_hash = parent_hash_h256.into(); let epoch_number: EpochNumber = block.epoch().number(); diff --git a/chain/src/tests/basic.rs b/chain/src/tests/basic.rs index ae69ec9cfd..0b3a0fe886 100644 --- a/chain/src/tests/basic.rs +++ b/chain/src/tests/basic.rs @@ -65,11 +65,11 @@ fn process_genesis_block() { .input(CellInput::new(OutPoint::null(), 0)) .outputs(vec![ CellOutputBuilder::default() - .capacity(capacity_bytes!(100_000_000).pack()) + .capacity(capacity_bytes!(100_000_000)) .build(); 100 ]) - .outputs_data(vec![Bytes::new(); 100].pack()) + .outputs_data(vec![packed::Bytes::default(); 100]) .build(); let always_success_tx = create_always_success_tx(); @@ -78,7 +78,7 @@ fn process_genesis_block() { let genesis_block = BlockBuilder::default() .transaction(tx.clone()) .transaction(always_success_tx.clone()) - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .dao(dao.clone()) .build(); @@ -104,7 +104,7 @@ fn process_genesis_block() { .transaction(tx) .transaction(always_success_tx) // Difficulty is changed here - .compact_target(difficulty_to_compact(U256::from(999u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(999u64))) .dao(dao) .build(); let result = chain_controller.blocking_process_block(Arc::new(different_genesis_block)); @@ -119,7 +119,7 @@ fn test_genesis_transaction_spend() { .input(CellInput::new(OutPoint::null(), 0)) .outputs(vec![ CellOutputBuilder::default() - .capacity(capacity_bytes!(100_000_000).into()) + .capacity(capacity_bytes!(100_000_000)) .build(); 100 ]) @@ -138,7 +138,7 @@ fn test_genesis_transaction_spend() { let genesis_block = BlockBuilder::default() .transaction(tx) .transaction(always_success_tx) - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .dao(dao) .build(); @@ -431,7 +431,7 @@ fn test_genesis_transaction_fetch() { .input(CellInput::new(OutPoint::null(), 0)) .outputs(vec![ CellOutputBuilder::default() - .capacity(capacity_bytes!(100_000_000).into()) + .capacity(capacity_bytes!(100_000_000)) .lock(Script::default()) .build(); 100 @@ -446,7 +446,7 @@ fn test_genesis_transaction_fetch() { let genesis_block = BlockBuilder::default() .dao(dao) .transaction(tx) - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .build(); let consensus = ConsensusBuilder::default() @@ -578,10 +578,10 @@ fn prepare_context_chain( let new_block = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .timestamp((parent.timestamp() + timestep).into()) - .compact_target(epoch.compact_target().into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .timestamp(parent.timestamp() + timestep) + .compact_target(epoch.compact_target()) .transactions(transactions) .dao(dao) .build(); @@ -618,10 +618,10 @@ fn prepare_context_chain( let new_block = BlockBuilder::default() .parent_hash(parent.hash()) .uncles(uncles) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .timestamp((parent.timestamp() + timestep).into()) - .compact_target(epoch.compact_target().into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .timestamp(parent.timestamp() + timestep) + .compact_target(epoch.compact_target()) .transactions(transactions) .dao(dao) .build(); @@ -644,7 +644,7 @@ fn test_epoch_hash_rate_dampening() { .build(); let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .transaction(cellbase) .dao(dao) .build(); @@ -737,7 +737,7 @@ fn test_orphan_rate_estimation_overflow() { let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .transaction(cellbase) .dao(dao) .build(); @@ -791,7 +791,7 @@ fn test_next_epoch_ext() { .build(); let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .transaction(cellbase) .dao(dao) .build(); diff --git a/chain/src/tests/block_assembler.rs b/chain/src/tests/block_assembler.rs index 3748d67936..bc3627cbd3 100644 --- a/chain/src/tests/block_assembler.rs +++ b/chain/src/tests/block_assembler.rs @@ -14,7 +14,7 @@ use ckb_types::{ TransactionBuilder, TransactionView, }, h256, - packed::{Block, CellInput, CellOutput, CellOutputBuilder, CellbaseWitness, OutPoint}, + packed::{self, Block, CellInput, CellOutput, CellOutputBuilder, CellbaseWitness, OutPoint}, prelude::*, }; use ckb_verification::{BlockVerifier, HeaderVerifier}; @@ -104,18 +104,18 @@ fn gen_block(parent_header: &HeaderView, nonce: u128, epoch: &EpochExt) -> Block let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let header = HeaderBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 10).into()) - .number(number.into()) - .epoch(epoch.number_with_fraction(number).into()) - .compact_target(epoch.compact_target().into()) - .nonce(nonce.into()) + .timestamp(parent_header.timestamp() + 10) + .number(number) + .epoch(epoch.number_with_fraction(number)) + .compact_target(epoch.compact_target()) + .nonce(nonce) .dao(dao) .build(); BlockBuilder::default() .header(header) .transaction(cellbase) - .proposal([1; 10].into()) + .proposal([1; 10]) .build_unchecked() } @@ -124,10 +124,10 @@ fn create_cellbase(number: BlockNumber, epoch: &EpochExt) -> TransactionView { .input(CellInput::new_cellbase_input(number)) .output( CellOutput::new_builder() - .capacity(epoch.block_reward(number).unwrap().into()) + .capacity(epoch.block_reward(number).unwrap()) .build(), ) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build() } @@ -383,7 +383,7 @@ fn build_tx(parent_tx: &TransactionView, inputs: &[u32], outputs_len: usize) -> (0..outputs_len) .map(|_| { CellOutputBuilder::default() - .capacity(per_output_capacity.into()) + .capacity(per_output_capacity) .build() }) .collect::>(), diff --git a/chain/src/tests/cell.rs b/chain/src/tests/cell.rs index 74efb94358..fc9438c542 100644 --- a/chain/src/tests/cell.rs +++ b/chain/src/tests/cell.rs @@ -35,12 +35,8 @@ pub(crate) fn create_cellbase( builder.build() } else { builder - .output( - CellOutputBuilder::default() - .capacity(capacity.into()) - .build(), - ) - .output_data(Bytes::new().into()) + .output(CellOutputBuilder::default().capacity(capacity).build()) + .output_data(Bytes::new()) .build() } } @@ -66,10 +62,10 @@ pub(crate) fn gen_block( let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 20_000).into()) - .number(number.into()) - .compact_target(epoch.compact_target().into()) - .epoch(epoch.number_with_fraction(number).into()) + .timestamp(parent_header.timestamp() + 20_000) + .number(number) + .compact_target(epoch.compact_target()) + .epoch(epoch.number_with_fraction(number)) .transactions(txs) .build(); @@ -88,11 +84,11 @@ pub(crate) fn create_transaction(parent: &TransactionView, index: u32) -> Transa TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap()) .build(), ) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build() } @@ -104,11 +100,11 @@ fn test_block_cells_update() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -116,7 +112,7 @@ fn test_block_cells_update() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); diff --git a/chain/src/tests/delay_verify.rs b/chain/src/tests/delay_verify.rs index 88f57bf650..b30e9b79b2 100644 --- a/chain/src/tests/delay_verify.rs +++ b/chain/src/tests/delay_verify.rs @@ -286,9 +286,9 @@ fn test_full_dead_transaction() { let block = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transaction(cellbase_tx) .build(); @@ -326,9 +326,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .proposals(vec![tx1.proposal_short_id()]) @@ -347,9 +347,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .build() @@ -364,9 +364,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .build() @@ -406,9 +406,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .proposals(vec![tx2.proposal_short_id(), tx3.proposal_short_id()]) @@ -428,9 +428,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .build() @@ -447,9 +447,9 @@ fn test_full_dead_transaction() { BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .build() @@ -478,9 +478,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .proposals(vec![tx2.proposal_short_id(), tx3.proposal_short_id()]) .transactions(transactions) @@ -500,9 +500,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .build() @@ -519,9 +519,9 @@ fn test_full_dead_transaction() { BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target((compact_target - 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(compact_target - 1) .dao(dao) .transactions(transactions) .build() diff --git a/chain/src/tests/dep_cell.rs b/chain/src/tests/dep_cell.rs index 6b88d0b476..ff3572e692 100644 --- a/chain/src/tests/dep_cell.rs +++ b/chain/src/tests/dep_cell.rs @@ -45,7 +45,7 @@ pub(crate) fn build_tx( (0..outputs_len) .map(|_| { CellOutputBuilder::default() - .capacity(per_output_capacity.into()) + .capacity(per_output_capacity) .lock(always_success_script.clone()) .build() }) @@ -79,18 +79,18 @@ fn test_package_txs_with_deps() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -98,7 +98,7 @@ fn test_package_txs_with_deps() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); @@ -211,25 +211,25 @@ fn test_package_txs_with_deps_unstable_sort() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) - .output_data(Bytes::new().into()) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) + .output_data(Bytes::new()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -237,7 +237,7 @@ fn test_package_txs_with_deps_unstable_sort() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); @@ -355,25 +355,25 @@ fn test_package_txs_with_deps2() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) - .output_data(Bytes::new().into()) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) + .output_data(Bytes::new()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -381,7 +381,7 @@ fn test_package_txs_with_deps2() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); @@ -492,18 +492,18 @@ fn test_package_txs_with_deps_priority() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -511,7 +511,7 @@ fn test_package_txs_with_deps_priority() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); diff --git a/chain/src/tests/find_fork.rs b/chain/src/tests/find_fork.rs index 4f4f3ade9f..3628914eed 100644 --- a/chain/src/tests/find_fork.rs +++ b/chain/src/tests/find_fork.rs @@ -429,10 +429,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block1 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .compact_target(parent.compact_target().into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .nonce(1u128.into()) + .number(parent.number() + 1) + .compact_target(parent.compact_target()) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .nonce(1u128) .uncle(uncle) .build(); chain_controller @@ -448,10 +448,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block2 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .compact_target(parent.compact_target().into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .nonce(2u128.into()) + .number(parent.number() + 1) + .compact_target(parent.compact_target()) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .nonce(2u128) .build(); parent = new_block2.clone(); chain_controller @@ -464,10 +464,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block3 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .compact_target(parent.compact_target().into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .nonce(2u128.into()) + .number(parent.number() + 1) + .compact_target(parent.compact_target()) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .nonce(2u128) .build(); chain_controller .blocking_process_block_with_switch(Arc::new(new_block3), Switch::DISABLE_ALL) @@ -482,10 +482,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block4 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .compact_target(parent.compact_target().into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .nonce(1u128.into()) + .number(parent.number() + 1) + .compact_target(parent.compact_target()) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .nonce(1u128) .build(); chain_controller .blocking_process_block_with_switch(Arc::new(new_block4.clone()), Switch::DISABLE_ALL) @@ -499,10 +499,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block5 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .compact_target(parent.compact_target().into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .nonce(1u128.into()) + .number(parent.number() + 1) + .compact_target(parent.compact_target()) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .nonce(1u128) .build(); chain_controller .blocking_process_block_with_switch(Arc::new(new_block5), Switch::DISABLE_ALL) diff --git a/chain/src/tests/load_code_with_snapshot.rs b/chain/src/tests/load_code_with_snapshot.rs index 24c50a955f..108b89f829 100644 --- a/chain/src/tests/load_code_with_snapshot.rs +++ b/chain/src/tests/load_code_with_snapshot.rs @@ -27,9 +27,9 @@ pub(crate) fn create_load_is_even_script_tx() -> TransactionView { .witness(load_is_even_script.clone().into_witness()) .input(CellInput::new(OutPoint::null(), 0)) .output(load_is_even_cell.clone()) - .output_data(load_is_even_data.into()) + .output_data(load_is_even_data) .output(is_even_lib_cell.clone()) - .output_data(is_even_lib_data.into()) + .output_data(is_even_lib_data) .build() } @@ -46,10 +46,10 @@ pub(crate) fn create_call_load_is_even_tx(parent: &TransactionView, index: u32) TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep(CellDep::new_builder().out_point(is_even_lib).build()) .cell_dep(CellDep::new_builder().out_point(load_is_even).build()) @@ -73,7 +73,7 @@ fn test_load_code() { }; let lock_script = Script::new_builder() - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .code_hash(load_is_even_script.code_hash()) .args(args) .build(); @@ -82,11 +82,11 @@ fn test_load_code() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(lock_script) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&load_is_even_script_tx, &issue_tx]).unwrap(); @@ -94,7 +94,7 @@ fn test_load_code() { let genesis_block = BlockBuilder::default() .transaction(load_is_even_script_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); @@ -134,7 +134,7 @@ fn test_load_code_with_snapshot() { }; let lock_script = Script::new_builder() - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .code_hash(load_is_even_script.code_hash()) .args(args) .build(); @@ -143,11 +143,11 @@ fn test_load_code_with_snapshot() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(lock_script) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&load_is_even_script_tx, &issue_tx]).unwrap(); @@ -155,7 +155,7 @@ fn test_load_code_with_snapshot() { let genesis_block = BlockBuilder::default() .transaction(load_is_even_script_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); @@ -213,7 +213,7 @@ fn _test_load_code_with_snapshot_after_hardfork(script_type: ScriptHashType) { }; let lock_script = Script::new_builder() - .hash_type(script_type.into()) + .hash_type(script_type) .code_hash(load_is_even_script.code_hash()) .args(args) .build(); @@ -222,11 +222,11 @@ fn _test_load_code_with_snapshot_after_hardfork(script_type: ScriptHashType) { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(lock_script) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&load_is_even_script_tx, &issue_tx]).unwrap(); @@ -234,7 +234,7 @@ fn _test_load_code_with_snapshot_after_hardfork(script_type: ScriptHashType) { let genesis_block = BlockBuilder::default() .transaction(load_is_even_script_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); diff --git a/chain/src/tests/load_input_cell_data.rs b/chain/src/tests/load_input_cell_data.rs index 67e15590b2..8e711fb25c 100644 --- a/chain/src/tests/load_input_cell_data.rs +++ b/chain/src/tests/load_input_cell_data.rs @@ -35,11 +35,11 @@ pub(crate) fn create_load_input_one_byte_transaction( TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap()) .lock(load_input_one_byte_script.clone()) .build(), ) - .output_data(Bytes::from(b"1".to_vec()).into()) + .output_data(Bytes::from(b"1".to_vec())) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep( CellDep::new_builder() @@ -59,11 +59,11 @@ fn test_load_input_one_byte_cell() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(load_input_one_byte_script.clone()) .build(), ) - .output_data(Bytes::from(b"1".to_vec()).into()) + .output_data(Bytes::from(b"1".to_vec())) .build(); let dao = genesis_dao_data(vec![&load_input_one_byte_cell_tx, &issue_tx]).unwrap(); @@ -71,7 +71,7 @@ fn test_load_input_one_byte_cell() { let genesis_block = BlockBuilder::default() .transaction(load_input_one_byte_cell_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); diff --git a/chain/src/tests/load_input_data_hash_cell.rs b/chain/src/tests/load_input_data_hash_cell.rs index f445dd2d19..ac0502c7e8 100644 --- a/chain/src/tests/load_input_data_hash_cell.rs +++ b/chain/src/tests/load_input_data_hash_cell.rs @@ -35,11 +35,11 @@ pub(crate) fn create_load_input_data_hash_transaction( TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap()) .lock(load_input_data_hash_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep( CellDep::new_builder() @@ -59,11 +59,11 @@ fn test_load_input_data_hash_cell() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(load_input_data_hash_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&load_input_data_hash_cell_tx, &issue_tx]).unwrap(); @@ -71,7 +71,7 @@ fn test_load_input_data_hash_cell() { let genesis_block = BlockBuilder::default() .transaction(load_input_data_hash_cell_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); diff --git a/chain/src/tests/non_contextual_block_txs_verify.rs b/chain/src/tests/non_contextual_block_txs_verify.rs index 41af7bf1a5..03cbbb5171 100644 --- a/chain/src/tests/non_contextual_block_txs_verify.rs +++ b/chain/src/tests/non_contextual_block_txs_verify.rs @@ -42,11 +42,11 @@ pub(crate) fn create_cellbase( builder .output( CellOutputBuilder::default() - .capacity(capacity.into()) + .capacity(capacity) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build() } } @@ -72,10 +72,10 @@ pub(crate) fn gen_block( let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 20_000).into()) - .number(number.into()) - .compact_target(epoch.compact_target().into()) - .epoch(epoch.number_with_fraction(number).into()) + .timestamp(parent_header.timestamp() + 20_000) + .number(number) + .compact_target(epoch.compact_target()) + .epoch(epoch.number_with_fraction(number)) .transactions(txs) .build(); @@ -101,7 +101,7 @@ pub(crate) fn create_transaction( let mut builder = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap()) .lock(always_success_script.clone()) .build(), ) @@ -113,7 +113,7 @@ pub(crate) fn create_transaction( ); if !missing_output_data { - builder = builder.output_data(Bytes::new().into()) + builder = builder.output_data(Bytes::new()) } builder.build() } @@ -127,11 +127,11 @@ fn non_contextual_block_txs_verify() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -139,7 +139,7 @@ fn non_contextual_block_txs_verify() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); diff --git a/chain/src/tests/orphan_block_pool.rs b/chain/src/tests/orphan_block_pool.rs index bc0ba1ceb9..5e6aa45775 100644 --- a/chain/src/tests/orphan_block_pool.rs +++ b/chain/src/tests/orphan_block_pool.rs @@ -5,7 +5,6 @@ use ckb_chain_spec::consensus::ConsensusBuilder; use ckb_systemtime::unix_time_as_millis; use ckb_types::core::{BlockBuilder, EpochNumberWithFraction, HeaderView}; use ckb_types::packed::Byte32; -use ckb_types::prelude::*; use std::collections::HashSet; use std::sync::Arc; use std::thread; @@ -16,10 +15,14 @@ fn gen_lonely_block(parent_header: &HeaderView) -> LonelyBlock { let number = parent_header.number() + 1; let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp(unix_time_as_millis().pack()) - .number(number.pack()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).pack()) - .nonce((parent_header.nonce() + 1).pack()) + .timestamp(unix_time_as_millis()) + .number(number) + .epoch(EpochNumberWithFraction::new( + number / 1000, + number % 1000, + 1000, + )) + .nonce(parent_header.nonce() + 1) .build(); LonelyBlock { block: Arc::new(block), @@ -238,10 +241,10 @@ fn test_remove_expired_blocks() { for _ in 1..block_number { let new_block = BlockBuilder::default() .parent_hash(parent.hash()) - .timestamp(unix_time_as_millis().pack()) - .number((parent.number() + 1).pack()) - .epoch(deprecated.clone().pack()) - .nonce((parent.nonce() + 1).pack()) + .timestamp(unix_time_as_millis()) + .number(parent.number() + 1) + .epoch(deprecated) + .nonce(parent.nonce() + 1) .build(); parent = new_block.header(); diff --git a/chain/src/tests/reward.rs b/chain/src/tests/reward.rs index a9dc168194..f11c7d1792 100644 --- a/chain/src/tests/reward.rs +++ b/chain/src/tests/reward.rs @@ -47,11 +47,11 @@ pub(crate) fn create_cellbase( builder .output( CellOutputBuilder::default() - .capacity(reward.unwrap_or(capacity).into()) + .capacity(reward.unwrap_or(capacity)) .lock(reward_lock) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build() } } @@ -91,10 +91,10 @@ pub(crate) fn gen_block( let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 20_000).into()) - .number(number.into()) - .compact_target(epoch.compact_target().into()) - .epoch(epoch.number_with_fraction(number).into()) + .timestamp(parent_header.timestamp() + 20_000) + .number(number) + .compact_target(epoch.compact_target()) + .epoch(epoch.number_with_fraction(number)) .dao(dao) .transactions(txs) .uncles(uncles) @@ -120,11 +120,11 @@ pub(crate) fn create_transaction(parent: &TransactionView, index: u32) -> Transa TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep( CellDep::new_builder() @@ -142,11 +142,11 @@ fn finalize_reward() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).into()) + .capacity(capacity_bytes!(5_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &tx]).unwrap(); @@ -154,7 +154,7 @@ fn finalize_reward() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(tx.clone()) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .dao(dao) .build(); @@ -181,14 +181,14 @@ fn finalize_reward() { let bob = ScriptBuilder::default() .args(bob_args) .code_hash(always_success_script.code_hash()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build(); let alice_args: packed::Bytes = Bytes::from(b"a11ce".to_vec()).into(); let alice = ScriptBuilder::default() .args(alice_args) .code_hash(always_success_script.code_hash()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build(); for i in 1..23 { diff --git a/chain/src/tests/util.rs b/chain/src/tests/util.rs index fae0de4d81..dcfc8df14d 100644 --- a/chain/src/tests/util.rs +++ b/chain/src/tests/util.rs @@ -42,18 +42,18 @@ pub(crate) fn start_chain_with_tx_pool_config( .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutput::new_builder() - .capacity(capacity_bytes!(50_000).into()) + .capacity(capacity_bytes!(50_000)) .lock(always_success_script.clone()) .build(), ) - .output_data(data.into()) + .output_data(data) .build() }) .collect(); let genesis_block = BlockBuilder::default() .dao(dao) - .compact_target(DIFF_TWO.into()) + .compact_target(DIFF_TWO) .transaction(tx) .transactions(transactions) .build(); diff --git a/devtools/ci/ci_main.sh b/devtools/ci/ci_main.sh index f3ff03a86b..713b438049 100755 --- a/devtools/ci/ci_main.sh +++ b/devtools/ci/ci_main.sh @@ -66,7 +66,7 @@ case $GITHUB_WORKFLOW in sudo apt-get install -y gcc-multilib sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu clang rustup target add aarch64-unknown-linux-gnu - curl -LO https://www.openssl.org/source/openssl-3.1.3.tar.gz + curl -LO https://openssl.org/source/old/3.1/openssl-3.1.3.tar.gz tar -xvzf openssl-3.1.3.tar.gz cd openssl-3.1.3 CC=aarch64-linux-gnu-gcc ./Configure linux-aarch64 shared diff --git a/miner/src/miner.rs b/miner/src/miner.rs index d600e760a4..55034f841f 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -128,10 +128,7 @@ impl Miner { fn submit_nonce(&mut self, pow_hash: Byte32, work: Work, nonce: u128) { self.notify_workers(WorkerMessage::Stop); let raw_header = work.block.header().raw(); - let header = Header::new_builder() - .raw(raw_header) - .nonce(nonce.into()) - .build(); + let header = Header::new_builder().raw(raw_header).nonce(nonce).build(); let block = work .block .as_advanced_builder() diff --git a/network/src/protocols/discovery/protocol.rs b/network/src/protocols/discovery/protocol.rs index c5f16f025c..85d23c4287 100644 --- a/network/src/protocols/discovery/protocol.rs +++ b/network/src/protocols/discovery/protocol.rs @@ -32,18 +32,16 @@ impl DiscoveryMessage { listen_port, required_flags, } => { - let version = version.into(); - let count = count.into(); let listen_port = packed::PortOpt::new_builder() .set(listen_port.map(|port| { let port_le = port.to_le_bytes(); packed::Uint16::new_builder() - .nth0(port_le[0].into()) - .nth1(port_le[1].into()) + .nth0(port_le[0]) + .nth1(port_le[1]) .build() })) .build(); - let required_flags = required_flags.bits().into(); + let required_flags = required_flags.bits(); let get_node = packed::GetNodes2::new_builder() .listen_port(listen_port) .count(count) @@ -70,7 +68,7 @@ impl DiscoveryMessage { ) } let bytes_vec = packed::BytesVec::new_builder().set(vec_addrs).build(); - let flags = item.flags.bits().into(); + let flags = item.flags.bits(); let node = packed::Node2::new_builder() .addresses(bytes_vec) .flags(flags) diff --git a/network/src/protocols/identify/mod.rs b/network/src/protocols/identify/mod.rs index 0c3a0bb8f7..074768ec08 100644 --- a/network/src/protocols/identify/mod.rs +++ b/network/src/protocols/identify/mod.rs @@ -588,9 +588,9 @@ impl Identify { fn new(name: String, flags: Flags, client_version: String) -> Self { Identify { encode_data: packed::Identify::new_builder() - .name(name.as_str().into()) - .flag(flags.bits().into()) - .client_version(client_version.as_str().into()) + .name(name.as_str()) + .flag(flags.bits()) + .client_version(client_version.as_str()) .build() .as_bytes(), name, diff --git a/network/src/protocols/ping.rs b/network/src/protocols/ping.rs index 984dbf2a15..e62dfb7cba 100644 --- a/network/src/protocols/ping.rs +++ b/network/src/protocols/ping.rs @@ -291,10 +291,10 @@ impl PingMessage { fn build_ping(nonce: u32) -> Bytes { let nonce_le = nonce.to_le_bytes(); let nonce = packed::Uint32::new_builder() - .nth0(nonce_le[0].into()) - .nth1(nonce_le[1].into()) - .nth2(nonce_le[2].into()) - .nth3(nonce_le[3].into()) + .nth0(nonce_le[0]) + .nth1(nonce_le[1]) + .nth2(nonce_le[2]) + .nth3(nonce_le[3]) .build(); let ping = packed::Ping::new_builder().nonce(nonce).build(); let payload = packed::PingPayload::new_builder().set(ping).build(); @@ -307,10 +307,10 @@ impl PingMessage { fn build_pong(nonce: u32) -> Bytes { let nonce_le = nonce.to_le_bytes(); let nonce = packed::Uint32::new_builder() - .nth0(nonce_le[0].into()) - .nth1(nonce_le[1].into()) - .nth2(nonce_le[2].into()) - .nth3(nonce_le[3].into()) + .nth0(nonce_le[0]) + .nth1(nonce_le[1]) + .nth2(nonce_le[2]) + .nth3(nonce_le[3]) .build(); let pong = packed::Pong::new_builder().nonce(nonce).build(); let payload = packed::PingPayload::new_builder().set(pong).build(); diff --git a/rpc/src/module/miner.rs b/rpc/src/module/miner.rs index c1df3387ac..506ba44665 100644 --- a/rpc/src/module/miner.rs +++ b/rpc/src/module/miner.rs @@ -340,7 +340,7 @@ impl MinerRpc for MinerRpcImpl { let tip_header = packed::VerifiableHeader::new_builder() .header(header.data()) .uncles_hash(block.calc_uncles_hash()) - .extension(block.extension().into()) + .extension(block.extension()) .parent_chain_root(parent_chain_root) .build(); let light_client_message = { diff --git a/rpc/src/module/net.rs b/rpc/src/module/net.rs index 54276a82e8..dd1fee9c33 100644 --- a/rpc/src/module/net.rs +++ b/rpc/src/module/net.rs @@ -741,7 +741,11 @@ impl NetRpc for NetRpcImpl { ibd: chain.is_initial_block_download(), assume_valid_target_reached: shared.assume_valid_target().is_none(), assume_valid_target: Into::::into( - state.assume_valid_target_specified().unwrap_or_default(), + shared + .assume_valid_target_specified() + .as_ref() + .clone() + .unwrap_or_default(), ) .into(), min_chain_work: min_chain_work.into(), @@ -752,9 +756,9 @@ impl NetRpc for NetRpcImpl { inflight_blocks_count: (state.read_inflight_blocks().total_inflight_count() as u64) .into(), unverified_tip_number: unverified_tip.number().into(), - unverified_tip_hash: unverified_tip.hash().unpack(), + unverified_tip_hash: unverified_tip.hash().into(), tip_number: chain.tip_number().into(), - tip_hash: chain.tip_hash().unpack(), + tip_hash: chain.tip_hash().into(), fast_time: fast_time.into(), normal_time: normal_time.into(), low_time: low_time.into(), diff --git a/rpc/src/module/test.rs b/rpc/src/module/test.rs index 2e2c20707d..a6acf8f08a 100644 --- a/rpc/src/module/test.rs +++ b/rpc/src/module/test.rs @@ -800,7 +800,7 @@ impl IntegrationTestRpc for IntegrationTestRpcImpl { let tx_hash = tx.hash(); match submit_tx.unwrap() { - Ok(_) => Ok(tx_hash.unpack()), + Ok(_) => Ok(tx_hash.into()), Err(reject) => Err(RPCError::from_submit_transaction_reject(&reject)), } } diff --git a/rpc/src/tests/examples.rs b/rpc/src/tests/examples.rs index 0e33e0ac9e..0b2fbd69dc 100644 --- a/rpc/src/tests/examples.rs +++ b/rpc/src/tests/examples.rs @@ -18,7 +18,7 @@ use std::path::PathBuf; use ckb_types::{ core::{capacity_bytes, Capacity, TransactionBuilder, TransactionView}, h256, - packed::{CellDep, CellInput, CellOutputBuilder, OutPoint}, + packed::{self, CellDep, CellInput, CellOutputBuilder, OutPoint}, prelude::*, H256, }; @@ -105,7 +105,7 @@ fn construct_example_transaction() -> TransactionView { let previous_output = OutPoint::new(EXAMPLE_TX_PARENT.clone().into(), 0); let input = CellInput::new(previous_output, 0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_cell().2.clone()) .build(); let cell_dep = CellDep::new_builder() @@ -114,7 +114,7 @@ fn construct_example_transaction() -> TransactionView { TransactionBuilder::default() .input(input) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(cell_dep) .header_dep(always_success_consensus().genesis_hash()) .build() diff --git a/rpc/src/tests/mod.rs b/rpc/src/tests/mod.rs index 71c54689a7..800066113b 100644 --- a/rpc/src/tests/mod.rs +++ b/rpc/src/tests/mod.rs @@ -198,10 +198,10 @@ fn next_block(shared: &Shared, parent: &HeaderView) -> BlockView { BlockBuilder::default() .transaction(cellbase) .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .timestamp((parent.timestamp() + 1).into()) - .compact_target(epoch.compact_target().into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .timestamp(parent.timestamp() + 1) + .compact_target(epoch.compact_target()) .dao(dao) .build() } @@ -215,7 +215,7 @@ fn always_success_transaction() -> TransactionView { TransactionBuilder::default() .input(CellInput::new(OutPoint::null(), 0)) .output(always_success_cell.clone()) - .output_data(always_success_cell_data.to_owned().into()) + .output_data(always_success_cell_data) .witness(always_success_script.clone().into_witness()) .build() } diff --git a/rpc/src/tests/module/miner.rs b/rpc/src/tests/module/miner.rs index a2f7981d30..29b0a6d252 100644 --- a/rpc/src/tests/module/miner.rs +++ b/rpc/src/tests/module/miner.rs @@ -3,7 +3,7 @@ use ckb_store::ChainStore; use ckb_test_chain_utils::{always_success_cell, always_success_consensus}; use ckb_types::{ core::{capacity_bytes, Capacity, TransactionBuilder}, - packed::{CellDep, CellInput, CellOutputBuilder, OutPoint}, + packed::{self, CellDep, CellInput, CellOutputBuilder, OutPoint}, prelude::*, }; use serde_json::json; @@ -31,7 +31,7 @@ fn test_get_block_template_cache() { parent .header() .as_advanced_builder() - .timestamp((parent.header().timestamp() + 1).into()) + .timestamp(parent.header().timestamp() + 1) .build(), ) .build(); @@ -67,7 +67,7 @@ fn test_get_block_template_cache() { let input = CellInput::new(previous_output, 0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_cell().2.clone()) .build(); let cell_dep = CellDep::new_builder() @@ -76,7 +76,7 @@ fn test_get_block_template_cache() { let tx = TransactionBuilder::default() .input(input) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(cell_dep) .build(); diff --git a/rpc/src/tests/module/pool.rs b/rpc/src/tests/module/pool.rs index 808ea89486..560d3d6bc0 100644 --- a/rpc/src/tests/module/pool.rs +++ b/rpc/src/tests/module/pool.rs @@ -151,8 +151,7 @@ fn test_send_transaction_exceeded_maximum_ancestors_count() { Capacity::bytes(1000) .unwrap() .safe_sub(Capacity::shannons(i * 41 * 1000)) - .unwrap() - .into(), + .unwrap(), ) .lock(always_success_cell().2.clone()) .build(); @@ -162,7 +161,7 @@ fn test_send_transaction_exceeded_maximum_ancestors_count() { let tx = TransactionBuilder::default() .input(input) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(cell_dep) .build(); let new_tx: ckb_jsonrpc_types::Transaction = tx.data().into(); @@ -191,8 +190,8 @@ fn build_tx( ) -> core::TransactionView { let lock = packed::ScriptBuilder::default() .code_hash(code_hash.clone()) - .hash_type(hash_type.into()) - .args(args.as_slice().into()) + .hash_type(hash_type) + .args(args.as_slice()) .build(); core::TransactionBuilder::default() .output(packed::CellOutput::new_builder().lock(lock).build()) @@ -208,18 +207,18 @@ fn build_tx_with_type( ) -> core::TransactionView { let lock = packed::ScriptBuilder::default() .code_hash(lock_code_hash.clone()) - .hash_type(lock_hash_type.into()) - .args(lock_args.pack()) + .hash_type(lock_hash_type) + .args(lock_args) .build(); let type_ = packed::ScriptBuilder::default() .code_hash(type_code_hash.clone()) - .hash_type(type_hash_type.into()) + .hash_type(type_hash_type) .build(); core::TransactionBuilder::default() .output( packed::CellOutput::new_builder() .lock(lock) - .type_(Some(type_).into()) + .type_(Some(type_)) .build(), ) .build() diff --git a/rpc/src/tests/setup.rs b/rpc/src/tests/setup.rs index 35d4a9b92b..03a1675973 100644 --- a/rpc/src/tests/setup.rs +++ b/rpc/src/tests/setup.rs @@ -40,9 +40,9 @@ pub(crate) fn always_success_consensus() -> Consensus { let always_success_tx = always_success_transaction(); let dao = genesis_dao_data(vec![&always_success_tx]).unwrap(); let genesis = BlockBuilder::default() - .timestamp(GENESIS_TIMESTAMP.into()) - .compact_target(GENESIS_TARGET.into()) - .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).into()) + .timestamp(GENESIS_TIMESTAMP) + .compact_target(GENESIS_TARGET) + .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0)) .dao(dao) .transaction(always_success_tx) .build(); @@ -154,12 +154,12 @@ pub(crate) fn setup_rpc_test_suite(height: u64, consensus: Option) -> let alert = AlertBuilder::default() .raw( RawAlertBuilder::default() - .id(42u32.into()) - .min_version(Some("0.0.1".to_string()).into()) - .max_version(Some("1.0.0".to_string()).into()) - .priority(1u32.into()) - .notice_until((ALERT_UNTIL_TIMESTAMP * 1000).into()) - .message("An example alert message!".into()) + .id(42u32) + .min_version(Some("0.0.1".to_string())) + .max_version(Some("1.0.0".to_string())) + .priority(1u32) + .notice_until(ALERT_UNTIL_TIMESTAMP * 1000) + .message("An example alert message!") .build(), ) .build(); @@ -258,7 +258,7 @@ pub(crate) fn setup_rpc_test_suite(height: u64, consensus: Option) -> parent .header() .as_advanced_builder() - .timestamp((parent.header().timestamp() + 1).into()) + .timestamp(parent.header().timestamp() + 1) .build(), ) .build(); diff --git a/script/fuzz/fuzz_targets/syscall_spawn.rs b/script/fuzz/fuzz_targets/syscall_spawn.rs index 8782bee23a..7c87e9f879 100644 --- a/script/fuzz/fuzz_targets/syscall_spawn.rs +++ b/script/fuzz/fuzz_targets/syscall_spawn.rs @@ -47,16 +47,16 @@ impl ExtensionProvider for MockDataLoader { fn mock_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.pack()) - .block_epoch(0u64.pack()) + .block_number(1u64) + .block_epoch(0u64) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.pack()) + .index(1u32) .build(), ) .build() - .unpack() + .into() } static PROGRAM_DATA: &[u8] = include_bytes!("../../testdata/spawn_fuzzing"); @@ -69,7 +69,7 @@ fn run(data: &[u8]) { let split_offset = usize::min(split_offset, data.len() - 1); let parent_witness = Bytes::copy_from_slice(&data[0..split_offset]); let child_witness = Bytes::copy_from_slice(&data[split_offset..]); - let witnesses = vec![parent_witness.pack(), child_witness.pack()]; + let witnesses = vec![parent_witness.into(), child_witness.into()]; let transaction = TransactionBuilder::default() .input(CellInput::new(OutPoint::null(), 0)) @@ -83,17 +83,17 @@ fn run(data: &[u8]) { .build(); let dep_cell = CellMetaBuilder::from_cell_output( CellOutput::new_builder() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(), data, ) .transaction_info(mock_transaction_info()) - .out_point(OutPoint::new(h256!("0x0").pack(), 0)) + .out_point(OutPoint::new(h256!("0x0"), 0)) .build(); let input_cell = CellMetaBuilder::from_cell_output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(script) .build(), Bytes::new(), @@ -121,7 +121,7 @@ fn run(data: &[u8]) { .hardfork_switch(hardfork_switch) .build(); let tx_verify_env = - TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.pack()).build()); + TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0).build()); let verifier = TransactionScriptsVerifier::new( rtx.into(), provider, diff --git a/script/src/syscalls/tests/utils.rs b/script/src/syscalls/tests/utils.rs index b8e43abf03..920f362265 100644 --- a/script/src/syscalls/tests/utils.rs +++ b/script/src/syscalls/tests/utils.rs @@ -41,7 +41,7 @@ pub(crate) fn new_mock_data_loader() -> MockDataLoader { pub(crate) fn build_cell_meta(capacity_bytes: usize, data: Bytes) -> CellMeta { let capacity = Capacity::bytes(capacity_bytes).expect("capacity bytes overflow"); - let builder = CellOutput::new_builder().capacity(capacity.into()); + let builder = CellOutput::new_builder().capacity(capacity); let data_hash = CellOutput::calc_data_hash(&data); CellMeta { out_point: OutPoint::default(), diff --git a/script/src/syscalls/tests/vm_latest/syscalls_1.rs b/script/src/syscalls/tests/vm_latest/syscalls_1.rs index 00ca304753..99bb2ec7b1 100644 --- a/script/src/syscalls/tests/vm_latest/syscalls_1.rs +++ b/script/src/syscalls/tests/vm_latest/syscalls_1.rs @@ -438,7 +438,7 @@ fn _test_load_cell_capacity(capacity: Capacity) -> Result<(), TestCaseError> { let input_cell = CellMeta { out_point: OutPoint::default(), transaction_info: None, - cell_output: CellOutput::new_builder().capacity(capacity.into()).build(), + cell_output: CellOutput::new_builder().capacity(capacity).build(), data_bytes: 0, mem_cell_data: Some(data), mem_cell_data_hash: Some(data_hash), @@ -499,7 +499,7 @@ fn _test_load_cell_occupied_capacity(data: &[u8]) -> Result<(), TestCaseError> { let input_cell = CellMeta { out_point: OutPoint::default(), transaction_info: None, - cell_output: CellOutput::new_builder().capacity(100.into()).build(), + cell_output: CellOutput::new_builder().capacity(100).build(), data_bytes: 0, mem_cell_data: Some(data), mem_cell_data_hash: Some(data_hash), @@ -561,7 +561,7 @@ fn test_load_missing_data_hash() { let input_cell = CellMeta { out_point: OutPoint::default(), transaction_info: None, - cell_output: CellOutput::new_builder().capacity(100.into()).build(), + cell_output: CellOutput::new_builder().capacity(100).build(), data_bytes: 0, mem_cell_data: None, mem_cell_data_hash: None, @@ -655,7 +655,7 @@ fn _test_load_header( machine.set_register(A4, source); //source: 4 header machine.set_register(A7, LOAD_HEADER_SYSCALL_NUMBER); // syscall number - let data_hash = blake2b_256(data).into(); + let data_hash = blake2b_256(data); let header = HeaderBuilder::default() .transactions_root(data_hash) .build(); @@ -671,7 +671,7 @@ fn _test_load_header( block_epoch: header.epoch(), index: 1, }), - cell_output: CellOutput::new_builder().capacity(100.into()).build(), + cell_output: CellOutput::new_builder().capacity(100).build(), data_bytes: 0, mem_cell_data: None, mem_cell_data_hash: None, @@ -775,9 +775,9 @@ fn _test_load_header_by_field(data: &[u8], field: HeaderField) -> Result<(), Tes let data_hash: H256 = blake2b_256(data).into(); let epoch = EpochNumberWithFraction::new(1, 40, 1000); let header = HeaderBuilder::default() - .transactions_root(data_hash.into()) - .number(2000.into()) - .epoch(epoch.into()) + .transactions_root(data_hash) + .number(2000) + .epoch(epoch) .build(); let mut correct_data = [0u8; 8]; @@ -847,9 +847,7 @@ fn _test_load_tx_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A2, 0); // offset machine.set_register(A7, LOAD_TX_HASH_SYSCALL_NUMBER); // syscall number - let transaction_view = TransactionBuilder::default() - .output_data(data.into()) - .build(); + let transaction_view = TransactionBuilder::default().output_data(data).build(); let hash = transaction_view.hash(); let hash_len = 32u64; @@ -898,9 +896,7 @@ fn _test_load_tx(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A2, 0); // offset machine.set_register(A7, LOAD_TRANSACTION_SYSCALL_NUMBER); // syscall number - let transaction_view = TransactionBuilder::default() - .output_data(data.into()) - .build(); + let transaction_view = TransactionBuilder::default().output_data(data).build(); let tx = transaction_view.data(); let tx_len = transaction_view.data().as_slice().len() as u64; @@ -950,8 +946,8 @@ fn _test_load_current_script_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_SCRIPT_HASH_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(data.to_owned())) + .hash_type(ScriptHashType::Data) .build(); let hash = script.calc_script_hash(); let data = hash.raw_data(); @@ -1005,8 +1001,8 @@ fn _test_load_input_lock_script_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(data.to_owned())) + .hash_type(ScriptHashType::Data) .build(); let h = script.calc_script_hash(); let hash = h.as_bytes(); @@ -1071,8 +1067,8 @@ fn _test_load_input_lock_script(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(data.to_owned())) + .hash_type(ScriptHashType::Data) .build(); let lock = script.as_slice(); @@ -1139,8 +1135,8 @@ fn _test_load_input_type_script(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(data.to_owned())) + .hash_type(ScriptHashType::Data) .build(); let type_ = script.as_slice(); @@ -1149,7 +1145,7 @@ fn _test_load_input_type_script(data: &[u8]) -> Result<(), TestCaseError> { .cell_output .clone() .as_builder() - .type_(Some(script.to_owned()).into()) + .type_(Some(script.to_owned())) .build(); input_cell.cell_output = output_with_type; @@ -1207,8 +1203,8 @@ fn _test_load_input_type_script_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(data.to_owned())) + .hash_type(ScriptHashType::Data) .build(); let type_h = script.calc_script_hash(); @@ -1219,7 +1215,7 @@ fn _test_load_input_type_script_hash(data: &[u8]) -> Result<(), TestCaseError> { .cell_output .clone() .as_builder() - .type_(Some(script).into()) + .type_(Some(script)) .build(); input_cell.cell_output = output_with_type; let outputs = Arc::new(vec![]); @@ -1397,7 +1393,7 @@ fn _test_load_script(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_SCRIPT_SYSCALL_NUMBER); // syscall number let script = ScriptBuilder::default() - .args(Bytes::from(data.to_owned()).into()) + .args(Bytes::from(data.to_owned())) .build(); let script_correct_data = script.as_slice(); @@ -1458,7 +1454,7 @@ fn _test_load_cell_data_as_code( let data_loader = new_mock_data_loader(); let rtx = Arc::new(ResolvedTransaction { transaction: TransactionBuilder::default() - .output_data(data.pack()) + .output_data(data.clone()) .build(), resolved_cell_deps: vec![dep_cell], resolved_inputs: vec![input_cell], @@ -1531,7 +1527,7 @@ fn _test_load_cell_data( let rtx = Arc::new(ResolvedTransaction { transaction: TransactionBuilder::default() - .output_data(data.pack()) + .output_data(data.clone()) .build(), resolved_cell_deps: vec![dep_cell], resolved_inputs: vec![input_cell], @@ -1962,15 +1958,10 @@ fn _test_load_input( prop_assert!(machine.memory_mut().store64(&size_addr, &addr_size).is_ok()); let data = Bytes::from(data.to_owned()); - let hash = blake2b_256(&data).into(); + let hash = blake2b_256(&data); let input = CellInput::new_builder() - .previous_output( - OutPoint::new_builder() - .tx_hash(hash) - .index(0u32.into()) - .build(), - ) - .since(10u64.into()) + .previous_output(OutPoint::new_builder().tx_hash(hash).index(0u32).build()) + .since(10u64) .build(); let previous_output = input.previous_output(); diff --git a/script/src/syscalls/tests/vm_latest/syscalls_2.rs b/script/src/syscalls/tests/vm_latest/syscalls_2.rs index 8d4ae72ca3..07d2eb6db2 100644 --- a/script/src/syscalls/tests/vm_latest/syscalls_2.rs +++ b/script/src/syscalls/tests/vm_latest/syscalls_2.rs @@ -87,7 +87,7 @@ fn _test_load_extension( block_epoch: header.epoch(), index: 1, }), - cell_output: CellOutput::new_builder().capacity(100.into()).build(), + cell_output: CellOutput::new_builder().capacity(100).build(), data_bytes: 0, mem_cell_data: None, mem_cell_data_hash: None, diff --git a/script/src/verify.rs b/script/src/verify.rs index d7a1b88e7f..a79e3d8c92 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -407,7 +407,7 @@ where .map(|(index, (cell_output, data))| { let out_point = OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(index.into()) + .index(index) .build(); let data_hash = CellOutput::calc_data_hash(&data); CellMeta { @@ -1078,7 +1078,7 @@ where max_cycles: Cycle, command_rx: &mut Receiver, ) -> Result { - if group.script.code_hash() == TYPE_ID_CODE_HASH.pack() + if group.script.code_hash() == TYPE_ID_CODE_HASH.into() && Into::::into(group.script.hash_type()) == Into::::into(ScriptHashType::Type) { let verifier = TypeIdSystemScript { diff --git a/script/src/verify/tests/ckb_latest/features_since_v2019.rs b/script/src/verify/tests/ckb_latest/features_since_v2019.rs index f65628231a..2cfa0ea806 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2019.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2019.rs @@ -25,7 +25,7 @@ fn check_always_success_hash() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script.clone()) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -74,7 +74,7 @@ fn check_signature() { .build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -82,9 +82,9 @@ fn check_signature() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).into()) - .code_hash(code_hash.into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(args)) + .code_hash(code_hash) + .hash_type(ScriptHashType::Data) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -94,7 +94,7 @@ fn check_signature() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -143,16 +143,13 @@ fn check_signature_referenced_via_type_hash() { .build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) - .type_( - Some( - Script::new_builder() - .code_hash(h256!("0x123456abcd90").into()) - .hash_type(ScriptHashType::Data.into()) - .build(), - ) - .into(), - ) + .capacity(Capacity::bytes(data.len()).unwrap()) + .type_(Some( + Script::new_builder() + .code_hash(h256!("0x123456abcd90")) + .hash_type(ScriptHashType::Data) + .build(), + )) .build(); let type_hash = output.type_().to_opt().as_ref().unwrap().calc_script_hash(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) @@ -161,9 +158,9 @@ fn check_signature_referenced_via_type_hash() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).into()) + .args(Bytes::from(args)) .code_hash(type_hash) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -173,7 +170,7 @@ fn check_signature_referenced_via_type_hash() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -217,16 +214,16 @@ fn check_invalid_signature() { let cell_dep = CellDep::new_builder().out_point(dep_out_point).build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) .build(); let script = Script::new_builder() - .args(Bytes::from(args).into()) - .code_hash(code_hash.into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(args)) + .code_hash(code_hash) + .hash_type(ScriptHashType::Data) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -236,7 +233,7 @@ fn check_invalid_signature() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -275,9 +272,9 @@ fn check_invalid_dep_reference() { let script_code_hash: Byte32 = blake2b_256(&buffer).into(); let script = Script::new_builder() - .args(Bytes::from(args).into()) + .args(Bytes::from(args)) .code_hash(script_code_hash.clone()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -287,7 +284,7 @@ fn check_invalid_dep_reference() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -325,7 +322,7 @@ fn check_output_contract() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -337,18 +334,18 @@ fn check_output_contract() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).into()) - .code_hash(blake2b_256(&buffer).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(args)) + .code_hash(blake2b_256(&buffer)) + .hash_type(ScriptHashType::Data) .build(); let output_data = Bytes::default(); let output = CellOutputBuilder::default() .lock( Script::new_builder() - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build(), ) - .type_(Some(script).into()) + .type_(Some(script)) .build(); let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); @@ -358,7 +355,7 @@ fn check_output_contract() { let dep_cell = { let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -369,7 +366,7 @@ fn check_output_contract() { let transaction = TransactionBuilder::default() .input(input) .output(output) - .output_data(output_data.into()) + .output_data(output_data) .cell_dep(cell_dep) .build(); @@ -406,7 +403,7 @@ fn check_invalid_output_contract() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -418,12 +415,12 @@ fn check_invalid_output_contract() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).into()) - .code_hash(blake2b_256(&buffer).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(args)) + .code_hash(blake2b_256(&buffer)) + .hash_type(ScriptHashType::Data) .build(); let output = CellOutputBuilder::default() - .type_(Some(script.clone()).into()) + .type_(Some(script.clone())) .build(); let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); @@ -431,7 +428,7 @@ fn check_invalid_output_contract() { let dep_cell = { let dep_cell_data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(dep_cell_data.len()).unwrap().into()) + .capacity(Capacity::bytes(dep_cell_data.len()).unwrap()) .build(); CellMetaBuilder::from_cell_output(output, dep_cell_data) .transaction_info(default_transaction_info()) @@ -441,7 +438,7 @@ fn check_invalid_output_contract() { let transaction = TransactionBuilder::default() .input(input) .output(output) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .cell_dep(cell_dep) .build(); @@ -477,9 +474,9 @@ fn check_same_lock_and_type_script_are_executed_twice() { args.extend(&to_hex_signature(&signature)); let script = Script::new_builder() - .args(Bytes::from(args).into()) - .code_hash(blake2b_256(&buffer).into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(args)) + .code_hash(blake2b_256(&buffer)) + .hash_type(ScriptHashType::Data) .build(); let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); @@ -488,7 +485,7 @@ fn check_same_lock_and_type_script_are_executed_twice() { .build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -502,9 +499,9 @@ fn check_same_lock_and_type_script_are_executed_twice() { // The lock and type scripts here are both executed. let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(script.clone()) - .type_(Some(script).into()) + .type_(Some(script)) .build(); let dummy_cell = create_dummy_cell(output); @@ -530,22 +527,22 @@ fn check_type_id_one_in_one_out() { let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(Bytes::from(h256!("0x1111").as_ref())) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script).into()) + .type_(Some(type_id_script)) .build(); let transaction = TransactionBuilder::default() @@ -595,22 +592,22 @@ fn check_type_id_one_in_one_out_not_enough_cycles() { let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(Bytes::from(h256!("0x1111").as_ref())) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script).into()) + .type_(Some(type_id_script)) .build(); let transaction = TransactionBuilder::default() @@ -661,7 +658,7 @@ fn check_type_id_creation() { let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) .build(); @@ -675,15 +672,15 @@ fn check_type_id_creation() { }; let type_id_script = Script::new_builder() - .args(input_hash.into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(input_hash) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script).into()) + .type_(Some(type_id_script)) .build(); let transaction = TransactionBuilder::default() @@ -727,20 +724,20 @@ fn check_type_id_termination() { let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(Bytes::from(h256!("0x1111").as_ref())) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) - .type_(Some(type_id_script).into()) + .type_(Some(type_id_script)) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) .build(); @@ -786,7 +783,7 @@ fn check_type_id_invalid_creation() { let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) .build(); @@ -806,15 +803,15 @@ fn check_type_id_invalid_creation() { }; let type_id_script = Script::new_builder() - .args(input_hash.into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(input_hash) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let transaction = TransactionBuilder::default() @@ -862,7 +859,7 @@ fn check_type_id_invalid_creation_length() { let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) .build(); @@ -885,15 +882,15 @@ fn check_type_id_invalid_creation_length() { }; let type_id_script = Script::new_builder() - .args(input_hash.into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(input_hash) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let transaction = TransactionBuilder::default() @@ -940,27 +937,27 @@ fn check_type_id_one_in_two_out() { let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(Bytes::from(h256!("0x1111").as_ref())) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).into()) + .capacity(capacity_bytes!(2000)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let output_cell2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let transaction = TransactionBuilder::default() @@ -1039,12 +1036,12 @@ fn create_rtx_to_load_code_to_stack_then_reuse( load_cell_from_path("testdata/load_code_to_stack_then_reuse"); let dyn_lock_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(dyn_lock_data_hash) .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(dyn_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1111,7 +1108,7 @@ fn check_debugger() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -1123,17 +1120,17 @@ fn check_debugger() { .build(); let script = Script::new_builder() - .code_hash(blake2b_256(&buffer).into()) - .hash_type(ScriptHashType::Data.into()) + .code_hash(blake2b_256(&buffer)) + .hash_type(ScriptHashType::Data) .build(); let output_data = Bytes::default(); let output = CellOutputBuilder::default() .lock( Script::new_builder() - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build(), ) - .type_(Some(script).into()) + .type_(Some(script)) .build(); let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); @@ -1143,7 +1140,7 @@ fn check_debugger() { let dep_cell = { let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) + .capacity(Capacity::bytes(data.len()).unwrap()) .build(); CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -1154,7 +1151,7 @@ fn check_debugger() { let transaction = TransactionBuilder::default() .input(input) .output(output) - .output_data(output_data.into()) + .output_data(output_data) .cell_dep(cell_dep) .build(); diff --git a/script/src/verify/tests/ckb_latest/features_since_v2021.rs b/script/src/verify/tests/ckb_latest/features_since_v2021.rs index 4aa227e557..4866fdb450 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2021.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2021.rs @@ -28,11 +28,11 @@ fn test_hint_instructions() { load_cell_from_path("testdata/cadd_hint_lock"); let always_success_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(always_success_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -79,12 +79,12 @@ fn test_b_extension() { let (cpop_lock_cell, cpop_lock_data_hash) = load_cell_from_path("testdata/cpop_lock"); let cpop_lock_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(cpop_lock_data_hash) .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(cpop_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -128,11 +128,11 @@ fn test_cycles_difference() { load_cell_from_path("testdata/mop_adc_lock"); let always_success_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(always_success_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -167,11 +167,11 @@ fn check_current_cycles() { load_cell_from_path("testdata/current_cycles"); let current_cycles_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(current_cycles_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(current_cycles_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -199,11 +199,11 @@ fn check_current_cycles_with_snapshot() { load_cell_from_path("testdata/current_cycles_with_snapshot"); let current_cycles_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(current_cycles_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(current_cycles_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -244,11 +244,11 @@ fn check_vm_version() { let (vm_version_cell, vm_version_data_hash) = load_cell_from_path("testdata/vm_version"); let vm_version_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(vm_version_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(vm_version_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -276,11 +276,11 @@ fn check_vm_version_with_snapshot() { load_cell_from_path("testdata/vm_version_with_snapshot"); let vm_version_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(vm_version_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(vm_version_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -323,11 +323,11 @@ fn check_exec_from_cell_data() { let (exec_callee_cell, _exec_callee_data_hash) = load_cell_from_path("testdata/exec_callee"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -356,11 +356,11 @@ fn check_exec_from_witness() { let (exec_callee_cell, _exec_caller_data_hash) = load_cell_from_path("testdata/exec_callee"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -399,11 +399,11 @@ fn check_exec_wrong_callee_format() { load_cell_from_slice(&[0x00, 0x01, 0x02, 0x03]); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -433,11 +433,11 @@ async fn async_check_exec_wrong_callee_format() { load_cell_from_slice(&[0x00, 0x01, 0x02, 0x03]); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -469,11 +469,11 @@ fn check_exec_big_offset_length() { load_cell_from_slice(&[0x00, 0x01, 0x02, 0x03]); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -503,22 +503,22 @@ fn _check_type_id_one_in_one_out_resume(step_cycles: Cycle) -> Result<(), TestCa let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(Bytes::from(h256!("0x1111").as_ref())) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script).into()) + .type_(Some(type_id_script)) .build(); let transaction = TransactionBuilder::default() @@ -653,22 +653,22 @@ fn _check_type_id_one_in_one_out_resume_with_state( let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).into()) - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) + .args(Bytes::from(h256!("0x1111").as_ref())) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).into()) + .type_(Some(type_id_script.clone())) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).into()) + .capacity(capacity_bytes!(990)) .lock(always_success_script.clone()) - .type_(Some(type_id_script).into()) + .type_(Some(type_id_script)) .build(); let transaction = TransactionBuilder::default() @@ -1050,12 +1050,12 @@ fn load_code_into_global() { load_cell_from_path("testdata/load_is_even_into_global"); let dyn_lock_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(dyn_lock_data_hash) .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(dyn_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1106,12 +1106,12 @@ fn load_code_with_snapshot() { load_cell_from_path("testdata/load_is_even_with_snapshot"); let dyn_lock_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(dyn_lock_data_hash) .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(dyn_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1204,12 +1204,12 @@ fn load_code_with_snapshot_more_times() { }; let lock_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(lock_data_hash) .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1341,12 +1341,12 @@ fn test_exec( always_success_cell(); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script.clone()) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1381,8 +1381,8 @@ fn test_exec( ExecFrom::GroupOutputWitness => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .type_(Some(exec_caller_script).into()) + .capacity(capacity_bytes!(100)) + .type_(Some(exec_caller_script)) .build(); let tx = TransactionBuilder::default() .output(output) @@ -1392,7 +1392,7 @@ fn test_exec( } ExecFrom::TxInputCell => { let callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script.clone()) .build(); let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); @@ -1405,9 +1405,9 @@ fn test_exec( } ExecFrom::GroupInputCell => { let caller_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) - .type_(Some(always_success_script.clone()).into()) + .type_(Some(always_success_script.clone())) .build(); let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let caller_cell = @@ -1420,25 +1420,25 @@ fn test_exec( ExecFrom::TxOutputCell => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_success_script.clone()) .build(); let tx = TransactionBuilder::default() .input(input) .output(callee_output) - .output_data(exec_callee_cell_data.into()) + .output_data(exec_callee_cell_data) .build(); (tx, vec![create_dummy_cell(output)]) } ExecFrom::GroupOutputCell => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .type_(Some(exec_caller_script).into()) + .capacity(capacity_bytes!(100)) + .type_(Some(exec_caller_script)) .build(); let tx = TransactionBuilder::default() .output(callee_output) - .output_data(exec_callee_cell_data.into()) + .output_data(exec_callee_cell_data) .build(); (tx, vec![]) } @@ -1796,16 +1796,13 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .out_point(dep_out_point.clone()) .build(); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) - .type_( - Some( - Script::new_builder() - .code_hash(h256!("0x123456abcd90").into()) - .hash_type(ScriptHashType::Data.into()) - .build(), - ) - .into(), - ) + .capacity(Capacity::bytes(data.len()).unwrap()) + .type_(Some( + Script::new_builder() + .code_hash(h256!("0x123456abcd90")) + .hash_type(ScriptHashType::Data) + .build(), + )) .build(); let type_hash = output.type_().to_opt().as_ref().unwrap().calc_script_hash(); let dep_cell = CellMetaBuilder::from_cell_output(output, data.clone()) @@ -1818,16 +1815,13 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .out_point(dep_out_point2.clone()) .build(); let output2 = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().into()) - .type_( - Some( - Script::new_builder() - .code_hash(h256!("0x123456abcd90").into()) - .hash_type(ScriptHashType::Data.into()) - .build(), - ) - .into(), - ) + .capacity(Capacity::bytes(data.len()).unwrap()) + .type_(Some( + Script::new_builder() + .code_hash(h256!("0x123456abcd90")) + .hash_type(ScriptHashType::Data) + .build(), + )) .build(); let dep_cell2 = CellMetaBuilder::from_cell_output(output2, data) .transaction_info(default_transaction_info()) @@ -1835,9 +1829,9 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).into()) + .args(Bytes::from(args)) .code_hash(type_hash) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1848,7 +1842,7 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -1878,11 +1872,11 @@ fn check_exec_callee_pause() { load_cell_from_path("testdata/exec_callee_pause"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); diff --git a/script/src/verify/tests/ckb_latest/features_since_v2023.rs b/script/src/verify/tests/ckb_latest/features_since_v2023.rs index 5006ca1996..e44809e783 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2023.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2023.rs @@ -14,12 +14,12 @@ fn simple_spawn_test(bin_path: &str, args: &[u8]) -> Result { let (cell, data_hash) = load_cell_from_path(bin_path); let script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(data_hash) - .args(Bytes::copy_from_slice(args).pack()) + .args(Bytes::copy_from_slice(args)) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -116,11 +116,11 @@ fn check_vm_version() { let (vm_version_cell, vm_version_data_hash) = load_cell_from_path("testdata/vm_version_2"); let vm_version_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(vm_version_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(vm_version_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -140,71 +140,6 @@ fn check_vm_version() { assert_eq!(result.is_ok(), script_version == ScriptVersion::V2); } -#[test] -fn check_get_memory_limit() { - let script_version = SCRIPT_VERSION; - - let (memory_limit_cell, memory_limit_data_hash) = - load_cell_from_path("testdata/get_memory_limit"); - - let memory_limit_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(memory_limit_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(memory_limit_script) - .build(); - - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![memory_limit_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_set_content() { - let script_version = SCRIPT_VERSION; - - let (set_content_cell, set_content_data_hash) = load_cell_from_path("testdata/set_content"); - - let memory_limit_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(set_content_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(memory_limit_script) - .build(); - - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![set_content_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - #[test] fn check_spawn_strcat() { let script_version = SCRIPT_VERSION; @@ -215,110 +150,10 @@ fn check_spawn_strcat() { load_cell_from_path("testdata/spawn_callee_strcat"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_spawn_strcat_data_hash() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_caller_strcat_data_hash"); - let (spawn_callee_cell, _spawn_callee_data_hash) = - load_cell_from_path("testdata/spawn_callee_strcat"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_spawn_get_memory_limit() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_caller_get_memory_limit"); - let (spawn_callee_cell, _spawn_callee_data_hash) = - load_cell_from_path("testdata/spawn_callee_get_memory_limit"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_spawn_set_content() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_caller_set_content"); - let (spawn_callee_cell, _spawn_callee_data_hash) = - load_cell_from_path("testdata/spawn_callee_set_content"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -347,11 +182,11 @@ fn check_spawn_out_of_cycles() { load_cell_from_path("testdata/spawn_callee_out_of_cycles"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -387,11 +222,11 @@ fn check_spawn_exec() { let (spawn_callee_callee_cell, _) = load_cell_from_path("testdata/spawn_callee_exec_callee"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -424,11 +259,11 @@ fn check_spawn_strcat_wrap() { let (spawn_callee_callee_cell, _) = load_cell_from_path("testdata/spawn_callee_strcat"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -461,11 +296,11 @@ fn check_spawn_out_of_cycles_wrap() { let (spawn_callee_callee_cell, _) = load_cell_from_path("testdata/spawn_callee_out_of_cycles"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -503,11 +338,11 @@ fn check_spawn_recursive() { load_cell_from_path("testdata/spawn_recursive"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -531,161 +366,6 @@ fn check_spawn_recursive() { } } -#[test] -fn check_spawn_big_memory_size() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_big_memory_size"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_spawn_big_content_length() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_big_content_length"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_peak_memory_4m_to_32m() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_peak_memory_4m_to_32m"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_peak_memory_2m_to_32m() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_peak_memory_2m_to_32m"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - -#[test] -fn check_peak_memory_512k_to_32m() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_peak_memory_512k_to_32m"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - #[test] fn check_spawn_snapshot() { let script_version = SCRIPT_VERSION; @@ -698,11 +378,11 @@ fn check_spawn_snapshot() { let (snapshot_cell, _) = load_cell_from_path("testdata/current_cycles_with_snapshot"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -739,11 +419,11 @@ async fn check_spawn_async() { let (snapshot_cell, _) = load_cell_from_path("testdata/current_cycles_with_snapshot"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -818,11 +498,11 @@ async fn check_spawn_suspend_shutdown() { let (snapshot_cell, _) = load_cell_from_path("testdata/infinite_loop"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -875,11 +555,11 @@ fn check_spawn_state() { let (snapshot_cell, _) = load_cell_from_path("testdata/current_cycles_with_snapshot"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -933,37 +613,6 @@ fn check_spawn_state() { assert!(chunks_count > 1); } -#[test] -fn check_spawn_current_memory() { - let script_version = SCRIPT_VERSION; - - let (spawn_caller_cell, spawn_caller_data_hash) = - load_cell_from_path("testdata/spawn_current_memory"); - - let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) - .code_hash(spawn_caller_data_hash) - .build(); - let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) - .lock(spawn_caller_script) - .build(); - let input = CellInput::new(OutPoint::null(), 0); - - let transaction = TransactionBuilder::default().input(input).build(); - let dummy_cell = create_dummy_cell(output); - - let rtx = ResolvedTransaction { - transaction, - resolved_cell_deps: vec![spawn_caller_cell], - resolved_inputs: vec![dummy_cell], - resolved_dep_groups: vec![], - }; - let verifier = TransactionScriptsVerifierWithEnv::new(); - let result = verifier.verify_without_limit(script_version, &rtx); - assert_eq!(result.is_ok(), script_version >= ScriptVersion::V2); -} - #[test] fn check_spawn_current_cycles() { let script_version = SCRIPT_VERSION; @@ -974,11 +623,11 @@ fn check_spawn_current_cycles() { load_cell_from_path("testdata/spawn_callee_current_cycles"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1051,19 +700,19 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { load_cell_from_path("testdata/always_success"); let spawn_callee_cell_data = spawn_callee_cell.mem_cell_data.as_ref().unwrap(); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) - .args(args.pack()) + .args(args) .build(); let always_success_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(always_success_data_hash) .build(); let input_spawn_caller = create_dummy_cell( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script.clone()) .build(), ); @@ -1072,7 +721,7 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { SpawnFrom::TxInputWitness | SpawnFrom::TxOutputWitness | SpawnFrom::GroupInputWitness => { ResolvedTransaction { transaction: TransactionBuilder::default() - .set_witnesses(vec![spawn_callee_cell_data.pack()]) + .set_witnesses(vec![spawn_callee_cell_data.into()]) .build(), resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell], resolved_inputs: vec![input_spawn_caller], @@ -1083,11 +732,11 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { transaction: TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) - .type_(Some(spawn_caller_script).pack()) + .capacity(capacity_bytes!(100)) + .type_(Some(spawn_caller_script)) .build(), ) - .set_witnesses(vec![spawn_callee_cell_data.pack()]) + .set_witnesses(vec![spawn_callee_cell_data.into()]) .build(), resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell], resolved_inputs: vec![], @@ -1101,7 +750,7 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { }, SpawnFrom::TxInputCell => { let input_spawn_callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000)) .lock(always_success_script) .build(); let input_spawn_callee = CellMetaBuilder::from_cell_output( @@ -1120,11 +769,11 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { transaction: TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(always_success_script) .build(), ) - .output_data(spawn_callee_cell_data.pack()) + .output_data(spawn_callee_cell_data) .build(), resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell, always_success_cell], resolved_inputs: vec![input_spawn_caller], @@ -1133,7 +782,7 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { SpawnFrom::GroupInputCell => { let input_spawn_caller = CellMetaBuilder::from_cell_output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(), spawn_callee_cell_data.clone(), @@ -1150,11 +799,11 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { transaction: TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) - .type_(Some(spawn_caller_script).pack()) + .capacity(capacity_bytes!(100)) + .type_(Some(spawn_caller_script)) .build(), ) - .output_data(spawn_callee_cell_data.pack()) + .output_data(spawn_callee_cell_data) .build(), resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell, always_success_cell], resolved_inputs: vec![], @@ -1168,7 +817,7 @@ fn check_spawn_configurable_once(spawn_from: SpawnFrom) { } ResolvedTransaction { transaction: TransactionBuilder::default() - .set_witnesses(vec![data.pack()]) + .set_witnesses(vec![data.into()]) .build(), resolved_cell_deps: vec![spawn_caller_cell, spawn_callee_cell], resolved_inputs: vec![input_spawn_caller], @@ -1481,17 +1130,17 @@ proptest! { let (code_dep, code_dep_hash) = load_cell_from_slice(&program[..]); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type() ) .code_hash(code_dep_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100) ) .lock(spawn_caller_script) .build(); let dummy_cell = create_dummy_cell(output); let rtx = ResolvedTransaction { - transaction: TransactionBuilder::default().witness(data.as_bytes().pack()).build(), + transaction: TransactionBuilder::default().witness(data.as_bytes()).build(), resolved_cell_deps: vec![code_dep], resolved_inputs: vec![dummy_cell], resolved_dep_groups: vec![], @@ -1541,11 +1190,11 @@ fn check_spawn_huge_swap() { load_cell_from_path("testdata/spawn_huge_swap"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1594,11 +1243,11 @@ fn check_spawn_cycles() { let (spawn_callee_cell, _spawn_callee_data_hash) = load_cell_from_path("testdata/spawn_cycles"); let spawn_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1629,12 +1278,12 @@ fn spawn_io_test(io_size: u64, enable_check: bool) -> Result { let (cell, data_hash) = load_cell_from_path("testdata/spawn_io_cycles"); let script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(data_hash) - .args(Bytes::copy_from_slice(&args).pack()) + .args(Bytes::copy_from_slice(&args)) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1684,11 +1333,11 @@ fn check_infinite_exec() { let (exec_caller_cell, exec_caller_data_hash) = load_cell_from_path("testdata/infinite_exec"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1721,11 +1370,11 @@ fn check_fuzz_crash_1() { let (exec_caller_cell, exec_caller_data_hash) = load_cell_from_path("testdata/crash-5a27052f"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1759,11 +1408,11 @@ fn check_fuzz_crash_2() { let script_version = SCRIPT_VERSION; let (exec_caller_cell, exec_caller_data_hash) = load_cell_from_path("testdata/crash-45a6098d"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1792,11 +1441,11 @@ fn check_fuzz_crash_3() { let script_version = SCRIPT_VERSION; let (exec_caller_cell, exec_caller_data_hash) = load_cell_from_path("testdata/crash-4717eb0e"); let exec_caller_script = Script::new_builder() - .hash_type(script_version.data_hash_type().into()) + .hash_type(script_version.data_hash_type()) .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100)) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); diff --git a/script/src/verify/tests/utils.rs b/script/src/verify/tests/utils.rs index 43b404d195..97ff7f6740 100644 --- a/script/src/verify/tests/utils.rs +++ b/script/src/verify/tests/utils.rs @@ -22,7 +22,7 @@ use ckb_types::{ }, h256, packed::{ - Byte32, CellDep, CellInput, OutPoint, Script, TransactionInfoBuilder, + self, Byte32, CellDep, CellInput, OutPoint, Script, TransactionInfoBuilder, TransactionKeyBuilder, WitnessArgs, }, H256, @@ -67,7 +67,7 @@ pub(crate) fn load_cell_from_path(path_str: &str) -> (CellMeta, Byte32) { pub(crate) fn load_cell_from_slice(slice: &[u8]) -> (CellMeta, Byte32) { let cell_data = Bytes::copy_from_slice(slice); let cell_output = CellOutput::new_builder() - .capacity(Capacity::bytes(cell_data.len()).unwrap().into()) + .capacity(Capacity::bytes(cell_data.len()).unwrap()) .build(); let cell_meta = CellMetaBuilder::from_cell_output(cell_output, cell_data) .transaction_info(default_transaction_info()) @@ -107,12 +107,12 @@ pub(crate) fn sign_args(args: &[u8], privkey: &Privkey) -> Signature { pub(crate) fn default_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.into()) - .block_epoch(0u64.into()) + .block_number(1u64) + .block_epoch(0u64) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.into()) + .index(1u32) .build(), ) .build() @@ -184,9 +184,7 @@ impl TransactionScriptsVerifierWithEnv { ScriptVersion::V1 => EpochNumberWithFraction::new(self.version_1_enabled_at, 0, 1), ScriptVersion::V2 => EpochNumberWithFraction::new(self.version_2_enabled_at, 0, 1), }; - let header = HeaderView::new_advanced_builder() - .epoch(epoch.pack()) - .build(); + let header = HeaderView::new_advanced_builder().epoch(epoch).build(); let tx_env = Arc::new(TxVerifyEnv::new_commit(&header)); let verifier = TransactionScriptsVerifier::new( Arc::new(rtx.clone()), @@ -275,9 +273,7 @@ impl TransactionScriptsVerifierWithEnv { ScriptVersion::V1 => EpochNumberWithFraction::new(self.version_1_enabled_at, 0, 1), ScriptVersion::V2 => EpochNumberWithFraction::new(self.version_2_enabled_at, 0, 1), }; - let header = HeaderView::new_advanced_builder() - .epoch(epoch.pack()) - .build(); + let header = HeaderView::new_advanced_builder().epoch(epoch).build(); let tx_env = Arc::new(TxVerifyEnv::new_commit(&header)); let verifier = TransactionScriptsVerifier::new( Arc::new(rtx.clone()), @@ -309,9 +305,7 @@ impl TransactionScriptsVerifierWithEnv { ScriptVersion::V1 => EpochNumberWithFraction::new(self.version_1_enabled_at, 0, 1), ScriptVersion::V2 => EpochNumberWithFraction::new(self.version_2_enabled_at, 0, 1), }; - let header = HeaderView::new_advanced_builder() - .epoch(epoch.into()) - .build(); + let header = HeaderView::new_advanced_builder().epoch(epoch).build(); let tx_env = Arc::new(TxVerifyEnv::new_commit(&header)); let mut verifier = TransactionScriptsVerifier::new( Arc::new(rtx.clone()), @@ -336,7 +330,7 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { let cell_dep = CellDep::new_builder() .out_point(secp_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let input1 = CellInput::new(OutPoint::new(h256!("0x1234").into(), 0), 0); @@ -351,23 +345,23 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { let lock_arg2 = Bytes::from((blake2b_256(pubkey_data2)[0..20]).to_owned()); let lock = Script::new_builder() - .args(lock_arg.into()) - .code_hash(type_lock_script_code_hash().into()) - .hash_type(ScriptHashType::Type.into()) + .args(lock_arg) + .code_hash(type_lock_script_code_hash()) + .hash_type(ScriptHashType::Type) .build(); let lock2 = Script::new_builder() - .args(lock_arg2.into()) - .code_hash(type_lock_script_code_hash().into()) - .hash_type(ScriptHashType::Type.into()) + .args(lock_arg2) + .code_hash(type_lock_script_code_hash()) + .hash_type(ScriptHashType::Type) .build(); let output1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock.clone()) .build(); let output2 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock2.clone()) .build(); let tx = TransactionBuilder::default() @@ -376,15 +370,15 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { .input(input2.clone()) .output(output1) .output(output2) - .output_data(Default::default()) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) + .output_data(packed::Bytes::default()) .build(); let tx_hash: H256 = tx.hash().into(); // sign input1 let witness = { WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build() }; let witness_len: u64 = witness.as_bytes().len() as u64; @@ -399,11 +393,11 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { }; let sig = privkey.sign_recoverable(&message).expect("sign"); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(sig.serialize())).into()) + .lock(Some(Bytes::from(sig.serialize()))) .build(); // sign input2 let witness2 = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build(); let witness2_len: u64 = witness2.as_bytes().len() as u64; let mut hasher = new_blake2b(); @@ -417,12 +411,12 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { }; let sig2 = privkey2.sign_recoverable(&message2).expect("sign"); let witness2 = WitnessArgs::new_builder() - .lock(Some(Bytes::from(sig2.serialize())).into()) + .lock(Some(Bytes::from(sig2.serialize()))) .build(); let tx = tx .as_advanced_builder() - .witness(witness.as_bytes().into()) - .witness(witness2.as_bytes().into()) + .witness(witness.as_bytes()) + .witness(witness2.as_bytes()) .build(); let serialized_size = tx.data().as_slice().len() as u64; @@ -438,7 +432,7 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { let (secp256k1_data_cell, secp256k1_data_cell_data) = secp256k1_data_cell(consensus); let input_cell1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock) .build(); @@ -447,7 +441,7 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { .build(); let input_cell2 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock2) .build(); diff --git a/shared/src/shared.rs b/shared/src/shared.rs index eb3221f4d5..570340d6d1 100644 --- a/shared/src/shared.rs +++ b/shared/src/shared.rs @@ -277,12 +277,12 @@ impl Shared { fn compact_block_body(&self, start: &packed::Byte32, end: &packed::Byte32) { let start_t = packed::TransactionKey::new_builder() .block_hash(start.clone()) - .index(0u32.into()) + .index(0u32) .build(); let end_t = packed::TransactionKey::new_builder() .block_hash(end.clone()) - .index(TX_INDEX_UPPER_BOUND.into()) + .index(TX_INDEX_UPPER_BOUND) .build(); if let Err(e) = self.store.compact_range( diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index 155a564a0f..1bb7537d31 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -22,7 +22,6 @@ use ckb_tx_pool::{ service::TxVerificationResult, TokioRwLock, TxEntry, TxPool, TxPoolServiceBuilder, }; use ckb_types::core::hardfork::HardForks; -use ckb_types::prelude::Pack; use ckb_types::{ core::service::PoolTransactionEntry, core::tx_pool::Reject, core::EpochExt, core::HeaderView, }; @@ -344,7 +343,7 @@ impl SharedBuilder { snapshot: &Snapshot, ) -> bool { if let Some(ref target) = sync_config.assume_valid_target { - if snapshot.block_exists(&target.pack()) { + if snapshot.block_exists(&target.into()) { info!("assume valid target is already in db, CKB will do full verification from now on"); return true; } diff --git a/spec/src/consensus.rs b/spec/src/consensus.rs index 1c5463b480..83f9b29af9 100644 --- a/spec/src/consensus.rs +++ b/spec/src/consensus.rs @@ -168,13 +168,13 @@ impl Default for ConsensusBuilder { let occupied = empty_output .occupied_capacity(Capacity::zero()) .expect("default occupied"); - empty_output.as_builder().capacity(occupied.into()).build() + empty_output.as_builder().capacity(occupied).build() }; let witness = Script::default().into_witness(); let cellbase = TransactionBuilder::default() .input(input) .output(output) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .witness(witness) .build(); @@ -200,8 +200,8 @@ impl Default for ConsensusBuilder { .expect("genesis dao data calculation error!"); let genesis_block = BlockBuilder::default() - .compact_target(DIFF_TWO.into()) - .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).into()) + .compact_target(DIFF_TWO) + .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0)) .dao(dao) .transaction(cellbase) .build(); diff --git a/spec/src/lib.rs b/spec/src/lib.rs index 2d54b047c3..588aa4657d 100644 --- a/spec/src/lib.rs +++ b/spec/src/lib.rs @@ -633,14 +633,14 @@ impl ChainSpec { ); let block = BlockBuilder::default() - .version(self.genesis.version.into()) - .parent_hash((&self.genesis.parent_hash).into()) - .timestamp(self.genesis.timestamp.into()) - .compact_target(self.genesis.compact_target.into()) - .extra_hash((&self.genesis.uncles_hash).into()) - .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).into()) + .version(self.genesis.version) + .parent_hash(&self.genesis.parent_hash) + .timestamp(self.genesis.timestamp) + .compact_target(self.genesis.compact_target) + .extra_hash(&self.genesis.uncles_hash) + .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0)) .dao(dao) - .nonce(u128::from_le_bytes(self.genesis.nonce.to_le_bytes()).into()) + .nonce(u128::from_le_bytes(self.genesis.nonce.to_le_bytes())) .transaction(cellbase_transaction) .transaction(dep_group_transaction) .build(); @@ -801,12 +801,12 @@ impl ChainSpec { outputs_data.extend(system_cells_data); let special_issued_lock = packed::Script::new_builder() - .args(secp_lock_arg(&Privkey::from(SPECIAL_CELL_PRIVKEY.clone())).into()) - .code_hash(CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL.clone().into()) - .hash_type(ScriptHashType::Data.into()) + .args(secp_lock_arg(&Privkey::from(SPECIAL_CELL_PRIVKEY.clone()))) + .code_hash(CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL.clone()) + .hash_type(ScriptHashType::Data) .build(); let special_issued_cell = packed::CellOutput::new_builder() - .capacity(special_cell_capacity.into()) + .capacity(special_cell_capacity) .lock(special_issued_lock) .build(); outputs.push(special_issued_cell); @@ -874,7 +874,7 @@ impl ChainSpec { let data = Into::::into(out_points).as_bytes(); let cell = packed::CellOutput::new_builder() - .lock(self.genesis.system_cells_lock.clone().into()) + .lock(self.genesis.system_cells_lock.clone()) .build_exact_capacity(Capacity::bytes(data.len())?)?; Ok((cell, data.into())) }) @@ -918,7 +918,7 @@ impl ChainSpec { let tx_hash: H256 = tx.hash().into(); let message = H256::from(blake2b_256(tx_hash)); let sig = privkey.sign_recoverable(&message).expect("sign"); - let witness = Bytes::from(sig.serialize()).into(); + let witness = Bytes::from(sig.serialize()); Ok(TransactionBuilder::default() .cell_deps(cell_deps) @@ -934,7 +934,7 @@ impl GenesisCell { fn build_output(&self) -> Result<(packed::CellOutput, Bytes), Box> { let data: Bytes = self.message.as_bytes().to_owned().into(); let cell = packed::CellOutput::new_builder() - .lock(self.lock.clone().into()) + .lock(self.lock.clone()) .build_exact_capacity(Capacity::bytes(data.len())?)?; Ok((cell, data)) } @@ -943,8 +943,8 @@ impl GenesisCell { impl IssuedCell { fn build_output(&self) -> packed::CellOutput { packed::CellOutput::new_builder() - .lock(self.lock.clone().into()) - .capacity(self.capacity.into()) + .lock(self.lock.clone()) + .capacity(self.capacity) .build() } } @@ -963,12 +963,12 @@ impl SystemCell { None }; let builder = packed::CellOutput::new_builder() - .type_(type_script.into()) - .lock(lock.clone().into()); + .type_(type_script) + .lock(lock.clone()); let data_len = Capacity::bytes(data.len())?; let cell = if let Some(capacity) = self.capacity { - let cell = builder.capacity(capacity.into()).build(); + let cell = builder.capacity(capacity).build(); let occupied_capacity = cell.occupied_capacity(data_len)?.as_u64(); if occupied_capacity > capacity { return Err(format!( @@ -1004,9 +1004,9 @@ pub(crate) fn build_type_id_script(input: &packed::CellInput, output_index: u64) blake2b.finalize(&mut ret); let script_arg = Bytes::from(ret.to_vec()); packed::Script::new_builder() - .code_hash(TYPE_ID_CODE_HASH.into()) - .hash_type(ScriptHashType::Type.into()) - .args(script_arg.into()) + .code_hash(TYPE_ID_CODE_HASH) + .hash_type(ScriptHashType::Type) + .args(script_arg) .build() } diff --git a/spec/src/tests/consensus.rs b/spec/src/tests/consensus.rs index d2fe44fe8e..4cbec57011 100644 --- a/spec/src/tests/consensus.rs +++ b/spec/src/tests/consensus.rs @@ -52,8 +52,8 @@ fn test_halving_epoch_reward() { let header = |epoch: &EpochExt, number: u64| { HeaderBuilder::default() - .number(number.into()) - .epoch(epoch.number_with_fraction(number).into()) + .number(number) + .epoch(epoch.number_with_fraction(number)) .build() }; diff --git a/spec/src/tests/versionbits.rs b/spec/src/tests/versionbits.rs index e4aa549b4d..898a17b97a 100644 --- a/spec/src/tests/versionbits.rs +++ b/spec/src/tests/versionbits.rs @@ -162,8 +162,8 @@ impl MockChain { let cellbase = TransactionBuilder::default().build(); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) .transaction(cellbase) .build() } @@ -175,16 +175,16 @@ impl MockChain { let version = self.compute_versionbits(parent).unwrap(); let cellbase_witness = CellbaseWitness::new_builder() - .message(version.to_le_bytes().as_slice().into()) + .message(version.to_le_bytes().as_slice()) .build(); - let witness = cellbase_witness.as_bytes().into(); + let witness = cellbase_witness.as_bytes(); let cellbase = TransactionBuilder::default().witness(witness).build(); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .number(parent.number() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) .transaction(cellbase) .build() } @@ -208,7 +208,7 @@ fn test_versionbits_active() { DEFAULT_ORPHAN_RATE_TARGET, ); let genesis = BlockBuilder::default() - .epoch(epoch_ext.number_with_fraction(0).into()) + .epoch(epoch_ext.number_with_fraction(0)) .transaction(cellbase) .build(); @@ -316,7 +316,7 @@ fn test_versionbits_failed() { DEFAULT_ORPHAN_RATE_TARGET, ); let genesis = BlockBuilder::default() - .epoch(epoch_ext.number_with_fraction(0).into()) + .epoch(epoch_ext.number_with_fraction(0)) .transaction(cellbase) .build(); diff --git a/store/src/cell.rs b/store/src/cell.rs index d840668230..182fb06459 100644 --- a/store/src/cell.rs +++ b/store/src/cell.rs @@ -41,23 +41,23 @@ pub fn attach_block_cell(txn: &StoreTransaction, block: &BlockView) -> Result<() .map(move |(index, (cell_output, data))| { let out_point = packed::OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(index.into()) + .index(index) .build(); let entry = packed::CellEntryBuilder::default() .output(cell_output) .block_hash(block_hash.clone()) - .block_number(block_number.into()) - .block_epoch(block_epoch.into()) - .index(tx_index.into()) - .data_size((data.len() as u64).into()) + .block_number(block_number) + .block_epoch(block_epoch) + .index(tx_index) + .data_size(data.len() as u64) .build(); let data_entry = if !data.is_empty() { let data_hash = packed::CellOutput::calc_data_hash(&data); Some( packed::CellDataEntryBuilder::default() - .output_data(data.into()) + .output_data(data) .output_data_hash(data_hash) .build(), ) @@ -111,23 +111,23 @@ pub fn detach_block_cell(txn: &StoreTransaction, block: &BlockView) -> Result<() tx.output_with_data(*index).map(|(cell_output, data)| { let out_point = packed::OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(index.into()) + .index(index) .build(); let entry = packed::CellEntryBuilder::default() .output(cell_output) .block_hash(block_hash.clone()) - .block_number(block_number.into()) - .block_epoch(block_epoch.into()) - .index(tx_index.into()) - .data_size((data.len() as u64).into()) + .block_number(block_number) + .block_epoch(block_epoch) + .index(tx_index) + .data_size(data.len() as u64) .build(); let data_entry = if !data.is_empty() { let data_hash = packed::CellOutput::calc_data_hash(&data); Some( packed::CellDataEntryBuilder::default() - .output_data(data.into()) + .output_data(data) .output_data_hash(data_hash) .build(), ) diff --git a/store/src/tests/db.rs b/store/src/tests/db.rs index 39aff4e9a7..5372d0f27e 100644 --- a/store/src/tests/db.rs +++ b/store/src/tests/db.rs @@ -31,8 +31,7 @@ fn save_and_get_block_with_transactions() { .transactions( (0..3) .map(|_| packed::Transaction::new_builder().build()) - .collect::>() - .into(), + .collect::>(), ) .build() .into_view(); @@ -98,7 +97,7 @@ fn freeze_blockv0() { let freezer = Freezer::open_in(&tmp_dir2).expect("tmp freezer"); let store = ChainDB::new_with_freezer(db, freezer.clone(), Default::default()); - let raw = packed::RawHeader::new_builder().number(1u64.into()).build(); + let raw = packed::RawHeader::new_builder().number(1u64).build(); let block = packed::Block::new_builder() .header(packed::Header::new_builder().raw(raw).build()) .build() @@ -132,7 +131,7 @@ fn freeze_blockv1_with_extension() { let store = ChainDB::new_with_freezer(db, freezer.clone(), Default::default()); let extension: packed::Bytes = [1u8; 96].as_slice().into(); - let raw = packed::RawHeader::new_builder().number(1u64.into()).build(); + let raw = packed::RawHeader::new_builder().number(1u64).build(); let block = packed::BlockV1::new_builder() .header(packed::Header::new_builder().raw(raw).build()) .extension(extension) diff --git a/store/src/transaction.rs b/store/src/transaction.rs index ea7506728e..51388d3091 100644 --- a/store/src/transaction.rs +++ b/store/src/transaction.rs @@ -189,7 +189,7 @@ impl StoreTransaction { self.insert_raw( COLUMN_NUMBER_HASH, packed::NumberHash::new_builder() - .number(block.number().into()) + .number(block.number()) .block_hash(hash.clone()) .build() .as_slice(), @@ -203,7 +203,7 @@ impl StoreTransaction { for (index, tx) in block.transactions().into_iter().enumerate() { let key = packed::TransactionKey::new_builder() .block_hash(hash.clone()) - .index(index.into()) + .index(index) .build(); let tx_data = Into::::into(tx); self.insert_raw(COLUMN_BLOCK_BODY, key.as_slice(), tx_data.as_slice())?; @@ -222,7 +222,7 @@ impl StoreTransaction { self.delete( COLUMN_NUMBER_HASH, packed::NumberHash::new_builder() - .number(block.number().into()) + .number(block.number()) .block_hash(hash.clone()) .build() .as_slice(), @@ -232,7 +232,7 @@ impl StoreTransaction { for index in 0..txs_len { let key = packed::TransactionKey::new_builder() .block_hash(hash.clone()) - .index(index.into()) + .index(index) .build(); self.delete(COLUMN_BLOCK_BODY, key.as_slice())?; } @@ -260,7 +260,7 @@ impl StoreTransaction { for (index, tx_hash) in block.tx_hashes().iter().enumerate() { let key = packed::TransactionKey::new_builder() .block_hash(block_hash.clone()) - .index(index.into()) + .index(index) .build(); let info = packed::TransactionInfo::new_builder() .key(key) diff --git a/store/src/write_batch.rs b/store/src/write_batch.rs index 367b9bb165..a2568505d2 100644 --- a/store/src/write_batch.rs +++ b/store/src/write_batch.rs @@ -100,7 +100,7 @@ impl StoreWriteBatch { self.inner.delete( COLUMN_NUMBER_HASH, packed::NumberHash::new_builder() - .number(number.into()) + .number(number) .block_hash(hash.clone()) .build() .as_slice(), @@ -109,7 +109,7 @@ impl StoreWriteBatch { let key_range = (0u32..txs_len).map(|i| { packed::TransactionKey::new_builder() .block_hash(hash.clone()) - .index(i.into()) + .index(i) .build() }); diff --git a/sync/src/filter/get_block_filter_check_points_process.rs b/sync/src/filter/get_block_filter_check_points_process.rs index 56ef4e08db..e7b36d58be 100644 --- a/sync/src/filter/get_block_filter_check_points_process.rs +++ b/sync/src/filter/get_block_filter_check_points_process.rs @@ -52,8 +52,8 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> { } } let content = packed::BlockFilterCheckPoints::new_builder() - .start_number(start_number.into()) - .block_filter_hashes(block_filter_hashes.into()) + .start_number(start_number) + .block_filter_hashes(block_filter_hashes) .build(); let message = packed::BlockFilterMessage::new_builder() diff --git a/sync/src/filter/get_block_filter_hashes_process.rs b/sync/src/filter/get_block_filter_hashes_process.rs index 25142bc2d6..3576ca0119 100644 --- a/sync/src/filter/get_block_filter_hashes_process.rs +++ b/sync/src/filter/get_block_filter_hashes_process.rs @@ -60,9 +60,9 @@ impl<'a> GetBlockFilterHashesProcess<'a> { } } let content = packed::BlockFilterHashes::new_builder() - .start_number(start_number.into()) + .start_number(start_number) .parent_block_filter_hash(parent_block_filter_hash) - .block_filter_hashes(block_filter_hashes.into()) + .block_filter_hashes(block_filter_hashes) .build(); let message = packed::BlockFilterMessage::new_builder() diff --git a/sync/src/filter/get_block_filters_process.rs b/sync/src/filter/get_block_filters_process.rs index 8d8257a04b..e5e6f38d31 100644 --- a/sync/src/filter/get_block_filters_process.rs +++ b/sync/src/filter/get_block_filters_process.rs @@ -51,9 +51,9 @@ impl<'a> GetBlockFiltersProcess<'a> { } } let content = packed::BlockFilters::new_builder() - .start_number(start_number.into()) - .block_hashes(block_hashes.into()) - .filters(filters.into()) + .start_number(start_number) + .block_hashes(block_hashes) + .filters(filters) .build(); let message = packed::BlockFilterMessage::new_builder() diff --git a/sync/src/net_time_checker.rs b/sync/src/net_time_checker.rs index 3b7c2acc79..aa384f9151 100644 --- a/sync/src/net_time_checker.rs +++ b/sync/src/net_time_checker.rs @@ -118,7 +118,7 @@ impl CKBProtocolHandler for NetTimeProtocol { // send local time to inbound peers if let Some(true) = nc.get_peer(peer_index).map(|peer| peer.is_inbound()) { let now = ckb_systemtime::unix_time_as_millis(); - let time = packed::Time::new_builder().timestamp(now.into()).build(); + let time = packed::Time::new_builder().timestamp(now).build(); let _status = send_message_to(nc.as_ref(), peer_index, &time); } } diff --git a/sync/src/relayer/block_transactions_process.rs b/sync/src/relayer/block_transactions_process.rs index 6e380b1751..c2c10077a4 100644 --- a/sync/src/relayer/block_transactions_process.rs +++ b/sync/src/relayer/block_transactions_process.rs @@ -162,8 +162,8 @@ impl<'a> BlockTransactionsProcess<'a> { let content = packed::GetBlockTransactions::new_builder() .block_hash(block_hash.clone()) - .indexes(missing_transactions.as_slice().into()) - .uncle_indexes(missing_uncles.as_slice().into()) + .indexes(missing_transactions.as_slice()) + .uncle_indexes(missing_uncles.as_slice()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/compact_block_process.rs b/sync/src/relayer/compact_block_process.rs index 483570f807..9ee0d40918 100644 --- a/sync/src/relayer/compact_block_process.rs +++ b/sync/src/relayer/compact_block_process.rs @@ -359,8 +359,8 @@ fn missing_or_collided_post_process( let content = packed::GetBlockTransactions::new_builder() .block_hash(block_hash) - .indexes(missing_transactions.as_slice().into()) - .uncle_indexes(missing_uncles.as_slice().into()) + .indexes(missing_transactions.as_slice()) + .uncle_indexes(missing_uncles.as_slice()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let sending = send_message_to(nc.as_ref(), peer, &message); diff --git a/sync/src/relayer/get_block_proposal_process.rs b/sync/src/relayer/get_block_proposal_process.rs index 052c684c37..59fd24189c 100644 --- a/sync/src/relayer/get_block_proposal_process.rs +++ b/sync/src/relayer/get_block_proposal_process.rs @@ -97,7 +97,7 @@ impl<'a> GetBlockProposalProcess<'a> { fn send_block_proposals(&self, txs: Vec) -> Status { let content = packed::BlockProposal::new_builder() - .transactions(txs.into()) + .transactions(txs) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); send_message_to(self.nc.as_ref(), self.peer, &message) diff --git a/sync/src/relayer/get_block_transactions_process.rs b/sync/src/relayer/get_block_transactions_process.rs index acb332993f..b6c249c2aa 100644 --- a/sync/src/relayer/get_block_transactions_process.rs +++ b/sync/src/relayer/get_block_transactions_process.rs @@ -84,15 +84,13 @@ impl<'a> GetBlockTransactionsProcess<'a> { transactions .into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .uncles( uncles .into_iter() .map(|uncle| uncle.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/get_transactions_process.rs b/sync/src/relayer/get_transactions_process.rs index 36370f22ae..766ff2af4d 100644 --- a/sync/src/relayer/get_transactions_process.rs +++ b/sync/src/relayer/get_transactions_process.rs @@ -76,7 +76,7 @@ impl<'a> GetTransactionsProcess<'a> { .into_iter() .map(|(_, (tx, cycles))| { packed::RelayTransaction::new_builder() - .cycles(cycles.into()) + .cycles(cycles) .transaction(tx.data()) .build() }) diff --git a/sync/src/relayer/mod.rs b/sync/src/relayer/mod.rs index 9acd6ab82a..366bd8e292 100644 --- a/sync/src/relayer/mod.rs +++ b/sync/src/relayer/mod.rs @@ -272,7 +272,7 @@ impl Relayer { if !to_ask_proposals.is_empty() { let content = packed::GetBlockProposal::new_builder() .block_hash(block_hash_and_number.hash) - .proposals(to_ask_proposals.clone().into()) + .proposals(to_ask_proposals.clone()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); if !send_message_to(nc, peer, &message).is_ok() { @@ -496,12 +496,11 @@ impl Relayer { let block = if let Some(extension) = compact_block.extension() { packed::BlockV1::new_builder() .header(compact_block.header()) - .uncles(uncles.into()) + .uncles(uncles) .transactions( txs.into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .proposals(compact_block.proposals()) .extension(extension) @@ -510,12 +509,11 @@ impl Relayer { } else { packed::Block::new_builder() .header(compact_block.header()) - .uncles(uncles.into()) + .uncles(uncles) .transactions( txs.into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .proposals(compact_block.proposals()) .build() @@ -604,7 +602,7 @@ impl Relayer { let send_block_proposals = |nc: &dyn CKBProtocolContext, peer_index: PeerIndex, txs: Vec| { let content = packed::BlockProposal::new_builder() - .transactions(txs.into()) + .transactions(txs) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let status = send_message_to(nc, peer_index, &message); @@ -650,7 +648,7 @@ impl Relayer { ); tx_hashes.truncate(MAX_RELAY_TXS_NUM_PER_BATCH); let content = packed::GetRelayTransactions::new_builder() - .tx_hashes(tx_hashes.into()) + .tx_hashes(tx_hashes) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let status = send_message_to(nc, peer, &message); @@ -732,7 +730,7 @@ impl Relayer { } for (peer, hashes) in selected { let content = packed::RelayTransactionHashes::new_builder() - .tx_hashes(hashes.into()) + .tx_hashes(hashes) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); @@ -801,7 +799,7 @@ fn build_and_broadcast_compact_block( let tip_header = packed::VerifiableHeader::new_builder() .header(block.header().data()) .uncles_hash(block.calc_uncles_hash()) - .extension(Pack::pack(&block.extension())) + .extension(block.extension()) .parent_chain_root(parent_chain_root) .build(); let light_client_message = { diff --git a/sync/src/relayer/tests/block_proposal_process.rs b/sync/src/relayer/tests/block_proposal_process.rs index bca97bcb0a..fb56fa01ce 100644 --- a/sync/src/relayer/tests/block_proposal_process.rs +++ b/sync/src/relayer/tests/block_proposal_process.rs @@ -20,8 +20,7 @@ fn test_no_unknown() { transactions .into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); @@ -41,8 +40,7 @@ fn test_no_asked() { transactions .into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); @@ -76,8 +74,7 @@ fn test_ok() { transactions .into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); @@ -111,8 +108,7 @@ fn test_clear_expired_inflight_proposals() { transactions .into_iter() .map(|tx| tx.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); diff --git a/sync/src/relayer/tests/block_transactions_process.rs b/sync/src/relayer/tests/block_transactions_process.rs index ad32e0c018..247baae90a 100644 --- a/sync/src/relayer/tests/block_transactions_process.rs +++ b/sync/src/relayer/tests/block_transactions_process.rs @@ -26,19 +26,19 @@ fn test_accept_block() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().into()) + .capacity(Capacity::bytes(1).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let tx3 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(2).unwrap().into()) + .capacity(Capacity::bytes(2).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let uncle = BlockBuilder::default() .proposals(Into::::into(vec![ @@ -72,8 +72,8 @@ fn test_accept_block() { let block_transactions: BlockTransactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].into()) - .uncles(vec![uncle.as_uncle().data()].into()) + .transactions(vec![tx2.data()]) + .uncles(vec![uncle.as_uncle().data()]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -106,10 +106,10 @@ fn test_unknown_request() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().into()) + .capacity(Capacity::bytes(1).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let block = BlockBuilder::default() @@ -135,7 +135,7 @@ fn test_unknown_request() { let block_transactions: BlockTransactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].into()) + .transactions(vec![tx2.data()]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -159,14 +159,14 @@ fn test_invalid_transaction_root() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().into()) + .capacity(Capacity::bytes(1).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let prefilled = IndexTransaction::new_builder() - .index(0u32.into()) + .index(0u32) .transaction(tx1.data()) .build(); @@ -180,8 +180,8 @@ fn test_invalid_transaction_root() { let compact_block = packed::CompactBlock::new_builder() .header(header_with_invalid_tx_root) - .short_ids(vec![tx2.proposal_short_id()].into()) - .prefilled_transactions(vec![prefilled].into()) + .short_ids(vec![tx2.proposal_short_id()]) + .prefilled_transactions(vec![prefilled]) .build(); let block_hash = compact_block.header().calc_header_hash(); @@ -200,7 +200,7 @@ fn test_invalid_transaction_root() { let block_transactions: BlockTransactions = packed::BlockTransactions::new_builder() .block_hash(block_hash) - .transactions(vec![tx2.data()].into()) + .transactions(vec![tx2.data()]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -236,28 +236,28 @@ fn test_collision_and_send_missing_indexes() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1000).unwrap().into()) + .capacity(Capacity::bytes(1000).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let tx3 = TransactionBuilder::default() .input(CellInput::new(OutPoint::new(last_cellbase.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(2).unwrap().into()) + .capacity(Capacity::bytes(2).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let fake_hash = tx3 .hash() .as_builder() - .nth31(0u8.into()) - .nth30(0u8.into()) - .nth29(0u8.into()) - .nth28(0u8.into()) + .nth31(0u8) + .nth30(0u8) + .nth29(0u8) + .nth28(0u8) .build(); // Fake tx with the same ProposalShortId but different hash with tx3 let fake_tx = tx3.clone().fake_hash(fake_hash); @@ -296,7 +296,7 @@ fn test_collision_and_send_missing_indexes() { let block_transactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].into()) + .transactions(vec![tx2.data()]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -315,7 +315,7 @@ fn test_collision_and_send_missing_indexes() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1u32, 2u32].into()) + .indexes([1u32, 2u32]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); @@ -339,7 +339,7 @@ fn test_collision_and_send_missing_indexes() { // resend BlockTransactions with all the transactions without prefilled let new_block_transactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data(), tx3.data()].into()) + .transactions(vec![tx2.data(), tx3.data()]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -372,18 +372,18 @@ fn test_missing() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().into()) + .capacity(Capacity::bytes(1).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let tx3 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(2).unwrap().into()) + .capacity(Capacity::bytes(2).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let block = BlockBuilder::default() @@ -410,7 +410,7 @@ fn test_missing() { let block_transactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].into()) + .transactions(vec![tx2.data()]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -429,7 +429,7 @@ fn test_missing() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1, 2u32].into()) + .indexes([1, 2u32]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/tests/block_transactions_verifier.rs b/sync/src/relayer/tests/block_transactions_verifier.rs index 485fe1573a..6934c1f5af 100644 --- a/sync/src/relayer/tests/block_transactions_verifier.rs +++ b/sync/src/relayer/tests/block_transactions_verifier.rs @@ -18,8 +18,8 @@ fn build_compact_block() -> CompactBlock { .collect::>(); CompactBlockBuilder::default() - .short_ids(short_ids.into()) - .prefilled_transactions(prefilled_iter.into()) + .short_ids(short_ids) + .prefilled_transactions(prefilled_iter) .build() } diff --git a/sync/src/relayer/tests/compact_block.rs b/sync/src/relayer/tests/compact_block.rs index 92ecaadb50..72b6169a81 100644 --- a/sync/src/relayer/tests/compact_block.rs +++ b/sync/src/relayer/tests/compact_block.rs @@ -13,18 +13,18 @@ fn test_block_short_ids() { ]; let prefilled_transactions = vec![ IndexTransactionBuilder::default() - .index(0u32.into()) + .index(0u32) .transaction(TransactionBuilder::default().build().data()) .build(), IndexTransactionBuilder::default() - .index(2u32.into()) + .index(2u32) .transaction(TransactionBuilder::default().build().data()) .build(), ]; let compact_block = compact_block_builder - .short_ids(short_ids.into()) - .prefilled_transactions(prefilled_transactions.into()) + .short_ids(short_ids) + .prefilled_transactions(prefilled_transactions) .build(); assert_eq!( diff --git a/sync/src/relayer/tests/compact_block_process.rs b/sync/src/relayer/tests/compact_block_process.rs index fca2194039..1948a47e81 100644 --- a/sync/src/relayer/tests/compact_block_process.rs +++ b/sync/src/relayer/tests/compact_block_process.rs @@ -113,9 +113,9 @@ fn test_unknow_parent() { let block = BlockBuilder::default() .header( HeaderBuilder::default() - .number(5.into()) - .epoch(EpochNumberWithFraction::new(1, 5, 1000).into()) - .timestamp(unix_time_as_millis().into()) + .number(5) + .epoch(EpochNumberWithFraction::new(1, 5, 1000)) + .timestamp(unix_time_as_millis()) .build(), ) .transaction(TransactionBuilder::default().build()) @@ -145,7 +145,7 @@ fn test_unknow_parent() { let locator_hash = active_chain.get_locator((&header).into()); let content = packed::GetHeaders::new_builder() - .block_locator_hashes(locator_hash.into()) + .block_locator_hashes(locator_hash) .hash_stop(packed::Byte32::zero()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); @@ -227,7 +227,7 @@ fn test_header_invalid() { // Better block but block number is invalid let header = new_header_builder(relayer.shared.shared(), &parent) - .number(4.into()) + .number(4) .build(); let block = BlockBuilder::default() @@ -285,10 +285,10 @@ fn test_send_missing_indexes() { TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().into()) + .capacity(Capacity::bytes(1).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(), ) .uncle(uncle.as_uncle()) @@ -321,8 +321,8 @@ fn test_send_missing_indexes() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1u32].into()) - .uncle_indexes([0u32].into()) + .indexes([1u32]) + .uncle_indexes([0u32]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); @@ -338,7 +338,7 @@ fn test_send_missing_indexes() { let content = packed::GetBlockProposal::new_builder() .block_hash(block.header().hash()) - .proposals(vec![proposal_id].into()) + .proposals(vec![proposal_id]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); @@ -368,12 +368,12 @@ fn test_accept_block() { ); let mock_block_1 = BlockBuilder::default() - .number(4.into()) - .epoch(EpochNumberWithFraction::new(1, 4, 1000).into()) + .number(4) + .epoch(EpochNumberWithFraction::new(1, 4, 1000)) .build(); let mock_compact_block_1 = CompactBlock::build_from_block(&mock_block_1, &Default::default()); - let mock_block_2 = block.as_advanced_builder().number(7.into()).build(); + let mock_block_2 = block.as_advanced_builder().number(7).build(); let mock_compact_block_2 = CompactBlock::build_from_block(&mock_block_2, &Default::default()); { let mut pending_compact_blocks = relayer.shared.state().pending_compact_blocks(); @@ -522,20 +522,20 @@ fn test_collision() { let missing_tx = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1000).unwrap().into()) + .capacity(Capacity::bytes(1000).unwrap()) .build(), ) .input(CellInput::new(OutPoint::new(last_cellbase.hash(), 0), 0)) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let fake_hash = missing_tx .hash() .as_builder() - .nth31(0u8.into()) - .nth30(0u8.into()) - .nth29(0u8.into()) - .nth28(0u8.into()) + .nth31(0u8) + .nth30(0u8) + .nth29(0u8) + .nth28(0u8) .build(); // Fake tx with the same ProposalShortId but different hash with missing_tx let fake_tx = missing_tx.clone().fake_hash(fake_hash); @@ -589,7 +589,7 @@ fn test_collision() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1u32].into()) + .indexes([1u32]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); diff --git a/sync/src/relayer/tests/compact_block_verifier.rs b/sync/src/relayer/tests/compact_block_verifier.rs index 4c0b9e686d..e85da0c024 100644 --- a/sync/src/relayer/tests/compact_block_verifier.rs +++ b/sync/src/relayer/tests/compact_block_verifier.rs @@ -11,7 +11,7 @@ fn test_unordered_prefilled() { .map(new_index_transaction) .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.into()) + .prefilled_transactions(prefilled) .build(); assert_eq!( PrefilledVerifier::verify(&block), @@ -25,7 +25,7 @@ fn test_ordered_prefilled() { .map(new_index_transaction) .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.into()) + .prefilled_transactions(prefilled) .build(); assert_eq!(PrefilledVerifier::verify(&block), Status::ok()); } @@ -37,7 +37,7 @@ fn test_overflow_prefilled() { .map(new_index_transaction) .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.into()) + .prefilled_transactions(prefilled) .build(); assert_eq!( PrefilledVerifier::verify(&block), @@ -57,7 +57,7 @@ fn test_cellbase_not_prefilled() { .map(new_index_transaction) .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.into()) + .prefilled_transactions(prefilled) .build(); assert_eq!( PrefilledVerifier::verify(&block), @@ -72,9 +72,7 @@ fn test_duplicated_short_ids() { .collect(); short_ids.push(short_ids[0].clone()); - let block = CompactBlockBuilder::default() - .short_ids(short_ids.into()) - .build(); + let block = CompactBlockBuilder::default().short_ids(short_ids).build(); assert_eq!( ShortIdsVerifier::verify(&block), StatusCode::CompactBlockHasDuplicatedShortIds.into(), @@ -91,8 +89,8 @@ fn test_intersected_short_ids() { .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.into()) - .short_ids(short_ids.into()) + .prefilled_transactions(prefilled) + .short_ids(short_ids) .build(); assert_eq!( ShortIdsVerifier::verify(&block), @@ -111,8 +109,8 @@ fn test_normal() { .map(|i| new_index_transaction(i).transaction().proposal_short_id()) .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.into()) - .short_ids(short_ids.into()) + .prefilled_transactions(prefilled) + .short_ids(short_ids) .build(); assert_eq!(ShortIdsVerifier::verify(&block), Status::ok()); } diff --git a/sync/src/relayer/tests/get_block_proposal_process.rs b/sync/src/relayer/tests/get_block_proposal_process.rs index 55a9adda42..f38308dc06 100644 --- a/sync/src/relayer/tests/get_block_proposal_process.rs +++ b/sync/src/relayer/tests/get_block_proposal_process.rs @@ -17,7 +17,7 @@ fn test_duplicate() { let content = packed::GetBlockProposal::new_builder() .block_hash(hash) - .proposals(vec![id.clone(), id].into()) + .proposals(vec![id.clone(), id]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); let nc = Arc::new(mock_protocol_context); diff --git a/sync/src/relayer/tests/get_transactions_process.rs b/sync/src/relayer/tests/get_transactions_process.rs index 9b206cdd50..6839daf7bb 100644 --- a/sync/src/relayer/tests/get_transactions_process.rs +++ b/sync/src/relayer/tests/get_transactions_process.rs @@ -13,7 +13,7 @@ fn test_duplicate() { let tx = new_transaction(&relayer, 1, &always_success_out_point); let tx_hash = tx.hash(); let content = packed::GetRelayTransactions::new_builder() - .tx_hashes(vec![tx_hash.clone(), tx_hash].into()) + .tx_hashes(vec![tx_hash.clone(), tx_hash]) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); let nc = Arc::new(mock_protocol_context); diff --git a/sync/src/relayer/tests/helper.rs b/sync/src/relayer/tests/helper.rs index 6f7e562959..72d85709cd 100644 --- a/sync/src/relayer/tests/helper.rs +++ b/sync/src/relayer/tests/helper.rs @@ -38,14 +38,14 @@ pub(crate) fn new_index_transaction(index: usize) -> IndexTransaction { let transaction = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(index).unwrap().into()) + .capacity(Capacity::bytes(index).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); IndexTransactionBuilder::default() - .index(index.into()) + .index(index) .transaction(transaction.data()) .build() } @@ -60,10 +60,10 @@ pub(crate) fn new_header_builder(shared: &Shared, parent: &HeaderView) -> Header .epoch(); HeaderBuilder::default() .parent_hash(parent_hash) - .number((parent.number() + 1).into()) - .timestamp((parent.timestamp() + 1).into()) - .epoch(epoch.number_with_fraction(parent.number() + 1).into()) - .compact_target(epoch.compact_target().into()) + .number(parent.number() + 1) + .timestamp(parent.timestamp() + 1) + .epoch(epoch.number_with_fraction(parent.number() + 1)) + .compact_target(epoch.compact_target()) } pub(crate) fn new_transaction( @@ -89,10 +89,10 @@ pub(crate) fn new_transaction( .input(CellInput::new(previous_output, 0)) .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(500 + index).unwrap().into()) // use capacity to identify transactions + .capacity(Capacity::bytes(500 + index).unwrap() ) // use capacity to identify transactions .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .cell_dep( CellDep::new_builder() .out_point(always_success_out_point.to_owned()) @@ -138,7 +138,7 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) { let always_success_tx = TransactionBuilder::default() .input(CellInput::new(OutPoint::null(), 0)) .output(always_success_cell.clone()) - .output_data(always_success_cell_data.into()) + .output_data(always_success_cell_data) .witness(always_success_script.clone().into_witness()) .build(); let always_success_out_point = OutPoint::new(always_success_tx.hash(), 0); @@ -146,9 +146,9 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) { let (shared, mut pack) = { let dao = genesis_dao_data(vec![&always_success_tx]).unwrap(); let genesis = BlockBuilder::default() - .timestamp(unix_time_as_millis().into()) + .timestamp(unix_time_as_millis()) .dao(dao) - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .transaction(always_success_tx) .build(); let epoch_ext = build_genesis_epoch_ext( @@ -188,11 +188,11 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) { .input(CellInput::new_cellbase_input(parent.header().number() + 1)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(50000).into()) + .capacity(capacity_bytes!(50000)) .lock(always_success_script.to_owned()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .witness(Script::default().into_witness()) .build(); let header = new_header_builder(&shared, &parent.header()).build(); @@ -273,22 +273,20 @@ pub(crate) fn gen_block( let mut block_builder = BlockBuilder::default() .parent_hash(parent_header.hash()) .timestamp( - (parent_header + parent_header .timestamp() .checked_add_signed(timestamp_delta) - .unwrap()) - .into(), + .unwrap(), ) - .number(number.into()) + .number(number) .compact_target( - (epoch + epoch .compact_target() .checked_add_signed(target_delta) - .unwrap()) - .into(), + .unwrap(), ) .dao(dao) - .epoch(epoch.number_with_fraction(number).into()) + .epoch(epoch.number_with_fraction(number)) .transactions(txs); if let Some(uncle) = uncle_opt { block_builder = block_builder.uncle(uncle) diff --git a/sync/src/relayer/tests/reconstruct_block.rs b/sync/src/relayer/tests/reconstruct_block.rs index 303e48db32..167356b822 100644 --- a/sync/src/relayer/tests/reconstruct_block.rs +++ b/sync/src/relayer/tests/reconstruct_block.rs @@ -25,7 +25,7 @@ fn test_missing_txs() { .map(|tx| tx.proposal_short_id()) .collect::>(); let transactions: Vec = prepare.iter().skip(1).cloned().collect(); - let compact = compact_block_builder.short_ids(short_ids.into()).build(); + let compact = compact_block_builder.short_ids(short_ids).build(); assert_eq!( relayer.reconstruct_block( &relayer.shared().active_chain(), @@ -53,7 +53,7 @@ fn test_missing_txs() { .step_by(2) .map(|(i, _)| i) .collect(); - let compact = compact_block_builder.short_ids(short_ids.into()).build(); + let compact = compact_block_builder.short_ids(short_ids).build(); assert_eq!( relayer.reconstruct_block( &relayer.shared().active_chain(), @@ -110,7 +110,7 @@ fn test_reconstruct_transactions_and_uncles() { // BLOCK_VALID let ext = packed::BlockExtBuilder::default() - .verified(Some(true).into()) + .verified(Some(true)) .build(); let compact = packed::CompactBlock::build_from_block(&block, &prefilled); @@ -155,7 +155,7 @@ fn test_reconstruct_invalid_uncles() { let uncle = BlockBuilder::default().build(); // BLOCK_VALID let ext = packed::BlockExtBuilder::default() - .verified(Some(false).into()) + .verified(Some(false)) .build(); let block = BlockBuilder::default() diff --git a/sync/src/synchronizer/get_headers_process.rs b/sync/src/synchronizer/get_headers_process.rs index cbb0738252..d5e8d7e4d7 100644 --- a/sync/src/synchronizer/get_headers_process.rs +++ b/sync/src/synchronizer/get_headers_process.rs @@ -85,8 +85,7 @@ impl<'a> GetHeadersProcess<'a> { headers .into_iter() .map(|x| x.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 3280825b0f..f79eaca4f7 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -281,7 +281,7 @@ impl BlockFetchCMD { fn send_getblocks(v_fetch: Vec, nc: &ServiceControl, peer: PeerIndex) { let content = packed::GetBlocks::new_builder() - .block_hashes(v_fetch.clone().into()) + .block_hashes(v_fetch.clone()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); @@ -785,7 +785,7 @@ impl Synchronizer { peer: PeerIndex, ) { let content = packed::GetBlocks::new_builder() - .block_hashes(v_fetch.clone().into()) + .block_hashes(v_fetch.clone()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); diff --git a/sync/src/tests/orphan_block_pool.rs b/sync/src/tests/orphan_block_pool.rs deleted file mode 100644 index c761ce89b1..0000000000 --- a/sync/src/tests/orphan_block_pool.rs +++ /dev/null @@ -1,152 +0,0 @@ -use ckb_chain_spec::consensus::ConsensusBuilder; -use ckb_systemtime::unix_time_as_millis; -use ckb_types::core::{BlockBuilder, BlockView, EpochNumberWithFraction, HeaderView}; -use std::collections::HashSet; -use std::sync::Arc; -use std::thread; - -use crate::orphan_block_pool::OrphanBlockPool; - -fn gen_block(parent_header: &HeaderView) -> BlockView { - let number = parent_header.number() + 1; - BlockBuilder::default() - .parent_hash(parent_header.hash()) - .timestamp(unix_time_as_millis().into()) - .number(number.into()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).into()) - .nonce((parent_header.nonce() + 1).into()) - .build() -} - -#[test] -fn test_remove_blocks_by_parent() { - let consensus = ConsensusBuilder::default().build(); - let block_number = 200; - let mut blocks = Vec::new(); - let mut parent = consensus.genesis_block().header(); - let pool = OrphanBlockPool::with_capacity(200); - let mut total_size = 0; - for _ in 1..block_number { - let new_block = gen_block(&parent); - total_size += new_block.data().total_size(); - blocks.push(new_block.clone()); - pool.insert(new_block.clone()); - parent = new_block.header(); - } - assert_eq!(total_size, pool.total_size()); - - let orphan = pool.remove_blocks_by_parent(&consensus.genesis_block().hash()); - let orphan_set: HashSet = orphan.into_iter().collect(); - let blocks_set: HashSet = blocks.into_iter().collect(); - assert_eq!(orphan_set, blocks_set); - assert_eq!(0, pool.total_size()); -} - -#[test] -fn test_remove_blocks_by_parent_and_get_block_should_not_deadlock() { - let consensus = ConsensusBuilder::default().build(); - let pool = OrphanBlockPool::with_capacity(1024); - let mut header = consensus.genesis_block().header(); - let mut hashes = Vec::new(); - for _ in 1..1024 { - let new_block = gen_block(&header); - pool.insert(new_block.clone()); - header = new_block.header(); - hashes.push(header.hash()); - } - - let pool_arc1 = Arc::new(pool); - let pool_arc2 = Arc::clone(&pool_arc1); - - let thread1 = thread::spawn(move || { - pool_arc1.remove_blocks_by_parent(&consensus.genesis_block().hash()); - }); - - for hash in hashes.iter().rev() { - pool_arc2.get_block(hash); - } - - thread1.join().unwrap(); -} - -#[test] -fn test_leaders() { - let consensus = ConsensusBuilder::default().build(); - let block_number = 20; - let mut blocks = Vec::new(); - let mut parent = consensus.genesis_block().header(); - let pool = OrphanBlockPool::with_capacity(20); - for i in 0..block_number - 1 { - let new_block = gen_block(&parent); - blocks.push(new_block.clone()); - parent = new_block.header(); - if i % 5 != 0 { - pool.insert(new_block.clone()); - } - } - - assert_eq!(pool.len(), 15); - assert_eq!(pool.leaders_len(), 4); - - pool.insert(blocks[5].clone()); - assert_eq!(pool.len(), 16); - assert_eq!(pool.leaders_len(), 3); - - pool.insert(blocks[10].clone()); - assert_eq!(pool.len(), 17); - assert_eq!(pool.leaders_len(), 2); - - // index 0 doesn't in the orphan pool, so do nothing - let orphan = pool.remove_blocks_by_parent(&consensus.genesis_block().hash()); - assert!(orphan.is_empty()); - assert_eq!(pool.len(), 17); - assert_eq!(pool.leaders_len(), 2); - - pool.insert(blocks[0].clone()); - assert_eq!(pool.len(), 18); - assert_eq!(pool.leaders_len(), 2); - - let orphan = pool.remove_blocks_by_parent(&consensus.genesis_block().hash()); - assert_eq!(pool.len(), 3); - assert_eq!(pool.leaders_len(), 1); - - pool.insert(blocks[15].clone()); - assert_eq!(pool.len(), 4); - assert_eq!(pool.leaders_len(), 1); - - let orphan_1 = pool.remove_blocks_by_parent(&blocks[14].hash()); - - let orphan_set: HashSet = orphan.into_iter().chain(orphan_1).collect(); - let blocks_set: HashSet = blocks.into_iter().collect(); - assert_eq!(orphan_set, blocks_set); - assert_eq!(pool.len(), 0); - assert_eq!(pool.leaders_len(), 0); -} - -#[test] -fn test_remove_expired_blocks() { - let consensus = ConsensusBuilder::default().build(); - let block_number = 20; - let mut parent = consensus.genesis_block().header(); - let pool = OrphanBlockPool::with_capacity(block_number); - - let deprecated = EpochNumberWithFraction::new(10, 0, 10); - - for _ in 1..block_number { - let new_block = BlockBuilder::default() - .parent_hash(parent.hash()) - .timestamp(unix_time_as_millis().into()) - .number((parent.number() + 1).into()) - .epoch(deprecated.into()) - .nonce((parent.nonce() + 1).into()) - .build(); - pool.insert(new_block.clone()); - parent = new_block.header(); - } - assert_eq!(pool.leaders_len(), 1); - - let v = pool.clean_expired_blocks(20_u64); - assert_eq!(v.len(), 19); - assert_eq!(pool.leaders_len(), 0); - assert_eq!(pool.total_size(), 0) -} diff --git a/sync/src/tests/sync_shared.rs b/sync/src/tests/sync_shared.rs index 5e3826e8b5..6219bc3eb5 100644 --- a/sync/src/tests/sync_shared.rs +++ b/sync/src/tests/sync_shared.rs @@ -102,7 +102,7 @@ fn test_insert_parent_unknown_block() { let invalid_orphan = block .as_advanced_builder() .header(block.header()) - .number(1000.into()) + .number(1000) .build(); Arc::new(invalid_orphan) @@ -256,7 +256,7 @@ fn test_switch_valid_fork() { .unwrap(); for _ in 3..shared.active_chain().tip_number() { let block = inherit_block(fork_shared.shared(), &parent_header.hash()) - .timestamp((parent_header.timestamp() + 3).into()) + .timestamp(parent_header.timestamp() + 3) .build(); let arc_block = Arc::new(block.clone()); assert!(fork_shared @@ -281,7 +281,7 @@ fn test_switch_valid_fork() { // Make the fork switch as the main chain. for _ in tip_number..tip_number + 2 { let block = inherit_block(fork_shared.shared(), &parent_header.hash()) - .timestamp((parent_header.timestamp() + 3).into()) + .timestamp(parent_header.timestamp() + 3) .build(); let arc_block = Arc::new(block.clone()); assert!(fork_shared @@ -330,7 +330,7 @@ fn test_sync_relay_collaboration() { packed::CompactBlock::build_from_block(&new_block, &std::collections::HashSet::new()); let headers_content = packed::SendHeaders::new_builder() - .headers([new_block.header()].map(|x| x.data()).pack()) + .headers(vec![new_block.header().data()]) .build(); // keep header process snapshot on old state, this is the bug reason @@ -404,7 +404,7 @@ fn test_sync_relay_collaboration2() { let next_timestamp = next_block.timestamp() + 2; let new_block = new_block .as_advanced_builder() - .timestamp(next_timestamp.pack()) + .timestamp(next_timestamp) .build(); Arc::new(new_block) @@ -417,7 +417,7 @@ fn test_sync_relay_collaboration2() { packed::CompactBlock::build_from_block(&new_block_1, &std::collections::HashSet::new()); let headers_content = packed::SendHeaders::new_builder() - .headers([new_block.header()].map(|x| x.data()).pack()) + .headers(vec![new_block.header().data()]) .build(); // keep header process snapshot on old state, this is the bug reason diff --git a/sync/src/tests/synchronizer/basic_sync.rs b/sync/src/tests/synchronizer/basic_sync.rs index 188f2198cd..4337fb5312 100644 --- a/sync/src/tests/synchronizer/basic_sync.rs +++ b/sync/src/tests/synchronizer/basic_sync.rs @@ -98,14 +98,14 @@ fn setup_node(height: u64) -> (TestNode, Shared) { .witness(always_success_script.clone().into_witness()) .input(CellInput::new(OutPoint::null(), 0)) .output(always_success_cell.clone()) - .output_data(always_success_cell_data.into()) + .output_data(always_success_cell_data) .build(); let dao = genesis_dao_data(vec![&always_success_tx]).unwrap(); let mut block = BlockBuilder::default() - .timestamp(unix_time_as_millis().into()) - .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) + .timestamp(unix_time_as_millis()) + .compact_target(difficulty_to_compact(U256::from(1000u64))) .dao(dao) .transaction(always_success_tx) .build(); @@ -150,11 +150,11 @@ fn setup_node(height: u64) -> (TestNode, Shared) { builder .output( CellOutputBuilder::default() - .capacity(reward.total.into()) + .capacity(reward.total) .lock(always_success_script.to_owned()) .build(), ) - .output_data(Bytes::default().into()) + .output_data(Bytes::default()) .build() }; @@ -181,10 +181,10 @@ fn setup_node(height: u64) -> (TestNode, Shared) { block = BlockBuilder::default() .transaction(cellbase) .parent_hash(block.header().hash()) - .number(number.into()) - .epoch(epoch.number_with_fraction(number).into()) - .timestamp(timestamp.into()) - .compact_target(epoch.compact_target().into()) + .number(number) + .epoch(epoch.number_with_fraction(number)) + .timestamp(timestamp) + .compact_target(epoch.compact_target()) .dao(dao) .extension(Some(bytes)) .build(); diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index 316d6a9c56..45892f1663 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -81,12 +81,8 @@ fn create_cellbase( builder.build() } else { builder - .output( - CellOutputBuilder::default() - .capacity(reward.total.into()) - .build(), - ) - .output_data(Bytes::new().into()) + .output(CellOutputBuilder::default().capacity(reward.total).build()) + .output_data(Bytes::new()) .build() } } @@ -119,11 +115,11 @@ fn gen_block( BlockBuilder::default() .transaction(cellbase) .parent_hash(parent_header.hash()) - .timestamp(now.into()) - .epoch(epoch.number_with_fraction(number).into()) - .number(number.into()) - .compact_target(epoch.compact_target().into()) - .nonce(nonce.into()) + .timestamp(now) + .epoch(epoch.number_with_fraction(number)) + .number(number) + .compact_target(epoch.compact_target()) + .nonce(nonce) .dao(dao) .extension(Some(bytes)) .build() @@ -634,8 +630,7 @@ fn test_sync_process() { headers .iter() .map(|h| h.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); @@ -699,8 +694,7 @@ fn test_sync_process() { headers .iter() .map(|h| h.data()) - .collect::>() - .into(), + .collect::>(), ) .build(); assert_eq!( @@ -778,7 +772,7 @@ fn test_chain_sync_timeout() { let consensus = Consensus::default(); let block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(3u64)).into()) + .compact_target(difficulty_to_compact(U256::from(3u64))) .transaction(consensus.genesis_block().transactions()[0].clone()) .build(); let consensus = ConsensusBuilder::default().genesis_block(block).build(); @@ -975,7 +969,7 @@ fn test_n_sync_started() { let consensus = Consensus::default(); let block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(3u64)).into()) + .compact_target(difficulty_to_compact(U256::from(3u64))) .transaction(consensus.genesis_block().transactions()[0].clone()) .build(); let consensus = ConsensusBuilder::default().genesis_block(block).build(); @@ -1122,9 +1116,7 @@ fn test_fix_last_common_header() { .map(|number| graph.get(&f_(number)).cloned().unwrap()) .map(|block| block.header().data()) .collect::>(); - let sendheaders = SendHeadersBuilder::default() - .headers(fork_headers.into()) - .build(); + let sendheaders = SendHeadersBuilder::default().headers(fork_headers).build(); synchronizer.on_connected(&nc, peer); assert!( HeadersProcess::new(sendheaders.as_reader(), &synchronizer, peer, &nc) @@ -1199,7 +1191,7 @@ fn get_blocks_process() { let genesis_hash = shared.consensus().genesis_hash(); let message_with_genesis = packed::GetBlocks::new_builder() - .block_hashes(vec![genesis_hash].into()) + .block_hashes(vec![genesis_hash]) .build(); let nc = mock_network_context(1); @@ -1212,7 +1204,7 @@ fn get_blocks_process() { let hash = shared.snapshot().get_block_hash(1).unwrap(); let message_with_dup = packed::GetBlocks::new_builder() - .block_hashes(vec![hash.clone(), hash].into()) + .block_hashes(vec![hash.clone(), hash]) .build(); let nc = mock_network_context(1); diff --git a/sync/src/tests/types.rs b/sync/src/tests/types.rs index f58d11b170..892e9c8f9f 100644 --- a/sync/src/tests/types.rs +++ b/sync/src/tests/types.rs @@ -21,9 +21,14 @@ fn test_get_ancestor_use_skip_list() { let mut parent_hash = None; for number in 0..SKIPLIST_LENGTH { - let mut header_builder = HeaderBuilder::default() - .number(number.into()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).into()); + let mut header_builder = + HeaderBuilder::default() + .number(number) + .epoch(EpochNumberWithFraction::new( + number / 1000, + number % 1000, + 1000, + )); if let Some(parent_hash) = parent_hash.take() { header_builder = header_builder.parent_hash(parent_hash); } diff --git a/sync/src/tests/util.rs b/sync/src/tests/util.rs index d59f9d4db9..4a314a3832 100644 --- a/sync/src/tests/util.rs +++ b/sync/src/tests/util.rs @@ -75,10 +75,10 @@ pub fn inherit_block(shared: &Shared, parent_hash: &Byte32) -> BlockBuilder { BlockBuilder::default() .parent_hash(parent_hash.to_owned()) - .number((parent.header().number() + 1).into()) - .timestamp((parent.header().timestamp() + 1).into()) - .epoch(epoch.number_with_fraction(parent_number + 1).into()) - .compact_target(epoch.compact_target().into()) + .number(parent.header().number() + 1) + .timestamp(parent.header().timestamp() + 1) + .epoch(epoch.number_with_fraction(parent_number + 1)) + .compact_target(epoch.compact_target()) .dao(dao) .transaction(cellbase) .extension(Some(bytes)) diff --git a/sync/src/types/mod.rs b/sync/src/types/mod.rs index 35fb940288..873882efc9 100644 --- a/sync/src/types/mod.rs +++ b/sync/src/types/mod.rs @@ -1946,7 +1946,7 @@ impl ActiveChain { ); let locator_hash = self.get_locator(block_number_and_hash); let content = packed::GetHeaders::new_builder() - .block_locator_hashes(locator_hash.into()) + .block_locator_hashes(locator_hash) .hash_stop(packed::Byte32::zero()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); diff --git a/test/src/node.rs b/test/src/node.rs index be9ee0b5d6..874b774f05 100644 --- a/test/src/node.rs +++ b/test/src/node.rs @@ -19,7 +19,9 @@ use ckb_types::{ self, capacity_bytes, BlockBuilder, BlockNumber, BlockView, Capacity, HeaderView, ScriptHashType, TransactionView, }, - packed::{Block, Byte32, CellDep, CellInput, CellOutput, CellOutputBuilder, OutPoint, Script}, + packed::{ + self, Block, Byte32, CellDep, CellInput, CellOutput, CellOutputBuilder, OutPoint, Script, + }, prelude::*, }; use std::borrow::{Borrow, BorrowMut}; @@ -230,7 +232,7 @@ impl Node { let always_success_code_hash = CellOutput::calc_data_hash(&always_success_raw); Script::new_builder() .code_hash(always_success_code_hash) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build() } @@ -256,7 +258,7 @@ impl Node { let always_failure_code_hash = CellOutput::calc_data_hash(&always_failure_raw); Script::new_builder() .code_hash(always_failure_code_hash) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build() } @@ -359,10 +361,7 @@ impl Node { // the new block in main fork which timestamp is greater than // or equal to the current time. let timestamp = block.timestamp(); - let uncle = block - .as_advanced_builder() - .timestamp((timestamp - 1).into()) - .build(); + let uncle = block.as_advanced_builder().timestamp(timestamp + 1).build(); (block, uncle) } @@ -589,11 +588,11 @@ impl Node { .cell_dep(always_success_cell_dep) .output( CellOutputBuilder::default() - .capacity(capacity.into()) + .capacity(capacity) .lock(always_success_script) .build(), ) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .input(CellInput::new(OutPoint::new(hash, index), since)) .build() } @@ -615,11 +614,11 @@ impl Node { .cell_dep(always_failure_cell_dep) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(always_failure_script) .build(), ) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .input(CellInput::new(OutPoint::new(hash, 0), 0)) .build() } diff --git a/test/src/specs/alert/alert_propagation.rs b/test/src/specs/alert/alert_propagation.rs index 027cfd9574..3af797ecd1 100644 --- a/test/src/specs/alert/alert_propagation.rs +++ b/test/src/specs/alert/alert_propagation.rs @@ -44,9 +44,9 @@ impl Spec for AlertPropagation { let id1: u32 = 42; let warning1: Bytes = b"pretend we are in dangerous status".to_vec().into(); let raw_alert = RawAlert::new_builder() - .id(id1.into()) - .message((&warning1).into()) - .notice_until(notice_until.into()) + .id(id1) + .message(&warning1) + .notice_until(notice_until) .build(); let alert = create_alert(raw_alert, &self.privkeys); node0.rpc_client().send_alert(alert.clone().into()); @@ -74,10 +74,10 @@ impl Spec for AlertPropagation { let id2: u32 = 43; let warning2: Bytes = b"alert is canceled".to_vec().into(); let raw_alert2 = RawAlert::new_builder() - .id(id2.into()) - .cancel(id1.into()) - .message((&warning2).into()) - .notice_until(notice_until.into()) + .id(id2) + .cancel(id1) + .message(&warning2) + .notice_until(notice_until) .build(); let alert2 = create_alert(raw_alert2, &self.privkeys); node0.rpc_client().send_alert(alert2.into()); @@ -156,6 +156,6 @@ fn create_alert(raw_alert: RawAlert, privkeys: &[Privkey]) -> Alert { .collect::>(); Alert::new_builder() .raw(raw_alert) - .signatures(signatures.into()) + .signatures(signatures) .build() } diff --git a/test/src/specs/consensus/insufficient_reward.rs b/test/src/specs/consensus/insufficient_reward.rs index 0c0c9042b5..831759eccd 100644 --- a/test/src/specs/consensus/insufficient_reward.rs +++ b/test/src/specs/consensus/insufficient_reward.rs @@ -2,6 +2,7 @@ use crate::global::VENDOR_PATH; use crate::specs::spec_name; use crate::{Node, Spec}; +use ckb_types::packed::Script; use ckb_types::{ core::{capacity_bytes, Capacity}, packed::CellOutput, @@ -46,8 +47,8 @@ impl Spec for InsufficientReward { // build a block with insufficient reward let output = CellOutput::new_builder() - .capacity(capacity_bytes!(1).into()) - .lock(Default::default()) + .capacity(capacity_bytes!(1)) + .lock(Script::default()) .build(); let cellbase = new_block_builder.clone().build().transactions()[0] .as_advanced_builder() diff --git a/test/src/specs/dao/dao_tx.rs b/test/src/specs/dao/dao_tx.rs index 9bed9be765..af9f4f8db5 100644 --- a/test/src/specs/dao/dao_tx.rs +++ b/test/src/specs/dao/dao_tx.rs @@ -61,10 +61,7 @@ impl Spec for WithdrawDAOWithOverflowCapacity { .map(|cell_output| { let old_capacity: Capacity = cell_output.capacity().into(); let new_capacity = old_capacity.safe_add(Capacity::one()).unwrap(); - cell_output - .as_builder() - .capacity(new_capacity.into()) - .build() + cell_output.as_builder().capacity(new_capacity).build() }) .collect(); withdrawal diff --git a/test/src/specs/dao/dao_user.rs b/test/src/specs/dao/dao_user.rs index 4f9587c16a..b54fd1c7d9 100644 --- a/test/src/specs/dao/dao_user.rs +++ b/test/src/specs/dao/dao_user.rs @@ -51,9 +51,9 @@ impl<'a> DAOUser<'a> { (0..outputs_len) .map(|_| { CellOutput::new_builder() - .capacity(capacity.into()) + .capacity(capacity) .lock(node.always_success_script()) - .type_(Some(self.dao_type_script()).into()) + .type_(Some(self.dao_type_script())) .build() }) .collect::>() @@ -68,7 +68,7 @@ impl<'a> DAOUser<'a> { .inputs(inputs) .outputs(outputs) .outputs_data(outputs_data) - .witness(Default::default()) + .witness(packed::Bytes::default()) .build(); self.deposit_utxo = TXOSet::from(&tx); tx @@ -83,7 +83,7 @@ impl<'a> DAOUser<'a> { .map(|(txo, _)| CellInput::new(txo.out_point(), 0)); let outputs = deposit_utxo_headers.iter().map(|(txo, _)| { CellOutput::new_builder() - .capacity(txo.capacity().into()) + .capacity(txo.capacity()) .lock(txo.lock()) .type_(txo.type_()) .build() @@ -108,7 +108,7 @@ impl<'a> DAOUser<'a> { .position(|hash| hash == &header.hash()) .unwrap() as u64; WitnessArgs::new_builder() - .input_type(Some(Bytes::from(index.to_le_bytes().to_vec())).into()) + .input_type(Some(Bytes::from(index.to_le_bytes().to_vec()))) .build() .as_bytes() .into() @@ -148,7 +148,7 @@ impl<'a> DAOUser<'a> { }) .sum::(); let output = CellOutput::new_builder() - .capacity(output_capacity.into()) + .capacity(output_capacity) .lock(node.always_success_script()) .build(); let cell_deps = vec![node.always_success_cell_dep(), self.dao_cell_dep()]; @@ -167,7 +167,7 @@ impl<'a> DAOUser<'a> { .position(|hash| hash == &header.hash()) .unwrap() as u64; WitnessArgs::new_builder() - .input_type(Some(Bytes::from(index.to_le_bytes().to_vec())).into()) + .input_type(Some(Bytes::from(index.to_le_bytes().to_vec()))) .build() .as_bytes() .into() @@ -179,7 +179,7 @@ impl<'a> DAOUser<'a> { .cell_deps(cell_deps) .header_deps(header_deps) .witnesses(witnesses) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); self.withdraw_utxo = TXOSet::from(&tx); tx @@ -188,7 +188,7 @@ impl<'a> DAOUser<'a> { pub fn dao_type_script(&self) -> Script { Script::new_builder() .code_hash(self.node.consensus().dao_type_hash()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build() } diff --git a/test/src/specs/dao/satoshi_dao_occupied.rs b/test/src/specs/dao/satoshi_dao_occupied.rs index 6fb8965cea..74ae15a3cc 100644 --- a/test/src/specs/dao/satoshi_dao_occupied.rs +++ b/test/src/specs/dao/satoshi_dao_occupied.rs @@ -95,7 +95,7 @@ impl Spec for SpendSatoshiCell { 0, ); let output = CellOutput::new_builder() - .capacity(satoshi_cell_occupied.into()) + .capacity(satoshi_cell_occupied) .lock(always_success_cell().2.clone()) .build(); @@ -103,7 +103,7 @@ impl Spec for SpendSatoshiCell { .cell_deps(vec![node0.always_success_cell_dep()]) .input(satoshi_input) .output(output) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let tx_hash = transaction.hash(); let sig = self @@ -113,10 +113,7 @@ impl Spec for SpendSatoshiCell { let mut witness_vec = sig.serialize(); witness_vec.extend_from_slice(&self.pubkey.serialize()); let witness = Bytes::from(witness_vec); - let transaction = transaction - .as_advanced_builder() - .witness(witness.into()) - .build(); + let transaction = transaction.as_advanced_builder().witness(witness).build(); node0.mine(1); node0 @@ -152,7 +149,7 @@ fn issue_satoshi_cell() -> IssuedCell { .2 .clone() .as_builder() - .args(Bytes::from(&SATOSHI_PUBKEY_HASH.0[..]).into()) + .args(Bytes::from(&SATOSHI_PUBKEY_HASH.0[..])) .build(); IssuedCell { capacity: SATOSHI_CELL_CAPACITY, diff --git a/test/src/specs/hardfork/v2021/cell_deps.rs b/test/src/specs/hardfork/v2021/cell_deps.rs index 801c12650c..c6f66e9f71 100644 --- a/test/src/specs/hardfork/v2021/cell_deps.rs +++ b/test/src/specs/hardfork/v2021/cell_deps.rs @@ -169,12 +169,12 @@ impl NewScript { let original_data = node.always_success_raw_data(); let data = packed::Bytes::new_builder() .extend(original_data.as_ref().iter().map(|x| (*x).into())) - .push(id.into()) + .push(id) .build(); let tx = Self::deploy(node, &data, inputs, type_script_opt); let cell_dep = packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) - .dep_type(core::DepType::Code.into()) + .dep_type(core::DepType::Code) .build(); let data_hash = packed::CellOutput::calc_data_hash(&data.raw_data()); let type_hash = tx @@ -219,7 +219,7 @@ impl NewScript { }; let cell_input = inputs.next().unwrap(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).into()) + .type_(Some(type_script)) .build_exact_capacity(core::Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -249,14 +249,14 @@ impl NewScript { }; packed::Script::new_builder() .code_hash(self.data_hash.clone()) - .hash_type(hash_type.into()) + .hash_type(hash_type) .build() } fn as_type_script(&self) -> packed::Script { packed::Script::new_builder() .code_hash(self.type_hash.clone()) - .hash_type(core::ScriptHashType::Type.into()) + .hash_type(core::ScriptHashType::Type) .build() } } @@ -443,7 +443,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { type_script: &NewScript, ) -> TransactionView { let output = packed::CellOutput::new_builder() - .type_(Some(type_script.as_data_script(0)).into()) + .type_(Some(type_script.as_data_script(0))) .build_exact_capacity(core::Capacity::bytes(data_script.data().len()).unwrap()) .unwrap(); let tx = TransactionView::new_advanced_builder() @@ -460,7 +460,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { fn convert_tx_to_code_cellep(tx: &TransactionView) -> packed::CellDep { packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) - .dep_type(core::DepType::Code.into()) + .dep_type(core::DepType::Code) .build() } @@ -489,7 +489,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { Self::submit_transaction_until_committed_to(node, &tx); packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) - .dep_type(core::DepType::DepGroup.into()) + .dep_type(core::DepType::DepGroup) .build() } } @@ -526,7 +526,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().into()) + .capacity(input_cell.capacity.value()) .lock(new_script.as_data_script(0)) .build(); let tx = TransactionView::new_advanced_builder() @@ -534,7 +534,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { .cell_dep(new_script.cell_dep()) .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); self.create_initial_input(tx) } @@ -546,16 +546,16 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().into()) + .capacity(input_cell.capacity.value()) .lock(self.node.always_success_script()) - .type_(Some(new_script.as_data_script(0)).into()) + .type_(Some(new_script.as_data_script(0))) .build(); let tx = TransactionView::new_advanced_builder() .cell_dep(self.node.always_success_cell_dep()) .cell_dep(new_script.cell_dep()) .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); self.create_initial_input(tx) } @@ -567,7 +567,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().into()) + .capacity(input_cell.capacity.value()) .lock(new_script.as_type_script()) .build(); let tx = TransactionView::new_advanced_builder() @@ -575,7 +575,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { .cell_dep(new_script.cell_dep()) .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); self.create_initial_input(tx) } @@ -587,16 +587,16 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().into()) + .capacity(input_cell.capacity.value()) .lock(self.node.always_success_script()) - .type_(Some(new_script.as_type_script()).into()) + .type_(Some(new_script.as_type_script())) .build(); let tx = TransactionView::new_advanced_builder() .cell_dep(self.node.always_success_cell_dep()) .cell_dep(new_script.cell_dep()) .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); self.create_initial_input(tx) } @@ -627,11 +627,11 @@ impl<'a> CheckCellDepsTestRunner<'a> { (HT::Data, ST::Lock) => cob.lock(new_script.as_data_script(0)), (HT::Data, ST::Type) => cob .lock(self.node.always_success_script()) - .type_(Some(new_script.as_data_script(0)).into()), + .type_(Some(new_script.as_data_script(0))), (HT::Type, ST::Lock) => cob.lock(new_script.as_type_script()), (HT::Type, ST::Type) => cob .lock(self.node.always_success_script()) - .type_(Some(new_script.as_type_script()).into()), + .type_(Some(new_script.as_type_script())), } } } @@ -700,7 +700,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { } .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); self.adjust_tip_before_test(); if let Some(errmsg) = expected.error_message() { diff --git a/test/src/specs/hardfork/v2021/vm_b_extension.rs b/test/src/specs/hardfork/v2021/vm_b_extension.rs index d03ac41f50..8c89d1d260 100644 --- a/test/src/specs/hardfork/v2021/vm_b_extension.rs +++ b/test/src/specs/hardfork/v2021/vm_b_extension.rs @@ -84,7 +84,7 @@ impl BExtScript { let tx = Self::deploy(node, &data, cell_input); let cell_dep = packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); let data_hash = packed::CellOutput::calc_data_hash(&data.raw_data()); let type_hash = tx @@ -105,7 +105,7 @@ impl BExtScript { let type_script = node.always_success_script(); let tx_template = TransactionView::new_advanced_builder(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).into()) + .type_(Some(type_script)) .build_exact_capacity(Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -131,7 +131,7 @@ impl BExtScript { }; packed::Script::new_builder() .code_hash(self.data_hash.clone()) - .hash_type(hash_type.into()) + .hash_type(hash_type) .args(args) .build() } @@ -139,7 +139,7 @@ impl BExtScript { fn as_type_script(&self, args: packed::Bytes) -> packed::Script { packed::Script::new_builder() .code_hash(self.type_hash.clone()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(args) .build() } @@ -225,7 +225,7 @@ impl<'a> CheckVmBExtensionTestRunner<'a> { let script = self.script.as_script(vm_opt, args); packed::CellOutput::new_builder() .lock(self.node.always_success_script()) - .type_(Some(script).into()) + .type_(Some(script)) .build_exact_capacity(Capacity::shannons(0)) .unwrap() }; @@ -234,7 +234,7 @@ impl<'a> CheckVmBExtensionTestRunner<'a> { .cell_dep(self.script.cell_dep()) .input(input) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); if let Some(errmsg) = expected.error_message() { assert_send_transaction_fail(self.node, &tx, errmsg); diff --git a/test/src/specs/hardfork/v2021/vm_version1.rs b/test/src/specs/hardfork/v2021/vm_version1.rs index 53911c67a6..e4f935d168 100644 --- a/test/src/specs/hardfork/v2021/vm_version1.rs +++ b/test/src/specs/hardfork/v2021/vm_version1.rs @@ -96,12 +96,12 @@ impl NewScript { let original_data = node.always_success_raw_data(); let data = packed::Bytes::new_builder() .extend(original_data.as_ref().iter().map(|x| (*x).into())) - .push(id.into()) + .push(id) .build(); let tx = Self::deploy(node, &data, inputs); let cell_dep = packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); let data_hash = packed::CellOutput::calc_data_hash(&data.raw_data()); let type_hash = tx @@ -127,7 +127,7 @@ impl NewScript { let tx_template = TransactionView::new_advanced_builder(); let cell_input = inputs.next().unwrap(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).into()) + .type_(Some(type_script)) .build_exact_capacity(Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -153,14 +153,14 @@ impl NewScript { }; packed::Script::new_builder() .code_hash(self.data_hash.clone()) - .hash_type(hash_type.into()) + .hash_type(hash_type) .build() } fn as_type_script(&self) -> packed::Script { packed::Script::new_builder() .code_hash(self.type_hash.clone()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build() } } @@ -218,7 +218,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { TransactionView::new_advanced_builder().cell_dep(cell_dep), packed::CellOutput::new_builder() .lock(self.node.always_success_script()) - .type_(Some(script).into()), + .type_(Some(script)), ) } else { ( @@ -228,14 +228,12 @@ impl<'a> CheckVmVersionTestRunner<'a> { }; let cell_input = inputs.next().unwrap(); let input_cell = self.get_previous_output(&cell_input); - let cell_output = co_builder - .capacity((input_cell.capacity.value() - 1).into()) - .build(); + let cell_output = co_builder.capacity(input_cell.capacity.value() - 1).build(); let tx = tx_builder .cell_dep(self.node.always_success_cell_dep()) .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); if let Some(errmsg) = expected.error_message() { assert_send_transaction_fail(self.node, &tx, errmsg); @@ -266,7 +264,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { .cell_dep(cell_dep) .input(input) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); if let Some(errmsg) = expected.error_message() { assert_send_transaction_fail(self.node, &tx, errmsg); diff --git a/test/src/specs/hardfork/v2023/vm_version2.rs b/test/src/specs/hardfork/v2023/vm_version2.rs index f28e4dd4c4..aa727f6e89 100644 --- a/test/src/specs/hardfork/v2023/vm_version2.rs +++ b/test/src/specs/hardfork/v2023/vm_version2.rs @@ -116,12 +116,12 @@ impl NewScript { let original_data = node.always_success_raw_data(); let data = packed::Bytes::new_builder() .extend(original_data.as_ref().iter().map(|x| (*x).into())) - .push(id.into()) + .push(id) .build(); let tx = Self::deploy(node, &data, inputs); let cell_dep = packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); let data_hash = packed::CellOutput::calc_data_hash(&data.raw_data()); let type_hash = tx @@ -147,7 +147,7 @@ impl NewScript { let tx_template = TransactionView::new_advanced_builder(); let cell_input = inputs.next().unwrap(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).into()) + .type_(Some(type_script)) .build_exact_capacity(Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -174,14 +174,14 @@ impl NewScript { }; packed::Script::new_builder() .code_hash(self.data_hash.clone()) - .hash_type(hash_type.into()) + .hash_type(hash_type) .build() } fn as_type_script(&self) -> packed::Script { packed::Script::new_builder() .code_hash(self.type_hash.clone()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build() } } @@ -239,7 +239,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { TransactionView::new_advanced_builder().cell_dep(cell_dep), packed::CellOutput::new_builder() .lock(self.node.always_success_script()) - .type_(Some(script).into()), + .type_(Some(script)), ) } else { ( @@ -249,14 +249,12 @@ impl<'a> CheckVmVersionTestRunner<'a> { }; let cell_input = inputs.next().unwrap(); let input_cell = self.get_previous_output(&cell_input); - let cell_output = co_builder - .capacity((input_cell.capacity.value() - 1).into()) - .build(); + let cell_output = co_builder.capacity(input_cell.capacity.value() - 1).build(); let tx = tx_builder .cell_dep(self.node.always_success_cell_dep()) .input(cell_input) .output(cell_output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); if let Some(errmsg) = expected.error_message() { assert_send_transaction_fail(self.node, &tx, errmsg); @@ -287,7 +285,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { .cell_dep(cell_dep) .input(input) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); if let Some(errmsg) = expected.error_message() { assert_send_transaction_fail(self.node, &tx, errmsg); diff --git a/test/src/specs/mining/basic.rs b/test/src/specs/mining/basic.rs index f78ec326c6..930fe933fa 100644 --- a/test/src/specs/mining/basic.rs +++ b/test/src/specs/mining/basic.rs @@ -49,7 +49,7 @@ impl Spec for BlockTemplates { block1 .header() .as_advanced_builder() - .timestamp((block1.header().timestamp() + 1).into()) + .timestamp(block1.header().timestamp() + 1) .build(), ) .build(); diff --git a/test/src/specs/mining/bootstrap.rs b/test/src/specs/mining/bootstrap.rs index 861f718abd..d5ae37b989 100644 --- a/test/src/specs/mining/bootstrap.rs +++ b/test/src/specs/mining/bootstrap.rs @@ -20,9 +20,9 @@ impl Spec for BootstrapCellbase { node.mine(DEFAULT_TX_PROPOSAL_WINDOW.1 + 1); let miner = packed::Script::new_builder() - .args(Bytes::from(vec![2, 1]).into()) - .code_hash(h256!("0xa2").into()) - .hash_type(ScriptHashType::Data.into()) + .args(Bytes::from(vec![2, 1])) + .code_hash(h256!("0xa2")) + .hash_type(ScriptHashType::Data) .build(); let is_bootstrap_cellbase = |number| { diff --git a/test/src/specs/mining/fee.rs b/test/src/specs/mining/fee.rs index c9cb84afb4..c7bd9be438 100644 --- a/test/src/specs/mining/fee.rs +++ b/test/src/specs/mining/fee.rs @@ -5,14 +5,10 @@ use crate::util::check::is_transaction_committed; use crate::util::transaction::always_success_transaction; use crate::{Node, Spec}; use crate::{DEFAULT_TX_PROPOSAL_WINDOW, FINALIZATION_DELAY_LENGTH}; -use ckb_types::core::TransactionBuilder; -use ckb_types::packed::CellInput; -use ckb_types::packed::CellOutput; -use ckb_types::packed::OutPoint; -use ckb_types::prelude::*; use ckb_types::{ - core::{capacity_bytes, Capacity}, - packed::CellOutputBuilder, + core::{capacity_bytes, Capacity, TransactionBuilder}, + packed::{self, CellInput, CellOutput, CellOutputBuilder, OutPoint}, + prelude::*, }; use rand::{thread_rng, Rng}; @@ -79,14 +75,14 @@ impl Spec for FeeOfMaxBlockProposalsLimit { let maximal_capacity = cell.capacity().as_u64(); let random_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = CellOutput::new_builder() - .capacity(random_capacity.into()) + .capacity(random_capacity) .lock(cell.cell_output.lock()) .type_(cell.cell_output.type_()) .build(); TransactionBuilder::default() .input(as_input(&cell)) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(node.always_success_cell_dep()) .build() }) @@ -135,14 +131,14 @@ impl Spec for FeeOfMultipleMaxBlockProposalsLimit { let maximal_capacity = cell.capacity().as_u64(); let random_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = CellOutput::new_builder() - .capacity(random_capacity.into()) + .capacity(random_capacity) .lock(cell.cell_output.lock()) .type_(cell.cell_output.type_()) .build(); TransactionBuilder::default() .input(as_input(&cell)) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(node.always_success_cell_dep()) .build() }) @@ -225,7 +221,7 @@ impl Spec for ProposeDuplicated { let uncle = node .new_block_builder(None, None, None) .proposal(tx.proposal_short_id()) - .nonce(99999.into()) + .nonce(99999) .build() .as_uncle(); node.mine(1); @@ -256,7 +252,7 @@ impl Spec for MalformedTx { let tx0 = node0.new_transaction_spend_tip_cellbase(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .build(); let child = tx0 diff --git a/test/src/specs/mining/proposal.rs b/test/src/specs/mining/proposal.rs index 5a29009c77..eb4abe8a2c 100644 --- a/test/src/specs/mining/proposal.rs +++ b/test/src/specs/mining/proposal.rs @@ -20,7 +20,7 @@ impl Spec for AvoidDuplicatedProposalsWithUncles { let block = node.new_block(None, None, None); let uncle = block .as_advanced_builder() - .timestamp((block.timestamp() + 1).into()) + .timestamp(block.timestamp() + 1) .set_proposals(vec![tx.proposal_short_id()]) .build(); node.submit_block(&block); diff --git a/test/src/specs/mining/uncle.rs b/test/src/specs/mining/uncle.rs index 9ef25609bc..6d51311d08 100644 --- a/test/src/specs/mining/uncle.rs +++ b/test/src/specs/mining/uncle.rs @@ -85,19 +85,16 @@ impl Spec for UncleInheritFromForkUncle { let uncle_child = uncle_parent .as_advanced_builder() - .number((uncle_parent.number() + 1).into()) + .number(uncle_parent.number() + 1) .parent_hash(uncle_parent.hash()) - .timestamp((uncle_parent.timestamp() + 1).into()) - .epoch( - { - let parent_epoch = uncle_parent.epoch(); - let epoch_number = parent_epoch.number(); - let epoch_index = parent_epoch.index(); - let epoch_length = parent_epoch.length(); - EpochNumberWithFraction::new(epoch_number, epoch_index + 1, epoch_length) - } - .into(), - ) + .timestamp(uncle_parent.timestamp() + 1) + .epoch({ + let parent_epoch = uncle_parent.epoch(); + let epoch_number = parent_epoch.number(); + let epoch_index = parent_epoch.index(); + let epoch_length = parent_epoch.length(); + EpochNumberWithFraction::new(epoch_number, epoch_index + 1, epoch_length) + }) .build(); let longer_fork = (0..=target_node.get_tip_block_number()).map(|_| { diff --git a/test/src/specs/relay/block_relay.rs b/test/src/specs/relay/block_relay.rs index 1f5b5a2efb..a3d054b98e 100644 --- a/test/src/specs/relay/block_relay.rs +++ b/test/src/specs/relay/block_relay.rs @@ -21,7 +21,7 @@ impl Spec for RelayTooNewBlock { let future = Duration::from_secs(6_000).as_millis() as u64; let too_new_block = node0 .new_block_builder(None, None, None) - .timestamp((now_ms() + future).into()) + .timestamp(now_ms() + future) .build(); let _too_new_hash = node0.process_block_without_verify(&too_new_block, true); diff --git a/test/src/specs/relay/compact_block.rs b/test/src/specs/relay/compact_block.rs index ab2b70a2c7..0cd024796c 100644 --- a/test/src/specs/relay/compact_block.rs +++ b/test/src/specs/relay/compact_block.rs @@ -40,7 +40,7 @@ impl Spec for CompactBlockEmptyParentUnknown { .new_block_builder(None, None, None) .header( HeaderBuilder::default() - .parent_hash(h256!("0x123456").into()) + .parent_hash(h256!("0x123456")) .build(), ) .build(); @@ -316,7 +316,7 @@ impl Spec for CompactBlockMissingWithDropTx { let content = packed::BlockTransactions::new_builder() .block_hash(new_block.hash()) - .transactions(vec![new_tx_2.data()].into()) + .transactions(vec![new_tx_2.data()]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); @@ -348,7 +348,7 @@ impl Spec for CompactBlockMissingWithDropTx { let content = packed::BlockTransactions::new_builder() .block_hash(new_block.hash()) - .transactions(vec![new_tx_1.data(), new_tx_2.data()].into()) + .transactions(vec![new_tx_1.data(), new_tx_2.data()]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/test/src/specs/relay/get_block_proposal_process.rs b/test/src/specs/relay/get_block_proposal_process.rs index b076b37666..9f7083180f 100644 --- a/test/src/specs/relay/get_block_proposal_process.rs +++ b/test/src/specs/relay/get_block_proposal_process.rs @@ -46,7 +46,7 @@ impl Spec for ProposalRespondSizelimit { let content = packed::GetBlockProposal::new_builder() .block_hash(tip_hash) - .proposals(proposal_ids.into()) + .proposals(proposal_ids) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/test/src/specs/relay/get_block_transactions_process.rs b/test/src/specs/relay/get_block_transactions_process.rs index d36fd6b579..b40b22b2da 100644 --- a/test/src/specs/relay/get_block_transactions_process.rs +++ b/test/src/specs/relay/get_block_transactions_process.rs @@ -24,21 +24,18 @@ impl Spec for MissingUncleRequest { node.mine(1); let builder = node.new_block_builder(None, None, None); - let block1 = builder.clone().nonce(0.into()).build(); - let block2 = builder.nonce(1.into()).build(); + let block1 = builder.clone().nonce(0).build(); + let block2 = builder.nonce(1).build(); node.submit_block(&block1); node.submit_block(&block2); let builder = node.new_block_builder(None, None, None); - let block = builder - .set_uncles(vec![block2.as_uncle()]) - .nonce(0.into()) - .build(); + let block = builder.set_uncles(vec![block2.as_uncle()]).nonce(0).build(); node.submit_block(&block); let content = packed::GetBlockTransactions::new_builder() .block_hash(block.hash()) - .uncle_indexes([0u32].into()) + .uncle_indexes([0u32]) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/test/src/specs/relay/transaction_relay.rs b/test/src/specs/relay/transaction_relay.rs index 46c7597216..28cd66a3fe 100644 --- a/test/src/specs/relay/transaction_relay.rs +++ b/test/src/specs/relay/transaction_relay.rs @@ -241,7 +241,7 @@ impl Spec for TransactionRelayConflict { let tx1 = node0.new_transaction(tx_hash_0.clone()); let tx2_temp = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).into()) + .capacity(capacity_bytes!(80)) .build(); let tx2 = tx2_temp diff --git a/test/src/specs/relay/transaction_relay_low_fee_rate.rs b/test/src/specs/relay/transaction_relay_low_fee_rate.rs index 1aad334416..f172f4b569 100644 --- a/test/src/specs/relay/transaction_relay_low_fee_rate.rs +++ b/test/src/specs/relay/transaction_relay_low_fee_rate.rs @@ -5,7 +5,10 @@ use crate::util::log_monitor::monitor_log_until_expected_show; use crate::util::mining::out_ibd_mode; use crate::{Node, Spec}; use ckb_logger::debug; -use ckb_types::core::{FeeRate, TransactionBuilder}; +use ckb_types::{ + core::{FeeRate, TransactionBuilder}, + packed, +}; pub struct TransactionRelayLowFeeRate; @@ -23,7 +26,7 @@ impl Spec for TransactionRelayLowFeeRate { let low_fee = TransactionBuilder::default() .input(as_input(&cells[0])) .output(as_output(&cells[0])) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(node0.always_success_cell_dep()) .build(); diff --git a/test/src/specs/rpc/submit_block.rs b/test/src/specs/rpc/submit_block.rs index adfa9ae399..7e1bb10470 100644 --- a/test/src/specs/rpc/submit_block.rs +++ b/test/src/specs/rpc/submit_block.rs @@ -14,10 +14,7 @@ impl Spec for RpcSubmitBlock { node1.mine_until_out_bootstrap_period(); // build block with wrong block number - let block = node0 - .new_block_builder(None, None, None) - .number(2.into()) - .build(); + let block = node0.new_block_builder(None, None, None).number(2).build(); let block_err = node0 .rpc_client() .submit_block("".to_owned(), block.data().into()) @@ -38,7 +35,7 @@ impl Spec for RpcSubmitBlock { let epoch = EpochNumberWithFraction::new(tip_epoch.number() + 1, 0, 100); let block = node0 .new_block_builder(None, None, None) - .epoch(epoch.into()) + .epoch(epoch) .build(); let block_err = node0 .rpc_client() @@ -84,7 +81,7 @@ impl Spec for RpcSubmitBlock { // so here plus another 15s to make sure when submit the block it still out of the limit let block = node0 .new_block_builder(None, None, None) - .timestamp((now_ms() + 30_000).into()) + .timestamp(now_ms() + 30_000) .build(); let block_err = node0 .rpc_client() @@ -99,7 +96,7 @@ impl Spec for RpcSubmitBlock { let median_time = node0.rpc_client().get_blockchain_info().median_time.value(); let block = node0 .new_block_builder(None, None, None) - .timestamp((median_time - 1).into()) + .timestamp(median_time - 1) .build(); let block_err = node0 .rpc_client() diff --git a/test/src/specs/sync/block_filter.rs b/test/src/specs/sync/block_filter.rs index cc4f85d83b..0c86a1cb57 100644 --- a/test/src/specs/sync/block_filter.rs +++ b/test/src/specs/sync/block_filter.rs @@ -31,7 +31,7 @@ impl Spec for GetBlockFilterCheckPoints { let start_number: u64 = 0; let request = { let content = packed::GetBlockFilterCheckPoints::new_builder() - .start_number(start_number.into()) + .start_number(start_number) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -113,7 +113,7 @@ impl Spec for GetBlockFilterHashes { let start_number: u64 = 2; let request = { let content = packed::GetBlockFilterHashes::new_builder() - .start_number(start_number.into()) + .start_number(start_number) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -205,7 +205,7 @@ impl Spec for GetBlockFilters { let start_number: u64 = 42; let request = { let content = packed::GetBlockFilters::new_builder() - .start_number(start_number.into()) + .start_number(start_number) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -289,7 +289,7 @@ impl Spec for GetBlockFiltersNotReachBatch { info!("start_number: {start_number}"); let request = { let content = packed::GetBlockFilters::new_builder() - .start_number(start_number.into()) + .start_number(start_number) .build(); packed::BlockFilterMessage::new_builder() .set(content) diff --git a/test/src/specs/sync/block_sync.rs b/test/src/specs/sync/block_sync.rs index 77232ab300..d283150a57 100644 --- a/test/src/specs/sync/block_sync.rs +++ b/test/src/specs/sync/block_sync.rs @@ -57,8 +57,8 @@ impl Spec for BlockSyncWithUncle { let node1 = &nodes[1]; let new_builder = node1.new_block_builder(None, None, None); - let new_block1 = new_builder.clone().nonce(0.into()).build(); - let new_block2 = new_builder.nonce(1.into()).build(); + let new_block1 = new_builder.clone().nonce(0).build(); + let new_block2 = new_builder.nonce(1).build(); node1.submit_block(&new_block1); node1.submit_block(&new_block2); @@ -329,7 +329,7 @@ impl Spec for BlockSyncNonAncestorBestBlocks { let b = a .data() .as_advanced_builder() - .timestamp((a.timestamp() + 1).into()) + .timestamp(a.timestamp() + 1) .build(); assert_ne!(a.hash(), b.hash()); node1.submit_block(&b); @@ -432,7 +432,7 @@ impl Spec for SyncTooNewBlock { for _ in 0..3 { let too_new_block = node0 .new_block_builder(None, None, None) - .timestamp((now_ms() + future).into()) + .timestamp(now_ms() + future) .build(); // node1 sync node1 with too new block @@ -471,9 +471,7 @@ impl Spec for HeaderSyncCycle { let mut net = Net::new(self.name(), node0.consensus(), vec![SupportProtocols::Sync]); net.connect(node0); - let send_headers = SendHeaders::new_builder() - .headers(Vec::new().into()) - .build(); + let send_headers = SendHeaders::new_builder().headers(Vec::new()).build(); let msg = SyncMessage::new_builder() .set(send_headers) diff --git a/test/src/specs/sync/chain_forks.rs b/test/src/specs/sync/chain_forks.rs index d7c777b904..446de599be 100644 --- a/test/src/specs/sync/chain_forks.rs +++ b/test/src/specs/sync/chain_forks.rs @@ -147,7 +147,7 @@ impl Spec for ChainFork3 { let old_capacity: Capacity = old_output.capacity().into(); let new_output = old_output .as_builder() - .capacity(old_capacity.safe_add(capacity_bytes!(1)).unwrap().into()) + .capacity(old_capacity.safe_add(capacity_bytes!(1)).unwrap()) .build(); transaction .as_advanced_builder() @@ -214,7 +214,7 @@ impl Spec for ChainFork4 { .unwrap() .to_entity() .as_builder() - .capacity(capacity_bytes!(1).into()) + .capacity(capacity_bytes!(1)) .build(); transaction .as_advanced_builder() @@ -402,11 +402,7 @@ impl Spec for ChainFork7 { let block = node1.new_block(None, None, None); let transaction = node1.new_transaction_spend_tip_cellbase(); let input = transaction.inputs().as_reader().get(0).unwrap().to_entity(); - let previous_output = input - .previous_output() - .as_builder() - .index(999u32.into()) - .build(); + let previous_output = input.previous_output().as_builder().index(999u32).build(); let input = input.as_builder().previous_output(previous_output).build(); let invalid_transaction = transaction .as_advanced_builder() @@ -576,7 +572,7 @@ impl Spec for ForksContainSameUncle { let block_b = node_b .new_block_builder(None, None, None) .set_uncles(vec![uncle.as_uncle()]) - .timestamp((block_a.timestamp() + 2).into()) + .timestamp(block_a.timestamp() + 2) .build(); node_a.submit_block(&block_a); node_b.submit_block(&block_b); diff --git a/test/src/specs/sync/invalid_locator_size.rs b/test/src/specs/sync/invalid_locator_size.rs index 44af4a7143..ed7091959c 100644 --- a/test/src/specs/sync/invalid_locator_size.rs +++ b/test/src/specs/sync/invalid_locator_size.rs @@ -27,7 +27,7 @@ impl Spec for InvalidLocatorSize { let message = SyncMessage::new_builder() .set( GetHeaders::new_builder() - .block_locator_hashes(hashes.into()) + .block_locator_hashes(hashes) .build(), ) .build() diff --git a/test/src/specs/tx_pool/collision.rs b/test/src/specs/tx_pool/collision.rs index 3a870e7328..0f05d7f580 100644 --- a/test/src/specs/tx_pool/collision.rs +++ b/test/src/specs/tx_pool/collision.rs @@ -4,8 +4,11 @@ use crate::util::check::{ use crate::utils::{assert_send_transaction_fail, blank, commit, propose}; use crate::{Node, Spec}; use ckb_types::bytes::Bytes; -use ckb_types::core::{capacity_bytes, Capacity, TransactionView}; use ckb_types::prelude::*; +use ckb_types::{ + core::{capacity_bytes, Capacity, TransactionView}, + packed, +}; // Convention: // * `tx1` and `tx2` are cousin transactions, with the same transaction content, except the @@ -213,7 +216,7 @@ fn cousin_txs_with_same_hash_different_witness_hash( let tx1 = node.new_transaction_spend_tip_cellbase(); let tx2 = tx1 .as_advanced_builder() - .witness(Default::default()) + .witness(packed::Bytes::default()) .build(); assert_eq!(tx1.hash(), tx2.hash()); assert_eq!(tx1.proposal_short_id(), tx2.proposal_short_id()); diff --git a/test/src/specs/tx_pool/dead_cell_deps.rs b/test/src/specs/tx_pool/dead_cell_deps.rs index 0b7816bf84..77ae8fb619 100644 --- a/test/src/specs/tx_pool/dead_cell_deps.rs +++ b/test/src/specs/tx_pool/dead_cell_deps.rs @@ -50,7 +50,7 @@ impl Spec for CellBeingCellDepThenSpentInSameBlockTestSubmitBlock { let tx_c = { let tx = always_success_transaction(node0, input_c); let cell_dep_to_tx_a = CellDepBuilder::default() - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .out_point(OutPoint::new(tx_a.hash(), 0)) .build(); tx.as_advanced_builder().cell_dep(cell_dep_to_tx_a).build() @@ -122,7 +122,7 @@ impl Spec for CellBeingSpentThenCellDepInSameBlockTestSubmitBlock { let tx_c = { let tx = always_success_transaction(node0, input_c); let cell_dep_to_tx_a = CellDepBuilder::default() - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .out_point(OutPoint::new(tx_a.hash(), 0)) .build(); tx.as_advanced_builder().cell_dep(cell_dep_to_tx_a).build() @@ -208,7 +208,7 @@ impl Spec for CellBeingCellDepAndSpentInSameBlockTestGetBlockTemplate { let mut tx_c = { let tx = always_success_transaction(node0, input_c); let cell_dep_to_tx_a = CellDepBuilder::default() - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .out_point(OutPoint::new(tx_a.hash(), 0)) .build(); tx.as_advanced_builder().cell_dep(cell_dep_to_tx_a).build() diff --git a/test/src/specs/tx_pool/different_txs_with_same_input.rs b/test/src/specs/tx_pool/different_txs_with_same_input.rs index 52ce496367..cdd1abf8dd 100644 --- a/test/src/specs/tx_pool/different_txs_with_same_input.rs +++ b/test/src/specs/tx_pool/different_txs_with_same_input.rs @@ -22,7 +22,7 @@ impl Spec for DifferentTxsWithSameInputWithOutRBF { // Set tx2 fee to a higher value, tx1 capacity is 100, set tx2 capacity to 80 for +20 fee. let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).into()) + .capacity(capacity_bytes!(80)) .build(); let tx2 = tx2_temp diff --git a/test/src/specs/tx_pool/limit.rs b/test/src/specs/tx_pool/limit.rs index ba9a84df80..60e2090ba2 100644 --- a/test/src/specs/tx_pool/limit.rs +++ b/test/src/specs/tx_pool/limit.rs @@ -83,7 +83,7 @@ impl Spec for TxPoolLimitAncestorCount { }; let cell_dep = CellDepBuilder::default() - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .out_point(OutPoint::new(tx_a.hash(), 0)) .build(); diff --git a/test/src/specs/tx_pool/orphan_tx.rs b/test/src/specs/tx_pool/orphan_tx.rs index cb6820d7ce..ac7605dc40 100644 --- a/test/src/specs/tx_pool/orphan_tx.rs +++ b/test/src/specs/tx_pool/orphan_tx.rs @@ -136,7 +136,7 @@ fn build_tx_chain( let script = node0.always_success_script(); let new_output1 = CellOutputBuilder::default() - .capacity(capacity_bytes!(200).into()) + .capacity(capacity_bytes!(200)) .lock(script.clone()) .build(); let new_output2 = new_output1.clone(); @@ -158,7 +158,7 @@ fn build_tx_chain( let cell_dep = node0.always_success_cell_dep(); let final_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).into()) + .capacity(capacity_bytes!(80)) .lock(script) .build(); let final_tx = TransactionBuilder::default() @@ -373,7 +373,7 @@ impl Spec for TxPoolOrphanDoubleSpend { let script = node0.always_success_script(); let new_output1 = CellOutputBuilder::default() - .capacity(capacity_bytes!(200).into()) + .capacity(capacity_bytes!(200)) .lock(script) .build(); let new_output2 = new_output1.clone(); diff --git a/test/src/specs/tx_pool/pool_reconcile.rs b/test/src/specs/tx_pool/pool_reconcile.rs index 277e433f8e..6377216689 100644 --- a/test/src/specs/tx_pool/pool_reconcile.rs +++ b/test/src/specs/tx_pool/pool_reconcile.rs @@ -161,7 +161,7 @@ impl Spec for PoolResolveConflictAfterReorg { .build() }]) .set_outputs(vec![CellOutputBuilder::default() - .capacity(capacity_bytes!(99).into()) + .capacity(capacity_bytes!(99)) .build()]) .build(); diff --git a/test/src/specs/tx_pool/replace.rs b/test/src/specs/tx_pool/replace.rs index 2b64548f69..2ff08a1f72 100644 --- a/test/src/specs/tx_pool/replace.rs +++ b/test/src/specs/tx_pool/replace.rs @@ -28,7 +28,7 @@ impl Spec for RbfEnable { let tx1 = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output]).build(); @@ -59,7 +59,7 @@ impl Spec for RbfBasic { let tx1 = node0.new_transaction(tx_hash_0.clone()); let tx2_temp = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(99).into()) + .capacity(capacity_bytes!(99)) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output]).build(); @@ -76,7 +76,7 @@ impl Spec for RbfBasic { // Set tx2 fee to a higher value, tx1 capacity is 99, set tx2 capacity to 95 for +4 fee. let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(95).into()) + .capacity(capacity_bytes!(95)) .build(); let tx2 = tx2_temp @@ -230,14 +230,14 @@ impl Spec for RbfSameInputwithLessFee { let tx2_temp = node0.new_transaction(tx_hash_0); let output1 = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).into()) + .capacity(capacity_bytes!(80)) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output1]).build(); // Set tx2 fee to a lower value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(90).into()) + .capacity(capacity_bytes!(90)) .build(); let tx2 = tx2_temp @@ -300,7 +300,7 @@ impl Spec for RbfTooManyDescendants { // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx2 = tx0_temp @@ -363,7 +363,7 @@ impl Spec for RbfContainNewTx { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx2 = clone_tx @@ -438,7 +438,7 @@ impl Spec for RbfContainInvalidInput { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx2 = clone_tx @@ -492,7 +492,7 @@ impl Spec for RbfChildPayForParent { let max_count = 5; let output5 = CellOutputBuilder::default() - .capacity(capacity_bytes!(50).into()) + .capacity(capacity_bytes!(50)) .build(); while txs.len() <= max_count { @@ -524,7 +524,7 @@ impl Spec for RbfChildPayForParent { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value, but not enough to pay for tx4 let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let new_tx = clone_tx @@ -552,7 +552,7 @@ impl Spec for RbfChildPayForParent { // let's try a new transaction with new higher fee let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(45).into()) + .capacity(capacity_bytes!(45)) .build(); let new_tx_ok = clone_tx .as_advanced_builder() @@ -609,7 +609,7 @@ impl Spec for RbfContainInvalidCells { // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx2 = clone_tx .as_advanced_builder() @@ -688,7 +688,7 @@ impl Spec for RbfRejectReplaceProposed { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx1_hash = txs[2].hash(); @@ -798,7 +798,7 @@ impl Spec for RbfReplaceProposedSuccess { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).into()) + .capacity(capacity_bytes!(70)) .build(); let tx1_hash = txs[2].hash(); @@ -893,7 +893,7 @@ impl Spec for RbfConcurrency { ]; for fee in fees.iter() { let tx2_temp = node0.new_transaction(tx_hash_0.clone()); - let output = CellOutputBuilder::default().capacity(fee.into()).build(); + let output = CellOutputBuilder::default().capacity(fee).build(); let tx2 = tx2_temp .as_advanced_builder() @@ -974,7 +974,7 @@ impl Spec for RbfCellDepsCheck { // Create a child transaction with celldep let tx = always_success_transaction(node0, input_c); let cell_dep_to_last = CellDepBuilder::default() - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .out_point(OutPoint::new(prev.hash(), 0)) .build(); let tx_c = tx @@ -988,7 +988,7 @@ impl Spec for RbfCellDepsCheck { // Create a new transaction for cell dep with high fee let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).into()) + .capacity(capacity_bytes!(80)) .build(); let new_tx = tx_a .as_advanced_builder() @@ -1024,7 +1024,7 @@ fn run_spec_send_conflict_relay(nodes: &mut [Node]) { let tx1 = node0.new_transaction(tx_hash_0.clone()); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(90).into()) + .capacity(capacity_bytes!(90)) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output]).build(); @@ -1050,7 +1050,7 @@ fn run_spec_send_conflict_relay(nodes: &mut [Node]) { // node0 will accept it and node1 will reject it and put it in conflicts pool let tx2_temp = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(95).into()) + .capacity(capacity_bytes!(95)) .build(); let tx2 = tx2_temp diff --git a/test/src/specs/tx_pool/send_defected_binary.rs b/test/src/specs/tx_pool/send_defected_binary.rs index a28b8d8f26..cc5667af28 100644 --- a/test/src/specs/tx_pool/send_defected_binary.rs +++ b/test/src/specs/tx_pool/send_defected_binary.rs @@ -55,10 +55,10 @@ impl Spec for SendDefectedBinary { let cell_dep = CellDep::new_builder() .out_point(secp_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(5000).into()) + .capacity(capacity_bytes!(5000)) .lock(node.always_success_script()) .build(); let data = include_bytes!("../../../../script/testdata/defected_binary"); @@ -66,12 +66,12 @@ impl Spec for SendDefectedBinary { .cell_dep(cell_dep.clone()) .inputs(inputs.clone()) .output(output.clone()) - .output_data(data[..].into()) + .output_data(&data[..]) .build(); let tx_hash = tx.hash(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build(); let witness_len = witness.as_slice().len() as u64; let message = { @@ -86,14 +86,14 @@ impl Spec for SendDefectedBinary { let sig = self.privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).into()) + .lock(Some(Bytes::from(sig.serialize()))) .build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .inputs(inputs) .output(output) - .output_data(data[..].into()) - .witness(witness.as_bytes().into()) + .output_data(&data[..]) + .witness(witness.as_bytes()) .build(); info!("Send 1 secp tx with defected binary"); diff --git a/test/src/specs/tx_pool/send_large_cycles_tx.rs b/test/src/specs/tx_pool/send_large_cycles_tx.rs index 1912cc3cd6..05c141cff6 100644 --- a/test/src/specs/tx_pool/send_large_cycles_tx.rs +++ b/test/src/specs/tx_pool/send_large_cycles_tx.rs @@ -13,7 +13,7 @@ use ckb_types::{ capacity_bytes, BlockView, Capacity, DepType, ScriptHashType, TransactionBuilder, TransactionView, }, - packed::{CellDep, CellInput, CellOutput, OutPoint, Script, WitnessArgs}, + packed::{self, CellDep, CellInput, CellOutput, OutPoint, Script, WitnessArgs}, prelude::*, H256, }; @@ -325,13 +325,13 @@ impl RandomKey { fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView { let secp_out_point = OutPoint::new(node.dep_group_tx_hash(), 0); let lock = Script::new_builder() - .args(lock_arg.into()) - .code_hash(type_lock_script_code_hash().into()) - .hash_type(ScriptHashType::Type.into()) + .args(lock_arg) + .code_hash(type_lock_script_code_hash()) + .hash_type(ScriptHashType::Type) .build(); let cell_dep = CellDep::new_builder() .out_point(secp_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let input1 = { let block = node.get_tip_block(); @@ -339,18 +339,18 @@ fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView CellInput::new(OutPoint::new(cellbase_hash, 0), 0) }; let output1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock) .build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .input(input1) .output(output1) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); let tx_hash: H256 = tx.hash().into(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build(); let witness_len = witness.as_slice().len() as u64; let message = { @@ -365,9 +365,7 @@ fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView let sig = privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).into()) + .lock(Some(Bytes::from(sig.serialize()))) .build(); - tx.as_advanced_builder() - .witness(witness.as_bytes().into()) - .build() + tx.as_advanced_builder().witness(witness.as_bytes()).build() } diff --git a/test/src/specs/tx_pool/send_low_fee_rate_tx.rs b/test/src/specs/tx_pool/send_low_fee_rate_tx.rs index 03341cade9..40a3ebcc6a 100644 --- a/test/src/specs/tx_pool/send_low_fee_rate_tx.rs +++ b/test/src/specs/tx_pool/send_low_fee_rate_tx.rs @@ -44,7 +44,7 @@ impl Spec for SendLowFeeRateTx { .get(0) .unwrap() .as_builder() - .capacity(capacity.into()) + .capacity(capacity) .build(); let tx_low_fee = tx_low_fee .data() @@ -64,7 +64,7 @@ impl Spec for SendLowFeeRateTx { .get(0) .unwrap() .as_builder() - .capacity(capacity.safe_sub(1000u32).unwrap().into()) + .capacity(capacity.safe_sub(1000u32).unwrap()) .build(); let tx_high_fee = tx_high_fee .data() diff --git a/test/src/specs/tx_pool/send_multisig_secp_tx.rs b/test/src/specs/tx_pool/send_multisig_secp_tx.rs index 31c10a2e9f..5eb2c96694 100644 --- a/test/src/specs/tx_pool/send_multisig_secp_tx.rs +++ b/test/src/specs/tx_pool/send_multisig_secp_tx.rs @@ -10,7 +10,7 @@ use ckb_resource::CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL; use ckb_types::{ bytes::Bytes, core::{capacity_bytes, Capacity, DepType, ScriptHashType, TransactionBuilder}, - packed::{CellDep, CellInput, CellOutput, OutPoint, WitnessArgs}, + packed::{self, CellDep, CellInput, CellOutput, OutPoint, WitnessArgs}, prelude::*, H160, H256, }; @@ -50,10 +50,10 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { let cell_dep = CellDep::new_builder() .out_point(secp_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(node.always_success_script()) .build(); let input = CellInput::new(OutPoint::new(cellbase_hash, 0), 0); @@ -61,7 +61,7 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { .cell_dep(cell_dep.clone()) .input(input.clone()) .output(output.clone()) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); let multi_sign_script = gen_multi_sign_script(&self.keys, self.keys.len() as u8, 0); let tx_hash = tx.hash(); @@ -69,7 +69,7 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { let mut lock = multi_sign_script.to_vec(); lock.extend(vec![0u8; 65 * self.keys.len()]); WitnessArgs::new_builder() - .lock(Some(Bytes::from(lock)).into()) + .lock(Some(Bytes::from(lock))) .build() }; let witness_len = witness.as_slice().len() as u64; @@ -88,16 +88,13 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { let sig = key.sign_recoverable(&message).expect("sign"); lock.extend_from_slice(&sig.serialize()); }); - let witness = witness - .as_builder() - .lock(Some(Bytes::from(lock)).into()) - .build(); + let witness = witness.as_builder().lock(Some(Bytes::from(lock))).build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .input(input) .output(output) - .output_data(Default::default()) - .witness(witness.as_bytes().into()) + .output_data(packed::Bytes::default()) + .witness(witness.as_bytes()) .build(); info!("Send 1 multisig tx use dep group"); diff --git a/test/src/specs/tx_pool/send_secp_tx.rs b/test/src/specs/tx_pool/send_secp_tx.rs index 4e7c9b0c9e..f8970c236c 100644 --- a/test/src/specs/tx_pool/send_secp_tx.rs +++ b/test/src/specs/tx_pool/send_secp_tx.rs @@ -7,7 +7,7 @@ use ckb_logger::info; use ckb_types::{ bytes::Bytes, core::{capacity_bytes, Capacity, DepType, ScriptHashType, TransactionBuilder}, - packed::{CellDep, CellInput, CellOutput, OutPoint, Script, WitnessArgs}, + packed::{self, CellDep, CellInput, CellOutput, OutPoint, Script, WitnessArgs}, prelude::*, H256, }; @@ -47,10 +47,10 @@ impl Spec for SendSecpTxUseDepGroup { let cell_dep = CellDep::new_builder() .out_point(secp_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(node.always_success_script()) .build(); let input = CellInput::new(OutPoint::new(cellbase_hash, 0), 0); @@ -58,12 +58,12 @@ impl Spec for SendSecpTxUseDepGroup { .cell_dep(cell_dep.clone()) .input(input.clone()) .output(output.clone()) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); let tx_hash = tx.hash(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build(); let witness_len = witness.as_slice().len() as u64; let message = { @@ -78,14 +78,14 @@ impl Spec for SendSecpTxUseDepGroup { let sig = self.privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).into()) + .lock(Some(Bytes::from(sig.serialize()))) .build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .input(input) .output(output) - .output_data(Default::default()) - .witness(witness.as_bytes().into()) + .output_data(packed::Bytes::default()) + .witness(witness.as_bytes()) .build(); info!("Send 1 secp tx use dep group"); @@ -140,7 +140,7 @@ impl Spec for CheckTypical2In2OutTx { let cell_dep = CellDep::new_builder() .out_point(secp_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let input1 = { let block = node.get_tip_block(); @@ -154,16 +154,16 @@ impl Spec for CheckTypical2In2OutTx { CellInput::new(OutPoint::new(cellbase_hash, 0), 0) }; let lock = Script::new_builder() - .args((&self.lock_arg).into()) - .code_hash(type_lock_script_code_hash().into()) - .hash_type(ScriptHashType::Type.into()) + .args(&self.lock_arg) + .code_hash(type_lock_script_code_hash()) + .hash_type(ScriptHashType::Type) .build(); let output1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock.clone()) .build(); let output2 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).into()) + .capacity(capacity_bytes!(100)) .lock(lock) .build(); let tx = TransactionBuilder::default() @@ -172,13 +172,13 @@ impl Spec for CheckTypical2In2OutTx { .input(input2) .output(output1) .output(output2) - .output_data(Default::default()) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) + .output_data(packed::Bytes::default()) .build(); let tx_hash: H256 = tx.hash().into(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).into()) + .lock(Some(Bytes::from(vec![0u8; 65]))) .build(); let witness_len = witness.as_slice().len() as u64; let witness2 = Bytes::new(); @@ -197,12 +197,12 @@ impl Spec for CheckTypical2In2OutTx { let sig = self.privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).into()) + .lock(Some(Bytes::from(sig.serialize()))) .build(); let tx = tx .as_advanced_builder() - .witness(witness.as_bytes().into()) - .witness(witness2.into()) + .witness(witness.as_bytes()) + .witness(witness2) .build(); info!("Send 1 secp tx use dep group"); diff --git a/test/src/txo.rs b/test/src/txo.rs index 9d3697d98c..98bcc997ae 100644 --- a/test/src/txo.rs +++ b/test/src/txo.rs @@ -1,5 +1,5 @@ use ckb_types::core::{Capacity, TransactionBuilder, TransactionView}; -use ckb_types::packed::{CellDep, CellInput, CellOutput, OutPoint, Script, ScriptOpt}; +use ckb_types::packed::{self, CellDep, CellInput, CellOutput, OutPoint, Script, ScriptOpt}; use ckb_types::prelude::*; use rand::{thread_rng, Rng}; use std::collections::HashMap; @@ -52,7 +52,7 @@ impl TXO { pub fn to_equivalent_output(&self) -> CellOutput { CellOutput::new_builder() .lock(self.lock()) - .capacity(self.capacity().into()) + .capacity(self.capacity()) .build() } @@ -145,7 +145,7 @@ impl TXOSet { .cell_deps(cell_deps.clone()) .input(txo.to_input()) .output(txo.to_equivalent_output()) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build() }) .collect() @@ -166,13 +166,13 @@ impl TXOSet { let output = txo .to_equivalent_output() .as_builder() - .capacity(actual_capacity.into()) + .capacity(actual_capacity) .build(); TransactionBuilder::default() .cell_deps(cell_deps.clone()) .input(txo.to_input()) .output(output) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build() }) .collect() @@ -185,7 +185,7 @@ impl TXOSet { let mut outputs = Vec::new(); while outputs.len() < EXPLODE_LIMIT { if input_capacity < 2 * minimal_capacity || outputs.len() == EXPLODE_LIMIT { - outputs.push(minimal.as_builder().capacity(input_capacity.into()).build()); + outputs.push(minimal.as_builder().capacity(input_capacity).build()); break; } else { input_capacity -= minimal_capacity; @@ -214,7 +214,7 @@ impl From<&TransactionView> for TXOSet { .map(move |(i, output)| { let out_point = OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(i.into()) + .index(i) .build(); TXO::new(out_point, output) }); diff --git a/test/src/util/cell.rs b/test/src/util/cell.rs index 70608c1123..37aaea9c03 100644 --- a/test/src/util/cell.rs +++ b/test/src/util/cell.rs @@ -102,6 +102,6 @@ pub fn as_output(cell: &CellMeta) -> CellOutput { CellOutput::new_builder() .lock(cell.cell_output.lock()) .type_(cell.cell_output.type_()) - .capacity(cell.capacity().into()) + .capacity(cell.capacity()) .build() } diff --git a/test/src/util/transaction.rs b/test/src/util/transaction.rs index bf5f7637eb..230251d56c 100644 --- a/test/src/util/transaction.rs +++ b/test/src/util/transaction.rs @@ -20,7 +20,7 @@ pub fn always_success_transaction(node: &Node, cell: &CellMeta) -> TransactionVi TransactionBuilder::default() .input(as_input(cell)) .output(as_output(cell)) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .cell_dep(node.always_success_cell_dep()) .build() } @@ -49,7 +49,7 @@ pub fn always_success_transactions_with_rand_data( pub fn send_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) { let relay_tx = packed::RelayTransaction::new_builder() - .cycles(cycles.pack()) + .cycles(cycles) .transaction(tx.data()) .build(); @@ -71,7 +71,7 @@ pub fn relay_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) { let tx_hashes_msg = packed::RelayMessage::new_builder() .set( packed::RelayTransactionHashes::new_builder() - .tx_hashes(vec![tx.hash()].into()) + .tx_hashes(vec![tx.hash()]) .build(), ) .build(); @@ -85,7 +85,7 @@ pub fn relay_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) { assert!(ret, "node should ask for tx"); let relay_tx = packed::RelayTransaction::new_builder() - .cycles(cycles.into()) + .cycles(cycles) .transaction(tx.data()) .build(); diff --git a/test/src/utils.rs b/test/src/utils.rs index 263ca9291e..c566e874c9 100644 --- a/test/src/utils.rs +++ b/test/src/utils.rs @@ -55,8 +55,7 @@ pub fn build_block_transactions(block: &BlockView) -> Bytes { .into_iter() .map(|view| view.data()) .skip(1) - .collect::>() - .into(), + .collect::>(), ) .build(); @@ -72,13 +71,7 @@ pub fn build_header(header: &HeaderView) -> Bytes { pub fn build_headers(headers: &[HeaderView]) -> Bytes { let send_headers = SendHeaders::new_builder() - .headers( - headers - .iter() - .map(|view| view.data()) - .collect::>() - .into(), - ) + .headers(headers.iter().map(|view| view.data()).collect::>()) .build(); SyncMessage::new_builder() @@ -100,8 +93,7 @@ pub fn build_get_blocks(hashes: &[Byte32]) -> Bytes { hashes .iter() .map(ToOwned::to_owned) - .collect::>() - .into(), + .collect::>(), ) .build(); @@ -116,13 +108,13 @@ pub fn build_relay_txs(transactions: &[(TransactionView, u64)]) -> Bytes { .iter() .map(|(tx, cycles)| { RelayTransaction::new_builder() - .cycles(cycles.into()) + .cycles(cycles) .transaction(tx.data()) .build() }) .collect::>(); let txs = RelayTransactions::new_builder() - .transactions(transactions.into()) + .transactions(transactions) .build(); RelayMessage::new_builder().set(txs).build().as_bytes() @@ -134,8 +126,7 @@ pub fn build_relay_tx_hashes(hashes: &[Byte32]) -> Bytes { hashes .iter() .map(ToOwned::to_owned) - .collect::>() - .into(), + .collect::>(), ) .build(); diff --git a/tx-pool/src/block_assembler/mod.rs b/tx-pool/src/block_assembler/mod.rs index 661f084b75..dfa9ce3c02 100644 --- a/tx-pool/src/block_assembler/mod.rs +++ b/tx-pool/src/block_assembler/mod.rs @@ -459,9 +459,9 @@ impl BlockAssembler { ) -> CellbaseWitness { let hash_type: ScriptHashType = config.hash_type.clone().into(); let cellbase_lock = Script::new_builder() - .args(config.args.as_bytes().into()) - .code_hash((&config.code_hash).into()) - .hash_type(hash_type.into()) + .args(config.args.as_bytes()) + .code_hash(&config.code_hash) + .hash_type(hash_type) .build(); let tip = snapshot.tip_header(); @@ -480,7 +480,7 @@ impl BlockAssembler { CellbaseWitness::new_builder() .lock(cellbase_lock) - .message(message.into()) + .message(message) .build() } @@ -502,11 +502,11 @@ impl BlockAssembler { })?; let input = CellInput::new_cellbase_input(candidate_number); let output = CellOutput::new_builder() - .capacity(block_reward.total.into()) + .capacity(block_reward.total) .lock(target_lock) .build(); - let witness = cellbase_witness.as_bytes().into(); + let witness = cellbase_witness.as_bytes(); let no_finalization_target = candidate_number <= snapshot.consensus().finalization_delay_length(); let tx_builder = TransactionBuilder::default().input(input).witness(witness); @@ -564,30 +564,28 @@ impl BlockAssembler { let block = if let Some(extension) = extension_opt { packed::BlockV1::new_builder() .header(header) - .transactions(vec![cellbase].into()) + .transactions(vec![cellbase]) .uncles( uncles .iter() .map(|u| u.data()) - .collect::>() - .into(), + .collect::>(), ) - .proposals(proposals.cloned().collect::>().into()) + .proposals(proposals.cloned().collect::>()) .extension(extension) .build() .as_v0() } else { packed::Block::new_builder() .header(header) - .transactions(vec![cellbase].into()) + .transactions(vec![cellbase]) .uncles( uncles .iter() .map(|u| u.data()) - .collect::>() - .into(), + .collect::>(), ) - .proposals(proposals.cloned().collect::>().into()) + .proposals(proposals.cloned().collect::>()) .build() }; block.serialized_size_without_uncle_proposals() diff --git a/tx-pool/src/block_assembler/tests.rs b/tx-pool/src/block_assembler/tests.rs index 8c66d154ca..4b9f15a5fd 100644 --- a/tx-pool/src/block_assembler/tests.rs +++ b/tx-pool/src/block_assembler/tests.rs @@ -27,8 +27,12 @@ fn test_candidate_uncles_max_size() { for i in 0..(MAX_CANDIDATE_UNCLES + 3) { let number = i as BlockNumber; let block = BlockBuilder::default() - .number(number.into()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 10000).into()) + .number(number) + .epoch(EpochNumberWithFraction::new( + number / 1000, + number % 1000, + 10000, + )) .build() .as_uncle(); blocks.push(block); @@ -57,7 +61,7 @@ fn test_candidate_uncles_max_per_height() { let mut blocks = Vec::new(); for i in 0..(MAX_PER_HEIGHT + 3) { let block = BlockBuilder::default() - .timestamp((i as u64).into()) + .timestamp(i as u64) .build() .as_uncle(); blocks.push(block); diff --git a/tx-pool/src/component/tests/chunk.rs b/tx-pool/src/component/tests/chunk.rs index 39df2dc1cd..9f4f2f1a31 100644 --- a/tx-pool/src/component/tests/chunk.rs +++ b/tx-pool/src/component/tests/chunk.rs @@ -2,7 +2,6 @@ use crate::component::tests::util::build_tx; use crate::component::verify_queue::{Entry, VerifyQueue}; use ckb_network::SessionId; use ckb_types::core::TransactionBuilder; -use ckb_types::prelude::Pack; use ckb_types::H256; use tokio::select; use tokio::sync::watch; @@ -95,22 +94,22 @@ async fn test_verify_different_cycles() { let remote = |cycles| Some((cycles, SessionId::default())); - let tx0 = build_tx(vec![(&H256([0; 32]).pack(), 0)], 1); + let tx0 = build_tx(vec![(&H256([0; 32]).into(), 0)], 1); assert!(queue.add_tx(tx0.clone(), remote(1001)).unwrap()); sleep(std::time::Duration::from_millis(100)).await; - let tx1 = build_tx(vec![(&H256([1; 32]).pack(), 0)], 1); + let tx1 = build_tx(vec![(&H256([1; 32]).into(), 0)], 1); assert!(queue .add_tx(tx1.clone(), remote(MAX_TX_VERIFY_CYCLES + 1)) .unwrap()); sleep(std::time::Duration::from_millis(100)).await; - let tx2 = build_tx(vec![(&H256([2; 32]).pack(), 0)], 1); + let tx2 = build_tx(vec![(&H256([2; 32]).into(), 0)], 1); assert!(queue.add_tx(tx2.clone(), remote(1001)).unwrap()); sleep(std::time::Duration::from_millis(100)).await; // now queue should be sorted by time (tx1, tx2) - let tx3 = build_tx(vec![(&H256([3; 32]).pack(), 0)], 1); + let tx3 = build_tx(vec![(&H256([3; 32]).into(), 0)], 1); assert!(queue.add_tx(tx3.clone(), remote(1001)).unwrap()); sleep(std::time::Duration::from_millis(100)).await; diff --git a/tx-pool/src/component/tests/proposed.rs b/tx-pool/src/component/tests/proposed.rs index 86f24b9704..ecac84398b 100644 --- a/tx-pool/src/component/tests/proposed.rs +++ b/tx-pool/src/component/tests/proposed.rs @@ -526,27 +526,27 @@ fn test_dep_group() { .input(CellInput::new(OutPoint::new(h256!("0x2").into(), 0), 0)) .output( CellOutput::new_builder() - .capacity(Capacity::bytes(1000).unwrap().into()) + .capacity(Capacity::bytes(1000).unwrap()) .build(), ) - .output_data((&tx2_data).into()) + .output_data(&tx2_data) .build(); let tx2_out_point = OutPoint::new(tx2.hash(), 0); // Transaction use dep group let dep = CellDep::new_builder() .out_point(tx2_out_point.clone()) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let tx3 = TransactionBuilder::default() .cell_dep(dep) .input(CellInput::new(OutPoint::new(h256!("0x3").into(), 0), 0)) .output( CellOutput::new_builder() - .capacity(Capacity::bytes(3).unwrap().into()) + .capacity(Capacity::bytes(3).unwrap()) .build(), ) - .output_data(Bytes::new().into()) + .output_data(Bytes::new()) .build(); let tx3_out_point = OutPoint::new(tx3.hash(), 0); @@ -716,12 +716,12 @@ fn test_container_bench_add_limits() { .previous_output( OutPoint::new_builder() .tx_hash(prev_tx.transaction().hash()) - .index(0u32.into()) + .index(0u32) .build(), ) .build(), ) - .witness(Bytes::new().into()) + .witness(Bytes::new()) .build(), rng.gen_range(0..1000), Capacity::shannons(200), @@ -748,26 +748,26 @@ fn test_pool_map_bench() { let mut time_spend = vec![]; for i in 0..20000 { let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).into()) - .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).into()) + .code_hash(H256(rand::random())) + .hash_type(ScriptHashType::Data) + .args(Bytes::from(b"lock_script1".to_vec())) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).into()) - .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).into()) + .code_hash(H256(rand::random())) + .hash_type(ScriptHashType::Data) + .args(Bytes::from(b"type_script1".to_vec())) .build(); let tx = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).into()) + .capacity(capacity_bytes!(1000)) .lock(lock_script1) - .type_(Some(type_script1).into()) + .type_(Some(type_script1)) .build(), ) - .output_data(Default::default()) + .output_data(packed::Bytes::default()) .build(); let entry = TxEntry::dummy_resolve( diff --git a/tx-pool/src/component/tests/score_key.rs b/tx-pool/src/component/tests/score_key.rs index 2a3660be7b..0155fa710c 100644 --- a/tx-pool/src/component/tests/score_key.rs +++ b/tx-pool/src/component/tests/score_key.rs @@ -111,12 +111,12 @@ fn test_remove_entry() { .previous_output( OutPoint::new_builder() .tx_hash(tx1.transaction().hash()) - .index(0u32.into()) + .index(0u32) .build(), ) .build(), ) - .witness(Bytes::new().into()) + .witness(Bytes::new()) .build(), 200, Capacity::shannons(200), @@ -129,12 +129,12 @@ fn test_remove_entry() { .previous_output( OutPoint::new_builder() .tx_hash(tx2.transaction().hash()) - .index(0u32.into()) + .index(0u32) .build(), ) .build(), ) - .witness(Bytes::new().into()) + .witness(Bytes::new()) .build(), 200, Capacity::shannons(200), @@ -184,12 +184,12 @@ fn test_remove_entry_and_descendants() { .previous_output( OutPoint::new_builder() .tx_hash(tx1.transaction().hash()) - .index(0u32.into()) + .index(0u32) .build(), ) .build(), ) - .witness(Bytes::new().into()) + .witness(Bytes::new()) .build(), 200, Capacity::shannons(200), @@ -202,12 +202,12 @@ fn test_remove_entry_and_descendants() { .previous_output( OutPoint::new_builder() .tx_hash(tx2.transaction().hash()) - .index(0u32.into()) + .index(0u32) .build(), ) .build(), ) - .witness(Bytes::new().into()) + .witness(Bytes::new()) .build(), 200, Capacity::shannons(200), diff --git a/tx-pool/src/component/tests/util.rs b/tx-pool/src/component/tests/util.rs index aa04530696..d55d37262e 100644 --- a/tx-pool/src/component/tests/util.rs +++ b/tx-pool/src/component/tests/util.rs @@ -19,7 +19,7 @@ pub(crate) fn build_tx(inputs: Vec<(&Byte32, u32)>, outputs_len: usize) -> Trans ) .outputs((0..outputs_len).map(|i| { CellOutput::new_builder() - .capacity(Capacity::bytes(i + 1).unwrap().into()) + .capacity(Capacity::bytes(i + 1).unwrap()) .build() })) .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) @@ -44,7 +44,7 @@ pub(crate) fn build_tx_with_dep( })) .outputs((0..outputs_len).map(|i| { CellOutput::new_builder() - .capacity(Capacity::bytes(i + 1).unwrap().into()) + .capacity(Capacity::bytes(i + 1).unwrap()) .build() })) .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) @@ -65,7 +65,7 @@ pub(crate) fn build_tx_with_header_dep( .set_header_deps(header_deps) .outputs((0..outputs_len).map(|i| { CellOutput::new_builder() - .capacity(Capacity::bytes(i + 1).unwrap().into()) + .capacity(Capacity::bytes(i + 1).unwrap()) .build() })) .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) diff --git a/util/dao/src/tests.rs b/util/dao/src/tests.rs index 586d8b50ba..7ac4ecb24f 100644 --- a/util/dao/src/tests.rs +++ b/util/dao/src/tests.rs @@ -63,8 +63,8 @@ fn check_dao_data_calculation() { let parent_number = 12345; let epoch = EpochNumberWithFraction::new(12, 345, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.into()) - .epoch(epoch.into()) + .number(parent_number) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(500_000_000_123_000), @@ -95,7 +95,7 @@ fn check_initial_dao_data_calculation() { let parent_number = 0; let parent_header = HeaderBuilder::default() - .number(parent_number.into()) + .number(parent_number) .dao(pack_dao_data( 10_000_000_000_000_000, Capacity::shannons(500_000_000_000_000), @@ -127,8 +127,8 @@ fn check_first_epoch_block_dao_data_calculation() { let parent_number = 12340; let epoch = EpochNumberWithFraction::new(12, 340, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.into()) - .epoch(epoch.into()) + .number(parent_number) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(500_000_000_123_000), @@ -160,8 +160,8 @@ fn check_dao_data_calculation_overflows() { let parent_number = 12345; let epoch = EpochNumberWithFraction::new(12, 345, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.into()) - .epoch(epoch.into()) + .number(parent_number) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(18_446_744_073_709_000_000), @@ -183,8 +183,8 @@ fn check_dao_data_calculation_with_transactions() { let parent_number = 12345; let epoch = EpochNumberWithFraction::new(12, 345, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.into()) - .epoch(epoch.into()) + .number(parent_number) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(500_000_000_123_000), @@ -196,16 +196,16 @@ fn check_dao_data_calculation_with_transactions() { let (_tmp_dir, store, parent_header) = prepare_store(&parent_header, None); let input_cell_data = Bytes::from("abcde"); let input_cell = CellOutput::new_builder() - .capacity(capacity_bytes!(10000).into()) + .capacity(capacity_bytes!(10000)) .build(); let output_cell_data = Bytes::from("abcde12345"); let output_cell = CellOutput::new_builder() - .capacity(capacity_bytes!(20000).into()) + .capacity(capacity_bytes!(20000)) .build(); let tx = TransactionBuilder::default() .output(output_cell) - .output_data(output_cell_data.into()) + .output_data(output_cell_data) .build(); let rtx = ResolvedTransaction { transaction: tx, @@ -235,16 +235,16 @@ fn check_dao_data_calculation_with_transactions() { fn check_withdraw_calculation() { let data = Bytes::from(vec![1; 10]); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(1000000).into()) + .capacity(capacity_bytes!(1000000)) .build(); let tx = TransactionBuilder::default() .output(output.clone()) - .output_data((&data).into()) + .output_data(&data) .build(); let epoch = EpochNumberWithFraction::new(1, 100, 1000); let deposit_header = HeaderBuilder::default() - .number(100.into()) - .epoch(epoch.into()) + .number(100) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_000_123_456, Default::default(), @@ -259,8 +259,8 @@ fn check_withdraw_calculation() { let epoch = EpochNumberWithFraction::new(1, 200, 1000); let withdrawing_header = HeaderBuilder::default() - .number(200.into()) - .epoch(epoch.into()) + .number(200) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_001_123_456, Default::default(), @@ -295,13 +295,13 @@ fn check_withdraw_calculation() { #[test] fn check_withdraw_calculation_overflows() { let output = CellOutput::new_builder() - .capacity(Capacity::shannons(18_446_744_073_709_550_000).into()) + .capacity(Capacity::shannons(18_446_744_073_709_550_000)) .build(); let tx = TransactionBuilder::default().output(output.clone()).build(); let epoch = EpochNumberWithFraction::new(1, 100, 1000); let deposit_header = HeaderBuilder::default() - .number(100.into()) - .epoch(epoch.into()) + .number(100) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_000_123_456, Default::default(), @@ -316,8 +316,8 @@ fn check_withdraw_calculation_overflows() { let epoch = EpochNumberWithFraction::new(1, 200, 1000); let withdrawing_header = HeaderBuilder::default() - .number(200.into()) - .epoch(epoch.into()) + .number(200) + .epoch(epoch) .dao(pack_dao_data( 10_000_000_001_123_456, Default::default(), diff --git a/util/gen-types/src/extension/calc_hash.rs b/util/gen-types/src/extension/calc_hash.rs index b552ca7e20..ff0b5a2e1c 100644 --- a/util/gen-types/src/extension/calc_hash.rs +++ b/util/gen-types/src/extension/calc_hash.rs @@ -17,7 +17,7 @@ where R: Reader<'r>, { fn calc_hash(&self) -> packed::Byte32 { - blake2b_256(self.as_slice()).pack() + blake2b_256(self.as_slice()).into() } } @@ -65,7 +65,7 @@ impl packed::CellOutput { if data.is_empty() { packed::Byte32::zero() } else { - blake2b_256(data).pack() + blake2b_256(data).into() } } } @@ -75,7 +75,7 @@ impl<'r> packed::BytesReader<'r> { /// /// Returns the empty hash if no data, otherwise, calculates the hash of the data and returns it. pub fn calc_raw_data_hash(&self) -> packed::Byte32 { - blake2b_256(self.raw_data()).pack() + blake2b_256(self.raw_data()).into() } } impl_calc_special_hash_for_entity!(Bytes, calc_raw_data_hash); @@ -116,7 +116,7 @@ impl<'r> packed::ProposalShortIdVecReader<'r> { blake2b.update(id.as_slice()); } blake2b.finalize(&mut ret); - ret.pack() + ret.into() } } } @@ -215,7 +215,7 @@ impl<'r> packed::UncleBlockVecReader<'r> { blake2b.update(uncle.calc_header_hash().as_slice()); } blake2b.finalize(&mut ret); - ret.pack() + ret.into() } } } diff --git a/util/gen-types/src/extension/capacity.rs b/util/gen-types/src/extension/capacity.rs index 7e958d49da..3970406295 100644 --- a/util/gen-types/src/extension/capacity.rs +++ b/util/gen-types/src/extension/capacity.rs @@ -71,7 +71,7 @@ impl packed::CellOutputBuilder { .transpose() .and_then(|y| y.unwrap_or_else(Capacity::zero).safe_add(x)) }) - .map(|x| self.capacity(x.into()).build()) + .map(|x| self.capacity(x).build()) } } diff --git a/util/gen-types/src/extension/shortcut.rs b/util/gen-types/src/extension/shortcut.rs index 6fcc732951..b10f9e68cd 100644 --- a/util/gen-types/src/extension/shortcut.rs +++ b/util/gen-types/src/extension/shortcut.rs @@ -48,14 +48,14 @@ impl packed::OutPoint { pub fn new(tx_hash: packed::Byte32, index: u32) -> Self { packed::OutPoint::new_builder() .tx_hash(tx_hash) - .index(index.into()) + .index(index) .build() } /// Creates a new null `OutPoint`. pub fn null() -> Self { packed::OutPoint::new_builder() - .index(u32::max_value().into()) + .index(u32::max_value()) .build() } @@ -93,7 +93,7 @@ impl packed::CellInput { /// Creates a new `CellInput`. pub fn new(previous_output: packed::OutPoint, block_number: BlockNumber) -> Self { packed::CellInput::new_builder() - .since(block_number.into()) + .since(block_number) .previous_output(previous_output) .build() } diff --git a/util/gen-types/src/extension/tests/calc_hash.rs b/util/gen-types/src/extension/tests/calc_hash.rs index b0715dd1ec..e828d9b512 100644 --- a/util/gen-types/src/extension/tests/calc_hash.rs +++ b/util/gen-types/src/extension/tests/calc_hash.rs @@ -1,100 +1,108 @@ -use crate::{packed, prelude::*, vec}; +use crate::{ + packed::{self, ProposalShortIdVec, UncleBlockVec}, + prelude::*, + vec, +}; use ckb_fixed_hash::h256; use ckb_hash::blake2b_256; #[test] fn proposals_hash() { - let proposal1 = [1; 10].pack(); - let proposal2 = [2; 10].pack(); - let proposals = vec![proposal1, proposal2].pack(); + let proposal1 = [1; 10].into(); + let proposal2 = [2; 10].into(); + let proposals: ProposalShortIdVec = vec![proposal1, proposal2].into(); let expect = h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562"); - assert_eq!(proposals.calc_proposals_hash(), expect.pack()); + assert_eq!(proposals.calc_proposals_hash(), expect.into()); } #[test] fn empty_proposals_hash() { let proposals = packed::ProposalShortIdVec::new_builder().build(); let expect = h256!("0x0"); - assert_eq!(proposals.calc_proposals_hash(), expect.pack()); + assert_eq!(proposals.calc_proposals_hash(), expect.into()); } #[test] fn uncles_hash() { let uncle1_raw_header = packed::RawHeader::new_builder() - .version(0u32.pack()) - .compact_target(0x1e08_3126u32.pack()) - .timestamp(0x5cd2_b117u64.pack()) - .number(0x400u64.pack()) - .epoch(0x0007_0800_1800_0001u64.pack()) - .parent_hash( - h256!("0x8381df265c9442d5c27559b167892c5a6a8322871112d3cc8ef45222c6624831").pack(), - ) - .transactions_root( - h256!("0x12214693b8bd5c3d8f96e270dc8fe32b1702bd97630a9eab53a69793e6bc893f").pack(), - ) - .proposals_hash( - h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").pack(), - ) - .extra_hash( - h256!("0x0000000000000000000000000000000000000000000000000000000000000000").pack(), - ) - .dao(h256!("0xb54bdd7f6be90000bb52f392d41cd70024f7ef29b437000000febffacf030000").pack()) + .version(0u32) + .compact_target(0x1e08_3126u32) + .timestamp(0x5cd2_b117u64) + .number(0x400u64) + .epoch(0x0007_0800_1800_0001u64) + .parent_hash(h256!( + "0x8381df265c9442d5c27559b167892c5a6a8322871112d3cc8ef45222c6624831" + )) + .transactions_root(h256!( + "0x12214693b8bd5c3d8f96e270dc8fe32b1702bd97630a9eab53a69793e6bc893f" + )) + .proposals_hash(h256!( + "0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562" + )) + .extra_hash(h256!( + "0x0000000000000000000000000000000000000000000000000000000000000000" + )) + .dao(h256!( + "0xb54bdd7f6be90000bb52f392d41cd70024f7ef29b437000000febffacf030000" + )) .build(); let uncle1_header = packed::Header::new_builder() .raw(uncle1_raw_header) - .nonce(0x5ff1_389a_f870_6543_11a2_bee6_1237u128.pack()) + .nonce(0x5ff1_389a_f870_6543_11a2_bee6_1237u128) .build(); - let uncle1_proposals = vec![[1; 10].pack(), [2; 10].pack()].pack(); + let uncle1_proposals: ProposalShortIdVec = vec![[1; 10].into(), [2; 10].into()].into(); let uncle1 = packed::UncleBlock::new_builder() .header(uncle1_header) .proposals(uncle1_proposals) .build(); let uncle2_raw_header = packed::RawHeader::new_builder() - .version(0u32.pack()) - .compact_target(0x2001_0000u32.pack()) - .timestamp(0x5cd2_1a16u64.pack()) - .number(0x400u64.pack()) - .epoch(0x0007_0800_1800_0001u64.pack()) - .parent_hash( - h256!("0x8381df265c9442d5c27559b167892c5a6a8322871112d3cc8ef45222c6624831").pack(), - ) - .transactions_root( - h256!("0x12214693b8bd5c3d8f96e270dc8fe32b1702bd97630a9eab53a69793e6bc893f").pack(), - ) - .proposals_hash( - h256!("0x0000000000000000000000000000000000000000000000000000000000000000").pack(), - ) - .extra_hash( - h256!("0x0000000000000000000000000000000000000000000000000000000000000000").pack(), - ) - .dao(h256!("0xb54bdd7f6be90000bb52f392d41cd70024f7ef29b437000000febffacf030000").pack()) + .version(0u32) + .compact_target(0x2001_0000u32) + .timestamp(0x5cd2_1a16u64) + .number(0x400u64) + .epoch(0x0007_0800_1800_0001u64) + .parent_hash(h256!( + "0x8381df265c9442d5c27559b167892c5a6a8322871112d3cc8ef45222c6624831" + )) + .transactions_root(h256!( + "0x12214693b8bd5c3d8f96e270dc8fe32b1702bd97630a9eab53a69793e6bc893f" + )) + .proposals_hash(h256!( + "0x0000000000000000000000000000000000000000000000000000000000000000" + )) + .extra_hash(h256!( + "0x0000000000000000000000000000000000000000000000000000000000000000" + )) + .dao(h256!( + "0xb54bdd7f6be90000bb52f392d41cd70024f7ef29b437000000febffacf030000" + )) .build(); let uncle2_header = packed::Header::new_builder() .raw(uncle2_raw_header) - .nonce(0x2f39_2d41_cd70_024fu128.pack()) + .nonce(0x2f39_2d41_cd70_024fu128) .build(); let uncle2 = packed::UncleBlock::new_builder() .header(uncle2_header) .build(); - let uncles = vec![uncle1, uncle2].pack(); + let uncles: UncleBlockVec = vec![uncle1, uncle2].into(); let expect = h256!("0x0135d01f169a870bd9c92b2b37aecfa0fbfb7c1862cc176e03bb525fab0649d9"); - assert_eq!(uncles.calc_uncles_hash(), expect.pack()); + assert_eq!(uncles.calc_uncles_hash(), expect.into()); } #[test] fn empty_uncles_hash() { let uncles = packed::UncleBlockVec::new_builder().build(); let expect = h256!("0x0"); - assert_eq!(uncles.calc_uncles_hash(), expect.pack()); + assert_eq!(uncles.calc_uncles_hash(), expect.into()); } #[test] fn empty_script_hash() { let script = packed::Script::new_builder().build(); let expect = h256!("0x77c93b0632b5b6c3ef922c5b7cea208fb0a7c427a13d50e13d3fefad17e0c590"); - assert_eq!(script.calc_script_hash(), expect.pack()); + assert_eq!(script.calc_script_hash(), expect.into()); } #[test] @@ -103,15 +111,15 @@ fn always_success_script_hash() { let always_success_hash = blake2b_256(&always_success[..]); let script = packed::Script::new_builder() - .code_hash(always_success_hash.pack()) + .code_hash(always_success_hash) .build(); let expect = h256!("0x4ceaa32f692948413e213ce6f3a83337145bde6e11fd8cb94377ce2637dcc412"); - assert_eq!(script.calc_script_hash(), expect.pack()); + assert_eq!(script.calc_script_hash(), expect.into()); } #[test] fn one_arg_script_hash() { - let script = packed::Script::new_builder().args([1].pack()).build(); + let script = packed::Script::new_builder().args([1]).build(); let expect = h256!("0x67951b34bce20cb71b7e235c1f8cda259628d99d94825bffe549c23b4dd2930f"); - assert_eq!(script.calc_script_hash(), expect.pack()); + assert_eq!(script.calc_script_hash(), expect.into()); } diff --git a/util/gen-types/src/extension/tests/capacity.rs b/util/gen-types/src/extension/tests/capacity.rs index 3502bf6a0b..223bbbb06b 100644 --- a/util/gen-types/src/extension/tests/capacity.rs +++ b/util/gen-types/src/extension/tests/capacity.rs @@ -10,7 +10,7 @@ fn script_occupied_capacity() { (vec![0, 0], 2 + 32 + 1), ]; for (args, ckb) in testcases.into_iter() { - let script = packed::Script::new_builder().args(args.pack()).build(); + let script = packed::Script::new_builder().args(args).build(); let expect = Capacity::bytes(ckb).unwrap(); assert_eq!(script.occupied_capacity().unwrap(), expect); } @@ -28,7 +28,7 @@ fn min_cell_output_capacity() { #[test] fn min_secp256k1_cell_output_capacity() { - let lock = packed::Script::new_builder().args([0u8; 20].pack()).build(); + let lock = packed::Script::new_builder().args([0u8; 20]).build(); let output = packed::CellOutput::new_builder().lock(lock).build(); assert_eq!( output.occupied_capacity(Capacity::zero()).unwrap(), diff --git a/util/gen-types/src/extension/tests/check_data.rs b/util/gen-types/src/extension/tests/check_data.rs index c66c247392..f4c567c370 100644 --- a/util/gen-types/src/extension/tests/check_data.rs +++ b/util/gen-types/src/extension/tests/check_data.rs @@ -1,17 +1,25 @@ -use crate::{borrow::ToOwned, packed, prelude::*}; +use crate::{ + borrow::ToOwned, + packed::{self, Bytes, CellOutput}, + prelude::*, +}; fn create_transaction( outputs: &[&packed::CellOutput], outputs_data: &[&[u8]], cell_deps: &[&packed::CellDep], ) -> packed::Transaction { - let outputs_iter = outputs.iter().map(|d| d.to_owned().to_owned()); - let outputs_data_iter = outputs_data.iter().map(|d| d.to_owned().to_owned().pack()); - let cell_deps_iter = cell_deps.iter().map(|d| d.to_owned().to_owned()); + let outputs_iter: Vec = outputs.iter().map(|d| d.to_owned().to_owned()).collect(); + let outputs_data_iter: Vec = outputs_data + .iter() + .map(|d| Into::::into(d.to_owned())) + .collect(); + let cell_deps_iter: Vec = + cell_deps.iter().map(|d| d.to_owned().to_owned()).collect(); let raw = packed::RawTransaction::new_builder() - .outputs(outputs_iter.pack()) - .outputs_data(outputs_data_iter.pack()) - .cell_deps(cell_deps_iter.pack()) + .outputs(outputs_iter) + .outputs_data(outputs_data_iter) + .cell_deps(cell_deps_iter) .build(); packed::Transaction::new_builder().raw(raw).build() } @@ -31,10 +39,10 @@ fn check_data() { for ht in 0..4 { if ht != 3 { for dt in 0..2 { - let ht_right = ht.into(); - let dt_right = dt.into(); - let ht_error = 3.into(); - let dt_error = 2.into(); + let ht_right = ht; + let dt_right = dt; + let ht_error = 3; + let dt_error = 2; let script_right = packed::Script::new_builder().hash_type(ht_right).build(); let script_error = packed::Script::new_builder().hash_type(ht_error).build(); diff --git a/util/gen-types/src/extension/tests/rust_core_traits.rs b/util/gen-types/src/extension/tests/rust_core_traits.rs index b3e3ce1adb..ee2bd21d9e 100644 --- a/util/gen-types/src/extension/tests/rust_core_traits.rs +++ b/util/gen-types/src/extension/tests/rust_core_traits.rs @@ -4,49 +4,50 @@ use numext_fixed_uint::U256; #[test] fn test_uint32_cmp() { - let a: Uint32 = 10u32.pack(); - let b = 20u32.pack(); - let c = 10u32.pack(); + let a: Uint32 = 10u32.into(); + let b = 20u32.into(); + let c = 10u32.into(); assert!(a < b); assert!(a == c); } #[test] fn test_uint64_cmp() { - let a: Uint64 = 10u64.pack(); - let b = 20u64.pack(); - let c = 10u64.pack(); + let a: Uint64 = 10u64.into(); + let b = 20u64.into(); + let c = 10u64.into(); assert!(a < b); assert!(a == c); - let a: Uint64 = 1000u64.pack(); - let b: Uint64 = 2000u64.pack(); + let a: Uint64 = 1000u64.into(); + let b: Uint64 = 2000u64.into(); assert!(a < b); } #[test] fn test_uint128_cmp() { - let a: Uint128 = 10u128.pack(); - let b = 20u128.pack(); - let c = 10u128.pack(); + let a: Uint128 = 10u128.into(); + let b = 20u128.into(); + let c = 10u128.into(); assert!(a < b); assert!(a == c); } #[test] fn test_uint256_cmp() { - let a = U256::from(10u32).pack(); - let b = U256::from(20u32).pack(); - let c = U256::from(10u32).pack(); + let a: Uint256 = U256::from(10u32).into(); + let b = U256::from(20u32).into(); + let c = U256::from(10u32).into(); assert!(a < b); assert!(a == c); } #[test] fn test_byte32_cmp() { - let a = h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").pack(); - let b = h256!("0xd2670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").pack(); - let c = h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").pack(); + let a: Byte32 = + h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").into(); + let b = h256!("0xd2670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").into(); + let c = h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562").into(); assert!(a < b); assert!(a == c); @@ -54,24 +55,27 @@ fn test_byte32_cmp() { #[test] fn test_bytesopt_cmp() { - let a = Some( - h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562") - .pack() - .as_bytes(), + let a: BytesOpt = Some( + Into::::into(h256!( + "0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562" + )) + .as_bytes(), ) - .pack(); + .into(); let b = Some( - h256!("0xd2670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562") - .pack() - .as_bytes(), + Into::::into(h256!( + "0xd2670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562" + )) + .as_bytes(), ) - .pack(); + .into(); let c = Some( - h256!("0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562") - .pack() - .as_bytes(), + Into::::into(h256!( + "0xd1670e45af1deb9cc00951d71c09ce80932e7ddf9fb151d744436bd04ac4a562" + )) + .as_bytes(), ) - .pack(); + .into(); let d = BytesOpt::new_builder().build(); assert!(d.is_none()); @@ -82,37 +86,37 @@ fn test_bytesopt_cmp() { #[test] fn test_script_cmp() { - let a = Script::new_builder().args([1].pack()).build(); - let b = Script::new_builder().args([2].pack()).build(); + let a = Script::new_builder().args([1]).build(); + let b = Script::new_builder().args([2]).build(); assert!(a < b); } #[test] fn test_celldep_cmp() { - let a = CellDep::new_builder().dep_type(1.into()).build(); - let b = CellDep::new_builder().dep_type(2.into()).build(); + let a = CellDep::new_builder().dep_type(1).build(); + let b = CellDep::new_builder().dep_type(2).build(); assert!(a < b); } #[test] fn test_outpoint_cmp() { - let a = OutPoint::new_builder().index(1u32.pack()).build(); - let b = OutPoint::new_builder().index(2u32.pack()).build(); + let a = OutPoint::new_builder().index(1u32).build(); + let b = OutPoint::new_builder().index(2u32).build(); assert!(a < b); } #[test] fn test_cellinput_cmp() { - let a = CellInput::new_builder().since(1000u64.pack()).build(); - let b = CellInput::new_builder().since(2000u64.pack()).build(); + let a = CellInput::new_builder().since(1000u64).build(); + let b = CellInput::new_builder().since(2000u64).build(); assert!(a > b); } #[test] fn test_celloutput_cmp() { - let script_lock = Script::new_builder().hash_type(1.into()).build(); - let script_type = Script::new_builder().hash_type(2.into()).build(); + let script_lock = Script::new_builder().hash_type(1).build(); + let script_type = Script::new_builder().hash_type(2).build(); let script_type_opt = ScriptOpt::new_builder().set(Some(script_type)).build(); let output_a = CellOutput::new_builder().lock(script_lock.clone()).build(); let output_b = CellOutput::new_builder() diff --git a/util/gen-types/src/extension/tests/serialized_size.rs b/util/gen-types/src/extension/tests/serialized_size.rs index 40bba83b2f..cc1d1bba48 100644 --- a/util/gen-types/src/extension/tests/serialized_size.rs +++ b/util/gen-types/src/extension/tests/serialized_size.rs @@ -1,13 +1,17 @@ -use crate::{packed, prelude::*, vec, vec::Vec}; +use crate::{ + packed::{self, ProposalShortId, ProposalShortIdVec}, + prelude::*, + vec::Vec, +}; #[test] fn block_size_should_not_include_uncles_proposals() { - let proposal1 = [1; 10].pack(); - let proposal2 = [2; 10].pack(); - let proposal3 = [3; 10].pack(); - let proposals1 = vec![proposal1.clone()].pack(); - let proposals2 = vec![proposal1.clone(), proposal2.clone()].pack(); - let proposals3 = vec![proposal1, proposal2, proposal3].pack(); + let proposal1: ProposalShortId = [1; 10].into(); + let proposal2: ProposalShortId = [2; 10].into(); + let proposal3 = [3; 10].into(); + let proposals1: ProposalShortIdVec = vec![proposal1.clone()].into(); + let proposals2: ProposalShortIdVec = vec![proposal1.clone(), proposal2.clone()].into(); + let proposals3: ProposalShortIdVec = vec![proposal1, proposal2, proposal3].into(); let uncle0 = packed::UncleBlock::new_builder().build(); let uncle1 = packed::UncleBlock::new_builder() .proposals(proposals1) @@ -31,11 +35,9 @@ fn block_size_should_not_include_uncles_proposals() { let mut uncles = uncles.clone(); loop { let block_with_empty_uncles = packed::Block::new_builder() - .uncles(empty_uncles.clone().pack()) - .build(); - let block_with_uncles = packed::Block::new_builder() - .uncles(uncles.clone().pack()) + .uncles(empty_uncles.clone()) .build(); + let block_with_uncles = packed::Block::new_builder().uncles(uncles.clone()).build(); let actual = block_with_uncles.serialized_size_without_uncle_proposals(); let actual_empty = block_with_empty_uncles.serialized_size_without_uncle_proposals(); let expected = block_with_empty_uncles.as_slice().len(); @@ -54,21 +56,21 @@ fn block_size_should_not_include_uncles_proposals() { let mut empty_uncles = empty_uncles; let mut uncles = uncles; let extensions: Vec = vec![ - [0u8].pack(), - [0u8; 24].pack(), - [0u8; 48].pack(), - [0u8; 72].pack(), - [0u8; 96].pack(), + [0u8].into(), + [0u8; 24].into(), + [0u8; 48].into(), + [0u8; 72].into(), + [0u8; 96].into(), ]; for extension in extensions { loop { let block_with_empty_uncles_v1 = packed::BlockV1::new_builder() - .uncles(empty_uncles.clone().pack()) + .uncles(empty_uncles.clone()) .extension(extension.clone()) .build(); let block_with_empty_uncles = block_with_empty_uncles_v1.as_v0(); let block_with_uncles = packed::BlockV1::new_builder() - .uncles(uncles.clone().pack()) + .uncles(uncles.clone()) .extension(extension.clone()) .build() .as_v0(); diff --git a/util/gen-types/src/generated/blockchain.rs b/util/gen-types/src/generated/blockchain.rs index e9dae42fab..97c34a09c6 100644 --- a/util/gen-types/src/generated/blockchain.rs +++ b/util/gen-types/src/generated/blockchain.rs @@ -164,24 +164,39 @@ impl Uint32Builder { pub const TOTAL_SIZE: usize = 4; pub const ITEM_SIZE: usize = 1; pub const ITEM_COUNT: usize = 4; - pub fn set(mut self, v: [Byte; 4]) -> Self { - self.0 = v; + pub fn set(mut self, v: T) -> Self + where + T: ::core::convert::Into<[Byte; 4]>, + { + self.0 = v.into(); self } - pub fn nth0(mut self, v: Byte) -> Self { - self.0[0] = v; + pub fn nth0(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[0] = v.into(); self } - pub fn nth1(mut self, v: Byte) -> Self { - self.0[1] = v; + pub fn nth1(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[1] = v.into(); self } - pub fn nth2(mut self, v: Byte) -> Self { - self.0[2] = v; + pub fn nth2(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[2] = v.into(); self } - pub fn nth3(mut self, v: Byte) -> Self { - self.0[3] = v; + pub fn nth3(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[3] = v.into(); self } } @@ -453,40 +468,67 @@ impl Uint64Builder { pub const TOTAL_SIZE: usize = 8; pub const ITEM_SIZE: usize = 1; pub const ITEM_COUNT: usize = 8; - pub fn set(mut self, v: [Byte; 8]) -> Self { - self.0 = v; + pub fn set(mut self, v: T) -> Self + where + T: ::core::convert::Into<[Byte; 8]>, + { + self.0 = v.into(); self } - pub fn nth0(mut self, v: Byte) -> Self { - self.0[0] = v; + pub fn nth0(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[0] = v.into(); self } - pub fn nth1(mut self, v: Byte) -> Self { - self.0[1] = v; + pub fn nth1(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[1] = v.into(); self } - pub fn nth2(mut self, v: Byte) -> Self { - self.0[2] = v; + pub fn nth2(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[2] = v.into(); self } - pub fn nth3(mut self, v: Byte) -> Self { - self.0[3] = v; + pub fn nth3(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[3] = v.into(); self } - pub fn nth4(mut self, v: Byte) -> Self { - self.0[4] = v; + pub fn nth4(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[4] = v.into(); self } - pub fn nth5(mut self, v: Byte) -> Self { - self.0[5] = v; + pub fn nth5(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[5] = v.into(); self } - pub fn nth6(mut self, v: Byte) -> Self { - self.0[6] = v; + pub fn nth6(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[6] = v.into(); self } - pub fn nth7(mut self, v: Byte) -> Self { - self.0[7] = v; + pub fn nth7(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[7] = v.into(); self } } @@ -835,72 +877,123 @@ impl Uint128Builder { pub const TOTAL_SIZE: usize = 16; pub const ITEM_SIZE: usize = 1; pub const ITEM_COUNT: usize = 16; - pub fn set(mut self, v: [Byte; 16]) -> Self { - self.0 = v; + pub fn set(mut self, v: T) -> Self + where + T: ::core::convert::Into<[Byte; 16]>, + { + self.0 = v.into(); self } - pub fn nth0(mut self, v: Byte) -> Self { - self.0[0] = v; + pub fn nth0(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[0] = v.into(); self } - pub fn nth1(mut self, v: Byte) -> Self { - self.0[1] = v; + pub fn nth1(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[1] = v.into(); self } - pub fn nth2(mut self, v: Byte) -> Self { - self.0[2] = v; + pub fn nth2(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[2] = v.into(); self } - pub fn nth3(mut self, v: Byte) -> Self { - self.0[3] = v; + pub fn nth3(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[3] = v.into(); self } - pub fn nth4(mut self, v: Byte) -> Self { - self.0[4] = v; + pub fn nth4(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[4] = v.into(); self } - pub fn nth5(mut self, v: Byte) -> Self { - self.0[5] = v; + pub fn nth5(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[5] = v.into(); self } - pub fn nth6(mut self, v: Byte) -> Self { - self.0[6] = v; + pub fn nth6(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[6] = v.into(); self } - pub fn nth7(mut self, v: Byte) -> Self { - self.0[7] = v; + pub fn nth7(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[7] = v.into(); self } - pub fn nth8(mut self, v: Byte) -> Self { - self.0[8] = v; + pub fn nth8(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[8] = v.into(); self } - pub fn nth9(mut self, v: Byte) -> Self { - self.0[9] = v; + pub fn nth9(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[9] = v.into(); self } - pub fn nth10(mut self, v: Byte) -> Self { - self.0[10] = v; + pub fn nth10(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[10] = v.into(); self } - pub fn nth11(mut self, v: Byte) -> Self { - self.0[11] = v; + pub fn nth11(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[11] = v.into(); self } - pub fn nth12(mut self, v: Byte) -> Self { - self.0[12] = v; + pub fn nth12(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[12] = v.into(); self } - pub fn nth13(mut self, v: Byte) -> Self { - self.0[13] = v; + pub fn nth13(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[13] = v.into(); self } - pub fn nth14(mut self, v: Byte) -> Self { - self.0[14] = v; + pub fn nth14(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[14] = v.into(); self } - pub fn nth15(mut self, v: Byte) -> Self { - self.0[15] = v; + pub fn nth15(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[15] = v.into(); self } } @@ -1396,136 +1489,235 @@ impl Byte32Builder { pub const TOTAL_SIZE: usize = 32; pub const ITEM_SIZE: usize = 1; pub const ITEM_COUNT: usize = 32; - pub fn set(mut self, v: [Byte; 32]) -> Self { - self.0 = v; + pub fn set(mut self, v: T) -> Self + where + T: ::core::convert::Into<[Byte; 32]>, + { + self.0 = v.into(); self } - pub fn nth0(mut self, v: Byte) -> Self { - self.0[0] = v; + pub fn nth0(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[0] = v.into(); self } - pub fn nth1(mut self, v: Byte) -> Self { - self.0[1] = v; + pub fn nth1(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[1] = v.into(); self } - pub fn nth2(mut self, v: Byte) -> Self { - self.0[2] = v; + pub fn nth2(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[2] = v.into(); self } - pub fn nth3(mut self, v: Byte) -> Self { - self.0[3] = v; + pub fn nth3(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[3] = v.into(); self } - pub fn nth4(mut self, v: Byte) -> Self { - self.0[4] = v; + pub fn nth4(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[4] = v.into(); self } - pub fn nth5(mut self, v: Byte) -> Self { - self.0[5] = v; + pub fn nth5(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[5] = v.into(); self } - pub fn nth6(mut self, v: Byte) -> Self { - self.0[6] = v; + pub fn nth6(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[6] = v.into(); self } - pub fn nth7(mut self, v: Byte) -> Self { - self.0[7] = v; + pub fn nth7(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[7] = v.into(); self } - pub fn nth8(mut self, v: Byte) -> Self { - self.0[8] = v; + pub fn nth8(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[8] = v.into(); self } - pub fn nth9(mut self, v: Byte) -> Self { - self.0[9] = v; + pub fn nth9(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[9] = v.into(); self } - pub fn nth10(mut self, v: Byte) -> Self { - self.0[10] = v; + pub fn nth10(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[10] = v.into(); self } - pub fn nth11(mut self, v: Byte) -> Self { - self.0[11] = v; + pub fn nth11(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[11] = v.into(); self } - pub fn nth12(mut self, v: Byte) -> Self { - self.0[12] = v; + pub fn nth12(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[12] = v.into(); self } - pub fn nth13(mut self, v: Byte) -> Self { - self.0[13] = v; + pub fn nth13(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[13] = v.into(); self } - pub fn nth14(mut self, v: Byte) -> Self { - self.0[14] = v; + pub fn nth14(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[14] = v.into(); self } - pub fn nth15(mut self, v: Byte) -> Self { - self.0[15] = v; + pub fn nth15(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[15] = v.into(); self } - pub fn nth16(mut self, v: Byte) -> Self { - self.0[16] = v; + pub fn nth16(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[16] = v.into(); self } - pub fn nth17(mut self, v: Byte) -> Self { - self.0[17] = v; + pub fn nth17(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[17] = v.into(); self } - pub fn nth18(mut self, v: Byte) -> Self { - self.0[18] = v; + pub fn nth18(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[18] = v.into(); self } - pub fn nth19(mut self, v: Byte) -> Self { - self.0[19] = v; + pub fn nth19(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[19] = v.into(); self } - pub fn nth20(mut self, v: Byte) -> Self { - self.0[20] = v; + pub fn nth20(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[20] = v.into(); self } - pub fn nth21(mut self, v: Byte) -> Self { - self.0[21] = v; + pub fn nth21(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[21] = v.into(); self } - pub fn nth22(mut self, v: Byte) -> Self { - self.0[22] = v; + pub fn nth22(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[22] = v.into(); self } - pub fn nth23(mut self, v: Byte) -> Self { - self.0[23] = v; + pub fn nth23(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[23] = v.into(); self } - pub fn nth24(mut self, v: Byte) -> Self { - self.0[24] = v; + pub fn nth24(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[24] = v.into(); self } - pub fn nth25(mut self, v: Byte) -> Self { - self.0[25] = v; + pub fn nth25(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[25] = v.into(); self } - pub fn nth26(mut self, v: Byte) -> Self { - self.0[26] = v; + pub fn nth26(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[26] = v.into(); self } - pub fn nth27(mut self, v: Byte) -> Self { - self.0[27] = v; + pub fn nth27(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[27] = v.into(); self } - pub fn nth28(mut self, v: Byte) -> Self { - self.0[28] = v; + pub fn nth28(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[28] = v.into(); self } - pub fn nth29(mut self, v: Byte) -> Self { - self.0[29] = v; + pub fn nth29(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[29] = v.into(); self } - pub fn nth30(mut self, v: Byte) -> Self { - self.0[30] = v; + pub fn nth30(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[30] = v.into(); self } - pub fn nth31(mut self, v: Byte) -> Self { - self.0[31] = v; + pub fn nth31(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[31] = v.into(); self } } @@ -2053,136 +2245,235 @@ impl Uint256Builder { pub const TOTAL_SIZE: usize = 32; pub const ITEM_SIZE: usize = 1; pub const ITEM_COUNT: usize = 32; - pub fn set(mut self, v: [Byte; 32]) -> Self { - self.0 = v; + pub fn set(mut self, v: T) -> Self + where + T: ::core::convert::Into<[Byte; 32]>, + { + self.0 = v.into(); self } - pub fn nth0(mut self, v: Byte) -> Self { - self.0[0] = v; + pub fn nth0(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[0] = v.into(); self } - pub fn nth1(mut self, v: Byte) -> Self { - self.0[1] = v; + pub fn nth1(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[1] = v.into(); self } - pub fn nth2(mut self, v: Byte) -> Self { - self.0[2] = v; + pub fn nth2(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[2] = v.into(); self } - pub fn nth3(mut self, v: Byte) -> Self { - self.0[3] = v; + pub fn nth3(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[3] = v.into(); self } - pub fn nth4(mut self, v: Byte) -> Self { - self.0[4] = v; + pub fn nth4(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[4] = v.into(); self } - pub fn nth5(mut self, v: Byte) -> Self { - self.0[5] = v; + pub fn nth5(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[5] = v.into(); self } - pub fn nth6(mut self, v: Byte) -> Self { - self.0[6] = v; + pub fn nth6(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[6] = v.into(); self } - pub fn nth7(mut self, v: Byte) -> Self { - self.0[7] = v; + pub fn nth7(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[7] = v.into(); self } - pub fn nth8(mut self, v: Byte) -> Self { - self.0[8] = v; + pub fn nth8(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[8] = v.into(); self } - pub fn nth9(mut self, v: Byte) -> Self { - self.0[9] = v; + pub fn nth9(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[9] = v.into(); self } - pub fn nth10(mut self, v: Byte) -> Self { - self.0[10] = v; + pub fn nth10(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[10] = v.into(); self } - pub fn nth11(mut self, v: Byte) -> Self { - self.0[11] = v; + pub fn nth11(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[11] = v.into(); self } - pub fn nth12(mut self, v: Byte) -> Self { - self.0[12] = v; + pub fn nth12(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[12] = v.into(); self } - pub fn nth13(mut self, v: Byte) -> Self { - self.0[13] = v; + pub fn nth13(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[13] = v.into(); self } - pub fn nth14(mut self, v: Byte) -> Self { - self.0[14] = v; + pub fn nth14(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[14] = v.into(); self } - pub fn nth15(mut self, v: Byte) -> Self { - self.0[15] = v; + pub fn nth15(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[15] = v.into(); self } - pub fn nth16(mut self, v: Byte) -> Self { - self.0[16] = v; + pub fn nth16(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[16] = v.into(); self } - pub fn nth17(mut self, v: Byte) -> Self { - self.0[17] = v; + pub fn nth17(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[17] = v.into(); self } - pub fn nth18(mut self, v: Byte) -> Self { - self.0[18] = v; + pub fn nth18(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[18] = v.into(); self } - pub fn nth19(mut self, v: Byte) -> Self { - self.0[19] = v; + pub fn nth19(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[19] = v.into(); self } - pub fn nth20(mut self, v: Byte) -> Self { - self.0[20] = v; + pub fn nth20(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[20] = v.into(); self } - pub fn nth21(mut self, v: Byte) -> Self { - self.0[21] = v; + pub fn nth21(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[21] = v.into(); self } - pub fn nth22(mut self, v: Byte) -> Self { - self.0[22] = v; + pub fn nth22(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[22] = v.into(); self } - pub fn nth23(mut self, v: Byte) -> Self { - self.0[23] = v; + pub fn nth23(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[23] = v.into(); self } - pub fn nth24(mut self, v: Byte) -> Self { - self.0[24] = v; + pub fn nth24(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[24] = v.into(); self } - pub fn nth25(mut self, v: Byte) -> Self { - self.0[25] = v; + pub fn nth25(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[25] = v.into(); self } - pub fn nth26(mut self, v: Byte) -> Self { - self.0[26] = v; + pub fn nth26(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[26] = v.into(); self } - pub fn nth27(mut self, v: Byte) -> Self { - self.0[27] = v; + pub fn nth27(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[27] = v.into(); self } - pub fn nth28(mut self, v: Byte) -> Self { - self.0[28] = v; + pub fn nth28(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[28] = v.into(); self } - pub fn nth29(mut self, v: Byte) -> Self { - self.0[29] = v; + pub fn nth29(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[29] = v.into(); self } - pub fn nth30(mut self, v: Byte) -> Self { - self.0[30] = v; + pub fn nth30(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[30] = v.into(); self } - pub fn nth31(mut self, v: Byte) -> Self { - self.0[31] = v; + pub fn nth31(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0[31] = v.into(); self } } @@ -2496,18 +2787,24 @@ impl BytesBuilder { self.0 = v; self } - pub fn push(mut self, v: Byte) -> Self { - self.0.push(v); + pub fn push(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0.push(v.into()); self } pub fn extend>(mut self, iter: T) -> Self { self.0.extend(iter); self } - pub fn replace(&mut self, index: usize, v: Byte) -> Option { + pub fn replace(&mut self, index: usize, v: T) -> Option + where + T: ::core::convert::Into, + { self.0 .get_mut(index) - .map(|item| ::core::mem::replace(item, v)) + .map(|item| ::core::mem::replace(item, v.into())) } } impl molecule::prelude::Builder for BytesBuilder { @@ -2717,8 +3014,11 @@ impl<'r> molecule::prelude::Reader<'r> for BytesOptReader<'r> { #[derive(Clone, Debug, Default)] pub struct BytesOptBuilder(pub(crate) Option); impl BytesOptBuilder { - pub fn set(mut self, v: Option) -> Self { - self.0 = v; + pub fn set(mut self, v: T) -> Self + where + T: ::core::convert::Into>, + { + self.0 = v.into(); self } } @@ -2979,18 +3279,24 @@ impl BytesOptVecBuilder { self.0 = v; self } - pub fn push(mut self, v: BytesOpt) -> Self { - self.0.push(v); + pub fn push(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0.push(v.into()); self } pub fn extend>(mut self, iter: T) -> Self { self.0.extend(iter); self } - pub fn replace(&mut self, index: usize, v: BytesOpt) -> Option { + pub fn replace(&mut self, index: usize, v: T) -> Option + where + T: ::core::convert::Into, + { self.0 .get_mut(index) - .map(|item| ::core::mem::replace(item, v)) + .map(|item| ::core::mem::replace(item, v.into())) } } impl molecule::prelude::Builder for BytesOptVecBuilder { @@ -3327,18 +3633,24 @@ impl BytesVecBuilder { self.0 = v; self } - pub fn push(mut self, v: Bytes) -> Self { - self.0.push(v); + pub fn push(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0.push(v.into()); self } pub fn extend>(mut self, iter: T) -> Self { self.0.extend(iter); self } - pub fn replace(&mut self, index: usize, v: Bytes) -> Option { + pub fn replace(&mut self, index: usize, v: T) -> Option + where + T: ::core::convert::Into, + { self.0 .get_mut(index) - .map(|item| ::core::mem::replace(item, v)) + .map(|item| ::core::mem::replace(item, v.into())) } } impl molecule::prelude::Builder for BytesVecBuilder { @@ -3632,18 +3944,24 @@ impl Byte32VecBuilder { self.0 = v; self } - pub fn push(mut self, v: Byte32) -> Self { - self.0.push(v); + pub fn push(mut self, v: T) -> Self + where + T: ::core::convert::Into, + { + self.0.push(v.into()); self } pub fn extend>(mut self, iter: T) -> Self { self.0.extend(iter); self } - pub fn replace(&mut self, index: usize, v: Byte32) -> Option { + pub fn replace(&mut self, index: usize, v: T) -> Option + where + T: ::core::convert::Into, + { self.0 .get_mut(index) - .map(|item| ::core::mem::replace(item, v)) + .map(|item| ::core::mem::replace(item, v.into())) } } impl molecule::prelude::Builder for Byte32VecBuilder { @@ -3862,8 +4180,11 @@ impl<'r> molecule::prelude::Reader<'r> for ScriptOptReader<'r> { #[derive(Clone, Debug, Default)] pub struct ScriptOptBuilder(pub(crate) Option