Skip to content

Commit

Permalink
[diem-transactional-tests] allow specifying sequence number, gas pric…
Browse files Browse the repository at this point in the history
…e and gas currency code as extra args
  • Loading branch information
vgao1996 authored and bors-libra committed Dec 17, 2021
1 parent 2d61827 commit fa53725
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions diem-move/diem-transactional-test-harness/src/diem_test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,42 @@ struct TransactionParameters {
/// Diem-specific arguments for the publish command.
#[derive(StructOpt, Debug)]
struct DiemPublishArgs {
#[structopt(short = "k", long = "private-key", parse(try_from_str = RawPrivateKey::parse))]
#[structopt(long = "private-key", parse(try_from_str = RawPrivateKey::parse))]
private_key: Option<RawPrivateKey>,

#[structopt(short = "t", long = "expiration")]
#[structopt(long = "expiration")]
expiration_time: Option<u64>,

#[structopt(long = "sequence-number")]
sequence_number: Option<u64>,

#[structopt(long = "gas-price")]
gas_unit_price: Option<u64>,

#[structopt(long = "gas-currency")]
gas_currency_code: Option<String>,
}

/// Diem-specifc arguments for the run command.
#[derive(StructOpt, Debug)]
struct DiemRunArgs {
#[structopt(short = "k", long = "private-key", parse(try_from_str = RawPrivateKey::parse))]
#[structopt(long = "private-key", parse(try_from_str = RawPrivateKey::parse))]
private_key: Option<RawPrivateKey>,

#[structopt(long = "--admin-script")]
admin_script: bool,

#[structopt(short = "t", long = "expiration")]
#[structopt(long = "expiration")]
expiration_time: Option<u64>,

#[structopt(long = "sequence-number")]
sequence_number: Option<u64>,

#[structopt(long = "gas-price")]
gas_unit_price: Option<u64>,

#[structopt(long = "gas-currency")]
gas_currency_code: Option<String>,
}

/// Diem-specifc arguments for the init command.
Expand Down Expand Up @@ -857,11 +875,13 @@ impl<'a> MoveTestAdapter<'a> for DiemTestAdapter<'a> {

let txn = RawTransaction::new_module(
*signer,
params.sequence_number,
extra_args.sequence_number.unwrap_or(params.sequence_number),
TransactionModule::new(module_blob),
gas_budget.unwrap_or(params.max_gas_amount),
params.gas_unit_price,
params.gas_currency_code,
extra_args.gas_unit_price.unwrap_or(params.gas_unit_price),
extra_args
.gas_currency_code
.unwrap_or(params.gas_currency_code),
extra_args
.expiration_time
.unwrap_or(params.expiration_timestamp_secs),
Expand Down Expand Up @@ -900,6 +920,12 @@ impl<'a> MoveTestAdapter<'a> for DiemTestAdapter<'a> {
if gas_budget.is_some() {
panic!("Cannot set gas budget for admin script.")
}
if extra_args.gas_unit_price.is_some() {
panic!("Cannot set gas price for admin script.")
}
if extra_args.gas_currency_code.is_some() {
panic!("Cannot set gas currency for admin script.")
}

let private_key = match (extra_args.private_key, &signers[0]) {
(Some(private_key), _) => self.resolve_private_key(&private_key),
Expand All @@ -918,7 +944,7 @@ impl<'a> MoveTestAdapter<'a> for DiemTestAdapter<'a> {

let txn = RawTransaction::new_writeset_script(
signer0,
params.sequence_number,
extra_args.sequence_number.unwrap_or(params.sequence_number),
TransactionScript::new(script_blob, type_args, txn_args),
signer1,
ChainId::test(),
Expand Down Expand Up @@ -966,16 +992,18 @@ impl<'a> MoveTestAdapter<'a> for DiemTestAdapter<'a> {
let params = self.fetch_default_transaction_parameters(&signer)?;
let txn = RawTransaction::new_script_function(
signer,
params.sequence_number,
extra_args.sequence_number.unwrap_or(params.sequence_number),
TransactionScriptFunction::new(
module.clone(),
function.to_owned(),
type_args,
convert_txn_args(&txn_args),
),
gas_budget.unwrap_or(params.max_gas_amount),
params.gas_unit_price,
params.gas_currency_code,
extra_args.gas_unit_price.unwrap_or(params.gas_unit_price),
extra_args
.gas_currency_code
.unwrap_or(params.gas_currency_code),
extra_args
.expiration_time
.unwrap_or(params.expiration_timestamp_secs),
Expand Down

0 comments on commit fa53725

Please sign in to comment.