Skip to content

Revert "small tests refactor" #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions sugondat-chain/pallets/blobs/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,38 @@ fn test_no_extrinsic_index() {
});
}

macro_rules! submit_blobs {
([blob_size] $blob_size: expr, [blobs_number] $n_blobs: expr) => {
let blob = get_blob($blob_size);
for i in 0..$n_blobs {
#[test]
fn test_max_blobs_reached() {
let max_blobs: u32 = <Test as pallet_blobs::Config>::MaxBlobs::get();

new_test_ext().execute_with(|| {
let blob = get_blob(1);
for i in 0..max_blobs {
assert_ok!(Blobs::submit_blob(
RuntimeOrigin::signed(alice()),
i,
blob.clone()
));
}
};
}

#[test]
fn test_max_blobs_reached() {
let max_blobs: u32 = <Test as pallet_blobs::Config>::MaxBlobs::get();
new_test_ext().execute_with(|| {
submit_blobs!([blob_size] 1, [blobs_number] max_blobs);
});
}

#[test]
#[should_panic = "Maximum blob limit exceeded"]
fn test_max_blobs_exceeded() {
let max_blobs: u32 = <Test as pallet_blobs::Config>::MaxBlobs::get();

new_test_ext().execute_with(|| {
submit_blobs!([blob_size] 1, [blobs_number] max_blobs + 1);
let blob = get_blob(1);
for i in 0..max_blobs {
assert_ok!(Blobs::submit_blob(
RuntimeOrigin::signed(alice()),
i,
blob.clone()
));
}

let _ = Blobs::submit_blob(RuntimeOrigin::signed(alice()), 0, blob.clone());
});
}

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

new_test_ext().execute_with(|| {
submit_blobs!([blob_size] max_blob_size, [blobs_number] blobs_needed);
let blob = get_blob(max_blob_size);
for i in 0..blobs_needed {
assert_ok!(Blobs::submit_blob(
RuntimeOrigin::signed(alice()),
i,
blob.clone()
));
}
});
}

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

new_test_ext().execute_with(|| {
submit_blobs!([blob_size] max_blob_size, [blobs_number] blobs_needed + 1);
let blob = get_blob(max_blob_size);
for i in 0..blobs_needed {
assert_ok!(Blobs::submit_blob(
RuntimeOrigin::signed(alice()),
i,
blob.clone()
));
}
let _ = Blobs::submit_blob(RuntimeOrigin::signed(alice()), 0, blob.clone());
});
}

Expand Down