From faa3219d22deac1ec398df95d4f3b9e4ccb58a09 Mon Sep 17 00:00:00 2001 From: Aleksandr Petrosyan Date: Fri, 15 Apr 2022 15:42:09 +0400 Subject: [PATCH] [fix] #2081: Fix role registration. Signed-off-by: Aleksandr Petrosyan --- client/tests/integration/roles.rs | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/client/tests/integration/roles.rs b/client/tests/integration/roles.rs index 8fbd54d9a3c..8089a3b1bbc 100644 --- a/client/tests/integration/roles.rs +++ b/client/tests/integration/roles.rs @@ -6,7 +6,10 @@ use eyre::{eyre, Result}; use iroha_client::client::{self, Client}; use iroha_core::{prelude::AllowAll, smartcontracts::permissions::ValidatorBuilder}; use iroha_data_model::{permissions::Permissions, prelude::*}; -use iroha_permissions_validators::public_blockchain::transfer; +use iroha_permissions_validators::public_blockchain::{ + key_value::{CAN_REMOVE_KEY_VALUE_IN_USER_METADATA, CAN_SET_KEY_VALUE_IN_USER_METADATA}, + transfer, +}; use test_network::{Peer as TestPeer, *}; use tokio::runtime::Runtime; @@ -126,3 +129,30 @@ fn register_role_with_empty_token_params() -> Result<()> { // TODO: When we have more sane default permissions, see if we can // test more about whether or not roles actually work. + +#[test] +fn register_and_grant_metadata_role_to_account() -> Result<()> { + let (_rt, _peer, mut test_client) = ::start_test_with_runtime(); + wait_for_genesis_committed(&vec![test_client.clone()], 0); + + let bob_id = ::Id::from_str("bob@wonderland")?; + let register_bob = RegisterBox::new(Account::new(bob_id.clone(), [])); + test_client.submit_blocking(register_bob)?; + + let role_id = iroha_data_model::role::Id::new("USER_METADATA_ACCESS".parse::()?); + let mut permissions = Permissions::new(); + let mut params = BTreeMap::new(); + params.insert(Name::from_str("account_id")?, bob_id.clone().into()); + permissions.insert(PermissionToken { + name: CAN_SET_KEY_VALUE_IN_USER_METADATA.clone(), + params: params.clone(), + }); + permissions.insert(PermissionToken { + name: CAN_REMOVE_KEY_VALUE_IN_USER_METADATA.clone(), + params, + }); + let register_role = RegisterBox::new(Role::new(role_id, permissions)); + + test_client.submit(register_role)?; + Ok(()) +}