diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 4c36dd4..a7f43cb 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -17,6 +17,7 @@ on: - ".github/workflows/shared-build-wasm.yml" - ".github/actions/**" - "**.rs" + - "*.move" - "**.toml" - "**.lock" - "bindings/**" diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 3bdcfd9..962e2a1 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -16,6 +16,7 @@ on: - "**.ts" - "**.js" - "**.json" + - "**.move" concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/hierarchies-move/sources/accreditation.move b/hierarchies-move/sources/accreditation.move index d3570ed..fd7d3d8 100644 --- a/hierarchies-move/sources/accreditation.move +++ b/hierarchies-move/sources/accreditation.move @@ -68,6 +68,8 @@ public(package) fun is_property_allowed( let accreditation = &self.accreditations[idx_properties_to_attest]; let maybe_property = accreditation.properties.try_get(property_name); + idx_properties_to_attest = idx_properties_to_attest + 1; + if (maybe_property.is_none()) { continue }; @@ -78,7 +80,6 @@ public(package) fun is_property_allowed( ) { return true }; - idx_properties_to_attest = idx_properties_to_attest + 1; }; return false } diff --git a/hierarchies-move/tests/hierarchies_tests.move b/hierarchies-move/tests/hierarchies_tests.move index d799555..767b2db 100644 --- a/hierarchies-move/tests/hierarchies_tests.move +++ b/hierarchies-move/tests/hierarchies_tests.move @@ -15,7 +15,8 @@ use hierarchies::{ add_root_authority, revoke_root_authority, is_root_authority, - revoke_property + revoke_property, + validate_property }, property, property_name::new_property_name, @@ -1296,3 +1297,74 @@ fun test_validate_properties_fails_for_revoked_property() { clock.destroy_for_testing(); let _ = scenario.end(); } + +#[test] +fun test_validate_property_returns_false_when_attester_has_different_property() { + let alice = @0x1; + let mut scenario = test_scenario::begin(alice); + let mut clock = clock::create_for_testing(scenario.ctx()); + clock.set_for_testing(1000); + + // Create a new federation + new_federation(scenario.ctx()); + scenario.next_tx(alice); + + let mut fed: Federation = scenario.take_shared(); + let root_cap: RootAuthorityCap = scenario.take_from_address(alice); + let accredit_cap: AccreditCap = scenario.take_from_address(alice); + + // Step 1: Add two properties to the federation: "role" and "foo" + let property_name_role = new_property_name(utf8(b"role")); + let property_value_example = new_property_value_number(1); + let mut allowed_values_role = vec_set::empty(); + allowed_values_role.insert(property_value_example); + + let property_name_foo = new_property_name(utf8(b"foo")); + let property_value_bar = new_property_value_number(2); + let mut allowed_values_foo = vec_set::empty(); + allowed_values_foo.insert(property_value_bar); + + let property_role = property::new_property( + property_name_role, + allowed_values_role, + false, + option::none(), + ); + let property_foo = property::new_property( + property_name_foo, + allowed_values_foo, + false, + option::none(), + ); + + fed.add_property(&root_cap, property_role, scenario.ctx()); + fed.add_property(&root_cap, property_foo, scenario.ctx()); + scenario.next_tx(alice); + + let bob_id = @0x2.to_id(); + let property_for_bob = property::new_property( + property_name_foo, + allowed_values_foo, + false, + option::none(), + ); + + fed.create_accreditation_to_attest( + &accredit_cap, + bob_id, + vector[property_for_bob], + &clock, + scenario.ctx(), + ); + + assert!(fed.validate_property(&bob_id, property_name_foo, property_value_bar, &clock), 0); + + assert!(!fed.validate_property(&bob_id, property_name_role, property_value_example, &clock), 1); + + // Cleanup + test_scenario::return_shared(fed); + test_scenario::return_to_address(alice, root_cap); + test_scenario::return_to_address(alice, accredit_cap); + clock.destroy_for_testing(); + let _ = scenario.end(); +} diff --git a/hierarchies-rs/hierarchies/src/core/operations.rs b/hierarchies-rs/hierarchies/src/core/operations.rs index 9b7d207..8fd0ad7 100644 --- a/hierarchies-rs/hierarchies/src/core/operations.rs +++ b/hierarchies-rs/hierarchies/src/core/operations.rs @@ -266,9 +266,7 @@ pub(crate) trait HierarchiesOperations { let fed_ref = HierarchiesImpl::get_fed_ref(client, federation_id).await?; let fed_ref = ptb.obj(fed_ref)?; - println!("✅ REACHED HERE 001"); let property = new_property(client.package_id(), &mut ptb, property)?; - println!("✅ REACHED HERE 002"); ptb.programmable_move_call( client.package_id(),