Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Add checks for role presence before granting it #5300

Merged
merged 9 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/iroha/tests/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,16 @@ fn grant_revoke_role_permissions() -> Result<()> {

Ok(())
}

#[test]
#[should_panic(expected = "a peer exited unexpectedly")]
fn grant_unexisting_role_in_genesis_fail() {
// Grant Alice UNEXISTING role
let alice_id = ALICE_ID.clone();
let role_id = "UNEXISTING".parse::<RoleId>().unwrap();
let grant_genesis_role = Grant::account_role(role_id, alice_id);

let _result = NetworkBuilder::new()
.with_genesis_instruction(grant_genesis_role)
.start_blocking();
}
2 changes: 1 addition & 1 deletion crates/iroha/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fn upgrade_executor(client: &Client, executor: impl AsRef<str>) -> Result<()> {
if !profile.is_optimized() {
client.submit_all_blocking::<InstructionBox>([InstructionBox::SetParameter(
SetParameter::new(Parameter::Executor(SmartContractParameter::Fuel(
std::num::NonZeroU64::new(80_000_000_u64).expect("Fuel must be positive."),
std::num::NonZeroU64::new(90_000_000_u64).expect("Fuel must be positive."),
))),
)])?;
}
Expand Down
1 change: 1 addition & 0 deletions crates/iroha_core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub mod isi {
let account_id = self.destination;
let role_id = self.object;

state_transaction.world.role(&role_id)?;
state_transaction.world.account(&account_id)?;

if state_transaction
Expand Down
12 changes: 12 additions & 0 deletions crates/iroha_core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,18 @@ pub trait WorldReadOnly {
fn asset_total_amount(&self, definition_id: &AssetDefinitionId) -> Result<Numeric, FindError> {
Ok(self.asset_definition(definition_id)?.total_quantity)
}

// Role-related methods

/// Get `Role` and return reference to it.
///
/// # Errors
/// Fails if there is no role
fn role(&self, id: &RoleId) -> Result<&Role, FindError> {
self.roles()
.get(id)
.ok_or_else(|| FindError::Role(id.clone()))
}
}

macro_rules! impl_world_ro {
Expand Down
Loading