Skip to content

Commit

Permalink
Returned TransactionStatus old attributes. Adde test: is_empty_storage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Aug 20, 2024
1 parent ad70951 commit 40d2eed
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 88 deletions.
12 changes: 3 additions & 9 deletions engine-tests/src/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::parameters::connector::{
Erc20Identifier, Erc20Metadata, SetErc20MetadataArgs,
};
use aurora_engine_types::parameters::engine::{EvmErrorKind, SetOwnerArgs};
use aurora_engine_types::parameters::engine::SetOwnerArgs;
use bstr::ByteSlice;

use libsecp256k1::SecretKey;
Expand Down Expand Up @@ -79,10 +79,7 @@ fn erc20_mint_out_of_gas() {
mint_tx.gas_price = U256::from(GAS_PRICE); // also set non-zero gas price to check gas still charged.
let outcome = runner.submit_transaction(&source_account.secret_key, mint_tx);
let error = outcome.unwrap();
assert_eq!(
error.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
);
assert_eq!(error.status, TransactionStatus::OutOfGas);

// Validate post-state

Expand Down Expand Up @@ -236,10 +233,7 @@ fn deploy_erc_20_out_of_gas() {
deploy_transaction.gas_limit = U256::from(intrinsic_gas + 1);
let outcome = runner.submit_transaction(&source_account, deploy_transaction);
let error = outcome.unwrap();
assert_eq!(
error.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
);
assert_eq!(error.status, TransactionStatus::OutOfGas);

// Validate post-state
utils::validate_address_balance_and_nonce(
Expand Down
28 changes: 6 additions & 22 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use aurora_engine_sdk as sdk;
use aurora_engine_types::borsh::BorshDeserialize;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine_types::parameters::connector::FungibleTokenMetadata;
use aurora_engine_types::parameters::engine::EvmErrorKind;
use aurora_engine_types::H160;
use libsecp256k1::SecretKey;
use near_vm_runner::ContractCode;
Expand Down Expand Up @@ -55,10 +54,7 @@ fn bench_memory_get_standalone() {
.unwrap();
let duration = start.elapsed().as_secs_f32();
assert!(
matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
matches!(result.status, TransactionStatus::OutOfGas),
"Infinite loops in the EVM run out of gas"
);
assert!(
Expand Down Expand Up @@ -112,10 +108,7 @@ fn test_returndatacopy() {
let address = deploy_contract(&mut runner, &mut signer, contract_bytes);
let result = call_contract(&mut runner, &mut signer, address);
assert!(
matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
matches!(result.status, TransactionStatus::OutOfGas),
"EVM must run out of gas if len > 0 with large memory offset"
);
}
Expand Down Expand Up @@ -571,10 +564,7 @@ fn test_create_out_of_gas() {
})
.unwrap();
assert!(
matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfGas)
),
matches!(result.status, TransactionStatus::OutOfGas),
"Unexpected status: {:?}",
result.status
);
Expand Down Expand Up @@ -768,10 +758,7 @@ fn test_eth_transfer_insufficient_balance() {
utils::transfer(dest_address, INITIAL_BALANCE + INITIAL_BALANCE, nonce)
})
.unwrap();
assert_eq!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);
assert_eq!(result.status, TransactionStatus::OutOfFund);

