Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 4e35d11

Browse files
authored
feat: only sender account is an EOA in tests (#659)
* feat: only sender account is an EOA in tests * satisfy clippy * happy trunk * Ignore validation failure due to EOA with code
1 parent e7d0f3e commit 4e35d11

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

crates/ef-testing/src/evm_sequencer/account/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub mod kkrt_account {
7575
_code: &Bytes,
7676
_nonce: U256,
7777
_evm_storage: &[(U256, U256)],
78+
_is_eoa: bool,
7879
) -> Result<Self, StarknetApiError> {
7980
Ok(Self {
8081
evm_address: StarkFelt::default(),

crates/ef-testing/src/evm_sequencer/account/v0.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ impl KakarotAccount {
1212
code: &Bytes,
1313
nonce: U256,
1414
evm_storage: &[(U256, U256)],
15+
is_eoa: bool,
1516
) -> Result<Self, StarknetApiError> {
1617
let nonce = StarkFelt::from(TryInto::<u128>::try_into(nonce).map_err(|err| {
1718
StarknetApiError::OutOfRange {
@@ -30,9 +31,8 @@ impl KakarotAccount {
3031
];
3132

3233
// Initialize the implementation and nonce based on account type.
33-
// The account is an EOA if it has no bytecode and no storage (or all storage is zero).
34-
let has_code_or_storage = !code.is_empty() || evm_storage.iter().any(|x| x.1 != U256::ZERO);
35-
let account_type = if !has_code_or_storage {
34+
// In tests, only the sender is an EOA.
35+
let account_type = if is_eoa {
3636
AccountType::EOA
3737
} else {
3838
storage.append(&mut vec![starknet_storage!("nonce", nonce)]);

crates/ef-testing/src/evm_sequencer/account/v1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl KakarotAccount {
2222
code: &Bytes,
2323
nonce: U256,
2424
evm_storage: &[(U256, U256)],
25+
is_eoa: bool,
2526
) -> Result<Self, StarknetApiError> {
2627
let nonce = StarkFelt::from(TryInto::<u128>::try_into(nonce).map_err(|err| {
2728
StarknetApiError::OutOfRange {
@@ -36,9 +37,8 @@ impl KakarotAccount {
3637
let mut storage = vec![starknet_storage!("evm_address", evm_address)];
3738

3839
// Initialize the implementation and nonce based on account type.
39-
// The account is an EOA if it has no bytecode and no storage (or all storage is zero).
40-
let has_code_or_storage = !code.is_empty() || evm_storage.iter().any(|x| x.1 != U256::ZERO);
41-
let account_type = if !has_code_or_storage {
40+
// In tests, only the sender is an EOA.
41+
let account_type = if is_eoa {
4242
AccountType::EOA
4343
} else {
4444
storage.push(starknet_storage!("contract_account_nonce", nonce));

crates/ef-testing/src/evm_sequencer/evm_state/v0.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,9 @@ mod tests {
335335
let nonce = U256::from(0);
336336

337337
// When
338-
let contract = KakarotAccount::new(&TEST_CONTRACT_ADDRESS, &bytecode, nonce, &[]).unwrap();
339-
let eoa = KakarotAccount::new(&PUBLIC_KEY, &Bytes::default(), nonce, &[]).unwrap();
338+
let contract =
339+
KakarotAccount::new(&TEST_CONTRACT_ADDRESS, &bytecode, nonce, &[], false).unwrap();
340+
let eoa = KakarotAccount::new(&PUBLIC_KEY, &Bytes::default(), nonce, &[], true).unwrap();
340341
sequencer.setup_account(contract).unwrap();
341342
sequencer.setup_account(eoa).unwrap();
342343
sequencer.execute_transaction(transaction).unwrap();

crates/ef-testing/src/evm_sequencer/evm_state/v1.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ impl Evm for KakarotSequencer {
4040
/// Sets up the evm state (coinbase, block number, etc.)
4141
fn setup_state(&mut self, _base_fee: U256) -> StateResult<()> {
4242
let coinbase_address = *self.address();
43-
let coinbase = KakarotAccount::new(&coinbase_address, &Bytes::default(), U256::ZERO, &[])?;
43+
let coinbase =
44+
KakarotAccount::new(&coinbase_address, &Bytes::default(), U256::ZERO, &[], true)?;
4445
self.setup_account(coinbase)?;
4546
self.fund(&coinbase_address, U256::ZERO)?;
4647

@@ -383,7 +384,7 @@ mod tests {
383384

384385
// When
385386
let account =
386-
KakarotAccount::new(&TEST_CONTRACT_ADDRESS, &bytecode, U256::ZERO, &[]).unwrap();
387+
KakarotAccount::new(&TEST_CONTRACT_ADDRESS, &bytecode, U256::ZERO, &[], false).unwrap();
387388
sequencer.setup_account(account).unwrap();
388389

389390
// Then
@@ -437,8 +438,8 @@ mod tests {
437438
]); // PUSH 01 PUSH 00 SSTORE
438439
let nonce = U256::from(0);
439440
let contract_account =
440-
KakarotAccount::new(&TEST_CONTRACT_ADDRESS, &bytecode, nonce, &[]).unwrap();
441-
let eoa = KakarotAccount::new(&PUBLIC_KEY, &Bytes::default(), nonce, &[]).unwrap();
441+
KakarotAccount::new(&TEST_CONTRACT_ADDRESS, &bytecode, nonce, &[], false).unwrap();
442+
let eoa = KakarotAccount::new(&PUBLIC_KEY, &Bytes::default(), nonce, &[], true).unwrap();
442443
sequencer.setup_account(contract_account).unwrap();
443444
sequencer.setup_account(eoa).unwrap();
444445
sequencer.execute_transaction(transaction).unwrap();

crates/ef-testing/src/models/case.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ impl BlockchainTestCase {
5656
}
5757

5858
fn handle_pre_state(&self, sequencer: &mut KakarotSequencer) -> Result<(), RunnerError> {
59+
let wallet = LocalWallet::from_bytes(&self.secret_key.0)
60+
.map_err(|err| RunnerError::Other(vec![err.to_string()].into()))?;
61+
let sender_address = wallet.address().to_fixed_bytes();
62+
5963
for (address, account) in self.pre.iter() {
64+
let is_eoa = address.0 == sender_address;
6065
let kakarot_account = KakarotAccount::new(
6166
address,
6267
&account.code,
6368
account.nonce,
6469
&account.storage.clone().into_iter().collect::<Vec<_>>()[..],
70+
is_eoa,
6571
)?;
6672
sequencer.setup_account(kakarot_account)?;
6773
sequencer.fund(address, account.balance)?;

crates/ef-testing/src/models/result.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ pub(crate) fn log_execution_result(
7070
TransactionExecutionResult::Err(TransactionExecutionError::ValidateTransactionError(
7171
EntryPointExecutionError::VirtualMachineExecutionErrorWithTrace { trace, .. },
7272
)) => {
73+
// There are specific test cases where validation failed because the sender account has code.
74+
// They're caught by EOA validation, and rejected with this specific error message.
75+
if trace.contains("EOAs cannot have code") {
76+
return;
77+
}
7378
let re = regex::Regex::new(
7479
r#"Error in the called contract \((0x[0-9a-zA-Z]+)\)[\s\S]*?EntryPointSelector\(StarkFelt\("(0x[0-9a-zA-Z]+)"\)\)"#,
7580
).unwrap();

0 commit comments

Comments
 (0)