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 16, 2022
1 parent d7bed07 commit c5404d6
Show file tree
Hide file tree
Showing 19 changed files with 253 additions and 198 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

32 changes: 31 additions & 1 deletion client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) = <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.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(())
}
2 changes: 1 addition & 1 deletion config/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod attrs {
pub const INNER: &str = "inner";
}

fn get_type_argument<'a, 'b>(s: &'a str, ty: &'b Type) -> Option<&'b GenericArgument> {
fn get_type_argument<'st, 'ty>(s: &'st str, ty: &'ty Type) -> Option<&'ty GenericArgument> {
let path = if let Type::Path(r#type) = ty {
r#type
} else {
Expand Down
8 changes: 4 additions & 4 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ pub trait Configurable: Serialize + DeserializeOwned {
/// Gets inner field of arbitrary inner depth and returns as json-value
/// # Errors
/// Fails if field was unknown
fn get_recursive<'a, T>(&self, inner_field: T) -> Result<Value, Self::Error>
fn get_recursive<'fld, T>(&self, inner_field: T) -> Result<Value, Self::Error>
where
T: AsRef<[&'a str]> + Send + 'a;
T: AsRef<[&'fld str]> + Send + 'fld;

/// Fails if fails to deserialize from environment
/// # Errors
Expand All @@ -184,8 +184,8 @@ pub trait Configurable: Serialize + DeserializeOwned {
/// Gets docs of inner field of arbitrary depth
/// # Errors
/// Fails if field was unknown
fn get_doc_recursive<'a>(
field: impl AsRef<[&'a str]>,
fn get_doc_recursive<'fld>(
field: impl AsRef<[&'fld str]>,
) -> Result<Option<&'static str>, Self::Error>;

/// Gets docs of field
Expand Down
2 changes: 1 addition & 1 deletion config/src/runtime_upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum ReloadError {
Other,
}

type PoisonErr<'a, T> = PoisonError<MutexGuard<'a, Option<Box<(dyn ReloadMut<T> + Send + Sync)>>>>;
type PoisonErr<'mutex, T> = PoisonError<MutexGuard<'mutex, Option<Box<(dyn ReloadMut<T> + Send + Sync)>>>>;

impl<T> From<PoisonErr<'_, T>> for ReloadError {
fn from(_: PoisonErr<'_, T>) -> Self {
Expand Down
14 changes: 7 additions & 7 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ impl Chain {
}

/// Chain iterator
pub struct ChainIterator<'a> {
chain: &'a Chain,
pub struct ChainIterator<'ch> {
chain: &'ch Chain,
pos_front: u64,
pos_back: u64,
}

impl<'a> ChainIterator<'a> {
fn new(chain: &'a Chain) -> Self {
impl<'ch> ChainIterator<'ch> {
fn new(chain: &'ch Chain) -> Self {
ChainIterator {
chain,
pos_front: 1,
Expand All @@ -118,8 +118,8 @@ impl<'a> ChainIterator<'a> {
}
}

impl<'a> Iterator for ChainIterator<'a> {
type Item = MapRef<'a, u64, VersionedCommittedBlock>;
impl<'ch> Iterator for ChainIterator<'ch> {
type Item = MapRef<'ch, u64, VersionedCommittedBlock>;
fn next(&mut self) -> Option<Self::Item> {
if !self.is_exhausted() {
let val = self.chain.blocks.get(&self.pos_front);
Expand Down Expand Up @@ -152,7 +152,7 @@ impl<'a> Iterator for ChainIterator<'a> {
}
}

impl<'a> DoubleEndedIterator for ChainIterator<'a> {
impl<'de> DoubleEndedIterator for ChainIterator<'de> {
fn next_back(&mut self) -> Option<Self::Item> {
if !self.is_exhausted() {
let val = self.chain.blocks.get(&self.pos_back);
Expand Down
10 changes: 5 additions & 5 deletions core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{collections::HashSet, fmt::Debug, fs::File, io::BufReader, ops::Deref,
use eyre::{eyre, Result, WrapErr};
use iroha_actor::Addr;
use iroha_crypto::{KeyPair, PublicKey};
use iroha_data_model::{asset::AssetDefinition, domain::NewDomain, prelude::*};
use iroha_data_model::{asset::AssetDefinition, prelude::*};
use iroha_schema::prelude::*;
use serde::{Deserialize, Serialize};
use small::SmallVec;
Expand Down Expand Up @@ -398,7 +398,7 @@ impl RawGenesisBlockBuilder {
/// be used to create assets and accounts.
pub fn domain(mut self, domain_name: Name) -> RawGenesisDomainBuilder {
let domain_id = DomainId::new(domain_name);
let new_domain = NewDomain::new(domain_id.clone());
let new_domain = Domain::new(domain_id.clone());
self.transaction
.isi
.push(Instruction::from(RegisterBox::new(new_domain)));
Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
let domain_id: DomainId = "wonderland".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[0],
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
Instruction::from(RegisterBox::new(Domain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[1],
Expand All @@ -521,7 +521,7 @@ mod tests {
let domain_id: DomainId = "tulgey_wood".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[3],
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
Instruction::from(RegisterBox::new(Domain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[4],
Expand All @@ -532,7 +532,7 @@ mod tests {
let domain_id: DomainId = "meadow".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[5],
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
Instruction::from(RegisterBox::new(Domain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[6],
Expand Down
22 changes: 11 additions & 11 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl From<ParseError> for Error {
}
}

struct Validator<'a, W: WorldTrait> {
struct Validator<'va, W: WorldTrait> {
/// Number of instructions in the smartcontract
instruction_count: u64,
/// Max allowed number of instructions in the smartcontract
Expand All @@ -78,7 +78,7 @@ struct Validator<'a, W: WorldTrait> {
/// If this particular query is allowed
is_query_allowed: Arc<IsQueryAllowedBoxed<W>>,
/// Current [`WorldStateview`]
wsv: &'a WorldStateView<W>,
wsv: &'va WorldStateView<W>,
}

impl<W: WorldTrait> Validator<'_, W> {
Expand Down Expand Up @@ -125,16 +125,16 @@ impl<W: WorldTrait> Validator<'_, W> {
}
}

struct State<'a, W: WorldTrait> {
struct State<'wrld, W: WorldTrait> {
account_id: AccountId,
/// Ensures smartcontract adheres to limits
validator: Option<Validator<'a, W>>,
validator: Option<Validator<'wrld, W>>,
store_limits: StoreLimits,
wsv: &'a WorldStateView<W>,
wsv: &'wrld WorldStateView<W>,
}

impl<'a, W: WorldTrait> State<'a, W> {
fn new(wsv: &'a WorldStateView<W>, account_id: AccountId, config: Configuration) -> Self {
impl<'wrld, W: WorldTrait> State<'wrld, W> {
fn new(wsv: &'wrld WorldStateView<W>, account_id: AccountId, config: Configuration) -> Self {
Self {
wsv,
account_id,
Expand Down Expand Up @@ -171,13 +171,13 @@ impl<'a, W: WorldTrait> State<'a, W> {
}

/// `WebAssembly` virtual machine
pub struct Runtime<'a, W: WorldTrait> {
pub struct Runtime<'wrld, W: WorldTrait> {
engine: Engine,
linker: Linker<State<'a, W>>,
linker: Linker<State<'wrld, W>>,
config: Configuration,
}

impl<'a, W: WorldTrait> Runtime<'a, W> {
impl<'wrld, W: WorldTrait> Runtime<'wrld, W> {
/// `Runtime` constructor with default configuration.
///
/// # Errors
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'a, W: WorldTrait> Runtime<'a, W> {
Ok(())
}

fn create_linker(engine: &Engine) -> Result<Linker<State<'a, W>>, Error> {
fn create_linker(engine: &Engine) -> Result<Linker<State<'wrld, W>>, Error> {
let mut linker = Linker::new(engine);

linker
Expand Down
4 changes: 2 additions & 2 deletions core/src/sumeragi/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ impl VersionedMessage {
/// Send this message over the network to multiple `peers`.
/// # Errors
/// Fails if network sending fails
pub async fn send_to_multiple<'a, I>(self, broker: &Broker, peers: I)
pub async fn send_to_multiple<'itm, I>(self, broker: &Broker, peers: I)
where
I: IntoIterator<Item = &'a PeerId> + Send,
I: IntoIterator<Item = &'itm PeerId> + Send,
{
let futures = peers
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ impl Topology {
}

/// Returns signatures of the peers with the specified `roles` from all `signatures`.
pub fn filter_signatures_by_roles<'a>(
&'a self,
roles: &'a [Role],
signatures: impl IntoIterator<Item = &'a SignatureOf<VersionedValidBlock>> + 'a,
pub fn filter_signatures_by_roles<'slf>(
&'slf self,
roles: &'slf [Role],
signatures: impl IntoIterator<Item = &'slf SignatureOf<VersionedValidBlock>> + 'slf,
) -> Vec<SignatureOf<VersionedValidBlock>> {
let roles: HashSet<Role> = roles.iter().copied().collect();
let public_keys: HashSet<_> = roles
Expand Down Expand Up @@ -481,8 +481,8 @@ mod tests {
fn correct_number_of_peers_genesis() {
let peers = topology_test_peers();
// set_a.len() = 2, is wrong as it is not possible to get integer f in: 2f + 1 = 2
let set_a: HashSet<_> = topology_test_peers().iter().cloned().take(3).collect();
let set_b: HashSet<_> = topology_test_peers().iter().cloned().skip(3).collect();
let set_a: HashSet<_> = topology_test_peers().iter().take(3).cloned().collect();
let set_b: HashSet<_> = topology_test_peers().iter().skip(3).cloned().collect();
let _network_topology = GenesisBuilder::new()
.with_leader(peers.iter().next().unwrap().clone())
.with_set_a(set_a)
Expand Down
4 changes: 2 additions & 2 deletions core/src/triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl TriggerSet {
///
/// Users should not try to modify [`TriggerSet`] before dropping actions,
/// returned by the current function
pub fn find_matching<'e, E>(&self, events: E) -> Vec<Action>
pub fn find_matching<'evnt, E>(&self, events: E) -> Vec<Action>
where
E: IntoIterator<Item = &'e Event>,
E: IntoIterator<Item = &'evnt Event>,
{
let mut result = Vec::new();

Expand Down
8 changes: 4 additions & 4 deletions crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ impl<T> IntoIterator for SignaturesOf<T> {
}
}

impl<'a, T> IntoIterator for &'a SignaturesOf<T> {
type Item = &'a SignatureOf<T>;
type IntoIter = btree_map::Values<'a, PublicKey, SignatureOf<T>>;
impl<'sig, T> IntoIterator for &'sig SignaturesOf<T> {
type Item = &'sig SignatureOf<T>;
type IntoIter = btree_map::Values<'sig, PublicKey, SignatureOf<T>>;
fn into_iter(self) -> Self::IntoIter {
self.signatures.values()
}
Expand Down Expand Up @@ -363,7 +363,7 @@ impl<T> SignaturesOf<T> {
/// # Warning:
///
/// This method uses [`core::mem::transmute`] internally
#[allow(unsafe_code)]
#[allow(unsafe_code, clippy::transmute_undefined_repr)]
pub fn transmute<F>(self) -> SignaturesOf<F> {
// SAFETY: Safe because we are transmuting to a pointer of
// type `<F>` which is related to type `<T>`.
Expand Down
4 changes: 2 additions & 2 deletions data_model/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct NewDomain {
/// The (IPFS) link to the logo of this domain.
logo: Option<IpfsPath>,
/// metadata associated to the domain builder.
pub metadata: Metadata,
metadata: Metadata,
}

impl PartialOrd for NewDomain {
Expand All @@ -94,7 +94,7 @@ impl Ord for NewDomain {
impl NewDomain {
/// Create a [`NewDomain`], reserved for internal use.
#[must_use]
pub fn new(id: <Domain as Identifiable>::Id) -> Self {
fn new(id: <Domain as Identifiable>::Id) -> Self {
Self {
id,
logo: None,
Expand Down
18 changes: 9 additions & 9 deletions data_model/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub enum Node<T> {

#[derive(Debug)]
/// BFS iterator over the Merkle tree
pub struct BreadthFirstIter<'a, T> {
queue: Vec<&'a Node<T>>,
pub struct BreadthFirstIter<'itm, T> {
queue: Vec<&'itm Node<T>>,
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -184,8 +184,8 @@ impl<T> Node<T> {
}
}

impl<'a, T> BreadthFirstIter<'a, T> {
fn new(root_node: &'a Node<T>) -> Self {
impl<'itm, T> BreadthFirstIter<'itm, T> {
fn new(root_node: &'itm Node<T>) -> Self {
BreadthFirstIter {
queue: vec![root_node],
}
Expand All @@ -196,8 +196,8 @@ impl<'a, T> BreadthFirstIter<'a, T> {
/// `'a` lifetime specified for `Node`. Because `Node` is recursive data structure with self
/// composition in case of `Node::Subtree` we use `Box` to know size of each `Node` object in
/// memory.
impl<'a, T> Iterator for BreadthFirstIter<'a, T> {
type Item = &'a Node<T>;
impl<'itm, T> Iterator for BreadthFirstIter<'itm, T> {
type Item = &'itm Node<T>;

fn next(&mut self) -> Option<Self::Item> {
match &self.queue.pop() {
Expand All @@ -213,9 +213,9 @@ impl<'a, T> Iterator for BreadthFirstIter<'a, T> {
}
}

impl<'a, T> IntoIterator for &'a MerkleTree<T> {
type Item = &'a Node<T>;
type IntoIter = BreadthFirstIter<'a, T>;
impl<'itm, T> IntoIterator for &'itm MerkleTree<T> {
type Item = &'itm Node<T>;
type IntoIter = BreadthFirstIter<'itm, T>;

fn into_iter(self) -> Self::IntoIter {
BreadthFirstIter::new(&self.root_node)
Expand Down
4 changes: 2 additions & 2 deletions schema/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ fn variant_index(v: &Variant, i: usize) -> TokenStream2 {
}

/// Finds specific attribute with codec ident satisfying predicate
fn find_meta_item<'a, F, R, I, M>(mut itr: I, mut pred: F) -> Option<R>
fn find_meta_item<'attr, F, R, I, M>(mut itr: I, mut pred: F) -> Option<R>
where
F: FnMut(M) -> Option<R> + Clone,
I: Iterator<Item = &'a Attribute>,
I: Iterator<Item = &'attr Attribute>,
M: Parse,
{
itr.find_map(|attr| {
Expand Down
Loading

0 comments on commit c5404d6

Please sign in to comment.