Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "substrate-txtesttool"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
description = "A library and CLI tool for sending transactions to substrate-based chains, enabling developers to test and monitor transaction scenarios."
license = "Apache-2.0 OR GPL-3.0"
Expand Down
67 changes: 67 additions & 0 deletions examples/kill_dev_entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.

//! Example: Send `TestPallet::kill_dev_entry` transactions using a custom payload builder.
//!
//! This example demonstrates how to use `with_tx_payload_builder_sub` to build a custom spammer
//! tool using specific transactions.
//!
//! Usage:
//! ```bash
//! cargo run --example kill_dev_entry -- --start-id 0 --last-id 99
//! ```

use clap::Parser;
use substrate_txtesttool::scenario::{ChainType, ScenarioBuilder};
use subxt::dynamic::Value;

#[derive(Parser)]
#[clap(name = "kill_dev_entry")]
struct Cli {
/// Start account ID (inclusive)
#[clap(long)]
start_id: u32,

/// Last account ID (inclusive)
#[clap(long)]
last_id: u32,

/// The RPC endpoint of the node to be used.
#[clap(long, default_value = "ws://127.0.0.1:9933")]
ws: String,

/// Send transactions threshold
#[clap(long, default_value_t = 10000)]
send_threshold: u32,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
substrate_txtesttool::init_logger();

let cli = Cli::parse();

let scenario_builder = ScenarioBuilder::new()
.with_rpc_uri(cli.ws)
.with_watched_txs(true)
.with_chain_type(ChainType::Sub)
.with_send_threshold(cli.send_threshold as usize)
.with_start_id(cli.start_id)
.with_last_id(cli.last_id)
.with_txs_count(1)
.with_legacy_backend(true)
.with_installed_ctrlc_stop_hook(true)
.with_tx_payload_builder_sub(|ctx| {
let x = ctx.account.parse::<u32>().unwrap();
const BATCH_SIZE: u32 = 5;
let start = Value::u128((BATCH_SIZE * x) as u128);
let count = Value::u128(BATCH_SIZE.into());
subxt::dynamic::tx("TestPallet", "kill_dev_entry", vec![start, count])
});

let scenario_executor = scenario_builder.build().await;
let _ = scenario_executor.execute().await;

Ok(())
}
2 changes: 1 addition & 1 deletion src/execution_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ pub mod journal {

writeln!(file, "hash,{}", CsvEntry::<T>::header_line()).unwrap();
for (h, v) in raw_data {
writeln!(file, "{:?},{}", h, v).unwrap();
writeln!(file, "{h:?},{v}").unwrap();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ pub mod subxt_api_connector;
pub mod subxt_transaction;
pub mod transaction;

// Re-export commonly used types for custom payload builders
pub use subxt_transaction::{
eth_transfer_payload_builder, remark_payload_builder, sub_transfer_payload_builder,
EthPayloadBuilderFn, EthTxBuildContext, PayloadBuilderFn, SubPayloadBuilderFn,
SubTxBuildContext, TxPayloadBuildContext,
};

/// Initialize the logger for various binaries (e.g. ttxt or test binaries).
pub fn init_logger() {
use std::sync::Once;
Expand Down
6 changes: 3 additions & 3 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ where
let default_file_name = self
.executor_id
.as_ref()
.map(|id| format!("ttxt_{}_{}.json", id, formatted_date))
.unwrap_or(format!("ttxt_{}.json", formatted_date));
.map(|id| format!("ttxt_{id}_{formatted_date}.json"))
.unwrap_or(format!("ttxt_{formatted_date}.json"));
self.base_dir_path
.as_ref()
.map(|basedir| {
let filename = self
.log_file_name
.as_ref()
.map(|filename| format!("{basedir}/{filename}_{}", formatted_date))
.map(|filename| format!("{basedir}/{filename}_{formatted_date}"))
.unwrap_or(format!("{basedir}/{default_file_name}"));
filename
})
Expand Down
Loading