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 ad67893
Show file tree
Hide file tree
Showing 18 changed files with 1,907 additions and 227 deletions.
80 changes: 40 additions & 40 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI workflow

on:
pull_request:
types: [ opened, synchronize, reopened ]
types: [opened, synchronize, reopened]
push:
branches:
- "develop"
Expand All @@ -18,63 +18,63 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-2019 ]
os: [ubuntu-latest, macos-latest, windows-2019]
steps:
- uses: actions/checkout@v2
- if: matrix.os == 'windows-2019'
name: Windows Dependencies
run: |
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
.\install-scoop.ps1 -RunAsAdmin
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
scoop install llvm yasm
- name: UnitTest
run: make test
- uses: actions/checkout@v2
- if: matrix.os == 'windows-2019'
name: Windows Dependencies
run: |
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
.\install-scoop.ps1 -RunAsAdmin
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
scoop install llvm yasm
- name: UnitTest
run: make test

build-examples:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-2019 ]
os: [ubuntu-latest, macos-latest, windows-2019]
steps:
- uses: actions/checkout@v2
- if: matrix.os == 'windows-2019'
name: Windows Dependencies
run: |
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
.\install-scoop.ps1 -RunAsAdmin
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
scoop install llvm yasm
- name: Build Cargo Examples
run: cargo build --examples
- uses: actions/checkout@v2
- if: matrix.os == 'windows-2019'
name: Windows Dependencies
run: |
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
.\install-scoop.ps1 -RunAsAdmin
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
scoop install llvm yasm
- name: Build Cargo Examples
run: cargo build --examples

linters:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Linters
run: |
cargo fmt --version || rustup component add rustfmt
cargo clippy --version || rustup component add clippy
make fmt
make clippy
- uses: actions/checkout@v2
- name: Linters
run: |
cargo fmt --version || rustup component add rustfmt
cargo clippy --version || rustup component add clippy
make fmt
make clippy
security-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Security Audit & Licenses
run: |
rustup toolchain install stable --profile minimal
cargo deny --version || cargo install cargo-deny --locked
make security-audit
make check-crates
make check-licenses
- uses: actions/checkout@v2
- name: Security Audit & Licenses
run: |
rustup toolchain install stable --profile minimal
cargo deny --version || cargo install cargo-deny --version 0.16.2 --locked
make security-audit
make check-crates
make check-licenses
ci-success:
name: ci
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sha3 = "0.10.1"
enum-repr-derive = "0.2.0"

# for feature test
rand = { version = "0.7.3", optional = true }
rand = { version = "0.7.3" }
ckb-mock-tx-types = { version = "0.119.0" }
ckb-chain-spec = "0.119.0"

Expand Down
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 ad67893

Please sign in to comment.