Skip to content

Commit f86762f

Browse files
authored
schemas: signature required location type checks (#2140)
# Goal The goal of this PR is ensure `SignatureRequired` is only going to be used for `Itemized` and `Paginated` locations. Closes #1874 # Checklist - [x] Unit Tests added? - [x] Spec version incremented?
1 parent 7d1f964 commit f86762f

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

pallets/schemas/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,13 @@ pub mod pallet {
838838
payload_location == PayloadLocation::Itemized,
839839
Error::<T>::InvalidSetting
840840
);
841+
// SignatureRequired is only valid for Itemized and Paginated payload locations
842+
ensure!(
843+
!settings.contains(&SchemaSetting::SignatureRequired) ||
844+
payload_location == PayloadLocation::Itemized ||
845+
payload_location == PayloadLocation::Paginated,
846+
Error::<T>::InvalidSetting
847+
);
841848
let schema_name = match optional_schema_name {
842849
None => None,
843850
Some(name_payload) => {

pallets/schemas/src/tests/other_tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,33 @@ fn create_schema_via_governance_v2_with_append_only_setting_and_non_itemized_sho
756756
);
757757
})
758758
}
759+
#[test]
760+
fn create_schema_via_governance_v2_with_signature_required_setting_and_wrong_location_should_fail()
761+
{
762+
new_test_ext().execute_with(|| {
763+
sudo_set_max_schema_size();
764+
765+
// arrange
766+
let settings = vec![SchemaSetting::SignatureRequired];
767+
let sender: AccountId = test_public(1);
759768

769+
for location in vec![PayloadLocation::OnChain, PayloadLocation::IPFS] {
770+
// act and assert
771+
assert_noop!(
772+
SchemasPallet::create_schema_via_governance_v2(
773+
RuntimeOrigin::from(pallet_collective::RawOrigin::Members(2, 3)),
774+
sender.clone(),
775+
create_bounded_schema_vec(r#"{"name":"John Doe"}"#),
776+
ModelType::AvroBinary,
777+
location,
778+
BoundedVec::try_from(settings.clone()).unwrap(),
779+
None,
780+
),
781+
Error::<Test>::InvalidSetting
782+
);
783+
}
784+
})
785+
}
760786
/// Test that a request to be a provider, makes the MSA a provider after the council approves it.
761787
#[test]
762788
fn propose_to_create_schema_v2_happy_path() {

runtime/frequency/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
375375
spec_name: create_runtime_str!("frequency"),
376376
impl_name: create_runtime_str!("frequency"),
377377
authoring_version: 1,
378-
spec_version: 111,
378+
spec_version: 112,
379379
impl_version: 0,
380380
apis: apis::RUNTIME_API_VERSIONS,
381381
transaction_version: 1,
@@ -389,7 +389,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
389389
spec_name: create_runtime_str!("frequency-testnet"),
390390
impl_name: create_runtime_str!("frequency"),
391391
authoring_version: 1,
392-
spec_version: 111,
392+
spec_version: 112,
393393
impl_version: 0,
394394
apis: apis::RUNTIME_API_VERSIONS,
395395
transaction_version: 1,

0 commit comments

Comments
 (0)