Skip to content

Commit 598ac01

Browse files
gabriele-0201rphmeier
authored andcommitted
small tests refactor
1 parent 1269569 commit 598ac01

File tree

1 file changed

+15
-35
lines changed
  • sugondat-chain/pallets/blobs/src

1 file changed

+15
-35
lines changed

sugondat-chain/pallets/blobs/src/tests.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,33 @@ fn test_no_extrinsic_index() {
5757
});
5858
}
5959

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 {
6764
assert_ok!(Blobs::submit_blob(
6865
RuntimeOrigin::signed(alice()),
6966
i,
7067
blob.clone()
7168
));
7269
}
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);
7378
});
7479
}
7580

7681
#[test]
7782
#[should_panic = "Maximum blob limit exceeded"]
7883
fn test_max_blobs_exceeded() {
7984
let max_blobs: u32 = <Test as pallet_blobs::Config>::MaxBlobs::get();
80-
8185
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);
9287
});
9388
}
9489

@@ -99,14 +94,7 @@ fn test_max_total_blob_size_reached() {
9994
let blobs_needed = max_total_blobs_size / max_blob_size;
10095

10196
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);
11098
});
11199
}
112100

@@ -118,15 +106,7 @@ fn test_max_total_blob_size_exceeded() {
118106
let blobs_needed = max_total_blobs_size / max_blob_size;
119107

120108
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);
130110
});
131111
}
132112

0 commit comments

Comments
 (0)