Skip to content

Commit

Permalink
test: add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Dec 13, 2024
1 parent 3ed8d5e commit 25a55dd
Show file tree
Hide file tree
Showing 16 changed files with 1,866 additions and 186 deletions.
1 change: 1 addition & 0 deletions examples/omnilock_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn main() -> Result<(), Box<dyn StdErr>> {
&SignContexts::new_omnilock(
[secp256k1::SecretKey::from_slice(private_key.as_bytes())?].to_vec(),
omni_cfg,
ckb_sdk::unlock::OmniUnlockMode::Normal,
),
)?;

Expand Down
2 changes: 2 additions & 0 deletions examples/omnilock_multisig_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fn main() -> Result<(), Box<dyn StdErr>> {
&SignContexts::new_omnilock(
[secp256k1::SecretKey::from_slice(private_key.as_bytes())?].to_vec(),
omni_cfg.clone(),
ckb_sdk::unlock::OmniUnlockMode::Normal,
),
)?;
let private_key = h256!("0x4fd809631a6aa6e3bb378dd65eae5d71df895a82c91a615a1e8264741515c79c");
Expand All @@ -70,6 +71,7 @@ fn main() -> Result<(), Box<dyn StdErr>> {
&SignContexts::new_omnilock(
[secp256k1::SecretKey::from_slice(private_key.as_bytes())?].to_vec(),
omni_cfg,
ckb_sdk::unlock::OmniUnlockMode::Normal,
),
)?;

Expand Down
3 changes: 2 additions & 1 deletion src/core/advanced_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ impl TransactionBuilder {
if witness_data.is_empty() {
WitnessArgs::default()
} else {
WitnessArgs::from_slice(witness_data.as_ref()).unwrap()
WitnessArgs::from_slice(witness_data.as_ref())
.expect("WitnessArgs expected but failed to decode ")
}
}

Expand Down
59 changes: 35 additions & 24 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,39 @@ mod tx_builder;

use std::{collections::HashMap, u64};

use ckb_dao_utils::pack_dao_data;
use ckb_hash::blake2b_256;
use ckb_jsonrpc_types as json_types;
use ckb_types::{
bytes::Bytes,
core::{BlockView, ScriptHashType},
core::{BlockView, Capacity, EpochNumberWithFraction, HeaderBuilder, ScriptHashType},
h160, h256,
packed::{OutPoint, Script},
packed::{CellInput, CellOutput, OutPoint, Script, ScriptOpt, WitnessArgs},
prelude::*,
H160, H256,
};

use crate::constants::{DAO_TYPE_HASH, MULTISIG_TYPE_HASH, ONE_CKB, SIGHASH_TYPE_HASH};
use crate::constants::{
CHEQUE_CELL_SINCE, DAO_TYPE_HASH, MULTISIG_TYPE_HASH, ONE_CKB, SIGHASH_TYPE_HASH,
};
use crate::traits::SecpCkbRawKeySigner;
use crate::unlock::{MultisigConfig, OmniLockConfig, ScriptUnlocker, SecpMultisigUnlocker};
use crate::ScriptId;
use crate::tx_builder::{
acp::{AcpTransferBuilder, AcpTransferReceiver},
cheque::{ChequeClaimBuilder, ChequeWithdrawBuilder},
dao::{
DaoDepositBuilder, DaoDepositReceiver, DaoPrepareBuilder, DaoWithdrawBuilder,
DaoWithdrawItem, DaoWithdrawReceiver,
},
transfer::CapacityTransferBuilder,
udt::{UdtIssueBuilder, UdtTargetReceiver, UdtTransferBuilder, UdtType},
unlock_tx, CapacityBalancer, TransferAction, TxBuilder,
};
use crate::unlock::{
AcpUnlocker, ChequeAction, ChequeUnlocker, MultisigConfig, OmniLockConfig, ScriptUnlocker,
SecpMultisigUnlocker, SecpSighashUnlocker,
};
use crate::util::{calculate_dao_maximum_withdraw4, minimal_unlock_point};
use crate::{ScriptId, Since, SinceType};

use crate::test_util::{random_out_point, Context};

