Skip to content

Commit

Permalink
fix: convert tests which rely on submitting to a single validator
Browse files Browse the repository at this point in the history
Indeed, that single validator's submission may now be a no-op.
  • Loading branch information
huitseeker committed Nov 11, 2022
1 parent a43dd21 commit 6e11698
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion crates/sui-cost/tests/empirical_transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async fn run_actual_and_estimate_costs(

for (tx_type, tx) in tx_map {
let gas_used = if tx_type.is_shared_object_tx() {
submit_shared_object_transaction(tx.clone(), &configs.validator_set()[0..1])
submit_shared_object_transaction(tx.clone(), configs.validator_set())
.await
.unwrap()
.gas_cost_summary()
Expand Down
50 changes: 23 additions & 27 deletions crates/sui/tests/shared_objects_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn shared_object_transaction() {

// Submit the transaction. Note that this transaction is random and we do not expect
// it to be successfully executed by the Move execution engine.
let _effects = submit_shared_object_transaction(transaction, &configs.validator_set()[0..1])
let _effects = submit_shared_object_transaction(transaction, configs.validator_set())
.await
.unwrap();
}
Expand Down Expand Up @@ -102,7 +102,7 @@ async fn call_shared_object_contract() {
CallArg::Pure(0u64.to_le_bytes().to_vec()),
],
);
let effects = submit_shared_object_transaction(transaction, &configs.validator_set()[0..1])
let effects = submit_shared_object_transaction(transaction, configs.validator_set())
.await
.unwrap();
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));
Expand All @@ -115,7 +115,7 @@ async fn call_shared_object_contract() {
package_ref,
vec![CallArg::Object(counter_object_arg)],
);
let effects = submit_shared_object_transaction(transaction, &configs.validator_set()[0..1])
let effects = submit_shared_object_transaction(transaction, configs.validator_set())
.await
.unwrap();
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));
Expand All @@ -131,7 +131,7 @@ async fn call_shared_object_contract() {
CallArg::Pure(1u64.to_le_bytes().to_vec()),
],
);
let effects = submit_shared_object_transaction(transaction, &configs.validator_set()[0..1])
let effects = submit_shared_object_transaction(transaction, configs.validator_set())
.await
.unwrap();
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));
Expand Down Expand Up @@ -217,6 +217,7 @@ async fn shared_object_flood() {

#[sim_test]
async fn shared_object_sync() {
telemetry_subscribers::init_for_testing();
let mut gas_objects = test_gas_objects();

// Get the authority configs and spawn them. Note that it is important to not drop
Expand All @@ -238,7 +239,9 @@ async fn shared_object_sync() {
);
let effects = submit_single_owner_transaction(
create_counter_transaction.clone(),
&configs.validator_set()[0..1],
// this is a bit fragile: validator #2 is one of the two validators that submit this TX,
// see consensus_adapter
&configs.validator_set()[2..3],
)
.await;
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));
Expand All @@ -248,27 +251,22 @@ async fn shared_object_sync() {
initial_shared_version: counter_initial_shared_version,
};

// Check that the counter object only exist in the first validator, but not the rest.
get_client(&configs.validator_set()[0])
.handle_object_info_request(ObjectInfoRequest {
object_id: counter_id,
request_kind: ObjectInfoRequestKind::LatestObjectInfo(None),
})
.await
.unwrap()
.object()
.unwrap();
for config in configs.validator_set().iter().skip(1) {
assert!(get_client(config)
// Check that the counter object only exist in one validator, but not the rest.
// count the number of validators that have the counter object.
let mut provisioned_authorities = 0;
for config in configs.validator_set() {
provisioned_authorities += get_client(config)
.handle_object_info_request(ObjectInfoRequest {
object_id: counter_id,
request_kind: ObjectInfoRequestKind::LatestObjectInfo(None),
})
.await
.unwrap()
.object()
.is_none());
.map(|_x| 1)
.unwrap_or_default();
}
assert_eq!(1, provisioned_authorities);

// Make a transaction to increment the counter.
let increment_counter_transaction = move_transaction(
Expand All @@ -279,23 +277,21 @@ async fn shared_object_sync() {
vec![CallArg::Object(counter_object_arg)],
);

// Let's submit the transaction to the first authority (the only one up-to-date).
// Let's submit the transaction to just one authority (including only one up-to-date).
let effects = submit_shared_object_transaction(
increment_counter_transaction.clone(),
&configs.validator_set()[0..1],
&configs.validator_set()[1..4],
)
.await
.unwrap();
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));

// Submit transactions to out-of-date authorities.
// It will succeed because we share owned object certificates through narwhal
let effects = submit_shared_object_transaction(
increment_counter_transaction,
&configs.validator_set()[1..],
)
.await
.unwrap();
let effects =
submit_shared_object_transaction(increment_counter_transaction, configs.validator_set())
.await
.unwrap();
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));
}

Expand Down Expand Up @@ -324,7 +320,7 @@ async fn replay_shared_object_transaction() {
for _ in 0..2 {
let effects = submit_single_owner_transaction(
create_counter_transaction.clone(),
&configs.validator_set()[0..1],
configs.validator_set(),
)
.await;
assert!(matches!(effects.status, ExecutionStatus::Success { .. }));
Expand Down

0 comments on commit 6e11698

Please sign in to comment.