Skip to content

Commit

Permalink
refactor: rename JsonValue to Json (#5154)
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic authored Oct 18, 2024
1 parent a1c720a commit 237a8c6
Show file tree
Hide file tree
Showing 34 changed files with 180 additions and 186 deletions.
8 changes: 4 additions & 4 deletions crates/iroha/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn permissions_differ_not_only_by_names() {
.submit_blocking(SetKeyValue::asset(
mouse_hat_id,
"color".parse().expect("Valid"),
"red".parse::<JsonValue>().expect("Valid"),
"red".parse::<Json>().expect("Valid"),
))
.expect("Failed to modify Mouse's hats");

Expand All @@ -270,7 +270,7 @@ fn permissions_differ_not_only_by_names() {
let set_shoes_color = SetKeyValue::asset(
mouse_shoes_id.clone(),
"color".parse().expect("Valid"),
"yellow".parse::<JsonValue>().expect("Valid"),
"yellow".parse::<Json>().expect("Valid"),
);
let _err = client
.submit_blocking(set_shoes_color.clone())
Expand Down Expand Up @@ -318,7 +318,7 @@ fn stored_vs_granted_permission_payload() -> Result<()> {
.expect("Failed to register mouse");

// Allow alice to mint mouse asset and mint initial value
let value_json = JsonValue::from_string_unchecked(format!(
let value_json = Json::from_string_unchecked(format!(
// NOTE: Permissions is created explicitly as a json string to introduce additional whitespace
// This way, if the executor compares permissions just as JSON strings, the test will fail
r##"{{ "asset" : "xor#wonderland#{mouse_id}" }}"##
Expand All @@ -341,7 +341,7 @@ fn stored_vs_granted_permission_payload() -> Result<()> {
let set_key_value = SetKeyValue::asset(
mouse_asset,
"color".parse()?,
"red".parse::<JsonValue>().expect("Valid"),
"red".parse::<Json>().expect("Valid"),
);
iroha
.submit_blocking(set_key_value)
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha/tests/integration/queries/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn live_query_is_dropped_after_smart_contract_end() -> Result<()> {
);
client.submit_transaction_blocking(&transaction)?;

let metadata_value: JsonValue = client.query_single(FindAccountMetadata::new(
let metadata_value: Json = client.query_single(FindAccountMetadata::new(
client.account.clone(),
"cursor".parse().unwrap(),
))?;
Expand Down
14 changes: 4 additions & 10 deletions crates/iroha/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> {
test_client.submit_transaction_blocking(&grant_role_tx)?;

// Alice modifies Mouse's metadata
let set_key_value = SetKeyValue::account(
mouse_id,
"key".parse::<Name>()?,
"value".parse::<JsonValue>()?,
);
let set_key_value =
SetKeyValue::account(mouse_id, "key".parse::<Name>()?, "value".parse::<Json>()?);
test_client.submit_blocking(set_key_value)?;

// Making request to find Alice's roles
Expand Down Expand Up @@ -219,11 +216,8 @@ fn grant_revoke_role_permissions() -> Result<()> {
.sign(mouse_keypair.private_key());
test_client.submit_transaction_blocking(&grant_role_tx)?;

let set_key_value = SetKeyValue::account(
mouse_id.clone(),
"key".parse()?,
"value".parse::<JsonValue>()?,
);
let set_key_value =
SetKeyValue::account(mouse_id.clone(), "key".parse()?, "value".parse::<Json>()?);
let can_set_key_value_in_mouse = CanModifyAccountMetadata {
account: mouse_id.clone(),
};
Expand Down
10 changes: 5 additions & 5 deletions crates/iroha/tests/integration/transfer_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iroha_executor_data_model::permission::{
trigger::CanUnregisterTrigger,
};
use iroha_genesis::GenesisBlock;
use iroha_primitives::json::JsonValue;
use iroha_primitives::json::Json;
use iroha_test_network::{Peer as TestPeer, *};
use iroha_test_samples::{gen_account_in, ALICE_ID, BOB_ID, SAMPLE_GENESIS_ACCOUNT_ID};
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -74,7 +74,7 @@ fn domain_owner_domain_permissions() -> Result<()> {

// check that "alice@wonderland" as owner of domain can edit metadata in her domain
let key: Name = "key".parse()?;
let value = JsonValue::new("value");
let value = Json::new("value");
test_client.submit_blocking(SetKeyValue::domain(kingdom_id.clone(), key.clone(), value))?;
test_client.submit_blocking(RemoveKeyValue::domain(kingdom_id.clone(), key))?;

Expand Down Expand Up @@ -111,7 +111,7 @@ fn domain_owner_account_permissions() -> Result<()> {

// check that "alice@wonderland" as owner of domain can edit metadata of account in her domain
let key: Name = "key".parse()?;
let value = JsonValue::new("value");
let value = Json::new("value");
test_client.submit_blocking(SetKeyValue::account(
mad_hatter_id.clone(),
key.clone(),
Expand Down Expand Up @@ -177,7 +177,7 @@ fn domain_owner_asset_definition_permissions() -> Result<()> {

// check that "alice@wonderland" as owner of domain can edit metadata of asset definition in her domain
let key: Name = "key".parse()?;
let value = JsonValue::new("value");
let value = Json::new("value");
test_client.submit_blocking(SetKeyValue::asset_definition(
coin_id.clone(),
key.clone(),
Expand Down Expand Up @@ -249,7 +249,7 @@ fn domain_owner_asset_permissions() -> Result<()> {

// check that "alice@wonderland" as owner of domain can edit metadata of store asset in her domain
let key: Name = "key".parse()?;
let value = JsonValue::new("value");
let value = Json::new("value");
let bob_store_id = AssetId::new(store_id, bob_id.clone());
test_client.submit_blocking(SetKeyValue::asset(bob_store_id.clone(), key.clone(), value))?;
test_client.submit_blocking(RemoveKeyValue::asset(bob_store_id.clone(), key))?;
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha/tests/integration/triggers/time_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn pre_commit_trigger_should_be_executed() -> Result<()> {
let sample_isi = SetKeyValue::account(
account_id.clone(),
"key".parse::<Name>()?,
"value".parse::<JsonValue>()?,
"value".parse::<Json>()?,
);
test_client.submit(sample_isi)?;
}
Expand Down Expand Up @@ -251,7 +251,7 @@ fn submit_sample_isi_on_every_block_commit(
let sample_isi = SetKeyValue::account(
account_id.clone(),
"key".parse::<Name>()?,
JsonValue::new("value"),
Json::new("value"),
);
test_client.submit(sample_isi)?;
}
Expand Down
14 changes: 7 additions & 7 deletions crates/iroha_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use erased_serde::Serialize;
use error_stack::{fmt::ColorMode, IntoReportCompat, ResultExt};
use eyre::{eyre, Error, Result, WrapErr};
use iroha::{client::Client, config::Config, data_model::prelude::*};
use iroha_primitives::{addr::SocketAddr, json::JsonValue};
use iroha_primitives::{addr::SocketAddr, json::Json};
use thiserror::Error;

/// Re-usable clap `--metadata <PATH>` (`-m`) argument.
Expand Down Expand Up @@ -58,15 +58,15 @@ pub struct MetadataValueArg {
/// Booleans: false/true
/// Objects: e.g. {"Vec":[{"String":"a"},{"String":"b"}]}
#[arg(short, long)]
value: JsonValue,
value: Json,
}

impl FromStr for MetadataValueArg {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(MetadataValueArg {
value: JsonValue::from_str(s)?,
value: Json::from_str(s)?,
})
}
}
Expand Down Expand Up @@ -1212,12 +1212,12 @@ mod tests {
}

// Boolean values
case!("true", JsonValue::new(true));
case!("false", JsonValue::new(false));
case!("true", Json::new(true));
case!("false", Json::new(false));

// Numeric values
case!("\"123\"", JsonValue::new(numeric!(123)));
case!("\"123.0\"", JsonValue::new(numeric!(123.0)));
case!("\"123\"", Json::new(numeric!(123)));
case!("\"123.0\"", Json::new(numeric!(123.0)));

// JSON Value
let json_str = r#"{"Vec":[{"String":"a"},{"String":"b"}]}"#;
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_codec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ mod tests {
let mut metadata = Metadata::default();
metadata.insert(
"hat".parse().expect("Valid"),
"white".parse::<JsonValue>().expect("Valid"),
"white".parse::<Json>().expect("Valid"),
);
let account = Account::new(ALICE_ID.clone()).with_metadata(metadata);

Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/query/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mod tests {
permission::Permission,
query::parameters::{FetchSize, Pagination, QueryParams, Sorting},
};
use iroha_primitives::json::JsonValue;
use iroha_primitives::json::Json;
use iroha_test_samples::ALICE_ID;
use nonzero_ext::nonzero;

Expand All @@ -355,7 +355,7 @@ mod tests {

// it's not important which type we use here, just to test the flow
let query_output =
(0..100).map(|_| Permission::new(String::default(), JsonValue::from(false)));
(0..100).map(|_| Permission::new(String::default(), Json::from(false)));
let query_output = crate::smartcontracts::query::apply_query_postprocessing(
query_output,
&query_params,
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ pub mod query {
},
},
};
use iroha_primitives::json::JsonValue;
use iroha_primitives::json::Json;

use super::*;
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};
Expand Down Expand Up @@ -508,7 +508,7 @@ pub mod query {

impl ValidSingularQuery for FindAccountMetadata {
#[metrics(+"find_account_key_value_by_id_and_key")]
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<JsonValue, Error> {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<Json, Error> {
let id = &self.id;
let key = &self.key;
iroha_logger::trace!(%id, %key);
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/src/smartcontracts/isi/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub mod query {
},
},
};
use iroha_primitives::json::JsonValue;
use iroha_primitives::json::Json;

use super::*;
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};
Expand Down Expand Up @@ -495,7 +495,7 @@ pub mod query {

impl ValidSingularQuery for FindAssetMetadata {
#[metrics(+"find_asset_key_value_by_id_and_key")]
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<JsonValue, Error> {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<Json, Error> {
let id = &self.id;
let key = &self.key;
let asset = state_ro.world().asset(id).map_err(|asset_err| {
Expand Down
6 changes: 3 additions & 3 deletions crates/iroha_core/src/smartcontracts/isi/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ pub mod query {
predicate::{predicate_atoms::domain::DomainPredicateBox, CompoundPredicate},
},
};
use iroha_primitives::json::JsonValue;
use iroha_primitives::json::Json;

use super::*;
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};
Expand All @@ -410,7 +410,7 @@ pub mod query {

impl ValidSingularQuery for FindDomainMetadata {
#[metrics(+"find_domain_key_value_by_id_and_key")]
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<JsonValue, Error> {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<Json, Error> {
let id = &self.id;
let key = &self.key;
iroha_logger::trace!(%id, %key);
Expand All @@ -424,7 +424,7 @@ pub mod query {

impl ValidSingularQuery for FindAssetDefinitionMetadata {
#[metrics(+"find_asset_definition_key_value_by_id_and_key")]
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<JsonValue, Error> {
fn execute(&self, state_ro: &impl StateReadOnly) -> Result<Json, Error> {
let id = &self.id;
let key = &self.key;
iroha_logger::trace!(%id, %key);
Expand Down
Loading

0 comments on commit 237a8c6

Please sign in to comment.