Skip to content

Commit

Permalink
Fix restriction handedness (#124)
Browse files Browse the repository at this point in the history
* Fix restriction handedness

Also adds in additional roles for l3

* Upgrade serdes
  • Loading branch information
mattdean-digicatapult authored Mar 21, 2023
1 parent 90ad26c commit 5241827
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 24 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion pallets/doas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions pallets/process-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
2 changes: 1 addition & 1 deletion pallets/process-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl<T: Config> ProcessValidator<T::TokenId, T::AccountId, T::RoleKey, T::TokenM
executed_len = executed_len + 1;
match symbol {
BooleanExpressionSymbol::Op(op) => {
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 {
Expand Down
164 changes: 162 additions & 2 deletions pallets/process-validation/src/tests/validate_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::insert(
ProcessIdentifier::A,
Expand Down Expand Up @@ -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::<Test>::insert(
ProcessIdentifier::A,
Expand Down Expand Up @@ -311,3 +311,163 @@ fn it_fails_wth_complex_tree() {
);
});
}

#[test]
fn it_succeeds_with_handed_expressions_r() {
new_test_ext().execute_with(|| {
ProcessModel::<Test>::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::<u32> {
success: true,
executed_len: 3u32
}
);
});
}

#[test]
fn it_succeeds_with_handed_expressions_l() {
new_test_ext().execute_with(|| {
ProcessModel::<Test>::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::<u32> {
success: true,
executed_len: 3u32
}
);
});
}

#[test]
fn it_fails_with_handed_expressions_r() {
new_test_ext().execute_with(|| {
ProcessModel::<Test>::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::<u32> {
success: false,
executed_len: 3u32
}
);
});
}

#[test]
fn it_fails_with_handed_expressions_l() {
new_test_ext().execute_with(|| {
ProcessModel::<Test>::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::<u32> {
success: false,
executed_len: 3u32
}
);
});
}
2 changes: 1 addition & 1 deletion pallets/simple-nft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }


Expand Down
2 changes: 1 addition & 1 deletion pallets/symmetric-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion pallets/transaction-payment-free/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dscp-node-runtime"
version = "5.0.0"
version = "5.0.1"
authors = ["Digital Catapult <https://www.digicatapult.org.uk>"]
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -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" }
Expand Down
7 changes: 5 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5241827

Please sign in to comment.