@@ -57,38 +57,33 @@ fn test_no_extrinsic_index() {
57
57
} ) ;
58
58
}
59
59
60
- #[ test]
61
- fn test_max_blobs_reached ( ) {
62
- let max_blobs: u32 = <Test as pallet_blobs:: Config >:: MaxBlobs :: get ( ) ;
63
-
64
- new_test_ext ( ) . execute_with ( || {
65
- let blob = get_blob ( 1 ) ;
66
- for i in 0 ..max_blobs {
60
+ macro_rules! submit_blobs {
61
+ ( [ blob_size] $blob_size: expr, [ blobs_number] $n_blobs: expr) => {
62
+ let blob = get_blob( $blob_size) ;
63
+ for i in 0 ..$n_blobs {
67
64
assert_ok!( Blobs :: submit_blob(
68
65
RuntimeOrigin :: signed( alice( ) ) ,
69
66
i,
70
67
blob. clone( )
71
68
) ) ;
72
69
}
70
+ } ;
71
+ }
72
+
73
+ #[ test]
74
+ fn test_max_blobs_reached ( ) {
75
+ let max_blobs: u32 = <Test as pallet_blobs:: Config >:: MaxBlobs :: get ( ) ;
76
+ new_test_ext ( ) . execute_with ( || {
77
+ submit_blobs ! ( [ blob_size] 1 , [ blobs_number] max_blobs) ;
73
78
} ) ;
74
79
}
75
80
76
81
#[ test]
77
82
#[ should_panic = "Maximum blob limit exceeded" ]
78
83
fn test_max_blobs_exceeded ( ) {
79
84
let max_blobs: u32 = <Test as pallet_blobs:: Config >:: MaxBlobs :: get ( ) ;
80
-
81
85
new_test_ext ( ) . execute_with ( || {
82
- let blob = get_blob ( 1 ) ;
83
- for i in 0 ..max_blobs {
84
- assert_ok ! ( Blobs :: submit_blob(
85
- RuntimeOrigin :: signed( alice( ) ) ,
86
- i,
87
- blob. clone( )
88
- ) ) ;
89
- }
90
-
91
- let _ = Blobs :: submit_blob ( RuntimeOrigin :: signed ( alice ( ) ) , 0 , blob. clone ( ) ) ;
86
+ submit_blobs ! ( [ blob_size] 1 , [ blobs_number] max_blobs + 1 ) ;
92
87
} ) ;
93
88
}
94
89
@@ -99,14 +94,7 @@ fn test_max_total_blob_size_reached() {
99
94
let blobs_needed = max_total_blobs_size / max_blob_size;
100
95
101
96
new_test_ext ( ) . execute_with ( || {
102
- let blob = get_blob ( max_blob_size) ;
103
- for i in 0 ..blobs_needed {
104
- assert_ok ! ( Blobs :: submit_blob(
105
- RuntimeOrigin :: signed( alice( ) ) ,
106
- i,
107
- blob. clone( )
108
- ) ) ;
109
- }
97
+ submit_blobs ! ( [ blob_size] max_blob_size, [ blobs_number] blobs_needed) ;
110
98
} ) ;
111
99
}
112
100
@@ -118,15 +106,7 @@ fn test_max_total_blob_size_exceeded() {
118
106
let blobs_needed = max_total_blobs_size / max_blob_size;
119
107
120
108
new_test_ext ( ) . execute_with ( || {
121
- let blob = get_blob ( max_blob_size) ;
122
- for i in 0 ..blobs_needed {
123
- assert_ok ! ( Blobs :: submit_blob(
124
- RuntimeOrigin :: signed( alice( ) ) ,
125
- i,
126
- blob. clone( )
127
- ) ) ;
128
- }
129
- let _ = Blobs :: submit_blob ( RuntimeOrigin :: signed ( alice ( ) ) , 0 , blob. clone ( ) ) ;
109
+ submit_blobs ! ( [ blob_size] max_blob_size, [ blobs_number] blobs_needed + 1 ) ;
130
110
} ) ;
131
111
}
132
112
0 commit comments