From 95e6d32e3de5c17cf00d2b9828ee1edb48f9ff20 Mon Sep 17 00:00:00 2001 From: Aramik Date: Wed, 28 Aug 2024 14:46:06 -0700 Subject: [PATCH 1/4] schemas: signature required location type checks --- e2e/package-lock.json | 9 ++++---- pallets/schemas/src/lib.rs | 7 +++++++ pallets/schemas/src/tests/other_tests.rs | 26 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/e2e/package-lock.json b/e2e/package-lock.json index 841fe0cb73..88fe17313d 100644 --- a/e2e/package-lock.json +++ b/e2e/package-lock.json @@ -2839,11 +2839,12 @@ "node_modules/@frequency-chain/api-augment": { "version": "0.0.0", "resolved": "file:../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz", - "integrity": "sha512-7prkQiSHJ0aCa9vqR6g5HwVZ55rstu94m1FjQvJQO7MIt8BgSQYAsP0N1pc2CmtN0k72wYeGRV3+nLnWkfKG1w==", + "integrity": "sha512-cUlKAOUBdFJutWnYl0PZtrWtkJJgL54DRgtdKq7BWZWkYZlENZnfC1PFGBC51Oc2qU+yHnqdij+wV+wjCP9D5Q==", + "license": "Apache-2.0", "dependencies": { - "@polkadot/api": "^12.2.3", - "@polkadot/rpc-provider": "^12.2.3", - "@polkadot/types": "^12.2.3", + "@polkadot/api": "^12.3.1", + "@polkadot/rpc-provider": "^12.3.1", + "@polkadot/types": "^12.3.1", "globals": "^15.9.0" } }, diff --git a/pallets/schemas/src/lib.rs b/pallets/schemas/src/lib.rs index ecb3cff04f..4151512c8e 100644 --- a/pallets/schemas/src/lib.rs +++ b/pallets/schemas/src/lib.rs @@ -838,6 +838,13 @@ pub mod pallet { payload_location == PayloadLocation::Itemized, Error::::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::::InvalidSetting + ); let schema_name = match optional_schema_name { None => None, Some(name_payload) => { diff --git a/pallets/schemas/src/tests/other_tests.rs b/pallets/schemas/src/tests/other_tests.rs index b205913131..1852b1414f 100644 --- a/pallets/schemas/src/tests/other_tests.rs +++ b/pallets/schemas/src/tests/other_tests.rs @@ -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::::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() { From 60863dab8343a12cc7f651af9ebc2aa166dda390 Mon Sep 17 00:00:00 2001 From: Aramik Date: Wed, 28 Aug 2024 14:48:33 -0700 Subject: [PATCH 2/4] bump spec --- runtime/frequency/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/frequency/src/lib.rs b/runtime/frequency/src/lib.rs index b45e48b993..cca334c7d3 100644 --- a/runtime/frequency/src/lib.rs +++ b/runtime/frequency/src/lib.rs @@ -361,7 +361,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("frequency"), impl_name: create_runtime_str!("frequency"), authoring_version: 1, - spec_version: 108, + spec_version: 109, impl_version: 0, apis: apis::RUNTIME_API_VERSIONS, transaction_version: 1, @@ -375,7 +375,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("frequency-testnet"), impl_name: create_runtime_str!("frequency"), authoring_version: 1, - spec_version: 108, + spec_version: 109, impl_version: 0, apis: apis::RUNTIME_API_VERSIONS, transaction_version: 1, From 46a299473918905e96408434197155245b0801fe Mon Sep 17 00:00:00 2001 From: Aramik Date: Fri, 30 Aug 2024 10:24:17 -0700 Subject: [PATCH 3/4] clean changed package lock --- e2e/package-lock.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/e2e/package-lock.json b/e2e/package-lock.json index 88fe17313d..841fe0cb73 100644 --- a/e2e/package-lock.json +++ b/e2e/package-lock.json @@ -2839,12 +2839,11 @@ "node_modules/@frequency-chain/api-augment": { "version": "0.0.0", "resolved": "file:../js/api-augment/dist/frequency-chain-api-augment-0.0.0.tgz", - "integrity": "sha512-cUlKAOUBdFJutWnYl0PZtrWtkJJgL54DRgtdKq7BWZWkYZlENZnfC1PFGBC51Oc2qU+yHnqdij+wV+wjCP9D5Q==", - "license": "Apache-2.0", + "integrity": "sha512-7prkQiSHJ0aCa9vqR6g5HwVZ55rstu94m1FjQvJQO7MIt8BgSQYAsP0N1pc2CmtN0k72wYeGRV3+nLnWkfKG1w==", "dependencies": { - "@polkadot/api": "^12.3.1", - "@polkadot/rpc-provider": "^12.3.1", - "@polkadot/types": "^12.3.1", + "@polkadot/api": "^12.2.3", + "@polkadot/rpc-provider": "^12.2.3", + "@polkadot/types": "^12.2.3", "globals": "^15.9.0" } }, From 2e7e0089e79068b98f16e3b65a35cc99d94021c7 Mon Sep 17 00:00:00 2001 From: Aramik Date: Fri, 30 Aug 2024 14:55:29 -0700 Subject: [PATCH 4/4] bump version --- runtime/frequency/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/frequency/src/lib.rs b/runtime/frequency/src/lib.rs index 31ee18bfa7..cf7498a11f 100644 --- a/runtime/frequency/src/lib.rs +++ b/runtime/frequency/src/lib.rs @@ -374,7 +374,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("frequency"), impl_name: create_runtime_str!("frequency"), authoring_version: 1, - spec_version: 109, + spec_version: 110, impl_version: 0, apis: apis::RUNTIME_API_VERSIONS, transaction_version: 1, @@ -388,7 +388,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("frequency-testnet"), impl_name: create_runtime_str!("frequency"), authoring_version: 1, - spec_version: 109, + spec_version: 110, impl_version: 0, apis: apis::RUNTIME_API_VERSIONS, transaction_version: 1,