Skip to content

Commit 6022499

Browse files
rphmeierpepyakin
authored andcommitted
chore: fix blobs tests
1 parent 6685abd commit 6022499

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ impl frame_system::Config for Test {
5252

5353
impl pallet_blobs::Config for Test {
5454
type RuntimeEvent = RuntimeEvent;
55-
type MaxBlobs = ConstU32<{ 100 * 1024 }>;
56-
type MaxBlobSize = ConstU32<{ 100 * 1024 }>;
57-
type MaxTotalBlobSize = ConstU32<{ 2 * 1024 * 1024 }>;
55+
type MaxBlobs = ConstU32<16>;
56+
type MaxBlobSize = ConstU32<1024>;
57+
type MaxTotalBlobSize = ConstU32<{ 10 * 1024 }>;
5858
type WeightInfo = ();
5959
}
6060

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,30 @@ fn test_max_blobs_reached() {
7070
blob.clone()
7171
));
7272
}
73-
assert_noop!(
74-
Blobs::submit_blob(RuntimeOrigin::signed(alice()), 0, blob.clone()),
75-
Error::<Test>::MaxBlobsReached
76-
);
7773
});
7874
}
7975

8076
#[test]
81-
fn test_max_total_blob_size() {
77+
#[should_panic = "Maximum blob limit exceeded"]
78+
fn test_max_blobs_exceeded() {
79+
let max_blobs: u32 = <Test as pallet_blobs::Config>::MaxBlobs::get();
80+
81+
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());
92+
});
93+
}
94+
95+
#[test]
96+
fn test_max_total_blob_size_reached() {
8297
let max_total_blobs_size: u32 = <Test as pallet_blobs::Config>::MaxTotalBlobSize::get();
8398
let max_blob_size: u32 = <Test as pallet_blobs::Config>::MaxBlobSize::get();
8499
let blobs_needed = max_total_blobs_size / max_blob_size;
@@ -92,10 +107,26 @@ fn test_max_total_blob_size() {
92107
blob.clone()
93108
));
94109
}
95-
assert_noop!(
96-
Blobs::submit_blob(RuntimeOrigin::signed(alice()), 0, blob.clone()),
97-
Error::<Test>::MaxTotalBlobsSizeReached
98-
);
110+
});
111+
}
112+
113+
#[test]
114+
#[should_panic = "Maximum total blob size exceeded"]
115+
fn test_max_total_blob_size_exceeded() {
116+
let max_total_blobs_size: u32 = <Test as pallet_blobs::Config>::MaxTotalBlobSize::get();
117+
let max_blob_size: u32 = <Test as pallet_blobs::Config>::MaxBlobSize::get();
118+
let blobs_needed = max_total_blobs_size / max_blob_size;
119+
120+
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());
99130
});
100131
}
101132

0 commit comments

Comments
 (0)