Skip to content

Commit

Permalink
chore: chore: Use SYSTEM_CELL_ALWAYS_SUCCESS_INDEX constant
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed Sep 20, 2019
1 parent 10a6ced commit 7b8aada
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
1 change: 1 addition & 0 deletions test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pub use specs::{Setup, Spec, TestProtocol};

// ckb doesn't support tx proposal window configuration, use a hardcoded value for integration test.
pub const DEFAULT_TX_PROPOSAL_WINDOW: (BlockNumber, BlockNumber) = (2, 10);
pub const SYSTEM_CELL_ALWAYS_SUCCESS_INDEX: u32 = 5;
8 changes: 6 additions & 2 deletions test/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::rpc::RpcClient;
use crate::utils::{temp_path, wait_until};
use crate::SYSTEM_CELL_ALWAYS_SUCCESS_INDEX;
use ckb_app_config::{BlockAssemblerConfig, CKBAppConfig};
use ckb_chain_spec::consensus::Consensus;
use ckb_chain_spec::ChainSpec;
Expand Down Expand Up @@ -330,7 +331,10 @@ impl Node {
since: u64,
capacity: Capacity,
) -> TransactionView {
let always_success_out_point = OutPoint::new(self.genesis_cellbase_hash.clone(), 5);
let always_success_out_point = OutPoint::new(
self.genesis_cellbase_hash.clone(),
SYSTEM_CELL_ALWAYS_SUCCESS_INDEX,
);
let always_success_script = self.always_success_script();

core::TransactionBuilder::default()
Expand Down Expand Up @@ -384,7 +388,7 @@ impl Node {
self.always_success_code_hash = CellOutput::calc_data_hash(
&consensus.genesis_block().transactions()[0]
.outputs_data()
.get(5)
.get(SYSTEM_CELL_ALWAYS_SUCCESS_INDEX as usize)
.unwrap()
.raw_data(),
);
Expand Down
7 changes: 3 additions & 4 deletions test/src/specs/dao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub use dao_tx::{
pub use satoshi_dao_occupied::{DAOWithSatoshiCellOccupied, SpendSatoshiCell};

use crate::utils::is_committed;
use crate::Node;
use crate::{Node, SYSTEM_CELL_ALWAYS_SUCCESS_INDEX};
use ckb_chain_spec::OUTPUT_INDEX_DAO;
use ckb_test_chain_utils::always_success_cell;
use ckb_types::{
bytes::Bytes,
Expand All @@ -18,8 +19,6 @@ use ckb_types::{
prelude::*,
};

const SYSTEM_CELL_ALWAYS_SUCCESS_INDEX: u32 = 5;
const SYSTEM_CELL_DAO_INDEX: u32 = 2;
const WITHDRAW_WINDOW_LEFT: u64 = 10;
// The second witness
const WITHDRAW_HEADER_INDEX: u64 = 1;
Expand Down Expand Up @@ -74,7 +73,7 @@ fn deposit_dao_deps(node: &Node) -> (Vec<CellDep>, Vec<Byte32>) {
.build();
// Reference to DAO type_script
let dao_dep = CellDep::new_builder()
.out_point(OutPoint::new(genesis_tx.hash(), SYSTEM_CELL_DAO_INDEX))
.out_point(OutPoint::new(genesis_tx.hash(), OUTPUT_INDEX_DAO as u32))
.build();

(vec![always_dep, dao_dep], vec![genesis_block.hash()])
Expand Down
25 changes: 5 additions & 20 deletions test/src/specs/dao/satoshi_dao_occupied.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use super::*;
use crate::utils::is_committed;
use crate::{Net, Spec};
use ckb_chain_spec::{ChainSpec, IssuedCell};
use ckb_chain_spec::{
build_genesis_type_id_script, ChainSpec, IssuedCell,
OUTPUT_INDEX_SECP256K1_RIPEMD160_SHA256_SIGHASH_ALL,
};
use ckb_crypto::secp::{Generator, Privkey, Pubkey};
use ckb_dao_utils::extract_dao_data;
use ckb_hash::new_blake2b;
use ckb_test_chain_utils::always_success_cell;
use ckb_types::{
bytes::Bytes,
constants::TYPE_ID_CODE_HASH,
core::{Capacity, DepType, Ratio},
prelude::*,
H160, H256,
Expand Down Expand Up @@ -186,23 +187,7 @@ fn issue_satoshi_cell(satoshi_pubkey_hash: H160) -> IssuedCell {
}

fn type_lock_script_code_hash() -> H256 {
let input = CellInput::new_cellbase_input(0);
// 0 => genesis cell, which contains a message and can never be spent.
// ....
// 4 => secp256k1_ripemd160_sha256_sighash_all cell
// define in integration.toml spec file
let output_index: u64 = 4;
let mut blake2b = new_blake2b();
blake2b.update(input.as_slice());
blake2b.update(&output_index.to_le_bytes());
let mut ret = [0; 32];
blake2b.finalize(&mut ret);
let script_arg = Bytes::from(&ret[..]).pack();
Script::new_builder()
.code_hash(TYPE_ID_CODE_HASH.pack())
.hash_type(ScriptHashType::Type.pack())
.args(vec![script_arg].pack())
.build()
build_genesis_type_id_script(OUTPUT_INDEX_SECP256K1_RIPEMD160_SHA256_SIGHASH_ALL)
.calc_script_hash()
.unpack()
}
Expand Down

0 comments on commit 7b8aada

Please sign in to comment.