Skip to content

Commit

Permalink
Merge pull request #1658 from multiversx/move-scenario-cli
Browse files Browse the repository at this point in the history
Moved scenario CLI to `sc-meta`
  • Loading branch information
andrei-marinica authored May 29, 2024
2 parents 0ecebc8 + 915df0b commit c81a6c4
Show file tree
Hide file tree
Showing 31 changed files with 95 additions and 112 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions framework/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ template-test-released = []

[dependencies]
clap = { version = "4.4.7", features = ["derive"] }
tokio = { version = "1.24", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = { version = "0.8.6", features = ["preserve_order"] }
Expand All @@ -39,13 +40,15 @@ copy_dir = "0.1.2"
pathdiff = "0.2.1"
common-path = "1.0.0"

[dependencies.multiversx-sc-meta-lib]
version = "=0.50.3"
path = "../meta-lib"

[dependencies.multiversx-sc]
version = "=0.50.3"
path = "../base"
features = ["alloc", "num-bigint"]


[dependencies.multiversx-sc-meta-lib]
[dependencies.multiversx-sc-snippets]
version = "=0.50.3"
path = "../meta-lib"

path = "../snippets"
33 changes: 25 additions & 8 deletions framework/meta/src/cli/cli_args_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct StandaloneCliArgs {

#[derive(Clone, PartialEq, Eq, Debug, Subcommand)]
pub enum StandaloneCliAction {
#[command(name = "install", about = "Installs framework dependencies")]
Install(InstallArgs),

#[command(
about = "General info about the contract an libraries residing in the targetted directory.."
)]
Expand All @@ -44,12 +47,6 @@ pub enum StandaloneCliAction {
)]
Upgrade(UpgradeArgs),

#[command(
name = "local-deps",
about = "Generates a report on the local depedencies of contract crates. Will explore indirect depdencies too."
)]
LocalDeps(LocalDepsArgs),

#[command(name = "new", about = "Creates a contract by a pre-existing template")]
Template(TemplateArgs),

Expand All @@ -68,8 +65,16 @@ pub enum StandaloneCliAction {
#[command(name = "test-coverage", about = "Run test coverage and output report")]
TestCoverage(TestCoverageArgs),

#[command(name = "install", about = "Installs framework dependencies")]
Install(InstallArgs),
#[command(
about = "Generates a scenario test initialized with real data fetched from the blockchain."
)]
Account(AccountArgs),

#[command(
name = "local-deps",
about = "Generates a report on the local depedencies of contract crates. Will explore indirect depdencies too."
)]
LocalDeps(LocalDepsArgs),
}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
Expand Down Expand Up @@ -326,3 +331,15 @@ pub struct InstallWasm32Args {}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct InstallWasmOptArgs {}

#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct AccountArgs {
/// Provide the target API you want the real data to come from
#[arg(long = "api")]
#[clap(global = true)]
pub api: Option<String>,

/// Provide the address you want to retrieve data from
#[arg(long = "address", verbatim_doc_comment)]
pub address: String,
}
14 changes: 9 additions & 5 deletions framework/meta/src/cli/cli_standalone_main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cli::{StandaloneCliAction, StandaloneCliArgs};
use crate::cmd::retrieve_address::retrieve_address;
use clap::Parser;

use crate::cmd::all::call_all_meta;
Expand All @@ -12,17 +13,15 @@ use crate::cmd::test_coverage::test_coverage;
use crate::cmd::upgrade::upgrade_sc;

