Skip to content

Commit

Permalink
Fix flaky tests (#723)
Browse files Browse the repository at this point in the history
* Add waits

* Import helper in archive state tests

* Fix clippy

* MOAR fixes

* Fix some more tests

* Disable logs for test

* Try increase timeout for gas price increase test
  • Loading branch information
rakanalh authored Jun 13, 2024
1 parent 38db27d commit abb1f54
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
12 changes: 12 additions & 0 deletions bin/citrea/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,7 @@ async fn sequencer_crash_and_replace_full_node() -> Result<(), anyhow::Error> {
seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(&seq_test_client, 4, None).await;

// second da block
da_service.publish_test_block().await.unwrap();
Expand Down Expand Up @@ -2016,6 +2017,7 @@ async fn sequencer_crash_and_replace_full_node() -> Result<(), anyhow::Error> {
seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(&seq_test_client, 9, None).await;

da_service.publish_test_block().await.unwrap();
wait_for_l1_block(&da_service, 4, None).await;
Expand Down Expand Up @@ -2286,6 +2288,10 @@ async fn sequencer_crash_restore_mempool() -> Result<(), anyhow::Error> {
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(&seq_test_client, 1, None).await;

// Mempool removal is an async operation that happens in a different
// tokio task, wait for 2 seconds for this to execute.
sleep(Duration::from_secs(2)).await;

// should be removed from mempool
assert!(seq_test_client
.eth_get_transaction_by_hash(tx_hash, Some(true))
Expand Down Expand Up @@ -2378,6 +2384,7 @@ async fn test_db_get_proof() {
test_client.send_publish_batch_request().await;
test_client.send_publish_batch_request().await;
test_client.send_publish_batch_request().await;
wait_for_l2_block(&test_client, 4, None).await;

da_service.publish_test_block().await.unwrap();
// Commitment
Expand Down Expand Up @@ -2724,6 +2731,7 @@ async fn test_all_flow() {
wait_for_l1_block(&da_service, 2, None).await;

test_client.send_publish_batch_request().await;
wait_for_l2_block(&test_client, 1, None).await;

// send one ether to some address
test_client
Expand All @@ -2737,12 +2745,15 @@ async fn test_all_flow() {
.unwrap();
test_client.send_publish_batch_request().await;
test_client.send_publish_batch_request().await;
wait_for_l2_block(&test_client, 3, None).await;

// send one ether to some address
test_client
.send_eth(addr, None, None, None, 1e18 as u128)
.await
.unwrap();
test_client.send_publish_batch_request().await;
wait_for_l2_block(&test_client, 4, None).await;

// Submit commitment
da_service.publish_test_block().await.unwrap();
Expand Down Expand Up @@ -3139,6 +3150,7 @@ async fn test_ledger_get_head_soft_batch() {

seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(&seq_test_client, 2, None).await;

let latest_block = seq_test_client
.eth_get_block_by_number(Some(BlockNumberOrTag::Latest))
Expand Down
11 changes: 10 additions & 1 deletion bin/citrea/tests/evm/archival_state.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::str::FromStr;
use std::time::Duration;

use citrea_evm::smart_contracts::SimpleStorageContract;
use citrea_stf::genesis_config::GenesisPaths;
use ethers::abi::Address;
use ethers_core::abi::Bytes;
use reth_primitives::BlockNumberOrTag;
use tokio::time::sleep;

use crate::evm::init_test_rollup;
use crate::test_client::TestClient;
use crate::test_helpers::{start_rollup, tempdir_with_children, NodeMode};
use crate::test_helpers::{start_rollup, tempdir_with_children, wait_for_l2_block, NodeMode};
use crate::{DEFAULT_DEPOSIT_MEMPOOL_FETCH_LIMIT, DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT};

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -126,6 +128,10 @@ async fn run_archival_valid_tests(addr: Address, seq_test_client: &TestClient) {
.await;
seq_test_client.send_publish_batch_request().await;
}
wait_for_l2_block(seq_test_client, 8, None).await;

// Wait for changeset storage
sleep(Duration::from_secs(2)).await;

assert_eq!(
seq_test_client
Expand Down Expand Up @@ -217,6 +223,7 @@ async fn run_archival_valid_tests(addr: Address, seq_test_client: &TestClient) {
.unwrap();

seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(seq_test_client, 9, None).await;

let contract_address = deploy_contract_req
.await
Expand All @@ -230,6 +237,7 @@ async fn run_archival_valid_tests(addr: Address, seq_test_client: &TestClient) {

seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(seq_test_client, 11, None).await;

let code = seq_test_client
.eth_get_code(contract_address, Some(BlockNumberOrTag::Number(9)))
Expand All @@ -251,6 +259,7 @@ async fn run_archival_valid_tests(addr: Address, seq_test_client: &TestClient) {

seq_test_client.send_publish_batch_request().await;
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(seq_test_client, 13, None).await;

let storage_slot = 0x0;
let storage_value = seq_test_client
Expand Down
3 changes: 2 additions & 1 deletion bin/citrea/tests/evm/gas_price.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::net::SocketAddr;
use std::time::Duration;

use citrea_evm::smart_contracts::SimpleStorageContract;
use citrea_stf::genesis_config::GenesisPaths;
Expand Down Expand Up @@ -101,7 +102,7 @@ async fn execute(

if i % tx_count_from_single_address == 0 {
client.send_publish_batch_request().await;
wait_for_l2_block(client, block_index, None).await;
wait_for_l2_block(client, block_index, Some(Duration::from_secs(60))).await;
block_index += 1;
}
}
Expand Down
5 changes: 4 additions & 1 deletion bin/citrea/tests/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sov_rollup_interface::CITREA_VERSION;

// use sov_demo_rollup::initialize_logging;
use crate::test_client::TestClient;
use crate::test_helpers::{start_rollup, tempdir_with_children, NodeMode};
use crate::test_helpers::{start_rollup, tempdir_with_children, wait_for_l2_block, NodeMode};
use crate::{DEFAULT_DEPOSIT_MEMPOOL_FETCH_LIMIT, DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT};

mod archival_state;
Expand Down Expand Up @@ -255,6 +255,7 @@ async fn test_getlogs(client: &Box<TestClient>) -> Result<(), Box<dyn std::error
)
.await;
client.send_publish_batch_request().await;
wait_for_l2_block(client, 1, None).await;

let empty_filter = serde_json::json!({});
// supposed to get all the logs
Expand Down Expand Up @@ -284,6 +285,7 @@ async fn test_getlogs(client: &Box<TestClient>) -> Result<(), Box<dyn std::error
let contract_address2 = {
let deploy_contract_req = client.deploy_contract(contract.byte_code(), None).await?;
client.send_publish_batch_request().await;
wait_for_l2_block(client, 2, None).await;

deploy_contract_req
.await?
Expand All @@ -301,6 +303,7 @@ async fn test_getlogs(client: &Box<TestClient>) -> Result<(), Box<dyn std::error
)
.await;
client.send_publish_batch_request().await;
wait_for_l2_block(client, 3, None).await;

// make sure the two contracts have different addresses
assert_ne!(contract_address, contract_address2);
Expand Down
8 changes: 8 additions & 0 deletions bin/citrea/tests/sequencer_commitments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async fn sequencer_sends_commitments_to_da_layer() {
for _ in 0..3 {
test_client.send_publish_batch_request().await;
}
wait_for_l2_block(&test_client, 3, None).await;

da_service.publish_test_block().await.unwrap();
wait_for_l1_block(&da_service, 2, None).await;
Expand Down Expand Up @@ -85,6 +86,7 @@ async fn sequencer_sends_commitments_to_da_layer() {

// Publish one more L2 block
test_client.send_publish_batch_request().await;
wait_for_l2_block(&test_client, 4, None).await;

// Trigger a commitment
da_service.publish_test_block().await.unwrap();
Expand All @@ -110,10 +112,14 @@ async fn sequencer_sends_commitments_to_da_layer() {
for _ in 0..4 {
test_client.send_publish_batch_request().await;
}
wait_for_l2_block(&test_client, 8, None).await;

da_service.publish_test_block().await.unwrap();
wait_for_l1_block(&da_service, 4, None).await;
wait_for_l1_block(&da_service, 5, None).await;

wait_for_l2_block(&test_client, 9, None).await;

let start_l2_block: u64 = end_l2_block + 1;
let end_l2_block: u64 = end_l2_block + 5; // can only be the block before the one comitment landed in
let start_l1_block = end_l1_block + 1;
Expand Down Expand Up @@ -250,6 +256,7 @@ async fn check_commitment_in_offchain_db() {
for _ in 0..3 {
test_client.send_publish_batch_request().await;
}
wait_for_l2_block(&test_client, 3, None).await;

da_service.publish_test_block().await.unwrap();
wait_for_l1_block(&da_service, 3, None).await;
Expand All @@ -261,6 +268,7 @@ async fn check_commitment_in_offchain_db() {
// commitment should be published with this call
da_service.publish_test_block().await.unwrap();
wait_for_l1_block(&da_service, 4, None).await;
wait_for_l1_block(&da_service, 5, None).await;

wait_for_postgres_commitment(
&db_test_client,
Expand Down

0 comments on commit abb1f54

Please sign in to comment.