Skip to content

Commit

Permalink
[fix] #2081: Fix role registration.
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Petrosyan <a-p-petrosyan@yandex.ru>
  • Loading branch information
appetrosyan committed Apr 15, 2022
1 parent d7bed07 commit 0cca2ba
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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::{transfer, key_value::{CAN_SET_KEY_VALUE_IN_USER_METADATA, CAN_REMOVE_KEY_VALUE_IN_USER_METADATA}};
use test_network::{Peer as TestPeer, *};
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -126,3 +126,31 @@ 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) = <TestPeer>::start_test_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);


let bob_id = <Account as Identifiable>::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::<Name>()?);
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(())
}

0 comments on commit 0cca2ba

Please sign in to comment.