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 24, 2022
1 parent 31e5270 commit e73bf08
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 280 deletions.
40 changes: 16 additions & 24 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ members = [
"core",
"core/test_network",
"crypto",
"tools/crypto_cli",
"tools/kura_inspector",
"tools/parity_scale_decoder",
"tools/generator",
"tools/kagami",
"data_model",
"data_model/primitives",
"futures",
Expand Down
32 changes: 30 additions & 2 deletions client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#![allow(clippy::restriction)]

use std::{str::FromStr as _, time::Duration};
use std::{collections::BTreeMap, str::FromStr as _, time::Duration};

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 @@ -122,3 +125,28 @@ 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::new(CAN_SET_KEY_VALUE_IN_USER_METADATA.clone())
.with_params(params.clone()),
);
permissions.insert(
PermissionToken::new(CAN_REMOVE_KEY_VALUE_IN_USER_METADATA.clone()).with_params(params),
);
let register_role = RegisterBox::new(Role::new(role_id, permissions));
test_client.submit(register_role)?;
Ok(())
}
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 @@ -414,7 +414,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 @@ -521,7 +521,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 @@ -537,7 +537,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 @@ -548,7 +548,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
8 changes: 5 additions & 3 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@ impl<'wrld, W: WorldTrait> Runtime<'wrld, W> {
Ok(())
}

/// Host defined function which prints given string. When calling this function, module
/// serializes ISI to linear memory and provides offset and length as parameters
/// Host defined function which prints given string. When calling
/// this function, module serializes ISI to linear memory and
/// provides offset and length as parameters
///
/// # Warning
///
/// This function doesn't take ownership of the provided allocation
/// This function doesn't take ownership of the provided
/// allocation
///
/// # Errors
///
Expand Down
12 changes: 8 additions & 4 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ use ursa::{
},
};

// Hiding constants is a bad idea. For one, you're forcing the user to
// create temporaries, but also you're not actually hiding any
// information that can be used in malicious ways. If you want to hide
// these, I'd prefer inlining them instead.
/// ed25519
const ED_25519: &str = "ed25519";
pub const ED_25519: &str = "ed25519";
/// secp256k1
const SECP_256_K1: &str = "secp256k1";
pub const SECP_256_K1: &str = "secp256k1";
/// bls normal
const BLS_NORMAL: &str = "bls_normal";
pub const BLS_NORMAL: &str = "bls_normal";
/// bls small
const BLS_SMALL: &str = "bls_small";
pub const BLS_SMALL: &str = "bls_small";

/// Error indicating algorithm could not be found
#[derive(Debug, Clone, Copy, Display, IntoSchema)]
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
5 changes: 3 additions & 2 deletions hooks/pre-commit.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -e
cargo run --bin iroha_gen -- --docs >docs/source/references/config.md
git add docs/source/references/config.md
cargo run --bin kagami -- --docs >docs/source/references/config.md
cargo run --bin kagami -- --genesis >configs/peer/genesis.json
git add docs/source/references/config.md configs/peer/genesis.json
4 changes: 2 additions & 2 deletions scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ TMPFILE=$(mktemp)

case $1 in
"docs")
cargo run --bin iroha_gen -- --docs >"$TMPFILE"
cargo run --bin kagami -- --docs >"$TMPFILE"
diff "$TMPFILE" docs/source/references/config.md || {
echo 'Please re-generate docs with git hook in ./hooks directory'
exit 1
};;
"genesis")
cargo run --bin iroha_gen -- --genesis >"$TMPFILE"
cargo run --bin kagami -- --genesis >"$TMPFILE"
diff "$TMPFILE" configs/peer/genesis.json || {
echo 'Please re-generate the genesis with `cargo run --bin iroha_gen -- --genesis`'
exit 1
Expand Down
15 changes: 0 additions & 15 deletions tools/crypto_cli/Cargo.toml

This file was deleted.

45 changes: 0 additions & 45 deletions tools/crypto_cli/README.md

This file was deleted.

Loading

0 comments on commit e73bf08

Please sign in to comment.