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 19, 2024
1 parent db372a1 commit bc7756f
Show file tree
Hide file tree
Showing 45 changed files with 286 additions and 330 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 @@ -110,9 +110,9 @@ impl Executor {

fn replace_token(accounts: &[(Account, DomainId)]) -> 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
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
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 {}
8 changes: 4 additions & 4 deletions client_cli/pytests/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
GIVEN_public_key,
GIVEN_numeric_asset_for_account,
GIVEN_numeric_value,
GIVEN_numeric_value_type,
GIVEN_numeric_type,
GIVEN_random_character,
GIVEN_registered_account,
GIVEN_registered_asset_definition_with_numeric_value_type,
GIVEN_registered_asset_definition_with_store_value_type,
GIVEN_registered_asset_definition_with_numeric_type,
GIVEN_registered_asset_definition_with_store_type,
GIVEN_registered_domain,
GIVEN_registered_domain_with_uppercase_letter,
GIVEN_store_value_type,
GIVEN_store_type,
GIVEN_string_with_reserved_character,
GIVEN_string_with_whitespaces,
before_all,
Expand Down
8 changes: 4 additions & 4 deletions client_cli/pytests/test/assets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
GIVEN_public_key,
GIVEN_numeric_asset_for_account,
GIVEN_numeric_value,
GIVEN_numeric_value_type,
GIVEN_numeric_type,
GIVEN_registered_account,
GIVEN_registered_asset_definition_with_numeric_value_type,
GIVEN_registered_asset_definition_with_store_value_type,
GIVEN_registered_asset_definition_with_numeric_type,
GIVEN_registered_asset_definition_with_store_type,
GIVEN_registered_domain,
GIVEN_store_value_type,
GIVEN_store_type,
before_all,
before_each,
)
Expand Down
Loading

0 comments on commit bc7756f

Please sign in to comment.