Skip to content

Commit

Permalink
test and lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eyusufatik committed Aug 29, 2024
1 parent 11a9685 commit ec5662b
Show file tree
Hide file tree
Showing 38 changed files with 606 additions and 444 deletions.
109 changes: 98 additions & 11 deletions crates/evm/src/tests/call_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ fn call_multiple_test() {
let contract_addr = address!("819c5497b157177315e1204f52e588b393771719");

let l1_fee_rate = 0;
let l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -70,7 +72,13 @@ fn call_multiple_test() {
let sender_address = generate_address::<C>("sender");

let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

let transactions: Vec<RlpEvmTransaction> = vec![
create_contract_transaction(&dev_signer1, 0, SimpleStorageContract::default()),
Expand Down Expand Up @@ -164,9 +172,11 @@ fn call_test() {

let (evm, mut working_set) = get_evm(&config);
let l1_fee_rate = 0;
let l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -184,7 +194,13 @@ fn call_test() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

let rlp_transactions = vec![
create_contract_message(&dev_signer, 0, SimpleStorageContract::default()),
Expand Down Expand Up @@ -244,9 +260,11 @@ fn failed_transaction_test() {
let (evm, mut working_set) = get_evm(&EvmConfig::default());
let working_set = &mut working_set;
let l1_fee_rate = 0;
let l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -262,7 +280,13 @@ fn failed_transaction_test() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);
let rlp_transactions = vec![create_contract_message(
&dev_signer,
0,
Expand Down Expand Up @@ -302,9 +326,11 @@ fn self_destruct_test() {
get_evm_config(U256::from_str("100000000000000000000").unwrap(), None);
let (evm, mut working_set) = get_evm(&config);
let l1_fee_rate = 0;
let mut l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -320,7 +346,13 @@ fn self_destruct_test() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

// deploy selfdestruct contract
// send some money to the selfdestruct contract
Expand All @@ -343,6 +375,8 @@ fn self_destruct_test() {
evm.end_soft_confirmation_hook(&mut working_set);
evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state());

l2_height += 1;

let db_contract = evm
.accounts
.get(&contract_addr, &mut working_set)
Expand All @@ -366,6 +400,7 @@ fn self_destruct_test() {

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 2,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -381,7 +416,13 @@ fn self_destruct_test() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);
// selfdestruct
evm.call(
CallMessage {
Expand All @@ -398,6 +439,7 @@ fn self_destruct_test() {
.unwrap();
}
evm.end_soft_confirmation_hook(&mut working_set);

let db_contract = evm
.accounts
.get(&contract_addr, &mut working_set)
Expand Down Expand Up @@ -445,9 +487,11 @@ fn test_block_hash_in_evm() {

let (evm, mut working_set) = get_evm(&config);
let l1_fee_rate = 0;
let mut l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -463,7 +507,13 @@ fn test_block_hash_in_evm() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

let deploy_message = create_contract_message(&dev_signer, 0, BlockHashContract::default());

Expand All @@ -479,11 +529,14 @@ fn test_block_hash_in_evm() {
evm.end_soft_confirmation_hook(&mut working_set);
evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state());

l2_height += 1;

for _i in 0..514 {
// generate 514 more blocks
let l1_fee_rate = 0;
evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -498,6 +551,8 @@ fn test_block_hash_in_evm() {
);
evm.end_soft_confirmation_hook(&mut working_set);
evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state());

l2_height += 1;
}

let _last_block_number = evm
Expand Down Expand Up @@ -558,9 +613,11 @@ fn test_block_gas_limit() {

let (evm, mut working_set) = get_evm(&config);
let l1_fee_rate = 0;
let l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -576,7 +633,13 @@ fn test_block_gas_limit() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

// deploy logs contract
let mut rlp_transactions = vec![create_contract_message(
Expand Down Expand Up @@ -841,6 +904,7 @@ fn test_l1_fee_success() {

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height: 2,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -856,7 +920,13 @@ fn test_l1_fee_success() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
2,
SovSpecId::Genesis,
l1_fee_rate,
);

let deploy_message = create_contract_message_with_priority_fee(
&dev_signer,
Expand Down Expand Up @@ -943,8 +1013,11 @@ fn test_l1_fee_not_enough_funds() {
let l1_fee_rate = 10000;
let (evm, mut working_set) = get_evm(&config);

let l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -960,7 +1033,13 @@ fn test_l1_fee_not_enough_funds() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

let deploy_message =
create_contract_message_with_fee(&dev_signer, 0, BlockHashContract::default(), 1);
Expand Down Expand Up @@ -1001,11 +1080,13 @@ fn test_l1_fee_halt() {
let (config, dev_signer, _) =
get_evm_config_starting_base_fee(U256::from_str("20000000000000").unwrap(), None, 1);

let (evm, mut working_set) = get_evm(&config);
let (evm, mut working_set) = get_evm(&config); // l2 height 1
let l1_fee_rate = 1;
let l2_height = 2;

evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [5u8; 32],
da_slot_height: 1,
da_slot_txs_commitment: [42u8; 32],
Expand All @@ -1021,7 +1102,13 @@ fn test_l1_fee_halt() {
{
let sender_address = generate_address::<C>("sender");
let sequencer_address = generate_address::<C>("sequencer");
let context = C::new(sender_address, sequencer_address, 1);
let context = C::new(
sender_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);

let deploy_message = create_contract_message_with_fee(
&dev_signer,
Expand Down
26 changes: 22 additions & 4 deletions crates/evm/src/tests/ef_tests/cases/blockchain_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,38 @@ impl BlockchainTestCase {
mut working_set: WorkingSet<DefaultContext>,
storage: ProverStorage<DefaultStorageSpec, SnapshotManager>,
root: &[u8; 32],
l2_height: u64,
) -> (
WorkingSet<DefaultContext>,
ProverStorage<DefaultStorageSpec, SnapshotManager>,
) {
let l1_fee_rate = 0;
// Call begin_soft_confirmation_hook
evm.begin_soft_confirmation_hook(
&HookSoftConfirmationInfo {
l2_height,
da_slot_hash: [0u8; 32],
da_slot_height: 0,
da_slot_txs_commitment: [0u8; 32],
pre_state_root: root.to_vec(),
current_spec: SovSpecId::Genesis,
pub_key: vec![],
deposit_data: vec![],
l1_fee_rate: 0,
l1_fee_rate,
timestamp: 0,
},
&mut working_set,
);

let dummy_address = generate_address::<DefaultContext>("dummy");
let sequencer_address = generate_address::<DefaultContext>("sequencer");
let context = DefaultContext::new(dummy_address, sequencer_address, 1);
let context = DefaultContext::new(
dummy_address,
sequencer_address,
l2_height,
SovSpecId::Genesis,
l1_fee_rate,
);
let _ = evm.execute_call(txs, &context, &mut working_set);

evm.end_soft_confirmation_hook(&mut working_set);
Expand Down Expand Up @@ -176,6 +185,7 @@ impl Case for BlockchainTestCase {
}

let (mut evm, _, mut storage) = get_evm_with_storage(&evm_config);
let mut l2_height = 2;

let mut working_set = WorkingSet::new(storage.clone());
evm.cfg.set(
Expand Down Expand Up @@ -217,8 +227,16 @@ impl Case for BlockchainTestCase {
})
.collect();

(working_set, storage) =
self.execute_transactions(&mut evm, txs, working_set, storage, &root);
(working_set, storage) = self.execute_transactions(
&mut evm,
txs,
working_set,
storage,
&root,
l2_height,
);

l2_height += 1;
}

// Validate the post-state for the test case.
Expand Down
Loading

0 comments on commit ec5662b

Please sign in to comment.