Skip to content

Commit

Permalink
[tests] Fix reference gas price for sui-core tests (MystenLabs#10918)
Browse files Browse the repository at this point in the history
## Description 

- Fixed sui-core tests with RGP of 1

## Test Plan 

- Updated tests 

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
tnowacki authored May 17, 2023
1 parent 7a94b4d commit 975320e
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/sui-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sui_types::multiaddr::Multiaddr;
pub const DEFAULT_GRPC_CONCURRENCY_LIMIT: usize = 20000000000;

/// Default gas price of 100 Mist
pub const DEFAULT_VALIDATOR_GAS_PRICE: u64 = 1000;
pub const DEFAULT_VALIDATOR_GAS_PRICE: u64 = sui_types::transaction::DEFAULT_VALIDATOR_GAS_PRICE;

/// Default commission rate of 2%
pub const DEFAULT_COMMISSION_RATE: u64 = 200;
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub fn make_transfer_object_transaction(
object_ref,
sender,
gas_object,
gas_price * TEST_ONLY_GAS_UNIT_FOR_TRANSFER,
gas_price * TEST_ONLY_GAS_UNIT_FOR_TRANSFER * 10,
gas_price,
);
to_sender_signed_transaction(data, keypair)
Expand Down
18 changes: 16 additions & 2 deletions crates/sui-core/src/unit_tests/authority_aggregator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async fn execute_transaction_with_fault_configs(
for (index, config) in configs_before_process_transaction {
set_local_client_config(&mut authorities, *index, *config);
}
let rgp = genesis.reference_gas_price();
let rgp = reference_gas_price(&authorities);
let tx = make_transfer_object_transaction(
gas_object1.compute_object_reference(),
gas_object2.compute_object_reference(),
Expand Down Expand Up @@ -288,6 +288,20 @@ async fn execute_transaction_with_fault_configs(
.is_ok()
}

fn reference_gas_price(authorities: &AuthorityAggregator<LocalAuthorityClient>) -> u64 {
authorities
.authority_clients
.values()
.find_map(|client| {
client
.authority_client()
.state
.reference_gas_price_for_testing()
.ok()
})
.unwrap()
}

fn effects_with_tx(digest: TransactionDigest) -> TransactionEffects {
let mut effects = TransactionEffects::default();
*effects.transaction_digest_mut_for_testing() = digest;
Expand Down Expand Up @@ -320,7 +334,7 @@ async fn test_quorum_map_and_reduce_timeout() {
let gas_object1 = Object::with_owner_for_testing(addr1);
let genesis_objects = vec![pkg.clone(), gas_object1.clone()];
let (mut authorities, _, genesis, _) = init_local_authorities(4, genesis_objects).await;
let rgp = genesis.reference_gas_price();
let rgp = reference_gas_price(&authorities);
let pkg = genesis.object(pkg.id()).unwrap();
let gas_object1 = genesis.object(gas_object1.id()).unwrap();
let gas_ref_1 = gas_object1.compute_object_reference();
Expand Down
57 changes: 47 additions & 10 deletions crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4114,7 +4114,7 @@ pub async fn call_move_(
*sender,
vec![gas_object_ref],
builder.finish(),
rgp * TEST_ONLY_GAS_UNIT_FOR_OBJECT_BASICS * 10,
rgp * TEST_ONLY_GAS_UNIT_FOR_OBJECT_BASICS * 5,
rgp,
);

Expand Down Expand Up @@ -4364,8 +4364,9 @@ pub async fn call_dev_inspect(
arguments,
));
let kind = TransactionKind::programmable(builder.finish());
let rgp = authority.reference_gas_price_for_testing().unwrap();
authority
.dev_inspect_transaction_block(*sender, kind, Some(1))
.dev_inspect_transaction_block(*sender, kind, Some(rgp))
.await
}

Expand Down Expand Up @@ -5062,16 +5063,31 @@ async fn test_for_inc_201_dry_run() {
builder.publish_immutable(modules, BuiltInFramework::all_package_ids());
let kind = TransactionKind::programmable(builder.finish());

let txn_data = TransactionData::new_with_gas_coins(kind, sender, vec![], 50_000_000, 1);
let rgp = fullnode.reference_gas_price_for_testing().unwrap();
let txn_data = TransactionData::new_with_gas_coins(
kind,
sender,
vec![],
TEST_ONLY_GAS_UNIT_FOR_PUBLISH * rgp,
rgp,
);

let signed = to_sender_signed_transaction(txn_data, &sender_key);
let (DryRunTransactionBlockResponse { events, .. }, _, _, _) = fullnode
let (
DryRunTransactionBlockResponse {
events, effects, ..
},
_,
_,
_,
) = fullnode
.dry_exec_transaction(
signed.data().intent_message().value.clone(),
*signed.digest(),
)
.await
.unwrap();
assert_eq!(effects.status(), &SuiExecutionStatus::Success);

assert_eq!(1, events.data.len());
assert_eq!(
Expand Down Expand Up @@ -5121,7 +5137,7 @@ async fn test_publish_transitive_dependencies_ok() {
sender,
vec![gas_ref],
rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH,
1,
rgp,
);
let signed = to_sender_signed_transaction(txn_data, &key);
let txn_effects = send_and_confirm_transaction(&state, signed)
Expand Down Expand Up @@ -5157,7 +5173,7 @@ async fn test_publish_transitive_dependencies_ok() {
sender,
vec![gas_ref],
rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH,
1,
rgp,
);
let signed = to_sender_signed_transaction(txn_data, &key);
let txn_effects = send_and_confirm_transaction(&state, signed)
Expand Down Expand Up @@ -5194,7 +5210,7 @@ async fn test_publish_transitive_dependencies_ok() {
sender,
vec![gas_ref],
rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH,
1,
rgp,
);
let signed = to_sender_signed_transaction(txn_data, &key);
let txn_effects = send_and_confirm_transaction(&state, signed)
Expand Down Expand Up @@ -5279,7 +5295,14 @@ async fn test_publish_missing_dependency() {
builder.publish_immutable(modules, vec![SUI_FRAMEWORK_PACKAGE_ID]);
let kind = TransactionKind::programmable(builder.finish());

let txn_data = TransactionData::new_with_gas_coins(kind, sender, vec![gas_ref], 10000, 1);
let rgp = state.reference_gas_price_for_testing().unwrap();
let txn_data = TransactionData::new_with_gas_coins(
kind,
sender,
vec![gas_ref],
rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH,
rgp,
);

let signed = to_sender_signed_transaction(txn_data, &key);
let (failure, _) = send_and_confirm_transaction(&state, signed)
Expand Down Expand Up @@ -5321,7 +5344,14 @@ async fn test_publish_missing_transitive_dependency() {
builder.publish_immutable(modules, vec![MOVE_STDLIB_PACKAGE_ID]);
let kind = TransactionKind::programmable(builder.finish());

let txn_data = TransactionData::new_with_gas_coins(kind, sender, vec![gas_ref], 10000, 1);
let rgp = state.reference_gas_price_for_testing().unwrap();
let txn_data = TransactionData::new_with_gas_coins(
kind,
sender,
vec![gas_ref],
rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH,
rgp,
);

let signed = to_sender_signed_transaction(txn_data, &key);
let (failure, _) = send_and_confirm_transaction(&state, signed)
Expand Down Expand Up @@ -5366,7 +5396,14 @@ async fn test_publish_not_a_package_dependency() {
builder.publish_immutable(modules, deps);
let kind = TransactionKind::programmable(builder.finish());

let txn_data = TransactionData::new_with_gas_coins(kind, sender, vec![gas_ref], 10000, 1);
let rgp = state.reference_gas_price_for_testing().unwrap();
let txn_data = TransactionData::new_with_gas_coins(
kind,
sender,
vec![gas_ref],
rgp * TEST_ONLY_GAS_UNIT_FOR_PUBLISH,
rgp,
);

let signed = to_sender_signed_transaction(txn_data, &key);
let failure = send_and_confirm_transaction(&state, signed)
Expand Down
5 changes: 3 additions & 2 deletions crates/sui-core/src/unit_tests/batch_transaction_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::*;
use crate::authority::authority_tests::init_state_with_ids_and_object_basics;
use bcs;
use sui_types::{
execution_status::ExecutionStatus,
programmable_transaction_builder::ProgrammableTransactionBuilder,
utils::to_sender_signed_transaction,
};
Expand Down Expand Up @@ -65,14 +66,14 @@ async fn test_batch_transaction_ok() -> anyhow::Result<()> {
.unwrap()
.compute_object_reference()],
builder.finish(),
rgp * TEST_ONLY_GAS_UNIT_FOR_OBJECT_BASICS * 10,
rgp * TEST_ONLY_GAS_UNIT_FOR_OBJECT_BASICS * (N as u64),
rgp,
);

let tx = to_sender_signed_transaction(data, &sender_key);
let response = send_and_confirm_transaction(&authority_state, tx).await?;
let effects = response.1.into_data();
assert!(effects.status().is_ok());
assert_eq!(effects.status(), &ExecutionStatus::Success);
assert_eq!(
(effects.created().len(), effects.mutated().len()),
(N, N + 1),
Expand Down
12 changes: 7 additions & 5 deletions crates/sui-core/src/unit_tests/gas_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ async fn touch_gas_coins(
.unwrap()
.unwrap()
.compute_object_reference();
let data = TransactionData::new(kind, sender, gas_object_ref, 100_000_000, 1);
let rgp = authority_state.reference_gas_price_for_testing().unwrap();
let data = TransactionData::new(kind, sender, gas_object_ref, 100_000_000, rgp);
let tx = to_sender_signed_transaction(data, sender_key);

send_and_confirm_transaction(authority_state, tx)
Expand Down Expand Up @@ -340,7 +341,7 @@ async fn test_oog_computation_oog_storage() -> SuiResult {
// - computation ok, OOG for storage, minimal storage ok
#[tokio::test]
async fn test_computation_ok_oog_storage_minimal_ok() -> SuiResult {
const GAS_PRICE: u64 = 30;
const GAS_PRICE: u64 = 1001;
const BUDGET: u64 = 1_100_000;
let (sender, sender_key) = get_key_pair();
check_oog_transaction(
Expand Down Expand Up @@ -372,7 +373,7 @@ async fn test_computation_ok_oog_storage_minimal_ok() -> SuiResult {
// - computation ok, OOG for storage, OOG for minimal storage (e.g. computation is entire budget)
#[tokio::test]
async fn test_computation_ok_oog_storage() -> SuiResult {
const GAS_PRICE: u64 = 30;
const GAS_PRICE: u64 = 1001;
const BUDGET: u64 = 35_000;
let (sender, sender_key) = get_key_pair();
check_oog_transaction(
Expand Down Expand Up @@ -515,14 +516,15 @@ async fn test_transfer_sui_insufficient_gas() {
let gas_object_ref = gas_object.compute_object_reference();
let authority_state = TestAuthorityBuilder::new().build().await;
authority_state.insert_genesis_object(gas_object).await;
let rgp = authority_state.reference_gas_price_for_testing().unwrap();

let pt = {
let mut builder = ProgrammableTransactionBuilder::new();
builder.transfer_sui(recipient, None);
builder.finish()
};
let kind = TransactionKind::ProgrammableTransaction(pt);
let data = TransactionData::new(kind, sender, gas_object_ref, *MIN_GAS_BUDGET, 1);
let data = TransactionData::new(kind, sender, gas_object_ref, *MIN_GAS_BUDGET, rgp);
let tx = to_sender_signed_transaction(data, &sender_key);

let effects = send_and_confirm_transaction(&authority_state, tx)
Expand Down Expand Up @@ -586,7 +588,7 @@ async fn test_invalid_gas_owners() {
sender,
vec![good_gas_object, bad_gas_object],
*MAX_GAS_BUDGET,
1,
1111,
);
let tx = to_sender_signed_transaction(data, sender_key);

Expand Down
21 changes: 12 additions & 9 deletions crates/sui-core/src/unit_tests/pay_sui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ async fn test_pay_sui_failure_insufficient_gas_balance_multiple_input_coins() {
#[tokio::test]
async fn test_pay_sui_failure_insufficient_total_balance_multiple_input_coins() {
let (sender, sender_key): (_, AccountKeyPair) = get_key_pair();
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 1400);
let coin2 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 1300);
let coin1 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 14000);
let coin2 = Object::with_id_owner_gas_for_testing(ObjectID::random(), sender, 13000);
let recipient1 = dbg_addr(1);
let recipient2 = dbg_addr(2);

let res = execute_pay_sui(
vec![coin1, coin2],
vec![recipient1, recipient2],
vec![400, 400],
vec![4000, 4000],
sender,
sender_key,
2000,
20000,
)
.await;
assert_eq!(
Expand All @@ -145,7 +145,8 @@ async fn test_pay_sui_failure_insufficient_total_balance_multiple_input_coins()
async fn test_pay_sui_success_one_input_coin() -> anyhow::Result<()> {
let (sender, sender_key): (_, AccountKeyPair) = get_key_pair();
let object_id = ObjectID::random();
let coin_obj = Object::with_id_owner_gas_for_testing(object_id, sender, 5000000);
let coin_amount = 50000000;
let coin_obj = Object::with_id_owner_gas_for_testing(object_id, sender, 50000000);
let recipient1 = dbg_addr(1);
let recipient2 = dbg_addr(2);
let recipient3 = dbg_addr(3);
Expand All @@ -157,7 +158,7 @@ async fn test_pay_sui_success_one_input_coin() -> anyhow::Result<()> {
vec![100, 200, 300],
sender,
sender_key,
4000000,
coin_amount - 300 - 200 - 100,
)
.await;

Expand Down Expand Up @@ -211,7 +212,7 @@ async fn test_pay_sui_success_one_input_coin() -> anyhow::Result<()> {
let gas_object = res.authority_state.get_object(&object_id).await?.unwrap();
assert_eq!(
GasCoin::try_from(&gas_object)?.value(),
5000000 - 100 - 200 - 300 - gas_used,
coin_amount - 100 - 200 - 300 - gas_used,
);

Ok(())
Expand Down Expand Up @@ -400,11 +401,12 @@ async fn execute_pay_sui(
.map(|obj| authority_state.insert_genesis_object(obj))
.collect();
join_all(handles).await;
let rgp = authority_state.reference_gas_price_for_testing().unwrap();

let mut builder = ProgrammableTransactionBuilder::new();
builder.pay_sui(recipients, amounts).unwrap();
let pt = builder.finish();
let data = TransactionData::new_programmable(sender, input_coin_refs, pt, gas_budget, 1);
let data = TransactionData::new_programmable(sender, input_coin_refs, pt, gas_budget, rgp);
let tx = to_sender_signed_transaction(data, &sender_key);
let txn_result = send_and_confirm_transaction(&authority_state, tx)
.await
Expand Down Expand Up @@ -438,6 +440,7 @@ async fn execute_pay_all_sui(
let keypair = network_config.validator_configs[0].protocol_key_pair();

let authority_state = init_state_with_committee(&genesis, keypair).await;
let rgp = authority_state.reference_gas_price_for_testing().unwrap();

let mut input_coins = Vec::new();
for coin in input_coin_objects {
Expand All @@ -454,7 +457,7 @@ async fn execute_pay_all_sui(
let mut builder = ProgrammableTransactionBuilder::new();
builder.pay_all_sui(recipient);
let pt = builder.finish();
let data = TransactionData::new_programmable(sender, input_coins, pt, gas_budget, 1);
let data = TransactionData::new_programmable(sender, input_coins, pt, gas_budget, rgp);
let tx = to_sender_signed_transaction(data, &sender_key);
let txn_result = send_and_confirm_transaction(&authority_state, tx)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl EpochStartSystemStateV1 {
Self {
epoch,
protocol_version: ProtocolVersion::MAX.as_u64(),
reference_gas_price: 1,
reference_gas_price: crate::transaction::DEFAULT_VALIDATOR_GAS_PRICE,
safe_mode: false,
epoch_start_timestamp_ms: 0,
epoch_duration_ms: 1000,
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub const TEST_ONLY_GAS_UNIT_FOR_SPLIT_COIN: u64 = 1_000_000;

pub const GAS_PRICE_FOR_SYSTEM_TX: u64 = 1;

pub const DEFAULT_VALIDATOR_GAS_PRICE: u64 = 1000;

const BLOCKED_MOVE_FUNCTIONS: [(ObjectID, &str, &str); 0] = [];

#[cfg(test)]
Expand Down

0 comments on commit 975320e

Please sign in to comment.