// validate post-state
utils::validate_address_balance_and_nonce(
Expand Down Expand Up @@ -1234,7 +1221,7 @@ mod workspace {
use crate::prelude::{Address, U256};
use crate::tests::sanity::{GAS_PRICE, INITIAL_BALANCE, INITIAL_NONCE, TRANSFER_AMOUNT};
use crate::utils;
use aurora_engine_types::parameters::engine::{EvmErrorKind, TransactionStatus};
use aurora_engine_types::parameters::engine::TransactionStatus;
use aurora_engine_workspace::EngineContract;

// Same as `test_eth_transfer_insufficient_balance` above, except runs through
Expand Down Expand Up @@ -1266,10 +1253,7 @@ mod workspace {
.await
.unwrap()
.into_value();
assert_eq!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);
assert_eq!(result.status, TransactionStatus::OutOfFund);

// validate post-state
assert_eq!(
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use aurora_engine::{
parameters::{ResultLog, SubmitResult, TransactionStatus},
};
use aurora_engine_transactions::eip_2930::AccessTuple;
use aurora_engine_types::parameters::engine::EvmErrorKind;
use aurora_engine_types::{types::Address, H160};

#[test]
fn test_serde_submit_result() {
let result = SubmitResult::new(
TransactionStatus::Error(EvmErrorKind::OutOfFund),
TransactionStatus::OutOfFund,
0,
vec![ResultLog {
address: Address::default(),
Expand Down
12 changes: 3 additions & 9 deletions engine-tests/src/tests/silo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use aurora_engine::engine::EngineErrorKind;
use aurora_engine_sdk as sdk;
use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::borsh::BorshSerialize;
use aurora_engine_types::parameters::engine::{EvmErrorKind, TransactionStatus};
use aurora_engine_types::parameters::engine::TransactionStatus;
use aurora_engine_types::parameters::silo::{
FixedGasArgs, SiloParamsArgs, WhitelistAccountArgs, WhitelistAddressArgs, WhitelistArgs,
WhitelistKind, WhitelistStatusArgs,
Expand Down Expand Up @@ -99,10 +99,7 @@ fn test_transfer_insufficient_balance() {
)
})
.unwrap();
assert_eq!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
);
assert_eq!(result.status, TransactionStatus::OutOfFund);

// validate post-state
validate_address_balance_and_nonce(
Expand Down Expand Up @@ -167,10 +164,7 @@ fn test_transfer_insufficient_balance_fee() {
utils::transfer_with_price(receiver, TRANSFER_AMOUNT, nonce, ONE_GAS_PRICE.raw())
})
.unwrap();
assert!(matches!(
result.status,
TransactionStatus::Error(EvmErrorKind::OutOfFund)
));
assert!(matches!(result.status, TransactionStatus::OutOfFund));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/xcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ pub mod workspace {
.unwrap();
anyhow::bail!("TX has been reverted with message: {revert_message}");
}
TransactionStatus::Error(_) => anyhow::bail!("Wrong status of the transaction"),
_ => anyhow::bail!("Wrong status of the transaction"),
}
}

Expand Down
4 changes: 1 addition & 3 deletions engine-tests/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,7 @@ pub fn panic_on_fail(status: TransactionStatus) -> Option<String> {
TransactionStatus::Revert(message) => {
Some(format!("Revert: {}", String::from_utf8_lossy(&message)))
}
TransactionStatus::Error(err) => {
Some(format!("Error: {}", String::from_utf8_lossy(err.as_ref())))
}
other => panic!("{}", String::from_utf8_lossy(other.as_ref())),
}
}

Expand Down
4 changes: 1 addition & 3 deletions engine-tests/src/utils/solidity/exit_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ impl Tester {
match result.status {
aurora_engine::parameters::TransactionStatus::Succeed(_) => Ok(result),
aurora_engine::parameters::TransactionStatus::Revert(_bytes) => Err(Revert),
aurora_engine::parameters::TransactionStatus::Error(err) => {
panic!("Unexpected status {err:?}")
}
other => panic!("Unexpected status {other:?}"),
}
}

Expand Down
27 changes: 14 additions & 13 deletions engine-types/src/parameters/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ pub struct ResultLog {
}

/// EVM error king of transaction status
///
/// It excludes, as it is part of `TransactionStatus`:
/// - `OutOfGas`
/// - `OutOfFund`
/// - `OutOfOffset`
/// - `CallTooDeep`
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
#[cfg_attr(feature = "impl-serde", derive(Serialize, Deserialize))]
pub enum EvmErrorKind {
Expand All @@ -191,21 +197,12 @@ pub enum EvmErrorKind {
InvalidRange,
/// Encountered the designated invalid opcode.
DesignatedInvalid,
/// Call stack is too deep (runtime).
CallTooDeep,
/// Create opcode encountered collision (runtime).
CreateCollision,
/// Create init code exceeds limit (runtime).
CreateContractLimit,
/// Invalid opcode during execution or starting byte is 0xef. See [EIP-3541](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3541.md).
InvalidCode(u8),
/// An opcode accesses external information, but the request is off offset
/// limit (runtime).
OutOfOffset,
/// Execution runs out of gas (runtime).
OutOfGas,
/// Not enough fund to start the execution (runtime).
OutOfFund,
/// PC underflowed (unused).
#[allow(clippy::upper_case_acronyms)]
PCUnderflow,
Expand All @@ -227,13 +224,9 @@ impl AsRef<[u8]> for EvmErrorKind {
Self::InvalidJump => b"INVALID_JUMP",
Self::InvalidRange => b"INVALID_RANGE",
Self::DesignatedInvalid => b"DESIGNATED_INVALID",
Self::CallTooDeep => b"CALL_TOO_DEEP",
Self::CreateCollision => b"CREATE_COLLISION",
Self::CreateContractLimit => b"CREATE_CONTRACT_LIMIT",
Self::InvalidCode(_) => b"INVALID_CODE",
Self::OutOfOffset => b"OUT_OF_OFFSET",
Self::OutOfGas => b"OUT_OF_GAS",
Self::OutOfFund => b"OUT_OF_FUND",
Self::PCUnderflow => b"PC_UNDERFLOW",
Self::CreateEmpty => b"CREATE_EMPTY",
Self::MaxNonce => b"MAX_NONCE",
Expand All @@ -249,6 +242,10 @@ impl AsRef<[u8]> for EvmErrorKind {
pub enum TransactionStatus {
Succeed(Vec<u8>),
Revert(Vec<u8>),
OutOfGas,
OutOfFund,
OutOfOffset,
CallTooDeep,
Error(EvmErrorKind),
}

Expand All @@ -274,6 +271,10 @@ impl AsRef<[u8]> for TransactionStatus {
match self {
Self::Succeed(_) => b"SUCCESS",
Self::Revert(_) => errors::ERR_REVERT,
Self::OutOfFund => errors::ERR_OUT_OF_FUNDS,
Self::OutOfGas => errors::ERR_OUT_OF_GAS,
Self::OutOfOffset => errors::ERR_OUT_OF_OFFSET,
Self::CallTooDeep => errors::ERR_CALL_TOO_DEEP,
Self::Error(kind) => kind.as_ref(),
}
}
Expand Down
Loading

0 comments on commit 40d2eed

Please sign in to comment.