Expand Down Expand Up @@ -161,7 +179,7 @@ fn init_context(
fn test_transfer_from_sighash() {
let sender = build_sighash_script(ACCOUNT1_ARG);
let receiver = build_sighash_script(ACCOUNT2_ARG);
let ctx = init_context(
let (ctx, _) = init_context(
Vec::new(),
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -218,7 +236,7 @@ fn test_transfer_from_sighash() {
fn test_transfer_capacity_overflow() {
let sender = build_sighash_script(ACCOUNT1_ARG);
let receiver = build_sighash_script(ACCOUNT2_ARG);
let ctx = init_context(Vec::new(), vec![(sender.clone(), Some(100 * ONE_CKB))]);
let (ctx, _) = init_context(Vec::new(), vec![(sender.clone(), Some(100 * ONE_CKB))]);

let large_amount: u64 = u64::MAX;
let output = CellOutput::new_builder()
Expand Down Expand Up @@ -251,7 +269,7 @@ fn test_transfer_from_multisig() {
let sender = build_multisig_script(&cfg);
let receiver = build_sighash_script(ACCOUNT2_ARG);

let ctx = init_context(
let (ctx, _) = init_context(
Vec::new(),
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -315,7 +333,7 @@ fn test_transfer_from_acp() {
.args(Bytes::from(ACCOUNT1_ARG.0.to_vec()).pack())
.build();
let receiver = build_sighash_script(ACCOUNT2_ARG);
let ctx = init_context(
let (ctx, _) = init_context(
vec![(ACP_BIN, true)],
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -376,7 +394,7 @@ fn test_transfer_to_acp() {
.hash_type(ScriptHashType::Data1.into())
.args(Bytes::from(ACCOUNT2_ARG.0.to_vec()).pack())
.build();
let ctx = init_context(
let (ctx, _) = init_context(
vec![(ACP_BIN, true)],
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -462,7 +480,7 @@ fn test_cheque_claim() {
.hash_type(ScriptHashType::Data1.into())
.args(Bytes::from(vec![9u8; 32]).pack())
.build();
let mut ctx = init_context(
let (mut ctx, _) = init_context(
vec![(CHEQUE_BIN, true), (SUDT_BIN, false)],
vec![
(receiver.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -582,7 +600,7 @@ fn test_cheque_withdraw() {
.hash_type(ScriptHashType::Data1.into())
.args(Bytes::from(vec![9u8; 32]).pack())
.build();
let mut ctx = init_context(
let (mut ctx, _) = init_context(
vec![(CHEQUE_BIN, true), (SUDT_BIN, false)],
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -667,7 +685,7 @@ fn test_cheque_withdraw() {
#[test]
fn test_dao_deposit() {
let sender = build_sighash_script(ACCOUNT1_ARG);
let ctx = init_context(
let (ctx, _) = init_context(
Vec::new(),
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -732,7 +750,7 @@ fn test_dao_deposit() {
#[test]
fn test_dao_prepare() {
let sender = build_sighash_script(ACCOUNT1_ARG);
let mut ctx = init_context(
let (mut ctx, _) = init_context(
Vec::new(),
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -821,7 +839,7 @@ fn test_dao_prepare() {
#[test]
fn test_dao_withdraw() {
let sender = build_sighash_script(ACCOUNT1_ARG);
let mut ctx = init_context(
let (mut ctx, _) = init_context(
Vec::new(),
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -961,7 +979,7 @@ fn test_udt_issue() {
let sudt_data_hash = H256::from(blake2b_256(SUDT_BIN));
let owner = build_sighash_script(ACCOUNT1_ARG);
let receiver = build_sighash_script(ACCOUNT2_ARG);
let ctx = init_context(
let (ctx, _) = init_context(
vec![(SUDT_BIN, false)],
vec![
(owner.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -1055,7 +1073,7 @@ fn test_udt_transfer() {
.hash_type(ScriptHashType::Data1.into())
.args(owner.calc_script_hash().as_bytes().pack())
.build();
let mut ctx = init_context(
let (mut ctx, _) = init_context(
vec![(ACP_BIN, true), (SUDT_BIN, false)],
vec![
(sender.clone(), Some(100 * ONE_CKB)),
Expand Down Expand Up @@ -1142,10 +1160,3 @@ fn test_udt_transfer() {
);
ctx.verify(tx, FEE_RATE).unwrap();
}

pub mod ckb_indexer_rpc;
pub mod ckb_rpc;
pub mod cycle;
pub mod omni_lock;
pub mod omni_lock_util;
pub mod transaction;
Loading

0 comments on commit 25a55dd

Please sign in to comment.