/// Entry point in the program when calling it as a standalone tool.
pub fn cli_main_standalone() {
pub async fn cli_main_standalone() {
let cli_args = StandaloneCliArgs::parse();
match &cli_args.command {
Some(StandaloneCliAction::Info(args)) => call_info(args),
Some(StandaloneCliAction::Install(args)) => install(args),
Some(StandaloneCliAction::All(args)) => call_all_meta(args),
Some(StandaloneCliAction::Upgrade(args)) => {
upgrade_sc(args);
},
Some(StandaloneCliAction::LocalDeps(args)) => {
local_deps(args);
},
Some(StandaloneCliAction::Template(args)) => {
create_contract(args);
},
Expand All @@ -36,7 +35,12 @@ pub fn cli_main_standalone() {
Some(StandaloneCliAction::TestCoverage(args)) => {
test_coverage(args);
},
Some(StandaloneCliAction::Install(args)) => install(args),
Some(StandaloneCliAction::Account(args)) => {
retrieve_address(args).await;
},
Some(StandaloneCliAction::LocalDeps(args)) => {
local_deps(args);
},
None => {},
}
}
1 change: 1 addition & 0 deletions framework/meta/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod info;
pub mod install;
pub mod local_deps;
pub mod print_util;
pub mod retrieve_address;
pub mod scen_test_gen;
pub mod template;
pub mod test;
Expand Down
9 changes: 9 additions & 0 deletions framework/meta/src/cmd/retrieve_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use multiversx_sc_snippets::account_tool;

use crate::cli::AccountArgs;

/// Interprets arguments and call the account tool from `multiversx_sc_snippets`.
pub async fn retrieve_address(args: &AccountArgs) {
let api_string = args.api.clone().expect("API needs to be specified");
account_tool::print_account_as_scenario_set_state(api_string, args.address.to_string()).await;
}
5 changes: 3 additions & 2 deletions framework/meta/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fn main() {
multiversx_sc_meta::cli::cli_main_standalone();
#[tokio::main]
async fn main() {
multiversx_sc_meta::cli::cli_main_standalone().await;
}
4 changes: 0 additions & 4 deletions framework/scenario/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ clap = { version = "4.4.7", features = ["derive"] }
tokio = { version = "1.24", features = ["full"] }
unwrap-infallible = "0.1.5"

[[bin]]
name = "sc-scenario"
path = "src/main.rs"

[features]
run-go-tests = []

Expand Down
2 changes: 0 additions & 2 deletions framework/scenario/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub use crate::{
ScenarioRunner,
},
scenario_format::interpret_trait::{InterpretableFrom, InterpreterContext},
standalone::retrieve_account_as_scenario_set_state,
test_wallets,
whitebox_legacy::*,
ScenarioTxRun,
};
2 changes: 0 additions & 2 deletions framework/scenario/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ mod facade;
pub mod managed_test_util;
pub mod scenario;
pub mod scenario_macros;
pub mod standalone;
pub mod test_wallets;
mod vm_go_tool;

pub mod whitebox_legacy;
Expand Down
4 changes: 0 additions & 4 deletions framework/scenario/src/main.rs

This file was deleted.

5 changes: 0 additions & 5 deletions framework/scenario/src/standalone/mod.rs

This file was deleted.

51 changes: 0 additions & 51 deletions framework/scenario/src/standalone/scenario_cli.rs

This file was deleted.

4 changes: 4 additions & 0 deletions framework/snippets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ futures = "0.3"
version = "=0.50.3"
path = "../scenario"

[dependencies.multiversx-chain-scenario-format]
version = "0.22.2"
path = "../../sdk/scenario-format"

[dependencies.multiversx-sdk]
version = "=0.4.1"
path = "../../sdk/core"
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
use crate::{
use multiversx_chain_scenario_format::interpret_trait::IntoRaw;
use multiversx_sc_scenario::{
imports::Bech32Address,
scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep},
scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep, Step},
};

use multiversx_chain_scenario_format::interpret_trait::IntoRaw;
use multiversx_sdk::{
blockchain::CommunicationProxy,
data::{address::Address, esdt::EsdtBalance},
};
use std::collections::{BTreeMap, HashMap};

/// Called directly from CLI, from `sc-meta`.
///
/// Retrieves an account data via the API,
/// then formats it as a scenario set state step.
pub async fn print_account_as_scenario_set_state(
api: &CommunicationProxy,
address: &Bech32Address,
api_string: String,
address_bech32_string: String,
) {
let set_state = retrieve_account_as_scenario_set_state(api, address).await;
let api = CommunicationProxy::new(api_string);
let address = Bech32Address::from_bech32_string(address_bech32_string);
let set_state = retrieve_account_as_scenario_set_state(&api, &address).await;
let scenario = build_scenario(set_state);
println!("{}", scenario.into_raw().to_json_string());
}
Expand All @@ -24,7 +29,7 @@ fn build_scenario(set_state: SetStateStep) -> Scenario {
name: None,
comment: None,
check_gas: None,
steps: vec![crate::scenario_model::Step::SetState(set_state)],
steps: vec![Step::SetState(set_state)],
}
}

Expand Down Expand Up @@ -61,7 +66,7 @@ pub async fn retrieve_account_as_scenario_set_state(
set_state_step.put_account(address, account_state)
}

pub fn set_account(
fn set_account(
account: multiversx_sdk::data::account::Account,
account_storage: HashMap<String, String>,
account_esdt: HashMap<String, EsdtBalance>,
Expand All @@ -71,7 +76,7 @@ pub fn set_account(
.nonce(account.nonce)
.balance(account.balance.as_str())
.code(account.code);
account_state.username = Some(account.username.as_str().into());
account_state.username = Some(format!("str:{}", account.username.as_str()).into());
account_state.storage = convert_storage(account_storage);

for (_, esdt_balance) in account_esdt.iter() {
Expand Down
4 changes: 3 additions & 1 deletion framework/snippets/src/imports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub use crate::multiversx_sc_scenario::imports::*;

pub use crate::{dns_address_for_name, Interactor, InteractorPrepareAsync, StepBuffer};
pub use crate::{
dns_address_for_name, test_wallets, Interactor, InteractorPrepareAsync, StepBuffer,
};

pub use env_logger;
pub use tokio;
4 changes: 2 additions & 2 deletions framework/snippets/src/interactor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sc_scenario::{
imports::{retrieve_account_as_scenario_set_state, Bech32Address, ScenarioRunner},
imports::{Bech32Address, ScenarioRunner},
mandos_system::{run_list::ScenarioRunnerList, run_trace::ScenarioTraceFile},
multiversx_sc::types::Address,
scenario_model::AddressValue,
Expand All @@ -15,7 +15,7 @@ use std::{
time::Duration,
};

use crate::Sender;
use crate::{account_tool::retrieve_account_as_scenario_set_state, Sender};

pub const INTERACTOR_SCENARIO_TRACE_PATH: &str = "interactor_trace.scen.json";

Expand Down
2 changes: 2 additions & 0 deletions framework/snippets/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod account_tool;
mod interactor;
mod interactor_dns;
mod interactor_retrieve;
mod interactor_scenario;
mod interactor_sender;
mod interactor_tx;
mod multi;
pub mod test_wallets;

pub use env_logger;
pub use hex;
Expand Down
Loading

0 comments on commit c81a6c4

Please sign in to comment.