Skip to content

Commit

Permalink
schemas: signature required location type checks (#2140)
Browse files Browse the repository at this point in the history
# 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?
  • Loading branch information
aramikm committed Sep 18, 2024
1 parent 7d1f964 commit f86762f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pallets/schemas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,13 @@ pub mod pallet {
payload_location == PayloadLocation::Itemized,
Error::<T>::InvalidSetting
);
// SignatureRequired is only valid for Itemized and Paginated payload locations
ensure!(
!settings.contains(&SchemaSetting::SignatureRequired) ||
payload_location == PayloadLocation::Itemized ||
payload_location == PayloadLocation::Paginated,
Error::<T>::InvalidSetting
);
let schema_name = match optional_schema_name {
None => None,
Some(name_payload) => {
Expand Down
26 changes: 26 additions & 0 deletions pallets/schemas/src/tests/other_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,33 @@ fn create_schema_via_governance_v2_with_append_only_setting_and_non_itemized_sho
);
})
}
#[test]
fn create_schema_via_governance_v2_with_signature_required_setting_and_wrong_location_should_fail()
{
new_test_ext().execute_with(|| {
sudo_set_max_schema_size();

// arrange
let settings = vec![SchemaSetting::SignatureRequired];
let sender: AccountId = test_public(1);

for location in vec![PayloadLocation::OnChain, PayloadLocation::IPFS] {
// act and assert
assert_noop!(
SchemasPallet::create_schema_via_governance_v2(
RuntimeOrigin::from(pallet_collective::RawOrigin::Members(2, 3)),
sender.clone(),
create_bounded_schema_vec(r#"{"name":"John Doe"}"#),
ModelType::AvroBinary,
location,
BoundedVec::try_from(settings.clone()).unwrap(),
None,
),
Error::<Test>::InvalidSetting
);
}
})
}
/// Test that a request to be a provider, makes the MSA a provider after the council approves it.
#[test]
fn propose_to_create_schema_v2_happy_path() {
Expand Down
4 changes: 2 additions & 2 deletions runtime/frequency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("frequency"),
impl_name: create_runtime_str!("frequency"),
authoring_version: 1,
spec_version: 111,
spec_version: 112,
impl_version: 0,
apis: apis::RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand All @@ -389,7 +389,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("frequency-testnet"),
impl_name: create_runtime_str!("frequency"),
authoring_version: 1,
spec_version: 111,
spec_version: 112,
impl_version: 0,
apis: apis::RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit f86762f

Please sign in to comment.