Skip to content

Commit

Permalink
test: adds sponsor to transactional test runner
Browse files Browse the repository at this point in the history
## Description

Add a way to create programmable transactions with gas from a sponsor
address, rather than a sender address

## Test plan

TBD -- will be used in a follow-up PR.
  • Loading branch information
amnn committed Sep 17, 2024
1 parent 5fca65a commit 6691ca3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions crates/sui-transactional-test-runner/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub struct ConsensusCommitPrologueCommand {
pub struct ProgrammableTransactionCommand {
#[clap(long = "sender")]
pub sender: Option<String>,
#[clap(long = "sponsor")]
pub sponsor: Option<String>,
#[clap(long = "gas-budget")]
pub gas_budget: Option<u64>,
#[clap(long = "gas-price")]
Expand Down
53 changes: 40 additions & 13 deletions crates/sui-transactional-test-runner/src/test_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use sui_types::storage::ObjectStore;
use sui_types::storage::ReadStore;
use sui_types::transaction::Command;
use sui_types::transaction::ProgrammableTransaction;
use sui_types::utils::to_sender_signed_transaction_with_multi_signers;
use sui_types::SUI_SYSTEM_ADDRESS;
use sui_types::{
base_types::{ObjectID, ObjectRef, SuiAddress, SUI_ADDRESS_LENGTH},
Expand Down Expand Up @@ -735,6 +736,7 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter {
}
SuiSubcommand::ProgrammableTransaction(ProgrammableTransactionCommand {
sender,
sponsor,
gas_budget,
gas_price,
dev_inspect,
Expand Down Expand Up @@ -782,15 +784,17 @@ impl<'a> MoveTestAdapter<'a> for SuiTestAdapter {
let summary = if !dev_inspect {
let gas_budget = gas_budget.unwrap_or(DEFAULT_GAS_BUDGET);
let gas_price = gas_price.unwrap_or(self.gas_price);
let transaction = self.sign_txn(sender, |sender, gas| {
TransactionData::new_programmable(
sender,
vec![gas],
ProgrammableTransaction { inputs, commands },
gas_budget,
gas_price,
)
});
let transaction =
self.sign_sponsor_txn(sender, sponsor, |sender, sponsor, gas| {
TransactionData::new_programmable_allow_sponsor(
sender,
vec![gas],
ProgrammableTransaction { inputs, commands },
gas_budget,
gas_price,
sponsor,
)
});
self.execute_txn(transaction).await?
} else {
assert!(
Expand Down Expand Up @@ -1360,13 +1364,36 @@ impl<'a> SuiTestAdapter {
sender: Option<String>,
txn_data: impl FnOnce(/* sender */ SuiAddress, /* gas */ ObjectRef) -> TransactionData,
) -> Transaction {
let test_account = self.get_sender(sender);
self.sign_sponsor_txn(sender, None, move |sender, _, gas| txn_data(sender, gas))
}

fn sign_sponsor_txn(
&self,
sender: Option<String>,
sponsor: Option<String>,
txn_data: impl FnOnce(
/* sender */ SuiAddress,
/* sponsor */ SuiAddress,
/* gas */ ObjectRef,
) -> TransactionData,
) -> Transaction {
let sender = self.get_sender(sender);
let sponsor = sponsor.map_or(sender, |a| self.get_sender(Some(a)));

let gas_payment = self
.get_object(&test_account.gas, None)
.get_object(&sender.gas, None)
.unwrap()
.compute_object_reference();
let data = txn_data(test_account.address, gas_payment);
to_sender_signed_transaction(data, &test_account.key_pair)

let data = txn_data(sender.address, sponsor.address, gas_payment);
if sender.address == sponsor.address {
to_sender_signed_transaction(data, &sender.key_pair)
} else {
to_sender_signed_transaction_with_multi_signers(
data,
vec![&sender.key_pair, &sponsor.key_pair],
)
}
}

fn get_sender(&self, sender: Option<String>) -> &TestAccount {
Expand Down

0 comments on commit 6691ca3

Please sign in to comment.