|
| 1 | +use crate::tests::framework::TestHarnessBuilder; |
| 2 | +use alloy_provider::Provider; |
| 3 | + |
| 4 | +/// This test ensures that the transaction size limit is respected. |
| 5 | +/// We will set limit to 1 byte and see that the builder will not include any transactions. |
| 6 | +#[tokio::test] |
| 7 | +async fn data_availability_tx_size_limit() -> eyre::Result<()> { |
| 8 | + let harness = TestHarnessBuilder::new("data_availability_tx_size_limit") |
| 9 | + .with_namespaces("admin,eth,miner") |
| 10 | + .build() |
| 11 | + .await?; |
| 12 | + |
| 13 | + let mut generator = harness.block_generator().await?; |
| 14 | + |
| 15 | + // Set (max_tx_da_size, max_block_da_size), with this case block won't fit any transaction |
| 16 | + let call = harness |
| 17 | + .provider()? |
| 18 | + .raw_request::<(i32, i32), bool>("miner_setMaxDASize".into(), (1, 0)) |
| 19 | + .await?; |
| 20 | + assert!(call, "miner_setMaxDASize should be executed successfully"); |
| 21 | + |
| 22 | + let unfit_tx = harness |
| 23 | + .create_transaction() |
| 24 | + .with_max_priority_fee_per_gas(50) |
| 25 | + .send() |
| 26 | + .await?; |
| 27 | + let block = generator.generate_block().await?; |
| 28 | + // tx should not be included because we set the tx_size_limit to 1 |
| 29 | + assert!( |
| 30 | + block.not_includes(*unfit_tx.tx_hash()), |
| 31 | + "transaction should not be included in the block" |
| 32 | + ); |
| 33 | + |
| 34 | + Ok(()) |
| 35 | +} |
| 36 | + |
| 37 | +/// This test ensures that the block size limit is respected. |
| 38 | +/// We will set limit to 1 byte and see that the builder will not include any transactions. |
| 39 | +#[tokio::test] |
| 40 | +async fn data_availability_block_size_limit() -> eyre::Result<()> { |
| 41 | + let harness = TestHarnessBuilder::new("data_availability_block_size_limit") |
| 42 | + .with_namespaces("admin,eth,miner") |
| 43 | + .build() |
| 44 | + .await?; |
| 45 | + |
| 46 | + let mut generator = harness.block_generator().await?; |
| 47 | + |
| 48 | + // Set block da size to be small, so it won't include tx |
| 49 | + let call = harness |
| 50 | + .provider()? |
| 51 | + .raw_request::<(i32, i32), bool>("miner_setMaxDASize".into(), (0, 1)) |
| 52 | + .await?; |
| 53 | + assert!(call, "miner_setMaxDASize should be executed successfully"); |
| 54 | + |
| 55 | + let unfit_tx = harness.send_valid_transaction().await?; |
| 56 | + let block = generator.generate_block().await?; |
| 57 | + // tx should not be included because we set the tx_size_limit to 1 |
| 58 | + assert!( |
| 59 | + block.not_includes(*unfit_tx.tx_hash()), |
| 60 | + "transaction should not be included in the block" |
| 61 | + ); |
| 62 | + |
| 63 | + Ok(()) |
| 64 | +} |
| 65 | + |
| 66 | +/// This test ensures that block will fill up to the limit. |
| 67 | +/// Size of each transaction is 100000000 |
| 68 | +/// We will set limit to 3 txs and see that the builder will include 3 transactions. |
| 69 | +/// We should not forget about builder transaction so we will spawn only 2 regular txs. |
| 70 | +#[tokio::test] |
| 71 | +async fn data_availability_block_fill() -> eyre::Result<()> { |
| 72 | + let harness = TestHarnessBuilder::new("data_availability_block_fill") |
| 73 | + .with_namespaces("admin,eth,miner") |
| 74 | + .build() |
| 75 | + .await?; |
| 76 | + |
| 77 | + let mut generator = harness.block_generator().await?; |
| 78 | + |
| 79 | + // Set block big enough so it could fit 3 transactions without tx size limit |
| 80 | + let call = harness |
| 81 | + .provider()? |
| 82 | + .raw_request::<(i32, i32), bool>("miner_setMaxDASize".into(), (0, 100000000 * 3)) |
| 83 | + .await?; |
| 84 | + assert!(call, "miner_setMaxDASize should be executed successfully"); |
| 85 | + |
| 86 | + // We already have 2 so we will spawn one more to check that it won't be included (it won't fit |
| 87 | + // because of builder tx) |
| 88 | + let fit_tx_1 = harness |
| 89 | + .create_transaction() |
| 90 | + .with_max_priority_fee_per_gas(50) |
| 91 | + .send() |
| 92 | + .await?; |
| 93 | + let fit_tx_2 = harness |
| 94 | + .create_transaction() |
| 95 | + .with_max_priority_fee_per_gas(50) |
| 96 | + .send() |
| 97 | + .await?; |
| 98 | + let unfit_tx_3 = harness.create_transaction().send().await?; |
| 99 | + |
| 100 | + let block = generator.generate_block().await?; |
| 101 | + // Now the first 2 txs will fit into the block |
| 102 | + assert!(block.includes(*fit_tx_1.tx_hash()), "tx should be in block"); |
| 103 | + assert!(block.includes(*fit_tx_2.tx_hash()), "tx should be in block"); |
| 104 | + assert!( |
| 105 | + block.not_includes(*unfit_tx_3.tx_hash()), |
| 106 | + "unfit tx should not be in block" |
| 107 | + ); |
| 108 | + assert!( |
| 109 | + harness.latest_block().await.transactions.len() == 4, |
| 110 | + "builder + deposit + 2 valid txs should be in the block" |
| 111 | + ); |
| 112 | + |
| 113 | + Ok(()) |
| 114 | +} |
0 commit comments