11use crate :: tests:: framework:: TestHarnessBuilder ;
2+ use alloy_provider:: Provider ;
23
34/// This test ensures that the transaction size limit is respected.
45/// We will set limit to 1 byte and see that the builder will not include any transactions.
56#[ tokio:: test]
67async fn data_availability_tx_size_limit ( ) -> eyre:: Result < ( ) > {
78 let harness = TestHarnessBuilder :: new ( "data_availability_tx_size_limit" )
8- . with_max_da_tx_size ( 1 )
9+ . with_namespaces ( "admin,eth,miner" )
910 . build ( )
1011 . await ?;
1112
1213 let mut generator = harness. block_generator ( ) . await ?;
1314
14- // generate regualr tx
15- let invalid_tx = harness. send_valid_transaction ( ) . await ?;
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" ) ;
1621
22+ let unfit_tx = harness
23+ . create_transaction ( )
24+ . with_max_priority_fee_per_gas ( 50 )
25+ . send ( )
26+ . await ?;
1727 let block = generator. generate_block ( ) . await ?;
18-
1928 // tx should not be included because we set the tx_size_limit to 1
2029 assert ! (
21- block. not_includes( * invalid_tx . tx_hash( ) ) ,
30+ block. not_includes( * unfit_tx . tx_hash( ) ) ,
2231 "transaction should not be included in the block"
2332 ) ;
2433
@@ -30,20 +39,24 @@ async fn data_availability_tx_size_limit() -> eyre::Result<()> {
3039#[ tokio:: test]
3140async fn data_availability_block_size_limit ( ) -> eyre:: Result < ( ) > {
3241 let harness = TestHarnessBuilder :: new ( "data_availability_block_size_limit" )
33- . with_max_da_block_size ( 1 )
42+ . with_namespaces ( "admin,eth,miner" )
3443 . build ( )
3544 . await ?;
3645
3746 let mut generator = harness. block_generator ( ) . await ?;
3847
39- // generate regualr tx
40- let invalid_tx = harness. send_valid_transaction ( ) . await ?;
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" ) ;
4154
55+ let unfit_tx = harness. send_valid_transaction ( ) . await ?;
4256 let block = generator. generate_block ( ) . await ?;
43-
4457 // tx should not be included because we set the tx_size_limit to 1
4558 assert ! (
46- block. not_includes( * invalid_tx . tx_hash( ) ) ,
59+ block. not_includes( * unfit_tx . tx_hash( ) ) ,
4760 "transaction should not be included in the block"
4861 ) ;
4962
@@ -56,29 +69,38 @@ async fn data_availability_block_size_limit() -> eyre::Result<()> {
5669/// We should not forget about builder transaction so we will spawn only 2 regular txs.
5770#[ tokio:: test]
5871async fn data_availability_block_fill ( ) -> eyre:: Result < ( ) > {
59- let harness = TestHarnessBuilder :: new ( "data_availability_block_fill " )
60- . with_max_da_block_size ( 100000000 * 3 )
72+ let harness = TestHarnessBuilder :: new ( "data_availability_tx_size_limit " )
73+ . with_namespaces ( "admin,eth,miner" )
6174 . build ( )
6275 . await ?;
6376
6477 let mut generator = harness. block_generator ( ) . await ?;
6578
66- // generate regualr tx
67- let valid_tx_1 = harness. send_valid_transaction ( ) . await ?;
68- let valid_tx_2 = harness. send_valid_transaction ( ) . await ?;
69- let unfit_tx_3 = harness. send_valid_transaction ( ) . await ?;
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 ?;
7099
71100 let block = generator. generate_block ( ) . await ?;
72-
73- // tx should not be included because we set the tx_size_limit to 1
74- assert ! (
75- block. includes( * valid_tx_1. tx_hash( ) ) ,
76- "tx should be in block"
77- ) ;
78- assert ! (
79- block. includes( * valid_tx_2. tx_hash( ) ) ,
80- "tx should be in block"
81- ) ;
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" ) ;
82104 assert ! (
83105 block. not_includes( * unfit_tx_3. tx_hash( ) ) ,
84106 "unfit tx should not be in block"
@@ -87,5 +109,6 @@ async fn data_availability_block_fill() -> eyre::Result<()> {
87109 harness. latest_block( ) . await . transactions. len( ) == 4 ,
88110 "builder + deposit + 2 valid txs should be in the block"
89111 ) ;
112+
90113 Ok ( ( ) )
91114}
0 commit comments