Skip to content

Commit

Permalink
Merge pull request #4 from cryptape/gp/v111
Browse files Browse the repository at this point in the history
  • Loading branch information
15168316096 authored Dec 29, 2023
2 parents 04579f8 + 9c33ea2 commit 98490c3
Show file tree
Hide file tree
Showing 77 changed files with 1,938 additions and 45 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,28 @@ jobs:
- name: Test
run: |
sh prepare.sh
cd feature/ && cargo test -- --nocapture
cd feature
rustup toolchain install nightly
cargo +nightly test -- --format=json -Z unstable-options --report-time > test-report.json
- name: json to report md
if: failure()
run: |
cd feature
cargo install markdown-test-report
markdown-test-report test-report.json -o test-report.md
- name: Upload to Qiniu
if: failure()
uses: gpBlockchain/upload-to-qiniu-action@main
with:
access_key: ${{ secrets.ACCESS_KEY }}
secret_key: ${{ secrets.SECRET_KEY }}
bucket_name: acceptance-test
key: ckb-rust-integration-test/test-report.md
local_file: /home/runner/work/ckb-rust-integration-test/ckb-rust-integration-test/feature/test-report.md
- name: print download url
if: failure()
run: |
log_message="https://github-test-logs.ckbapp.dev/ckb-rust-integration-test/test-report.md"
echo "::set-output name=log_message::$log_message"
echo $log_message
6 changes: 3 additions & 3 deletions feature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ ckb-jsonrpc-types = "=0.111.0"
ckb-hash = "=0.111.0"
ckb-resource = "=0.111.0"
ckb-crypto = { version = "=0.111.0", features = ["secp"] }
ckb-script = { version = "=0.111.0"}
ckb-sdk = {git = "https://github.com/nervosnetwork/ckb-sdk-rust.git", branch = "master"}
ckb-script = { version = "=0.111.0" }
ckb-sdk = { git = "https://github.com/nervosnetwork/ckb-sdk-rust.git", branch = "master" }
ckb-logger = "0.111.0"
bitflags = "1.3.2"
sha3 = "0.10.1"
enum-repr-derive = "0.2.0"

# for feature test
rand = { version = "0.8.5", optional = true }
ckb-mock-tx-types = {git = "https://github.com/nervosnetwork/ckb-standalone-debugger", branch = "develop"}
ckb-mock-tx-types = { git = "https://github.com/nervosnetwork/ckb-standalone-debugger", branch = "develop" }
ckb-chain-spec = { version = "0.111.0", optional = true }

sparse-merkle-tree = "0.6.1"
Expand Down
11 changes: 5 additions & 6 deletions feature/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use ckb_sdk::CkbRpcClient;

pub fn setup(){
//!todo 公共部分完成环境预处理准备
}
// pub fn setup(){
// todo 公共部分完成环境预处理准备
// }

pub const CKB_DEVNET: &str = "https://testnet.ckbapp.dev/";

pub const CKB_DEVNET2: &str = "https://testnet.ckb.dev/";
// pub const CKB_DEVNET2: &str = "https://testnet.ckb.dev/";

pub const CKB_MOCKNET: &str = "http://127.0.0.1:5000/test";
// pub const CKB_MOCKNET: &str = "http://127.0.0.1:5000/test";

pub fn remove_quotes(json_string: &String) -> &str {
// 去除字符串开头和结尾的双引号
Expand Down
26 changes: 13 additions & 13 deletions feature/tests/integration0108_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const ARGS: [u8; 32] = [
];
#[test]
fn test_get_indexer_tip() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);
let indexer_tip = ckb_client.get_indexer_tip().unwrap().unwrap();
let tip_block_number = ckb_client.get_tip_block_number().unwrap().value();
assert!(indexer_tip.block_number.value() - tip_block_number <= 1);
}

