Skip to content

Commit

Permalink
refactor!: rename wasm to smart contract
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Jul 8, 2024
1 parent 9174001 commit d69b1b2
Show file tree
Hide file tree
Showing 51 changed files with 255 additions and 241 deletions.
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ mod tests {
}

fn dummy_executor() -> Executor {
Executor::new(WasmSmartContract::from_compiled(vec![1, 2, 3]))
Executor::new(SmartContract::from_compiled(vec![1, 2, 3]))
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ where
.optimize()?
.into_bytes()?;

Ok(Executor::new(WasmSmartContract::from_compiled(wasm_blob)))
Ok(Executor::new(SmartContract::from_compiled(wasm_blob)))
}
2 changes: 1 addition & 1 deletion client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Config {
let clients = network.clients();
wait_for_genesis_committed_with_max_retries(&clients, 0, self.genesis_max_retries);

client.submit_blocking(SetParameter::new(Parameter::Block(self.block_limits)))?;
client.submit_blocking(SetParameter::new(self.block_limits))?;

let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
Expand Down
2 changes: 1 addition & 1 deletion client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn generate_genesis(
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);
let wasm = SmartContract::from_compiled(wasm);
let (account_id, _account_keypair) = gen_account_in("wonderland");

let build_trigger = |trigger_id: TriggerId| {
Expand Down
9 changes: 5 additions & 4 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use futures_util::StreamExt;
use http_default::{AsyncWebSocketStream, WebSocketStream};
pub use iroha_config::client_api::ConfigDTO;
use iroha_logger::prelude::*;
use iroha_primitives::json;
use iroha_telemetry::metrics::Status;
use iroha_torii_const::uri as torii_uri;
use iroha_version::prelude::*;
Expand Down Expand Up @@ -327,7 +326,7 @@ impl_query_output! {
crate::data_model::account::Account,
crate::data_model::domain::Domain,
crate::data_model::block::BlockHeader,
json::JsonString,
crate::data_model::prelude::JsonString,
crate::data_model::query::TransactionQueryOutput,
crate::data_model::executor::ExecutorDataModel,
crate::data_model::trigger::Trigger,
Expand Down Expand Up @@ -447,7 +446,7 @@ impl Client {
}
}

/// Builds transaction out of supplied instructions or wasm.
/// Builds transaction out of supplied instructions or smart contract.
///
/// # Errors
/// Fails if signing transaction fails
Expand All @@ -460,7 +459,9 @@ impl Client {

let mut tx_builder = match instructions.into() {
Executable::Instructions(instructions) => tx_builder.with_instructions(instructions),
Executable::Wasm(wasm) => tx_builder.with_wasm(wasm),
Executable::SmartContract(smart_contract) => {
tx_builder.with_smart_contract(smart_contract)
}
};

if let Some(transaction_ttl) = self.transaction_ttl {
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();

client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
client.submit_blocking(SetParameter::new(BlockParameter::MaxTransactions(
nonzero!(1_u64),
)))?;

let create_domain: InstructionBox =
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fmt::Write as _, sync::mpsc, thread};

use eyre::Result;
use iroha::data_model::{prelude::*, transaction::WasmSmartContract};
use iroha::data_model::{prelude::*, transaction::SmartContract};
use iroha_executor_data_model::permission::account::{
CanRemoveKeyValueInAccount, CanSetKeyValueInAccount,
};
Expand Down Expand Up @@ -125,7 +125,7 @@ fn wasm_execution_should_produce_events() -> Result<()> {
);

transaction_execution_should_produce_events(
WasmSmartContract::from_compiled(wat.into_bytes()),
SmartContract::from_compiled(wat.into_bytes()),
10_615,
)
}
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ fn test_with_instruction_and_status_and_port(
wait_for_genesis_committed(&clients, 0);
let pipeline_time = Config::pipeline_time();

client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
client.submit_blocking(SetParameter::new(BlockParameter::MaxTransactions(
nonzero!(1_u64),
)))?;

// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fn long_multiple_blocks_created() -> Result<()> {
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();

client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
client.submit_blocking(SetParameter::new(BlockParameter::MaxTransactions(
nonzero!(1_u64),
)))?;

let create_domain: InstructionBox = Register::domain(Domain::new("domain".parse()?)).into();
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/extra_functional/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fn tranasctions_should_be_applied() {
let (_rt, network, iroha) = NetworkBuilder::new(4, Some(11_300)).create_with_runtime();
wait_for_genesis_committed(&network.clients(), 0);
iroha
.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
.submit_blocking(SetParameter::new(BlockParameter::MaxTransactions(
nonzero!(1_u64),
)))
.unwrap();

Expand Down
4 changes: 1 addition & 3 deletions client/tests/integration/extra_functional/unregister_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ fn init() -> Result<(
let pipeline_time = Config::pipeline_time();
iroha_logger::info!("Started");

let set_max_txns_in_block = SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
));
let set_max_txns_in_block = SetParameter::new(BlockParameter::MaxTransactions(nonzero!(1_u64)));

let create_domain = Register::domain(Domain::new("domain".parse()?));
let (account_id, _account_keypair) = gen_account_in("domain");
Expand Down
9 changes: 3 additions & 6 deletions client/tests/integration/extra_functional/unstable_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use std::thread;

use iroha::{
client::{self, QueryResult},
data_model::{
parameter::{BlockParameter, Parameter},
prelude::*,
},
data_model::{parameter::BlockParameter, prelude::*},
};
use iroha_config::parameters::actual::Root as Config;
use nonzero_ext::nonzero;
Expand Down Expand Up @@ -64,8 +61,8 @@ fn unstable_network(
.create_with_runtime();
wait_for_genesis_committed(&network.clients(), n_offline_peers);
iroha
.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(5_u64)),
.submit_blocking(SetParameter::new(BlockParameter::MaxTransactions(
nonzero!(5_u64),
)))
.unwrap();

Expand Down
16 changes: 10 additions & 6 deletions client/tests/integration/queries/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ fn live_query_is_dropped_after_smart_contract_end() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(11_140).start_with_runtime();
wait_for_genesis_committed(&[client.clone()], 0);

let wasm = iroha_wasm_builder::Builder::new(
let smart_contract = iroha_wasm_builder::Builder::new(
"tests/integration/smartcontracts/query_assets_and_save_cursor",
)
.show_output()
.build()?
.optimize()?
.into_bytes()?;

let transaction =
client.build_transaction(WasmSmartContract::from_compiled(wasm), Metadata::default());
let transaction = client.build_transaction(
SmartContract::from_compiled(smart_contract),
Metadata::default(),
);
client.submit_transaction_blocking(&transaction)?;

let metadata_value: JsonString = client.request(FindAccountKeyValueByIdAndKey::new(
Expand Down Expand Up @@ -49,16 +51,18 @@ fn smart_contract_can_filter_queries() -> Result<()> {
let (_rt, _peer, client) = <PeerBuilder>::new().with_port(11_260).start_with_runtime();
wait_for_genesis_committed(&[client.clone()], 0);

let wasm = iroha_wasm_builder::Builder::new(
let smart_contract = iroha_wasm_builder::Builder::new(
"tests/integration/smartcontracts/smart_contract_can_filter_queries",
)
.show_output()
.build()?
.optimize()?
.into_bytes()?;

let transaction =
client.build_transaction(WasmSmartContract::from_compiled(wasm), Metadata::default());
let transaction = client.build_transaction(
SmartContract::from_compiled(smart_contract),
Metadata::default(),
);
client.submit_transaction_blocking(&transaction)?;

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions client/tests/integration/triggers/by_call_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iroha::{
data_model::{
prelude::*,
query::error::{FindError, QueryExecutionFail},
transaction::{Executable, WasmSmartContract},
transaction::{Executable, SmartContract},
},
};
use iroha_executor_data_model::permission::trigger::CanRegisterUserTrigger;
Expand Down Expand Up @@ -430,7 +430,7 @@ fn trigger_in_genesis_using_base64() -> Result<()> {
let trigger = Trigger::new(
trigger_id.clone(),
Action::new(
serde_json::from_str::<WasmSmartContract>(&wasm_base64)
serde_json::from_str::<SmartContract>(&wasm_base64)
.wrap_err("Can't deserialize wasm using base64")?,
Repeats::Indefinitely,
account_id.clone(),
Expand Down Expand Up @@ -585,7 +585,7 @@ fn unregistering_one_of_two_triggers_with_identical_wasm_should_not_cause_origin
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);
let wasm = SmartContract::from_compiled(wasm);

let build_trigger = |trigger_id: TriggerId| {
Trigger::new(
Expand Down
6 changes: 3 additions & 3 deletions client/tests/integration/triggers/time_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iroha::{
events::pipeline::{BlockEventFilter, BlockStatus},
parameter::SumeragiParameters,
prelude::*,
transaction::WasmSmartContract,
transaction::SmartContract,
Level,
},
};
Expand Down Expand Up @@ -228,7 +228,7 @@ fn mint_nft_for_every_user_every_1_sec() -> Result<()> {
.optimize()?
.into_bytes()?;

info!("WASM size is {} bytes", wasm.len());
info!("Smart contract size is {} bytes", wasm.len());

let (_rt, _peer, mut test_client) = <PeerBuilder>::new().with_port(10_780).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);
Expand Down Expand Up @@ -265,7 +265,7 @@ fn mint_nft_for_every_user_every_1_sec() -> Result<()> {
let register_trigger = Register::trigger(Trigger::new(
"mint_nft_for_all".parse()?,
Action::new(
WasmSmartContract::from_compiled(wasm),
SmartContract::from_compiled(wasm),
Repeats::Indefinitely,
alice_id.clone(),
filter,
Expand Down
7 changes: 3 additions & 4 deletions client/tests/integration/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ fn define_custom_parameter() -> Result<()> {

let parameter = DomainLimits {
id_len: 2_u32.pow(6),
}
.into();
};
let set_param_isi: InstructionBox = SetParameter::new(parameter).into();
client.submit_all_blocking([set_param_isi, create_domain.into()])?;

Expand All @@ -422,9 +421,9 @@ fn upgrade_executor(client: &Client, executor: impl AsRef<Path>) -> Result<()> {
.optimize()?
.into_bytes()?;

info!("WASM size is {} bytes", wasm.len());
info!("Smart contract size is {} bytes", wasm.len());

let upgrade_executor = Upgrade::new(Executor::new(WasmSmartContract::from_compiled(wasm)));
let upgrade_executor = Upgrade::new(Executor::new(SmartContract::from_compiled(wasm)));
client.submit_blocking(upgrade_executor)?;

Ok(())
Expand Down
21 changes: 11 additions & 10 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ enum Subcommand {
/// The subcommand related to event streaming
#[clap(subcommand)]
Events(events::Args),
/// The subcommand related to Wasm
Wasm(wasm::Args),
/// The subcommand related to smart contracts
SmartContract(smart_contract::Args),
/// The subcommand related to block streaming
Blocks(blocks::Args),
/// The subcommand related to multi-instructions as Json or Json5
Expand Down Expand Up @@ -169,7 +169,7 @@ macro_rules! match_all {
impl RunArgs for Subcommand {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
use Subcommand::*;
match_all!((self, context), { Domain, Account, Asset, Peer, Events, Wasm, Blocks, Json })
match_all!((self, context), { Domain, Account, Asset, Peer, Events, SmartContract, Blocks, Json })
}
}

Expand Down Expand Up @@ -1006,37 +1006,38 @@ mod peer {
}
}

mod wasm {
mod smart_contract {
use std::{io::Read, path::PathBuf};

use super::*;

/// Subcommand for dealing with Wasm
/// Subcommand for dealing with smart contracts
#[derive(Debug, clap::Args)]
pub struct Args {
/// Specify a path to the Wasm file or skip this flag to read from stdin
/// Specify a path to the smart contract file or skip this flag to read from stdin
#[arg(short, long)]
path: Option<PathBuf>,
}

impl RunArgs for Args {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let raw_data = if let Some(path) = self.path {
read_file(path).wrap_err("Failed to read a Wasm from the file into the buffer")?
read_file(path)
.wrap_err("Failed to read a smart contract from the file into the buffer")?
} else {
let mut buf = Vec::<u8>::new();
stdin()
.read_to_end(&mut buf)
.wrap_err("Failed to read a Wasm from stdin into the buffer")?;
.wrap_err("Failed to read a smart contract from stdin into the buffer")?;
buf
};

submit(
WasmSmartContract::from_compiled(raw_data),
SmartContract::from_compiled(raw_data),
Metadata::default(),
context,
)
.wrap_err("Failed to submit a Wasm smart contract")
.wrap_err("Failed to submit a smart contract")
}
}
}
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn build_state(rt: &tokio::runtime::Handle, account_id: &AccountId) -> State
.join("../configs/swarm/executor.wasm");
let wasm = std::fs::read(&path_to_executor)
.unwrap_or_else(|_| panic!("Failed to read file: {}", path_to_executor.display()));
let executor = Executor::new(WasmSmartContract::from_compiled(wasm));
let executor = Executor::new(SmartContract::from_compiled(wasm));
Upgrade::new(executor)
.execute(account_id, &mut state_transaction)
.expect("Failed to load executor");
Expand Down
4 changes: 2 additions & 2 deletions core/benches/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ fn build_test_and_transient_state() -> State {
let mut state_transaction = state_block.transaction();
let path_to_executor = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../configs/swarm/executor.wasm");
let wasm = std::fs::read(&path_to_executor)
let smart_contract = std::fs::read(&path_to_executor)
.unwrap_or_else(|_| panic!("Failed to read file: {}", path_to_executor.display()));
let executor = Executor::new(WasmSmartContract::from_compiled(wasm));
let executor = Executor::new(SmartContract::from_compiled(smart_contract));
let (authority, _authority_keypair) = gen_account_in("genesis");
Upgrade::new(executor)
.execute(&authority, &mut state_transaction)
Expand Down
2 changes: 1 addition & 1 deletion core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl LoadedExecutor {
raw_executor: data_model_executor::Executor,
) -> Result<Self, wasm::error::Error> {
Ok(Self {
module: wasm::load_module(engine, &raw_executor.wasm)?,
module: wasm::load_module(engine, &raw_executor.smart_contract)?,
raw_executor,
})
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/triggers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub mod isi {
.map_err(|e: &str| Error::Conversion(e.to_owned()))?,
),
}
.map_err(|e| InvalidParameterError::Wasm(e.to_string()))?;
.map_err(|e| InvalidParameterError::SmartContract(e.to_string()))?;

if !success {
return Err(RepetitionError {
Expand Down
Loading

0 comments on commit d69b1b2

Please sign in to comment.