Skip to content

Commit

Permalink
Minimal changes to test utils api to support running benchmarks (Myst…
Browse files Browse the repository at this point in the history
  • Loading branch information
sadhansood authored Jul 28, 2022
1 parent 33f1185 commit 71d57e7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
19 changes: 16 additions & 3 deletions crates/sui-benchmark/src/stress/shared_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use test_utils::{
authority::test_authority_aggregator,
messages::{make_counter_create_transaction, make_counter_increment_transaction},
objects::{generate_gas_object, generate_gas_objects_for_testing},
test_account_keys,
transaction::publish_counter_package,
};

Expand All @@ -38,7 +39,14 @@ impl Payload for SharedCounterTestPayload {
})
}
fn make_transaction(&self) -> TransactionEnvelope<EmptySignInfo> {
make_counter_increment_transaction(self.gas.0, self.package_ref, self.counter_id)
let (sender, keypair) = test_account_keys().pop().unwrap();
make_counter_increment_transaction(
self.gas.0,
self.package_ref,
self.counter_id,
sender,
&keypair,
)
}
fn get_object_id(&self) -> ObjectID {
self.counter_id
Expand Down Expand Up @@ -83,8 +91,13 @@ impl StressTestCtx<dyn Payload> for SharedCounterTestCtx {
.map(|g| (quorum_driver_handler.clone_quorum_driver(), g));
// create counters
let futures = qd_and_gas.map(|(qd, gas_object)| async move {
let tx =
make_counter_create_transaction(gas_object.compute_object_reference(), package_ref);
let (sender, keypair) = test_account_keys().pop().unwrap();
let tx = make_counter_create_transaction(
gas_object.compute_object_reference(),
package_ref,
sender,
&keypair,
);
if let ExecuteTransactionResponse::EffectsCert(result) = qd
.execute_transaction(ExecuteTransactionRequest {
transaction: tx,
Expand Down
10 changes: 9 additions & 1 deletion crates/sui/tests/quorum_driver_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use test_utils::authority::{
};
use test_utils::messages::make_transfer_sui_transaction;
use test_utils::objects::test_gas_objects;
use test_utils::test_account_keys;

async fn setup() -> (
Vec<SuiNode>,
Expand All @@ -26,7 +27,14 @@ async fn setup() -> (
let configs = test_authority_configs();
let handles = spawn_test_authorities(gas_objects.clone(), &configs).await;
let clients = test_authority_aggregator(&configs);
let tx = make_transfer_sui_transaction(gas_objects.pop().unwrap(), SuiAddress::default());
let (sender, keypair) = test_account_keys().pop().unwrap();
let tx = make_transfer_sui_transaction(
gas_objects.pop().unwrap().compute_object_reference(),
SuiAddress::default(),
None,
sender,
&keypair,
);
(handles, clients, tx)
}

Expand Down
43 changes: 22 additions & 21 deletions crates/test-utils/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ pub fn test_shared_object_transactions() -> Vec<Transaction> {
}

/// Make a transaction to publish a test move contracts package.
pub fn create_publish_move_package_transaction(gas_object: Object, path: PathBuf) -> Transaction {
pub fn create_publish_move_package_transaction(
gas_object_ref: ObjectRef,
path: PathBuf,
sender: SuiAddress,
keypair: &AccountKeyPair,
) -> Transaction {
let build_config = BuildConfig::default();
let modules = sui_framework::build_move_package(&path, build_config).unwrap();

Expand All @@ -128,26 +133,20 @@ pub fn create_publish_move_package_transaction(gas_object: Object, path: PathBuf
module_bytes
})
.collect();

let gas_object_ref = gas_object.compute_object_reference();

let (sender, keypair) = test_account_keys().pop().unwrap();

let data = TransactionData::new_module(sender, gas_object_ref, all_module_bytes, MAX_GAS);
let signature = Signature::new(&data, &keypair);
let signature = Signature::new(&data, keypair);
Transaction::new(data, signature)
}

pub fn make_transfer_sui_transaction(gas_object: Object, recipient: SuiAddress) -> Transaction {
let (sender, keypair) = test_account_keys().pop().unwrap();
let data = TransactionData::new_transfer_sui(
recipient,
sender,
None,
gas_object.compute_object_reference(),
MAX_GAS,
);
let signature = Signature::new(&data, &keypair);
pub fn make_transfer_sui_transaction(
gas_object: ObjectRef,
recipient: SuiAddress,
amount: Option<u64>,
sender: SuiAddress,
keypair: &AccountKeyPair,
) -> Transaction {
let data = TransactionData::new_transfer_sui(recipient, sender, amount, gas_object, MAX_GAS);
let signature = Signature::new(&data, keypair);
Transaction::new(data, signature)
}

Expand Down Expand Up @@ -185,8 +184,9 @@ pub fn make_publish_basics_transaction(gas_object: ObjectRef) -> Transaction {
pub fn make_counter_create_transaction(
gas_object: ObjectRef,
package_ref: ObjectRef,
sender: SuiAddress,
keypair: &AccountKeyPair,
) -> Transaction {
let (sender, keypair) = test_account_keys().pop().unwrap();
let data = TransactionData::new_move_call(
sender,
package_ref,
Expand All @@ -197,16 +197,17 @@ pub fn make_counter_create_transaction(
vec![],
MAX_GAS,
);
let signature = Signature::new(&data, &keypair);
let signature = Signature::new(&data, keypair);
Transaction::new(data, signature)
}

pub fn make_counter_increment_transaction(
gas_object: ObjectRef,
package_ref: ObjectRef,
counter_id: ObjectID,
sender: SuiAddress,
keypair: &AccountKeyPair,
) -> Transaction {
let (sender, keypair) = test_account_keys().pop().unwrap();
let data = TransactionData::new_move_call(
sender,
package_ref,
Expand All @@ -217,7 +218,7 @@ pub fn make_counter_increment_transaction(
vec![CallArg::Object(ObjectArg::SharedObject(counter_id))],
MAX_GAS,
);
let signature = Signature::new(&data, &keypair);
let signature = Signature::new(&data, keypair);
Transaction::new(data, signature)
}

Expand Down
12 changes: 9 additions & 3 deletions crates/test-utils/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::authority::get_client;
use crate::messages::{create_publish_move_package_transaction, make_certificates};
use crate::test_account_keys;
use move_package::BuildConfig;
use serde_json::json;
use std::collections::HashMap;
Expand All @@ -23,7 +24,13 @@ pub async fn publish_package(
path: PathBuf,
configs: &[ValidatorInfo],
) -> ObjectRef {
let transaction = create_publish_move_package_transaction(gas_object, path);
let (sender, keypair) = test_account_keys().pop().unwrap();
let transaction = create_publish_move_package_transaction(
gas_object.compute_object_reference(),
path,
sender,
&keypair,
);
let effects = submit_single_owner_transaction(transaction, configs).await;
parse_package_ref(&effects).unwrap()
}
Expand Down Expand Up @@ -170,7 +177,6 @@ pub async fn submit_single_owner_transaction(
let certificate = make_certificates(vec![transaction]).pop().unwrap();

let mut responses = Vec::new();

for config in configs {
let client = get_client(config);
let reply = client
Expand Down Expand Up @@ -234,7 +240,7 @@ pub fn get_unique_effects(replies: Vec<TransactionInfoResponse>) -> TransactionE

/// Extract the package reference from a transaction effect. This is useful to deduce the
/// authority-created package reference after attempting to publish a new Move package.
fn parse_package_ref(effects: &TransactionEffects) -> Option<ObjectRef> {
pub fn parse_package_ref(effects: &TransactionEffects) -> Option<ObjectRef> {
effects
.created
.iter()
Expand Down

0 comments on commit 71d57e7

Please sign in to comment.