#[test]
fn test_cells_search_mode_default_partitial() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
// default with partitial args
Expand All @@ -46,7 +46,7 @@ fn test_cells_search_mode_default_partitial() {
}
#[test]
fn test_cells_search_mode_prefix_partitial() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
// prefix with partitial args
Expand All @@ -69,7 +69,7 @@ fn test_cells_search_mode_prefix_partitial() {
}
#[test]
fn test_cells_search_mode_exact_partitial() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -91,7 +91,7 @@ fn test_cells_search_mode_exact_partitial() {
}
#[test]
fn test_cells_search_mode_exact() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -114,7 +114,7 @@ fn test_cells_search_mode_exact() {

#[test]
fn test_get_transactions_search_mode_default() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -137,7 +137,7 @@ fn test_get_transactions_search_mode_default() {

#[test]
fn test_get_transactions_search_mode_prefix_partial() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -159,7 +159,7 @@ fn test_get_transactions_search_mode_prefix_partial() {
}
#[test]
fn test_get_transactions_search_mode_exact_partitial() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -181,7 +181,7 @@ fn test_get_transactions_search_mode_exact_partitial() {
}
#[test]
fn test_get_transactions_search_mode_exact_full() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
// exact search
Expand All @@ -204,7 +204,7 @@ fn test_get_transactions_search_mode_exact_full() {
}
#[test]
fn test_get_cells_capacity_search_mode_default() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -225,7 +225,7 @@ fn test_get_cells_capacity_search_mode_default() {

#[test]
fn test_get_cells_capacity_search_mode_prefix_partial() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -246,7 +246,7 @@ fn test_get_cells_capacity_search_mode_prefix_partial() {

#[test]
fn test_get_cells_capacity_search_mode_exact_partital() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand All @@ -267,7 +267,7 @@ fn test_get_cells_capacity_search_mode_exact_partital() {

#[test]
fn test_get_cells_capacity_search_mode_exact() {
let mut ckb_client = CkbRpcClient::new(CKB_DEVNET);
let ckb_client = CkbRpcClient::new(CKB_DEVNET);

let block_range = Some(ValueRangeOption::new(0, 1));
let script = ckb_types::packed::Script::new_builder()
Expand Down
8 changes: 3 additions & 5 deletions feature/tests/integration0111_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
mod mockrpc;
mod common;

use std::fmt::Debug;
use ckb_jsonrpc_types::{Cycle, DeploymentPos, Transaction};
use ckb_types::H256;
use crate::common::remove_quotes;
use serde::Serialize;
use crate::mockrpc::mock_rpc_data;
use crate::mockrpc::MockRpcData;
use rstest::*;

#[rstest(mock_rpc_data("estimate_cycles", "[tx]"))]
fn estimate_cycles_tx(mock_rpc_data: MockRpcData) {
let mut ckb_client = mock_rpc_data.client();
let ckb_client = mock_rpc_data.client();
let json_str = serde_json::to_string(&mock_rpc_data.request_data["params"][0]).unwrap();
let transaction: Transaction = serde_json::from_str(&*json_str).unwrap();
let cycle = ckb_client.estimate_cycles(transaction).unwrap();
Expand All @@ -23,7 +21,7 @@ fn estimate_cycles_tx(mock_rpc_data: MockRpcData) {

#[rstest(mock_rpc_data("get_block", "[block_hash]"))]
fn get_block_block_hash(mock_rpc_data: MockRpcData) {
let mut ckb_client = mock_rpc_data.client();
let ckb_client = mock_rpc_data.client();
let code_hash: H256 = serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap();
let block = ckb_client.get_block(code_hash).unwrap().unwrap();
assert_eq!("0x".to_owned() + &block.header.hash.to_string(), remove_quotes(&serde_json::to_string(
Expand All @@ -32,7 +30,7 @@ fn get_block_block_hash(mock_rpc_data: MockRpcData) {

#[rstest(mock_rpc_data("get_consensus", "[]"))]
fn get_consensus(mock_rpc_data: MockRpcData) {
let mut ckb_client = mock_rpc_data.client();
let ckb_client = mock_rpc_data.client();
let consensus = ckb_client.get_consensus().unwrap();
assert_eq!(
serde_json::to_string(&consensus.block_version).unwrap(),
Expand Down
14 changes: 14 additions & 0 deletions feature/tests/mock_light_rpc/fetch_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("fetch_header", "fetched"))]
fn add_node_with_peer_id_address(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.fetch_header(
serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap()
).unwrap();
assert_eq!(ret, serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
14 changes: 14 additions & 0 deletions feature/tests/mock_light_rpc/fetch_transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("fetch_transaction", "fetched"))]
fn fetch_transaction_fetched(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.fetch_transaction(
serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap()
).unwrap();
assert_eq!(ret, serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
19 changes: 19 additions & 0 deletions feature/tests/mock_light_rpc/get_cells.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_cells", "[search_key,order,limit,after_cursor]:rust"))]
fn get_cells_search_key_order_limit_after_cursor(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_cells(
serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap(),
serde_json::from_value(mock_rpc_data.request_data["params"][1].clone()).unwrap(),
serde_json::from_value(mock_rpc_data.request_data["params"][2].clone()).unwrap(),
None

).unwrap();

// assert_eq!(ret, serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
15 changes: 15 additions & 0 deletions feature/tests/mock_light_rpc/get_cells_capacity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_cells_capacity", "[search_key:rust]"))]
fn get_cells_capacity_search_key(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_cells_capacity(
serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap()
).unwrap();

// assert_eq!(ret, serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
12 changes: 12 additions & 0 deletions feature/tests/mock_light_rpc/get_genesis_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_genesis_block", "[]"))]
fn get_genesis_block(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_genesis_block().unwrap();
assert_eq!(ret, serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
14 changes: 14 additions & 0 deletions feature/tests/mock_light_rpc/get_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_header", "[block_hash]"))]
fn get_header(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_header(
serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap()
).unwrap();
assert_eq!(ret.unwrap(), serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
13 changes: 13 additions & 0 deletions feature/tests/mock_light_rpc/get_peers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_peers", "[]"))]
fn get_peers(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_peers(
).unwrap();
// assert_eq!(ret, serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
13 changes: 13 additions & 0 deletions feature/tests/mock_light_rpc/get_scripts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_scripts", "[]"))]
fn get_scripts(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_scripts(
).unwrap();
// assert_eq!(ret.unwrap(), serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
13 changes: 13 additions & 0 deletions feature/tests/mock_light_rpc/get_tip_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_tip_header", "[]"))]
fn get_tip_header(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_tip_header(
).unwrap();
// assert_eq!(ret.unwrap(), serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
14 changes: 14 additions & 0 deletions feature/tests/mock_light_rpc/get_transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use rstest::rstest;
use crate::mock_light_rpc::{mock_rpc_data, MockRpcData};

#[rstest(mock_rpc_data("get_transaction", "[transaction_hash]"))]
fn get_transaction(mock_rpc_data: MockRpcData) {
println!("method:{}",mock_rpc_data.method);
println!("params:{}",mock_rpc_data.params);
let ckb_light_client = mock_rpc_data.client();

let ret= ckb_light_client.get_transaction(
serde_json::from_value(mock_rpc_data.request_data["params"][0].clone()).unwrap()
).unwrap();
assert_eq!(ret.unwrap(), serde_json::from_value(mock_rpc_data.response_data["result"].clone()).unwrap());
}
Loading

0 comments on commit 98490c3

Please sign in to comment.