From 5241827bd342542709740f0ed4ad65bab12fcd43 Mon Sep 17 00:00:00 2001 From: Matthew Dean Date: Tue, 21 Mar 2023 14:27:38 +0000 Subject: [PATCH] Fix restriction handedness (#124) * Fix restriction handedness Also adds in additional roles for l3 * Upgrade serdes --- Cargo.lock | 20 +-- node/Cargo.toml | 2 +- pallets/doas/Cargo.toml | 2 +- pallets/process-validation/Cargo.toml | 4 +- pallets/process-validation/src/lib.rs | 2 +- .../src/tests/validate_process.rs | 164 +++++++++++++++++- pallets/simple-nft/Cargo.toml | 2 +- pallets/symmetric-key/Cargo.toml | 2 +- pallets/transaction-payment-free/Cargo.toml | 2 +- runtime/Cargo.toml | 4 +- runtime/src/lib.rs | 7 +- 11 files changed, 187 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ff3d08c..9e1f1d7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1585,7 +1585,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "dscp-node" -version = "5.0.1" +version = "5.0.2" dependencies = [ "bs58", "clap", @@ -1629,7 +1629,7 @@ dependencies = [ [[package]] name = "dscp-node-runtime" -version = "5.0.0" +version = "5.0.1" dependencies = [ "frame-benchmarking", "frame-executive", @@ -4669,7 +4669,7 @@ dependencies = [ [[package]] name = "pallet-process-validation" -version = "3.4.0" +version = "3.4.1" dependencies = [ "dscp-pallet-traits", "frame-benchmarking", @@ -7086,22 +7086,22 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.157" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca" +checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.157" +version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5" +checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.4", ] [[package]] @@ -8179,9 +8179,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59d3276aee1fa0c33612917969b5172b5be2db051232a6e4826f1a1a9191b045" +checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" dependencies = [ "proc-macro2", "quote", diff --git a/node/Cargo.toml b/node/Cargo.toml index 8887d200..f741c4e3 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -6,7 +6,7 @@ edition = '2021' license = 'Apache-2.0' repository = 'https://github.com/digicatapult/dscp-node/' name = 'dscp-node' -version = '5.0.1' +version = '5.0.2' [[bin]] name = 'dscp-node' diff --git a/pallets/doas/Cargo.toml b/pallets/doas/Cargo.toml index 3afb2644..ea2a5105 100644 --- a/pallets/doas/Cargo.toml +++ b/pallets/doas/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.157", optional = true } +serde = { version = "1.0.158", optional = true } scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] } frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } diff --git a/pallets/process-validation/Cargo.toml b/pallets/process-validation/Cargo.toml index 7ffa8df5..36c28377 100644 --- a/pallets/process-validation/Cargo.toml +++ b/pallets/process-validation/Cargo.toml @@ -5,14 +5,14 @@ edition = '2021' license = 'Apache-2.0' repository = 'https://github.com/digicatapult/dscp-node/' name = 'pallet-process-validation' -version = "3.4.0" +version = "3.4.1" [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] [dependencies] -serde = { version = "1.0.157", optional = true } +serde = { version = "1.0.158", optional = true } scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] } dscp-pallet-traits = { default-features = false, path = '../traits' } diff --git a/pallets/process-validation/src/lib.rs b/pallets/process-validation/src/lib.rs index e32ca8bd..86ce0ef7 100644 --- a/pallets/process-validation/src/lib.rs +++ b/pallets/process-validation/src/lib.rs @@ -417,7 +417,7 @@ impl ProcessValidator { - if let (Some(a), Some(b)) = (stack.pop(), stack.pop()) { + if let (Some(b), Some(a)) = (stack.pop(), stack.pop()) { stack.push(op.eval(a, b)); } else { return ValidationResult { diff --git a/pallets/process-validation/src/tests/validate_process.rs b/pallets/process-validation/src/tests/validate_process.rs index 39cd7ca1..879fce6a 100644 --- a/pallets/process-validation/src/tests/validate_process.rs +++ b/pallets/process-validation/src/tests/validate_process.rs @@ -223,7 +223,7 @@ fn it_fails_when_one_restrictions_fails() { } #[test] -fn it_succeeds_wth_complex_tree() { +fn it_succeeds_with_complex_tree() { new_test_ext().execute_with(|| { ProcessModel::::insert( ProcessIdentifier::A, @@ -268,7 +268,7 @@ fn it_succeeds_wth_complex_tree() { } #[test] -fn it_fails_wth_complex_tree() { +fn it_fails_with_complex_tree() { new_test_ext().execute_with(|| { ProcessModel::::insert( ProcessIdentifier::A, @@ -311,3 +311,163 @@ fn it_fails_wth_complex_tree() { ); }); } + +#[test] +fn it_succeeds_with_handed_expressions_r() { + new_test_ext().execute_with(|| { + ProcessModel::::insert( + ProcessIdentifier::A, + 1u32, + Process { + status: ProcessStatus::Enabled, + program: bounded_vec![ + BooleanExpressionSymbol::Restriction(Restriction::None), + BooleanExpressionSymbol::Restriction(Restriction::Fail), + BooleanExpressionSymbol::Op(BooleanOperator::NotR), + ] + } + ); + + let result = ProcessValidation::validate_process( + ProcessFullyQualifiedId { + id: ProcessIdentifier::A, + version: 1u32 + }, + &1u64, + &vec![ProcessIO { + id: 1u128, + roles: BTreeMap::new(), + metadata: BTreeMap::new() + }], + &bounded_vec![] + ); + + assert_eq!( + result, + ValidationResult:: { + success: true, + executed_len: 3u32 + } + ); + }); +} + +#[test] +fn it_succeeds_with_handed_expressions_l() { + new_test_ext().execute_with(|| { + ProcessModel::::insert( + ProcessIdentifier::A, + 1u32, + Process { + status: ProcessStatus::Enabled, + program: bounded_vec![ + BooleanExpressionSymbol::Restriction(Restriction::Fail), + BooleanExpressionSymbol::Restriction(Restriction::None), + BooleanExpressionSymbol::Op(BooleanOperator::NotL), + ] + } + ); + + let result = ProcessValidation::validate_process( + ProcessFullyQualifiedId { + id: ProcessIdentifier::A, + version: 1u32 + }, + &1u64, + &vec![ProcessIO { + id: 1u128, + roles: BTreeMap::new(), + metadata: BTreeMap::new() + }], + &bounded_vec![] + ); + + assert_eq!( + result, + ValidationResult:: { + success: true, + executed_len: 3u32 + } + ); + }); +} + +#[test] +fn it_fails_with_handed_expressions_r() { + new_test_ext().execute_with(|| { + ProcessModel::::insert( + ProcessIdentifier::A, + 1u32, + Process { + status: ProcessStatus::Enabled, + program: bounded_vec![ + BooleanExpressionSymbol::Restriction(Restriction::Fail), + BooleanExpressionSymbol::Restriction(Restriction::None), + BooleanExpressionSymbol::Op(BooleanOperator::NotR), + ] + } + ); + + let result = ProcessValidation::validate_process( + ProcessFullyQualifiedId { + id: ProcessIdentifier::A, + version: 1u32 + }, + &1u64, + &vec![ProcessIO { + id: 1u128, + roles: BTreeMap::new(), + metadata: BTreeMap::new() + }], + &bounded_vec![] + ); + + assert_eq!( + result, + ValidationResult:: { + success: false, + executed_len: 3u32 + } + ); + }); +} + +#[test] +fn it_fails_with_handed_expressions_l() { + new_test_ext().execute_with(|| { + ProcessModel::::insert( + ProcessIdentifier::A, + 1u32, + Process { + status: ProcessStatus::Enabled, + program: bounded_vec![ + BooleanExpressionSymbol::Restriction(Restriction::None), + BooleanExpressionSymbol::Restriction(Restriction::Fail), + BooleanExpressionSymbol::Op(BooleanOperator::NotL), + ] + } + ); + + let result = ProcessValidation::validate_process( + ProcessFullyQualifiedId { + id: ProcessIdentifier::A, + version: 1u32 + }, + &1u64, + &vec![ProcessIO { + id: 1u128, + roles: BTreeMap::new(), + metadata: BTreeMap::new() + }], + &bounded_vec![] + ); + + assert_eq!( + result, + ValidationResult:: { + success: false, + executed_len: 3u32 + } + ); + }); +} diff --git a/pallets/simple-nft/Cargo.toml b/pallets/simple-nft/Cargo.toml index 60df317f..37ad63fa 100644 --- a/pallets/simple-nft/Cargo.toml +++ b/pallets/simple-nft/Cargo.toml @@ -24,7 +24,7 @@ sp-std = { default-features = false, version = "5.0.0", git = "https://github.co [dev-dependencies] -serde = { version = "1.0.157" } +serde = { version = "1.0.158" } sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } diff --git a/pallets/symmetric-key/Cargo.toml b/pallets/symmetric-key/Cargo.toml index 1af25a3e..7d296a47 100644 --- a/pallets/symmetric-key/Cargo.toml +++ b/pallets/symmetric-key/Cargo.toml @@ -21,7 +21,7 @@ sp-io = { default-features = false, version = "7.0.0", git = "https://github.com sp-std = { default-features = false, version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } [dev-dependencies] -serde = { version = "1.0.157" } +serde = { version = "1.0.158" } frame-support-test = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } pallet-scheduler = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } sp-core = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } diff --git a/pallets/transaction-payment-free/Cargo.toml b/pallets/transaction-payment-free/Cargo.toml index 3b81c87c..1821b622 100644 --- a/pallets/transaction-payment-free/Cargo.toml +++ b/pallets/transaction-payment-free/Cargo.toml @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] } -serde = { version = "1.0.157", optional = true } +serde = { version = "1.0.158", optional = true } sp-std = { default-features = false, version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } sp-runtime = { default-features = false, version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index f4c96b77..7bef26a7 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dscp-node-runtime" -version = "5.0.0" +version = "5.0.1" authors = ["Digital Catapult "] edition = "2021" license = "Apache-2.0" @@ -65,7 +65,7 @@ pallet-process-validation = { default-features = false, package = 'pallet-proces pallet-symmetric-key = { default-features = false, package = 'pallet-symmetric-key', path = '../pallets/symmetric-key' } pallet-transaction-payment-free = { default-features = false, package = 'pallet-transaction-payment-free', path = '../pallets/transaction-payment-free' } -serde = { version = "1.0.157" } +serde = { version = "1.0.158" } [build-dependencies] substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 73926244..86d3199e 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -101,7 +101,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("dscp"), impl_name: create_runtime_str!("dscp"), authoring_version: 1, - spec_version: 454, + spec_version: 501, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -327,7 +327,10 @@ pub enum Role { Laboratory = 3, Buyer = 4, Supplier = 5, - Reviewer = 6 + Reviewer = 6, + Optimiser = 7, + MemberA = 8, + MemberB = 9 } impl Default for Role {