Skip to content

Commit 647d11d

Browse files
authoredApr 13, 2024··
ci(bench): add bench code files into ci lint checking (#1563)
for origin one, the --benches arguments cannot cover rooch-benchmarks may caused by ``` [lib] bench = false ``` setting in rooch-benchmarks/Cargo.toml I add the checking manually and fix clippy warnings
1 parent 1b2cb31 commit 647d11d

File tree

5 files changed

+18
-25
lines changed

5 files changed

+18
-25
lines changed
 

‎crates/rooch-benchmarks/benches/bench_tx_query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn transaction_query_benchmark(c: &mut Criterion) {
3232
let _ = rt.block_on(async { rpc_service.execute_tx(tx).await.unwrap() });
3333
}
3434

35-
let mut tx_orders = (1..500).cycle().map(|v| v);
35+
let mut tx_orders = (1..500).cycle();
3636
c.bench_function("get_transactions_by_order", |b| {
3737
b.to_async(Runtime::new().unwrap()).iter(|| {
3838
rooch_server.get_transactions_by_order(

‎crates/rooch-benchmarks/benches/bench_tx_sequence.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ use rooch_types::transaction::LedgerTxData;
1212
use std::time::Duration;
1313

1414
pub fn tx_sequence_benchmark(c: &mut Criterion) {
15-
let mut binding_test = binding_test::RustBindingTest::new().unwrap();
15+
let binding_test = binding_test::RustBindingTest::new().unwrap();
1616
let keystore = InMemKeystore::new_insecure_for_tests(10);
1717

1818
let rooch_account = keystore.addresses()[0];
1919
let rooch_key_pair = keystore
20-
.get_key_pairs(&rooch_account, None)?
20+
.get_key_pairs(&rooch_account, None)
21+
.unwrap()
2122
.pop()
2223
.expect("key pair should have value");
2324
let sequencer_keypair = rooch_key_pair.copy();
2425
let mut sequencer =
25-
gen_sequencer(sequencer_keypair, binding_test.executor().get_rooch_store())?;
26+
gen_sequencer(sequencer_keypair, binding_test.executor().get_rooch_store()).unwrap();
2627

2728
let mut test_transaction_builder = TestTransactionBuilder::new(rooch_account.into());
2829
let tx_cnt = 100;

‎crates/rooch-benchmarks/src/tx.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use std::time::Duration;
6262
use std::{env, fs};
6363
use tracing::info;
6464

65-
pub const EXAMPLE_SIMPLE_BLOG_PACKAGE_NAME: &'static str = "simple_blog";
65+
pub const EXAMPLE_SIMPLE_BLOG_PACKAGE_NAME: &str = "simple_blog";
6666
pub const EXAMPLE_SIMPLE_BLOG_NAMED_ADDRESS: &str = "simple_blog";
6767

6868
#[derive(PartialEq, Eq)]
@@ -319,7 +319,7 @@ pub fn create_l2_tx(
319319
pub fn find_block_height(dir: String) -> Result<Vec<u64>> {
320320
let mut block_heights = Vec::new();
321321

322-
for entry in fs::read_dir(&dir)? {
322+
for entry in fs::read_dir(dir)? {
323323
let entry = entry?;
324324
let path = entry.path();
325325
if path.is_file() && path.extension().unwrap_or_default() == "hex" {
@@ -387,8 +387,7 @@ pub fn tx_exec_benchmark(c: &mut Criterion) {
387387
let btc_blk_dir = env::var("ROOCH_BENCH_BTC_BLK_DIR").unwrap();
388388

389389
let heights = find_block_height(btc_blk_dir.clone()).unwrap();
390-
let mut cnt = 0;
391-
for height in heights {
390+
for (cnt, height) in heights.into_iter().enumerate() {
392391
if cnt >= tx_cnt {
393392
break;
394393
}
@@ -401,7 +400,6 @@ pub fn tx_exec_benchmark(c: &mut Criterion) {
401400
.validate_l1_block(ctx, l1_block.clone())
402401
.unwrap();
403402
transactions.push(move_tx);
404-
cnt += 1;
405403
}
406404
}
407405

‎crates/rooch-test-transaction-builder/src/lib.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,19 @@ impl TestTransactionBuilder {
8080
}
8181

8282
pub fn call_article_create(&self) -> MoveAction {
83-
let mut args = vec![];
84-
args.push(
83+
let args = vec![
8584
bcs::to_bytes(&random_string_with_size(20)).expect("serialize title should success"),
86-
);
87-
args.push(bcs::to_bytes(&random_string()).expect("serialize body should success"));
85+
bcs::to_bytes(&random_string()).expect("serialize body should success"),
86+
];
8887

8988
self.new_function_call("simple_blog", "create_article", args, vec![])
9089
}
9190

9291
pub fn call_article_create_with_size(&self, len: usize) -> MoveAction {
93-
let mut args = vec![];
94-
args.push(
92+
let args = vec![
9593
bcs::to_bytes(&random_string_with_size(20)).expect("serialize title should success"),
96-
);
97-
args.push(
9894
bcs::to_bytes(&random_string_with_size(len)).expect("serialize body should success"),
99-
);
95+
];
10096

10197
self.new_function_call("simple_blog", "create_article", args, vec![])
10298
}
@@ -135,13 +131,10 @@ impl TestTransactionBuilder {
135131
let mut config = BuildConfig::default();
136132

137133
// Parse named addresses from context and update config
138-
match named_address_key {
139-
Some(key) => {
140-
let mut named_addresses = BTreeMap::<String, AccountAddress>::new();
141-
named_addresses.insert(key, self.sender);
142-
config.additional_named_addresses = named_addresses;
143-
}
144-
None => {}
134+
if let Some(key) = named_address_key {
135+
let mut named_addresses = BTreeMap::<String, AccountAddress>::new();
136+
named_addresses.insert(key, self.sender);
137+
config.additional_named_addresses = named_addresses;
145138
};
146139
let config_cloned = config.clone();
147140

‎scripts/pr.sh

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ MOVE_TEST_CRATES="\
9191
if [ ! -z "$CHECK" ]; then
9292
cargo fmt -- --check
9393
cargo clippy --all-targets --all-features --tests --benches -- -D warnings
94+
cargo clippy -p rooch-benchmarks --all-features --tests --benches -- -D warnings
9495
fi
9596

9697
cargo build

0 commit comments

Comments
 (0)
Please sign in to comment.