# Create Determined Transaction in CKB Capsule Test ## Metadata **Status**:: #x **Zettel**:: #zettel/fleeting **Created**:: [[2023-12-19]] **Topic**:: [[♯ CKB Script]] ## Synopsis The functions in `Context` will use random values: - `Context::create_cell` returns random previous transaction hash. - `Context::deploy_cell` returns random previous transaction hash, and random type script hash. ```rust use ckb_testtool::{ ckb_types::{ bytes::Bytes, core::{TransactionBuilder, TransactionView}, packed, prelude::*, }, context::Context, }; fn build_determined_tx(context: &mut Context) -> TransactionView { // `deploy_cell` creates random outpoint and random type script hash, so create the code cell // manually. let code_binary = Loader::default().load_binary("my-contract"); // Fixed out point let code_out_point = packed::OutPoint::new_builder() .tx_hash(PREVIOUS_TX_HASH.pack()) .index(CODE_CELL_INDEX.pack()) .build(); let code_cell = packed::CellOutput::new_builder() .capacity(50_0000_0000_0000.pack()) // Fixed type script hash .type_( Some( packed::Script::new_builder() .code_hash([0u8; 32].pack()) .build(), ) .pack(), ) .build(); context.create_cell_with_out_point(code_out_point.clone(), code_cell, code_binary); let lock_args = Bytes::new(); let lock_script = context .build_script(&code_out_point, lock_args) .expect("build script"); let test_cell = packed::CellOutput::new_builder() .capacity(1000_0000_0000u64.pack()) .lock(lock_script) .build(); // Fixed input cell out point let test_cell_out_point = packed::OutPoint::new_builder() .tx_hash(PREVIOUS_TX_HASH.pack()) .index(TEST_CELL_INDEX.pack()) .build(); context.create_cell_with_out_point( test_cell_out_point.clone(), test_cell.clone(), Bytes::new(), ); let input = packed::CellInput::new_builder() .previous_output(test_cell_out_point) .build(); // build transaction let tx = TransactionBuilder::default() .input(input) .output(test_cell) .output_data(Bytes::new().pack()) .build(); // the tx always has the hash 3ba6e4514bd742ff0cd24498e5a768511ea0636c5d70507fcf4651b180b3b3c6 context.complete_tx(tx) } ```