Skip to content

Commit

Permalink
refactor!: fix naming convention for assets and permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Jun 18, 2024
1 parent db372a1 commit c2c6282
Show file tree
Hide file tree
Showing 35 changed files with 192 additions and 267 deletions.
2 changes: 1 addition & 1 deletion client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn generate_genesis(
.account(signatory_alice.clone())
.asset(
format!("xor-{i}").parse().expect("Valid"),
AssetValueType::Numeric(NumericSpec::default()),
AssetType::Numeric(NumericSpec::default()),
)
.finish_domain();
}
Expand Down
8 changes: 4 additions & 4 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use iroha::{
client::{self, QueryResult},
crypto::KeyPair,
data_model::{
asset::{AssetId, AssetValue, AssetValueType},
asset::{AssetId, AssetType, AssetValue},
isi::error::{InstructionEvaluationError, InstructionExecutionError, Mismatch, TypeError},
prelude::*,
transaction::error::TransactionRejectionReason,
Expand Down Expand Up @@ -402,7 +402,7 @@ fn fail_if_dont_satisfy_spec() {
// Create asset definition which accepts only integers
let asset_definition = AssetDefinition::new(
asset_definition_id.clone(),
AssetValueType::Numeric(NumericSpec::integer()),
AssetType::Numeric(NumericSpec::integer()),
);

test_client
Expand Down Expand Up @@ -435,8 +435,8 @@ fn fail_if_dont_satisfy_spec() {
&TransactionRejectionReason::Validation(ValidationFail::InstructionFailed(
InstructionExecutionError::Evaluate(InstructionEvaluationError::Type(
TypeError::from(Mismatch {
expected: AssetValueType::Numeric(NumericSpec::integer()),
actual: AssetValueType::Numeric(NumericSpec::fractional(2))
expected: AssetType::Numeric(NumericSpec::integer()),
actual: AssetType::Numeric(NumericSpec::fractional(2))
})
))
))
Expand Down
8 changes: 4 additions & 4 deletions client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ fn produce_multiple_events() -> Result<()> {
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_1.id.clone(),
permission: token_1.clone(),
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_2.id.clone(),
permission: token_2.clone(),
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleGranted(
Expand All @@ -258,13 +258,13 @@ fn produce_multiple_events() -> Result<()> {
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_1.id,
permission: token_1,
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account: bob_id.clone(),
permission: token_2.id,
permission: token_2,
},
))),
DataEvent::Domain(DomainEvent::Account(AccountEvent::RoleRevoked(
Expand Down
8 changes: 4 additions & 4 deletions client/tests/integration/queries/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn find_accounts_with_asset() -> Result<()> {

assert_eq!(received_asset_definition.id(), asset_definition.id());
assert!(matches!(
received_asset_definition.value_type(),
AssetValueType::Numeric(_)
received_asset_definition.type_(),
AssetType::Numeric(_)
));

let accounts: [AccountId; 5] = [
Expand Down Expand Up @@ -61,8 +61,8 @@ fn find_accounts_with_asset() -> Result<()> {

assert_eq!(received_asset_definition.id(), asset_definition.id());
assert_eq!(
received_asset_definition.value_type(),
AssetValueType::Numeric(NumericSpec::default()),
received_asset_definition.type_(),
AssetType::Numeric(NumericSpec::default()),
);

let found_accounts = test_client
Expand Down
6 changes: 3 additions & 3 deletions client/tests/integration/queries/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn find_asset_total_quantity() -> Result<()> {
&test_client,
&accounts,
"quantity#wonderland",
AssetValueType::Numeric(NumericSpec::default()),
AssetType::Numeric(NumericSpec::default()),
numeric!(1),
numeric!(10),
numeric!(5),
Expand All @@ -56,7 +56,7 @@ fn find_asset_total_quantity() -> Result<()> {
&test_client,
&accounts,
"fixed#wonderland",
AssetValueType::Numeric(NumericSpec::default()),
AssetType::Numeric(NumericSpec::default()),
numeric!(1.0),
numeric!(10.0),
numeric!(5.0),
Expand Down Expand Up @@ -131,7 +131,7 @@ fn test_total_quantity<T>(
test_client: &Client,
accounts: &[AccountId; 5],
definition: &str,
asset_value_type: AssetValueType,
asset_value_type: AssetType,
initial_value: T,
to_mint: T,
to_burn: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ fn main(_owner: AccountId) {

Register::asset_definition(AssetDefinition::new(
time_id.clone(),
AssetValueType::Numeric(NumericSpec::default()),
AssetType::Numeric(NumericSpec::default()),
))
.execute()
.dbg_unwrap();

Register::asset_definition(AssetDefinition::new(
space_id.clone(),
AssetValueType::Numeric(NumericSpec::default()),
AssetType::Numeric(NumericSpec::default()),
))
.execute()
.dbg_unwrap();
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn executor_upgrade_should_revoke_removed_permissions() -> Result<()> {
assert!(client
.request(FindExecutorDataModel)?
.permissions()
.contains(&can_unregister_domain_token.id));
.contains(can_unregister_domain_token.name()));

// Check that `TEST_ROLE` has permission
assert!(client
Expand Down Expand Up @@ -174,7 +174,7 @@ fn executor_upgrade_should_revoke_removed_permissions() -> Result<()> {
assert!(!client
.request(FindExecutorDataModel)?
.permissions()
.contains(&can_unregister_domain_token.id));
.contains(can_unregister_domain_token.name()));

// Check that `TEST_ROLE` doesn't have permission
assert!(!client
Expand Down
2 changes: 1 addition & 1 deletion client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ mod asset {
pub unmintable: bool,
/// Value type stored in asset
#[arg(short, long)]
pub value_type: AssetValueType,
pub value_type: AssetType,
#[command(flatten)]
pub metadata: MetadataArgs,
}
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
14 changes: 7 additions & 7 deletions configs/swarm/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Register": {
"AssetDefinition": {
"id": "rose#wonderland",
"value_type": "Numeric",
"type": "Numeric",
"mintable": "Infinitely",
"logo": null,
"metadata": {}
Expand Down Expand Up @@ -69,7 +69,7 @@
"Register": {
"AssetDefinition": {
"id": "cabbage#garden_of_live_flowers",
"value_type": "Numeric",
"type": "Numeric",
"mintable": "Infinitely",
"logo": null,
"metadata": {}
Expand Down Expand Up @@ -114,7 +114,7 @@
"Grant": {
"Permission": {
"object": {
"id": "CanSetParameters",
"name": "CanSetParameters",
"payload": null
},
"destination": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
Expand Down Expand Up @@ -169,15 +169,15 @@
"id": "ALICE_METADATA_ACCESS",
"permissions": [
{
"id": "CanRemoveKeyValueInAccount",
"name": "CanRemoveKeyValueInAccount",
"payload": {
"account_id": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
"account": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
},
{
"id": "CanSetKeyValueInAccount",
"name": "CanSetKeyValueInAccount",
"payload": {
"account_id": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
"account": "ed0120CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03@wonderland"
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion core/src/query/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use std::{
use indexmap::IndexMap;
use iroha_config::parameters::actual::LiveQueryStore as Config;
use iroha_data_model::{
query::{cursor::ForwardCursor, error::QueryExecutionFail, QueryId, QueryOutputBox},
query::{
cursor::{ForwardCursor, QueryId},
error::QueryExecutionFail,
QueryOutputBox,
},
BatchedResponse, BatchedResponseV1, ValidationFail,
};
use iroha_logger::trace;
Expand Down
52 changes: 20 additions & 32 deletions core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Registrable for iroha_data_model::account::NewAccount {
/// - Revoke permissions or roles
pub mod isi {
use iroha_data_model::{
asset::{AssetValue, AssetValueType},
asset::{AssetType, AssetValue},
isi::{
error::{MintabilityError, RepetitionError},
InstructionType,
Expand Down Expand Up @@ -78,7 +78,7 @@ pub mod isi {
_ => Err(err.into()),
},
Ok(_) => Err(RepetitionError {
instruction_type: InstructionType::Register,
instruction: InstructionType::Register,
id: IdBox::AssetId(asset_id.clone()),
}
.into()),
Expand Down Expand Up @@ -243,41 +243,31 @@ pub mod isi {
) -> Result<(), Error> {
let account_id = self.destination;
let permission = self.object;
let permission_id = permission.id.clone();

// Check if account exists
state_transaction.world.account_mut(&account_id)?;

if !state_transaction
.world
.executor_data_model
.permissions
.contains(&permission_id)
{
return Err(FindError::Permission(permission_id).into());
}

if state_transaction
.world
.account_contains_inherent_permission(&account_id, &permission)
{
return Err(RepetitionError {
instruction_type: InstructionType::Grant,
id: permission.id.into(),
instruction: InstructionType::Grant,
id: permission.into(),
}
.into());
}

state_transaction
.world
.add_account_permission(&account_id, permission);
.add_account_permission(&account_id, permission.clone());

state_transaction
.world
.emit_events(Some(AccountEvent::PermissionAdded(
AccountPermissionChanged {
account: account_id,
permission: permission_id,
permission,
},
)));

Expand All @@ -302,15 +292,15 @@ pub mod isi {
.world
.remove_account_permission(&account_id, &permission)
{
return Err(FindError::Permission(permission.id).into());
return Err(FindError::Permission(permission).into());
}

state_transaction
.world
.emit_events(Some(AccountEvent::PermissionRemoved(
AccountPermissionChanged {
account: account_id,
permission: permission.id,
permission,
},
)));

Expand All @@ -333,10 +323,8 @@ pub mod isi {
.roles
.get(&role_id)
.ok_or_else(|| FindError::Role(role_id.clone()))?
.clone()
.permissions
.into_iter()
.map(|token| token.id);
.clone();

state_transaction.world.account(&account_id)?;

Expand All @@ -350,7 +338,7 @@ pub mod isi {
.is_some()
{
return Err(RepetitionError {
instruction_type: InstructionType::Grant,
instruction: InstructionType::Grant,
id: IdBox::RoleId(role_id),
}
.into());
Expand All @@ -359,10 +347,11 @@ pub mod isi {
state_transaction.world.emit_events({
let account_id_clone = account_id.clone();
permissions
.into_iter()
.zip(core::iter::repeat_with(move || account_id.clone()))
.map(|(permission_id, account_id)| AccountPermissionChanged {
.map(|(permission, account_id)| AccountPermissionChanged {
account: account_id,
permission: permission_id,
permission,
})
.map(AccountEvent::PermissionAdded)
.chain(std::iter::once(AccountEvent::RoleGranted(
Expand Down Expand Up @@ -392,10 +381,8 @@ pub mod isi {
.roles
.get(&role_id)
.ok_or_else(|| FindError::Role(role_id.clone()))?
.clone()
.permissions
.into_iter()
.map(|token| token.id);
.clone();

if state_transaction
.world
Expand All @@ -412,10 +399,11 @@ pub mod isi {
state_transaction.world.emit_events({
let account_id_clone = account_id.clone();
permissions
.into_iter()
.zip(core::iter::repeat_with(move || account_id.clone()))
.map(|(permission_id, account_id)| AccountPermissionChanged {
.map(|(permission, account_id)| AccountPermissionChanged {
account: account_id,
permission: permission_id,
permission,
})
.map(AccountEvent::PermissionRemoved)
.chain(std::iter::once(AccountEvent::RoleRevoked(
Expand All @@ -436,9 +424,9 @@ pub mod isi {
state_transaction: &mut StateTransaction<'_, '_>,
value: &AssetValue,
) -> Result<(), Error> {
let expected_asset_value_type = match value.value_type() {
AssetValueType::Numeric(_) => asset::isi::expected_asset_value_type_numeric,
AssetValueType::Store => asset::isi::expected_asset_value_type_store,
let expected_asset_value_type = match value.type_() {
AssetType::Numeric(_) => asset::isi::expected_asset_value_type_numeric,
AssetType::Store => asset::isi::expected_asset_value_type_store,
};
let definition = asset::isi::assert_asset_type(
definition_id,
Expand Down
Loading

0 comments on commit c2c6282

Please sign in to comment.