Skip to content

Commit c6d80db

Browse files
committed
test: add more test
1 parent 3ed8d5e commit c6d80db

File tree

20 files changed

+1911
-230
lines changed

20 files changed

+1911
-230
lines changed

.github/workflows/ci.yaml

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI workflow
22

33
on:
44
pull_request:
5-
types: [ opened, synchronize, reopened ]
5+
types: [opened, synchronize, reopened]
66
push:
77
branches:
88
- "develop"
@@ -18,63 +18,64 @@ jobs:
1818
runs-on: ${{ matrix.os }}
1919
strategy:
2020
matrix:
21-
os: [ ubuntu-latest, macos-latest, windows-2019 ]
21+
os: [ubuntu-latest, macos-latest, windows-2019]
2222
steps:
23-
- uses: actions/checkout@v2
24-
- if: matrix.os == 'windows-2019'
25-
name: Windows Dependencies
26-
run: |
27-
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
28-
.\install-scoop.ps1 -RunAsAdmin
29-
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
30-
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
31-
scoop install llvm yasm
32-
- name: UnitTest
33-
run: make test
23+
- uses: actions/checkout@v2
24+
- if: matrix.os == 'windows-2019'
25+
name: Windows Dependencies
26+
run: |
27+
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
28+
.\install-scoop.ps1 -RunAsAdmin
29+
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
30+
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
31+
scoop install llvm yasm
32+
- name: UnitTest
33+
run: make test
3434

3535
build-examples:
3636
runs-on: ${{ matrix.os }}
3737
strategy:
3838
matrix:
39-
os: [ ubuntu-latest, macos-latest, windows-2019 ]
39+
os: [ubuntu-latest, macos-latest, windows-2019]
4040
steps:
41-
- uses: actions/checkout@v2
42-
- if: matrix.os == 'windows-2019'
43-
name: Windows Dependencies
44-
run: |
45-
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
46-
.\install-scoop.ps1 -RunAsAdmin
47-
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
48-
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
49-
scoop install llvm yasm
50-
- name: Build Cargo Examples
51-
run: cargo build --examples
41+
- uses: actions/checkout@v2
42+
- if: matrix.os == 'windows-2019'
43+
name: Windows Dependencies
44+
run: |
45+
iwr -useb get.scoop.sh -outfile 'install-scoop.ps1'
46+
.\install-scoop.ps1 -RunAsAdmin
47+
echo "LIBCLANG_PATH=$($HOME)/scoop/apps/llvm/current/bin" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
48+
echo "$env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
49+
scoop install llvm yasm
50+
- name: Build Cargo Examples
51+
run: cargo build --examples
5252

5353
linters:
5454
runs-on: ${{ matrix.os }}
5555
strategy:
5656
matrix:
5757
os: [ubuntu-latest, macos-latest]
5858
steps:
59-
- uses: actions/checkout@v2
60-
- name: Linters
61-
run: |
62-
cargo fmt --version || rustup component add rustfmt
63-
cargo clippy --version || rustup component add clippy
64-
make fmt
65-
make clippy
59+
- uses: actions/checkout@v2
60+
- name: Linters
61+
run: |
62+
cargo fmt --version || rustup component add rustfmt
63+
cargo clippy --version || rustup component add clippy
64+
make fmt
65+
make clippy
6666
6767
security-audit:
6868
runs-on: ubuntu-latest
6969
steps:
70-
- uses: actions/checkout@v2
71-
- name: Security Audit & Licenses
72-
run: |
73-
rustup toolchain install stable --profile minimal
74-
cargo deny --version || cargo install cargo-deny --locked
75-
make security-audit
76-
make check-crates
77-
make check-licenses
70+
- uses: actions/checkout@v2
71+
- name: Security Audit & Licenses
72+
run: |
73+
rustup toolchain install stable --profile minimal
74+
rm rust-toolchain.toml
75+
cargo deny --version || cargo install cargo-deny --locked
76+
make security-audit
77+
make check-crates
78+
make check-licenses
7879
7980
ci-success:
8081
name: ci

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sha3 = "0.10.1"
5555
enum-repr-derive = "0.2.0"
5656

