Skip to content

Commit

Permalink
[fix] hyperledger-iroha#3962: Add test to check if associated token i…
Browse files Browse the repository at this point in the history
…s removed

Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Jan 25, 2024
1 parent 2f4a6d6 commit c5ee988
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use iroha_client::{
crypto::KeyPair,
data_model::prelude::*,
};
use iroha_data_model::permission::PermissionToken;
use iroha_genesis::GenesisNetwork;
use serde_json::json;
use test_network::{PeerBuilder, *};
Expand Down Expand Up @@ -381,3 +382,50 @@ fn permission_tokens_are_unified() {
.submit_blocking(allow_alice_to_transfer_rose_2)
.expect_err("permission tokens are not unified");
}

#[test]
fn associated_permission_tokens_removed_on_unregister() {
let (_rt, _peer, iroha_client) = <PeerBuilder>::new().with_port(11_240).start_with_runtime();
wait_for_genesis_committed(&[iroha_client.clone()], 0);

let bob_id: AccountId = "bob@wonderland".parse().expect("Valid");
let kingdom_id: DomainId = "kingdom".parse().expect("Valid");
let kingdom = Domain::new(kingdom_id.clone());

// register kingdom and give bob permissions in this domain
let register_domain = Register::domain(kingdom);
let bob_to_set_kv_in_domain_token = PermissionToken::new(
"CanSetKeyValueInDomain".parse().unwrap(),
&json!({ "domain_id": kingdom_id }),
);
let allow_bob_to_set_kv_in_domain =
Grant::permission_token(bob_to_set_kv_in_domain_token.clone(), bob_id.clone());

iroha_client
.submit_all_blocking([
InstructionBox::from(register_domain),
allow_bob_to_set_kv_in_domain.into(),
])
.expect("failed to register domain and grant permission");

// check that bob indeed have granted permission
assert!(iroha_client
.request(client::permission::by_account_id(bob_id.clone()))
.and_then(std::iter::Iterator::collect::<QueryResult<Vec<PermissionToken>>>)
.expect("failed to get permissions for bob")
.into_iter()
.any(|token| { token == bob_to_set_kv_in_domain_token }));

// unregister kingdom
iroha_client
.submit_blocking(Unregister::domain(kingdom_id))
.expect("failed to unregister domain");

// check that permission is removed from bob
assert!(iroha_client
.request(client::permission::by_account_id(bob_id))
.and_then(std::iter::Iterator::collect::<QueryResult<Vec<PermissionToken>>>)
.expect("failed to get permissions for bob")
.into_iter()
.all(|token| { token != bob_to_set_kv_in_domain_token }));
}

0 comments on commit c5ee988

Please sign in to comment.