Skip to content

Commit

Permalink
Add feature gate and golden test
Browse files Browse the repository at this point in the history
  • Loading branch information
areshand committed Jun 27, 2024
1 parent cea6cf8 commit e3e1827
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[
{
"version": "0",
"hash": "",
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "3",
"success": false,
"vm_status": "LINKER_ERROR\nExecution failed with message: Linker Error: Module 0000000000000000000000000000000000000000000000000000000000000001::MemeCoin doesn't exist",
"accumulator_root_hash": "",
"changes": [
{
"address": "0xa550c18",
"state_key_hash": "",
"data": {
"type": "0x1::account::Account",
"data": {
"authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a",
"coin_register_events": {
"counter": "1",
"guid": {
"id": {
"addr": "0xa550c18",
"creation_num": "0"
}
}
},
"guid_creation_num": "4",
"key_rotation_events": {
"counter": "0",
"guid": {
"id": {
"addr": "0xa550c18",
"creation_num": "1"
}
}
},
"rotation_capability_offer": {
"for": {
"vec": []
}
},
"sequence_number": "1",
"signer_capability_offer": {
"for": {
"vec": []
}
}
}
},
"type": "write_resource"
}
],
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "100000000",
"gas_unit_price": "0",
"expiration_timestamp_secs": "18446744073709551615",
"payload": {
"function": "0x1::MemeCoin::transfer",
"type_arguments": [
"0x1::aptos_coin::AptosCoin"
],
"arguments": [
"0x00000000000000000000000000000000000000000000000000000000000000dd",
"0x0100000000000000"
],
"type": "entry_function_payload"
},
"signature": {
"public_key": "0x14418f867a0bd6d42abb2daa50cd68a5a869ce208282481f57504f630510d0d3",
"signature": "0x1d4f1d6c0b140deb6c63e81c742ffd546c832683a14970c687fa823641d34395197548c242c126ea7226730ce66b9ab2f695a2bcda982f30944163179f9a3c08",
"type": "ed25519_signature"
},
"events": [
{
"guid": {
"creation_number": "0",
"account_address": "0x0"
},
"sequence_number": "0",
"type": "0x1::transaction_fee::FeeStatement",
"data": {
"execution_gas_units": "3",
"io_gas_units": "0",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "3"
}
}
],
"timestamp": "0"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[
{
"version": "3",
"hash": "",
"state_change_hash": "",
"event_root_hash": "",
"state_checkpoint_hash": null,
"gas_used": "11",
"success": false,
"vm_status": "Move abort in 0x1::coin: EINSUFFICIENT_BALANCE(0x10006): Not enough coins to complete transaction",
"accumulator_root_hash": "",
"changes": [
{
"address": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf",
"state_key_hash": "",
"data": {
"type": "0x1::account::Account",
"data": {
"authentication_key": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf",
"coin_register_events": {
"counter": "1",
"guid": {
"id": {
"addr": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf",
"creation_num": "0"
}
}
},
"guid_creation_num": "4",
"key_rotation_events": {
"counter": "0",
"guid": {
"id": {
"addr": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf",
"creation_num": "1"
}
}
},
"rotation_capability_offer": {
"for": {
"vec": []
}
},
"sequence_number": "1",
"signer_capability_offer": {
"for": {
"vec": []
}
}
}
},
"type": "write_resource"
}
],
"sender": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf",
"sequence_number": "0",
"max_gas_amount": "100000000",
"gas_unit_price": "0",
"expiration_timestamp_secs": "18446744073709551615",
"payload": {
"function": "0x1::aptos_account::transfer",
"type_arguments": [],
"arguments": [
"0x1",
"999999999999999999"
],
"type": "entry_function_payload"
},
"signature": {
"public_key": "0xd5a781494d2bf1a174ddffde1e02cb8881cff6dab70e61cbdef393deac0ce639",
"signature": "0x0090fadcba9d32d9918286f8b651772a4d04a23633cc9d10f4339ad4d0b1b7c4ca4829542aa9a8b5a6a28e0e63dfd52863d38ca1ba1d2a57c4bf1efc72c0fb06",
"type": "ed25519_signature"
},
"events": [
{
"guid": {
"creation_number": "0",
"account_address": "0x0"
},
"sequence_number": "0",
"type": "0x1::transaction_fee::FeeStatement",
"data": {
"execution_gas_units": "6",
"io_gas_units": "6",
"storage_fee_octas": "0",
"storage_fee_refund_octas": "0",
"total_charge_gas_units": "11"
}
}
],
"timestamp": "500000"
}
]
41 changes: 37 additions & 4 deletions api/src/tests/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,42 @@ async fn test_simulation_failure_error_message() {
.contains("Division by zero"));
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_simulation_failure_with_move_abort_error_rendering() {
let mut context = new_test_context(current_function_name!());
let account = context.create_account().await;
let raw_txn = context
.transaction_factory()
.entry_function(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal("0x1").unwrap(),
Identifier::new("aptos_account").unwrap(),
),
Identifier::new("transfer").unwrap(),
vec![],
vec![
bcs::to_bytes(&AccountAddress::from_hex_literal("0x1").unwrap()).unwrap(),
bcs::to_bytes(&999999999999999999u64).unwrap(),
],
))
.sender(account.address())
.sequence_number(account.sequence_number())
.expiration_timestamp_secs(u64::MAX)
.build();
let invalid_key = AccountKey::generate(&mut context.rng());

let txn = raw_txn
.sign(invalid_key.private_key(), account.public_key().clone())
.unwrap()
.into_inner();
let body = bcs::to_bytes(&txn).unwrap();
let resp = context
.expect_status_code(200)
.post_bcs_txn("/transactions/simulate", body)
.await;
context.check_golden_output(resp);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_simulation_failure_with_detail_error() {
let mut context = new_test_context(current_function_name!());
Expand Down Expand Up @@ -1536,10 +1572,7 @@ async fn test_simulation_failure_with_detail_error() {
.expect_status_code(200)
.post_bcs_txn("/transactions/simulate", body)
.await;
assert!(resp.as_array().unwrap()[0]["vm_status"]
.as_str()
.unwrap()
.contains("LINKER_ERROR"));
context.check_golden_output(resp);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down
5 changes: 4 additions & 1 deletion api/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,10 @@ impl TransactionsApi {
let version = ledger_info.version();

// Ensure that all known statuses return their values in the output (even if they aren't supposed to)
let exe_status = ExecutionStatus::convert_vm_status_for_simulation(vm_status.clone());
let exe_status = ExecutionStatus::conmbine_vm_status_for_simulation(
output.auxiliary_data(),
output.status().clone(),
);

let stats_key = match txn.payload() {
TransactionPayload::Script(_) => {
Expand Down
29 changes: 21 additions & 8 deletions types/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,14 +925,27 @@ impl ExecutionStatus {
}

// Used by simulation API for showing detail error message. Should not be used by production code.
pub fn convert_vm_status_for_simulation(vm_status: VMStatus) -> Self {
let mut show_error_flags = Features::default();
show_error_flags.disable(FeatureFlag::REMOVE_DETAILED_ERROR_FROM_HASH);
let (txn_status, _aux_data) =
TransactionStatus::from_vm_status(vm_status, true, &show_error_flags);
txn_status.status().unwrap_or_else(|discarded_code| {
ExecutionStatus::MiscellaneousError(Some(discarded_code))
})
pub fn conmbine_vm_status_for_simulation(
aux_data: &TransactionAuxiliaryData,
partial_status: TransactionStatus,
) -> Self {
match partial_status {
TransactionStatus::Keep(exec_status) => {
if let Some(aux_error) = aux_data.get_detail_error_message() {
let status_code = aux_error.status_code;
match exec_status {
ExecutionStatus::MiscellaneousError(_) => {
ExecutionStatus::MiscellaneousError(Some(status_code))
},
_ => exec_status,
}
} else {
exec_status
}
},
TransactionStatus::Discard(status) => ExecutionStatus::MiscellaneousError(Some(status)),
_ => ExecutionStatus::MiscellaneousError(None),
}
}

pub fn remove_error_detail(self) -> Self {
Expand Down

0 comments on commit e3e1827

Please sign in to comment.