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

refactor!: fix naming convention for assets and permissions #4741

Merged
merged 1 commit into from
Jun 28, 2024
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
2 changes: 1 addition & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ You may deploy Iroha as a [native binary](#native-binary) or by using [Docker](#

We provide a sample configuration for Docker in [`docker-compose.yml`](../configs/swarm/docker-compose.yml). We highly recommend that you adjust the `config.json` to include a set of new key pairs.

[Generate the keys](#generating-keys) and put them into `services.*.environment` in `docker-compose.yml`. Don't forget to update the public keys of `TRUSTED_PEERS`.
[Generate the keys](#generating-keys) and put them into `services.*.environment` in `docker-compose.yml`. Don't forget to update the public keys of `SUMERAGI_TRUSTED_PEERS`.

- Build images:

Expand Down
2 changes: 1 addition & 1 deletion client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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
8 changes: 4 additions & 4 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_type: AssetType,
initial_value: T,
to_mint: T,
to_burn: T,
Expand All @@ -147,7 +147,7 @@ where
// Registering new asset definition
let definition_id: AssetDefinitionId =
definition.parse().expect("Failed to parse `definition_id`");
let asset_definition = AssetDefinition::new(definition_id.clone(), asset_value_type);
let asset_definition = AssetDefinition::new(definition_id.clone(), asset_type);
test_client.submit_blocking(Register::asset_definition(asset_definition))?;

let asset_ids = accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ mod expression {
pub struct EvaluatesTo<V> {
#[serde(flatten)]
pub(crate) expression: Box<Expression>,
_value_type: PhantomData<V>,
type_: PhantomData<V>,
}

impl<V> EvaluatesTo<V> {
pub fn new_unchecked(expression: impl Into<Expression>) -> Self {
Self {
expression: Box::new(expression.into()),
_value_type: PhantomData,
type_: PhantomData,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ impl Executor {

fn replace_token(accounts: &[Account]) -> MigrationResult {
let can_unregister_domain_definition_id =
iroha_executor::default::permissions::domain::CanUnregisterDomain::id();
iroha_executor::default::permissions::domain::CanUnregisterDomain::name();

let can_control_domain_lives_definition_id = token::CanControlDomainLives::id();
let can_control_domain_lives_definition_id = token::CanControlDomainLives::name();

accounts
.iter()
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
18 changes: 9 additions & 9 deletions client/tests/integration/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ fn executor_upgrade_should_run_migration() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(10_990).start_with_runtime();
wait_for_genesis_committed(&vec![client.clone()], 0);

let can_unregister_domain_token_id = "CanUnregisterDomain".parse().unwrap();
let can_unregister_domain_token_id = "CanUnregisterDomain";

// Check that `CanUnregisterDomain` exists
assert!(client
.request(FindExecutorDataModel)?
.permissions()
.iter()
.any(|id| id == &can_unregister_domain_token_id));
.any(|id| id == can_unregister_domain_token_id));

// Check that Alice has permission to unregister Wonderland
let alice_id = ALICE_ID.clone();
Expand All @@ -89,7 +89,7 @@ fn executor_upgrade_should_run_migration() -> Result<()> {
.collect::<QueryResult<Vec<_>>>()
.expect("Valid");
assert!(alice_tokens.contains(&Permission::new(
can_unregister_domain_token_id.clone(),
can_unregister_domain_token_id.parse().unwrap(),
json!({ "domain": DomainId::from_str("wonderland").unwrap() }),
)));

Expand All @@ -103,22 +103,22 @@ fn executor_upgrade_should_run_migration() -> Result<()> {
assert!(!data_model
.permissions()
.iter()
.any(|id| id == &can_unregister_domain_token_id));
.any(|id| id == can_unregister_domain_token_id));

let can_control_domain_lives_token_id = "CanControlDomainLives".parse().unwrap();
let can_control_domain_lives_token_id = "CanControlDomainLives";

assert!(data_model
.permissions()
.iter()
.any(|id| id == &can_control_domain_lives_token_id));
.any(|id| id == can_control_domain_lives_token_id));

// Check that Alice has `can_control_domain_lives` permission
let alice_tokens = client
.request(FindPermissionsByAccountId::new(alice_id))?
.collect::<QueryResult<Vec<_>>>()
.expect("Valid");
assert!(alice_tokens.contains(&Permission::new(
can_control_domain_lives_token_id,
can_control_domain_lives_token_id.parse().unwrap(),
json!(null),
)));

Expand Down 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
8 changes: 4 additions & 4 deletions client_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Check the [Bash guide in Iroha Tutorial](https://hyperledger.github.io/iroha-2-d
```bash
./iroha domain register --id="Soramitsu"
./iroha account register --id="ed01204A3C5A6B77BBE439969F95F0AA4E01AE31EC45A0D68C131B2C622751FCC5E3B6@Soramitsu"
./iroha asset register --id="XOR#Soramitsu" --value-type=Numeric
./iroha asset register --id="XOR#Soramitsu" --type=Numeric
./iroha asset mint --account="ed01204A3C5A6B77BBE439969F95F0AA4E01AE31EC45A0D68C131B2C622751FCC5E3B6@Soramitsu" --asset="XOR#Soramitsu" --quantity=1010
./iroha asset get --account="ed01204A3C5A6B77BBE439969F95F0AA4E01AE31EC45A0D68C131B2C622751FCC5E3B6@Soramitsu" --asset="XOR#Soramitsu"
```
Expand Down Expand Up @@ -111,7 +111,7 @@ To do so, you must first register an Asset Definition and only then add some Ass
Every asset has its own value spec. In this example, it is defined as `Numeric`, a 96-bit unsigned decimal. We also support `Store` for key-value structured data.

```bash
./iroha asset register --id="XOR#Soramitsu" --value-type=Numeric
./iroha asset register --id="XOR#Soramitsu" --type=Numeric
./iroha asset mint --account="ed01204A3C5A6B77BBE439969F95F0AA4E01AE31EC45A0D68C131B2C622751FCC5E3B6@Soramitsu" --asset="XOR#Soramitsu" --quantity=1010
```

Expand Down Expand Up @@ -186,8 +186,8 @@ To test transactions in the JSON format (used in the genesis block and by other
cat /path/to/file.json | ./iroha json transaction
```

### Request arbitrary query
### Request arbitrary query

```bash
```bash
echo '{ "FindAllParameters": null }' | ./iroha --config client.toml json query
```
2 changes: 1 addition & 1 deletion client_cli/pytests/common/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Stderr(Enum):
TOO_LONG = "Name length violation"
FAILED_TO_FIND_DOMAIN = "Failed to find domain"
INVALID_CHARACTER = "Failed to parse"
INVALID_VALUE_TYPE = "should be either `Store` or `Numeric`"
INVALID_TYPE = "should be either `Store` or `Numeric`"
RESERVED_CHARACTER = (
"The `@` character is reserved for `account@domain` constructs, "
"and `#` — for `asset#domain`."
Expand Down
6 changes: 3 additions & 3 deletions client_cli/pytests/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class AssetDefinition:
:type name: str
:param domain: The domain of the asset definition.
:type domain: str
:param value_type: The value type of the asset definition.
:type value_type: str
:param type_: The value type of the asset definition.
:type type_: str
"""

name: str
domain: str
value_type: str
type_: str

def __repr__(self):
return f"{self.name}#{self.domain}"
Expand Down
18 changes: 9 additions & 9 deletions client_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ def account(self, signatory: str, domain: str):
self.execute()
return self

def asset(self, asset_definition=None, account=None, value_of_value_type=None):
def asset(self, asset_definition=None, account=None, value_of_type=None):
"""
Executes the 'asset' command with the given asset definition, account, and value.
:param asset_definition: The asset definition to be queried, defaults to None.
:type asset_definition: AssetDefinition
:param account: The account to be queried, defaults to None.
:type account: Account
:param value_of_value_type: The value of the value type, defaults to None.
:type value_of_value_type: str, optional
:param value_of_type: The value of the asset type, defaults to None.
:type value_of_type: str, optional
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.insert(2, "asset")
if asset_definition and account and value_of_value_type:
if asset_definition and account and value_of_type:
self.command.append(
"--asset-id="
+ asset_definition.name
Expand All @@ -175,7 +175,7 @@ def asset(self, asset_definition=None, account=None, value_of_value_type=None):
+ "@"
+ account.domain
)
self.command.append("--quantity=" + value_of_value_type)
self.command.append("--quantity=" + value_of_type)
self.execute()
return self

Expand Down Expand Up @@ -239,21 +239,21 @@ def burn(self, account, asset, quantity: str):
self.execute()
return self

def definition(self, asset: str, domain: str, value_type: str):
def definition(self, asset: str, domain: str, type_: str):
"""
Executes the 'definition' command for the given asset, domain, and value type.
:param asset: The asset to be defined.
:type asset: str
:param domain: The domain of the asset.
:type domain: str
:param value_type: The value type of the asset.
:type value_type: str
:param type_: The value type of the asset.
:type type_: str
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.append("--definition-id=" + asset + "#" + domain)
self.command.append("--value-type=" + value_type)
self.command.append("--type=" + type_)
self.execute()
return self

Expand Down
6 changes: 3 additions & 3 deletions client_cli/pytests/src/client_cli/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def asset_definitions(self) -> Dict[str, str]:
for domain in domains:
asset_defs = domain.get("asset_definitions")
for asset_def in asset_defs.values():
value_type = asset_def.get("value_type")
if value_type:
asset_definitions[asset_def["id"]] = value_type
type_ = asset_def.get("type_")
if type_:
asset_definitions[asset_def["id"]] = type_
return asset_definitions
else:
return {}
Loading
Loading