5757
# for feature test
58-
rand = { version = "0.7.3", optional = true }
58+
rand = { version = "0.7.3" }
5959
ckb-mock-tx-types = { version = "0.119.0" }
6060
ckb-chain-spec = "0.119.0"
6161

deny.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ ignore = [
7474
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
7575
#"[email protected]", # you can also ignore yanked crate versions if you wish
7676
#{ crate = "[email protected]", reason = "you can specify why you are ignoring the yanked crate"
77-
"RUSTSEC-2024-0370" # proc-macro-error's maintainer seems to be unreachable, ignore this
77+
"RUSTSEC-2024-0370", # proc-macro-error's maintainer seems to be unreachable, ignore this
78+
"RUSTSEC-2024-0384", # instant is no longer maintained, ignore this
7879
]
7980
# If this is true, then cargo deny will use the git executable to fetch advisory database.
8081
# If this is false, then it uses a built-in git library.
@@ -97,7 +98,7 @@ allow = [
9798
"ISC",
9899
"MIT",
99100
"Unicode-DFS-2016",
100-
"BSL-1.0", # xxhash-rust 0.8.10
101+
"BSL-1.0", # xxhash-rust 0.8.10
101102

102103
#"MIT",
103104
#"Apache-2.0",

examples/omnilock_examples.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fn main() -> Result<(), Box<dyn StdErr>> {
5151
&SignContexts::new_omnilock(
5252
[secp256k1::SecretKey::from_slice(private_key.as_bytes())?].to_vec(),
5353
omni_cfg,
54+
ckb_sdk::unlock::OmniUnlockMode::Normal,
5455
),
5556
)?;
5657

examples/omnilock_multisig_example.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn main() -> Result<(), Box<dyn StdErr>> {
6262
&SignContexts::new_omnilock(
6363
[secp256k1::SecretKey::from_slice(private_key.as_bytes())?].to_vec(),
6464
omni_cfg.clone(),
65+
ckb_sdk::unlock::OmniUnlockMode::Normal,
6566
),
6667
)?;
6768
let private_key = h256!("0x4fd809631a6aa6e3bb378dd65eae5d71df895a82c91a615a1e8264741515c79c");
@@ -70,6 +71,7 @@ fn main() -> Result<(), Box<dyn StdErr>> {
7071
&SignContexts::new_omnilock(
7172
[secp256k1::SecretKey::from_slice(private_key.as_bytes())?].to_vec(),
7273
omni_cfg,
74+
ckb_sdk::unlock::OmniUnlockMode::Normal,
7375
),
7476
)?;
7577

rust-toolchain

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/core/advanced_builders.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ impl TransactionBuilder {
232232
if witness_data.is_empty() {
233233
WitnessArgs::default()
234234
} else {
235-
WitnessArgs::from_slice(witness_data.as_ref()).unwrap()
235+
WitnessArgs::from_slice(witness_data.as_ref())
236+
.expect("WitnessArgs expected but failed to decode ")
236237
}
237238
}
238239

src/tests/mod.rs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,39 @@ mod tx_builder;
55

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

8+
use ckb_dao_utils::pack_dao_data;
89
use ckb_hash::blake2b_256;
910
use ckb_jsonrpc_types as json_types;
1011
use ckb_types::{
1112
bytes::Bytes,
12-
core::{BlockView, ScriptHashType},
13+
core::{BlockView, Capacity, EpochNumberWithFraction, HeaderBuilder, ScriptHashType},
1314
h160, h256,
14-
packed::{OutPoint, Script},
15+
packed::{CellInput, CellOutput, OutPoint, Script, ScriptOpt, WitnessArgs},
1516
prelude::*,
1617
H160, H256,
1718
};
1819

19-
use crate::constants::{DAO_TYPE_HASH, MULTISIG_TYPE_HASH, ONE_CKB, SIGHASH_TYPE_HASH};
20+
use crate::constants::{
21+
CHEQUE_CELL_SINCE, DAO_TYPE_HASH, MULTISIG_TYPE_HASH, ONE_CKB, SIGHASH_TYPE_HASH,
22+
};
2023
use crate::traits::SecpCkbRawKeySigner;
21-
use crate::unlock::{MultisigConfig, OmniLockConfig, ScriptUnlocker, SecpMultisigUnlocker};
22-
use crate::ScriptId;
24+
use crate::tx_builder::{
25+
acp::{AcpTransferBuilder, AcpTransferReceiver},
26+
cheque::{ChequeClaimBuilder, ChequeWithdrawBuilder},
27+
dao::{
28+
DaoDepositBuilder, DaoDepositReceiver, DaoPrepareBuilder, DaoWithdrawBuilder,
29+
DaoWithdrawItem, DaoWithdrawReceiver,
30+
},
31+
transfer::CapacityTransferBuilder,
32+
udt::{UdtIssueBuilder, UdtTargetReceiver, UdtTransferBuilder, UdtType},
33+
unlock_tx, CapacityBalancer, TransferAction, TxBuilder,
34+
};
35+
use crate::unlock::{
36+
AcpUnlocker, ChequeAction, ChequeUnlocker, MultisigConfig, OmniLockConfig, ScriptUnlocker,
37+
SecpMultisigUnlocker, SecpSighashUnlocker,
38+
};
39+
use crate::util::{calculate_dao_maximum_withdraw4, minimal_unlock_point};
40+
use crate::{ScriptId, Since, SinceType};
2341

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

@@ -161,7 +179,7 @@ fn init_context(
161179
fn test_transfer_from_sighash() {
162180
let sender = build_sighash_script(ACCOUNT1_ARG);
163181
let receiver = build_sighash_script(ACCOUNT2_ARG);
164-
let ctx = init_context(
182+
let (ctx, _) = init_context(
165183
Vec::new(),
166184
vec![
167185
(sender.clone(), Some(100 * ONE_CKB)),
@@ -218,7 +236,7 @@ fn test_transfer_from_sighash() {
218236
fn test_transfer_capacity_overflow() {
219237
let sender = build_sighash_script(ACCOUNT1_ARG);
220238
let receiver = build_sighash_script(ACCOUNT2_ARG);
221-
let ctx = init_context(Vec::new(), vec![(sender.clone(), Some(100 * ONE_CKB))]);
239+
let (ctx, _) = init_context(Vec::new(), vec![(sender.clone(), Some(100 * ONE_CKB))]);
222240

223241
let large_amount: u64 = u64::MAX;
224242
let output = CellOutput::new_builder()
@@ -251,7 +269,7 @@ fn test_transfer_from_multisig() {
251269
let sender = build_multisig_script(&cfg);
252270
let receiver = build_sighash_script(ACCOUNT2_ARG);
253271

254-
let ctx = init_context(
272+
let (ctx, _) = init_context(
255273
Vec::new(),
256274
vec![
257275
(sender.clone(), Some(100 * ONE_CKB)),
@@ -315,7 +333,7 @@ fn test_transfer_from_acp() {
315333
.args(Bytes::from(ACCOUNT1_ARG.0.to_vec()).pack())
316334
.build();
317335
let receiver = build_sighash_script(ACCOUNT2_ARG);
318-
let ctx = init_context(
336+
let (ctx, _) = init_context(
319337
vec![(ACP_BIN, true)],
320338
vec![
321339
(sender.clone(), Some(100 * ONE_CKB)),
@@ -376,7 +394,7 @@ fn test_transfer_to_acp() {
376394
.hash_type(ScriptHashType::Data1.into())
377395
.args(Bytes::from(ACCOUNT2_ARG.0.to_vec()).pack())
378396
.build();
379-
let ctx = init_context(
397+
let (ctx, _) = init_context(
380398
vec![(ACP_BIN, true)],
381399
vec![
382400
(sender.clone(), Some(100 * ONE_CKB)),
@@ -462,7 +480,7 @@ fn test_cheque_claim() {
462480
.hash_type(ScriptHashType::Data1.into())
463481
.args(Bytes::from(vec![9u8; 32]).pack())
464482
.build();
465-
let mut ctx = init_context(
483+
let (mut ctx, _) = init_context(
466484
vec![(CHEQUE_BIN, true), (SUDT_BIN, false)],
467485
vec![
468486
(receiver.clone(), Some(100 * ONE_CKB)),
@@ -582,7 +600,7 @@ fn test_cheque_withdraw() {
582600
.hash_type(ScriptHashType::Data1.into())
583601
.args(Bytes::from(vec![9u8; 32]).pack())
584602
.build();
585-
let mut ctx = init_context(
603+
let (mut ctx, _) = init_context(
586604
vec![(CHEQUE_BIN, true), (SUDT_BIN, false)],
587605
vec![
588606
(sender.clone(), Some(100 * ONE_CKB)),
@@ -667,7 +685,7 @@ fn test_cheque_withdraw() {
667685
#[test]
668686
fn test_dao_deposit() {
669687
let sender = build_sighash_script(ACCOUNT1_ARG);
670-
let ctx = init_context(
688+
let (ctx, _) = init_context(
671689
Vec::new(),
672690
vec![
673691
(sender.clone(), Some(100 * ONE_CKB)),
@@ -732,7 +750,7 @@ fn test_dao_deposit() {
732750
#[test]
733751
fn test_dao_prepare() {
734752
let sender = build_sighash_script(ACCOUNT1_ARG);
735-
let mut ctx = init_context(
753+
let (mut ctx, _) = init_context(
736754
Vec::new(),
737755
vec![
738756
(sender.clone(), Some(100 * ONE_CKB)),
@@ -821,7 +839,7 @@ fn test_dao_prepare() {
821839
#[test]
822840
fn test_dao_withdraw() {
823841
let sender = build_sighash_script(ACCOUNT1_ARG);
824-
let mut ctx = init_context(
842+
let (mut ctx, _) = init_context(
825843
Vec::new(),
826844
vec![
827845
(sender.clone(), Some(100 * ONE_CKB)),
@@ -961,7 +979,7 @@ fn test_udt_issue() {
961979
let sudt_data_hash = H256::from(blake2b_256(SUDT_BIN));
962980
let owner = build_sighash_script(ACCOUNT1_ARG);
963981
let receiver = build_sighash_script(ACCOUNT2_ARG);
964-
let ctx = init_context(
982+
let (ctx, _) = init_context(
965983
vec![(SUDT_BIN, false)],
966984
vec![
967985
(owner.clone(), Some(100 * ONE_CKB)),
@@ -1055,7 +1073,7 @@ fn test_udt_transfer() {
10551073
.hash_type(ScriptHashType::Data1.into())
10561074
.args(owner.calc_script_hash().as_bytes().pack())
10571075
.build();
1058-
let mut ctx = init_context(
1076+
let (mut ctx, _) = init_context(
10591077
vec![(ACP_BIN, true), (SUDT_BIN, false)],
10601078
vec![
10611079
(sender.clone(), Some(100 * ONE_CKB)),
@@ -1142,10 +1160,3 @@ fn test_udt_transfer() {
11421160
);
11431161
ctx.verify(tx, FEE_RATE).unwrap();
11441162
}
1145-
1146-
pub mod ckb_indexer_rpc;
1147-
pub mod ckb_rpc;
1148-
pub mod cycle;
1149-
pub mod omni_lock;
1150-
pub mod omni_lock_util;
1151-
pub mod transaction;

0 commit comments

Comments
 (0)