Skip to content

Commit

Permalink
Make better API with Into<Value>
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
  • Loading branch information
Arjentix committed Dec 4, 2023
1 parent 1b7975f commit f933434
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
8 changes: 4 additions & 4 deletions client/tests/integration/domain_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn domain_owner_domain_permissions() -> Result<()> {
test_client.submit_blocking(SetKeyValueBox::domain(
kingdom_id.clone(),
key.clone(),
value.into(),
value,
))?;
test_client.submit_blocking(RemoveKeyValueBox::domain(kingdom_id.clone(), key))?;

Expand Down Expand Up @@ -82,7 +82,7 @@ fn domain_owner_account_permissions() -> Result<()> {
test_client.submit_blocking(SetKeyValueBox::account(
mad_hatter_id.clone(),
key.clone(),
value.into(),
value,
))?;
test_client.submit_blocking(RemoveKeyValueBox::account(mad_hatter_id.clone(), key))?;

Expand Down Expand Up @@ -142,7 +142,7 @@ fn domain_owner_asset_definition_permissions() -> Result<()> {
test_client.submit_blocking(SetKeyValueBox::asset_definition(
coin_id.clone(),
key.clone(),
value.into(),
value,
))?;
test_client.submit_blocking(RemoveKeyValueBox::asset_definition(coin_id.clone(), key))?;

Expand Down Expand Up @@ -209,7 +209,7 @@ fn domain_owner_asset_permissions() -> Result<()> {
test_client.submit_blocking(SetKeyValueBox::asset(
bob_store_id.clone(),
key.clone(),
value.into(),
value,
))?;
test_client.submit_blocking(RemoveKeyValueBox::asset(bob_store_id.clone(), key))?;

Expand Down
11 changes: 4 additions & 7 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn permissions_differ_not_only_by_names() {
.submit_blocking(SetKeyValueBox::asset(
mouse_hat_id,
Name::from_str("color").expect("Valid"),
"red".to_owned().into(),
"red".to_owned(),
))
.expect("Failed to modify Mouse's hats");

Expand All @@ -256,7 +256,7 @@ fn permissions_differ_not_only_by_names() {
let set_shoes_color = SetKeyValueBox::asset(
mouse_shoes_id.clone(),
Name::from_str("color").expect("Valid"),
"yellow".to_owned().into(),
"yellow".to_owned(),
);
let _err = client
.submit_blocking(set_shoes_color.clone())
Expand Down Expand Up @@ -330,11 +330,8 @@ fn stored_vs_granted_token_payload() -> Result<()> {
.expect("Failed to grant permission to alice.");

// Check that alice can indeed mint mouse asset
let set_key_value = SetKeyValueBox::asset(
mouse_asset,
Name::from_str("color")?,
"red".to_owned().into(),
);
let set_key_value =
SetKeyValueBox::asset(mouse_asset, Name::from_str("color")?, "red".to_owned());
iroha_client
.submit_blocking(set_key_value)
.expect("Failed to mint asset for mouse.");
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/triggers/time_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn pre_commit_trigger_should_be_executed() -> Result<()> {
let sample_isi = SetKeyValueBox::account(
account_id.clone(),
"key".parse::<Name>()?,
String::from("value").into(),
String::from("value"),
);
test_client.submit(sample_isi)?;
}
Expand Down Expand Up @@ -301,7 +301,7 @@ fn submit_sample_isi_on_every_block_commit(
let sample_isi = SetKeyValueBox::account(
account_id.clone(),
"key".parse::<Name>()?,
String::from("value").into(),
String::from("value"),
);
test_client.submit(sample_isi)?;
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/smartcontracts/isi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mod tests {
SetKeyValueBox::asset(
asset_id.clone(),
Name::from_str("Bytes")?,
vec![1_u32, 2_u32, 3_u32].into(),
vec![1_u32, 2_u32, 3_u32],
)
.execute(&account_id, &mut wsv)?;
let asset = wsv.asset(&asset_id)?;
Expand All @@ -291,7 +291,7 @@ mod tests {
SetKeyValueBox::account(
account_id.clone(),
Name::from_str("Bytes")?,
vec![1_u32, 2_u32, 3_u32].into(),
vec![1_u32, 2_u32, 3_u32],
)
.execute(&account_id, &mut wsv)?;
let bytes = wsv.map_account(&account_id, |account| {
Expand Down Expand Up @@ -320,7 +320,7 @@ mod tests {
SetKeyValueBox::asset_definition(
definition_id.clone(),
Name::from_str("Bytes")?,
vec![1_u32, 2_u32, 3_u32].into(),
vec![1_u32, 2_u32, 3_u32],
)
.execute(&account_id, &mut wsv)?;
let bytes = wsv
Expand Down Expand Up @@ -348,7 +348,7 @@ mod tests {
SetKeyValueBox::domain(
domain_id.clone(),
Name::from_str("Bytes")?,
vec![1_u32, 2_u32, 3_u32].into(),
vec![1_u32, 2_u32, 3_u32],
)
.execute(&account_id, &mut wsv)?;
let bytes = wsv
Expand Down
16 changes: 8 additions & 8 deletions data_model/src/isi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,27 +475,27 @@ isi_box! {

impl SetKeyValueBox {
/// Constructs a new [`SetKeyValueBox`] for a [`Domain`] with the given `key` and `value`.
pub fn domain(domain_id: DomainId, key: Name, value: Value) -> Self {
Self::Domain(SetKeyValue::new(domain_id, key, value))
pub fn domain(domain_id: DomainId, key: Name, value: impl Into<Value>) -> Self {
Self::Domain(SetKeyValue::new(domain_id, key, value.into()))
}

/// Constructs a new [`SetKeyValueBox`] for an [`Account`] with the given `key` and `value`.
pub fn account(account_id: AccountId, key: Name, value: Value) -> Self {
Self::Account(SetKeyValue::new(account_id, key, value))
pub fn account(account_id: AccountId, key: Name, value: impl Into<Value>) -> Self {
Self::Account(SetKeyValue::new(account_id, key, value.into()))
}

/// Constructs a new [`SetKeyValueBox`] for an [`AssetDefinition`] with the given `key` and `value`.
pub fn asset_definition(
asset_definition_id: AssetDefinitionId,
key: Name,
value: Value,
value: impl Into<Value>,
) -> Self {
Self::AssetDefinition(SetKeyValue::new(asset_definition_id, key, value))
Self::AssetDefinition(SetKeyValue::new(asset_definition_id, key, value.into()))
}

/// Constructs a new [`SetKeyValueBox`] for an [`Asset`] with the given `key` and `value`.
pub fn asset(asset_id: AssetId, key: Name, value: Value) -> Self {
Self::Asset(SetKeyValue::new(asset_id, key, value))
pub fn asset(asset_id: AssetId, key: Name, value: impl Into<Value>) -> Self {
Self::Asset(SetKeyValue::new(asset_id, key, value.into()))
}
}

Expand Down

0 comments on commit f933434

Please sign in to comment.