diff --git a/Cargo.lock b/Cargo.lock index 61739eaf..47203c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,6 +517,29 @@ dependencies = [ "multiversx-sc-meta-lib", ] +[[package]] +name = "enshrine_esdt_safe_interactor" +version = "0.0.0" +dependencies = [ + "clap", + "enshrine-esdt-safe", + "fee-market", + "header-verifier", + "interactor", + "max-bridged-amount-module", + "multiversx-sc", + "multiversx-sc-snippets", + "proxies", + "serde", + "setup-phase", + "token-handler", + "token-whitelist", + "toml", + "transaction", + "tx-batch-module", + "utils", +] + [[package]] name = "env_filter" version = "0.1.2" @@ -577,6 +600,24 @@ dependencies = [ "utils", ] +[[package]] +name = "esdt-safe-interactor" +version = "0.0.0" +dependencies = [ + "clap", + "esdt-safe", + "fee-market", + "interactor", + "multiversx-sc", + "multiversx-sc-scenario", + "multiversx-sc-snippets", + "proxies", + "serde", + "toml", + "transaction", + "tx-batch-module", +] + [[package]] name = "esdt-safe-meta" version = "0.0.0" @@ -1096,6 +1137,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "interactor" +version = "0.1.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-snippets", + "serde", + "toml", +] + [[package]] name = "ipnet" version = "2.10.1" @@ -1824,45 +1875,6 @@ dependencies = [ "windows-registry", ] -[[package]] -name = "rust-interact" -version = "0.0.0" -dependencies = [ - "clap", - "esdt-safe", - "fee-market", - "multiversx-sc", - "multiversx-sc-scenario", - "multiversx-sc-snippets", - "proxies", - "serde", - "toml", - "transaction", - "tx-batch-module", -] - -[[package]] -name = "rust-interact-esdt-safe" -version = "0.0.0" -dependencies = [ - "clap", - "enshrine-esdt-safe", - "fee-market", - "header-verifier", - "max-bridged-amount-module", - "multiversx-sc", - "multiversx-sc-snippets", - "proxies", - "serde", - "setup-phase", - "token-handler", - "token-whitelist", - "toml", - "transaction", - "tx-batch-module", - "utils", -] - [[package]] name = "rustc-demangle" version = "0.1.24" diff --git a/common/interactor/Cargo.toml b/common/interactor/Cargo.toml new file mode 100644 index 00000000..14acbe64 --- /dev/null +++ b/common/interactor/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "interactor" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies] +toml = "0.8.6" + +[dependencies.multiversx-sc] +version = "=0.54.5" + +[dependencies.multiversx-sc-snippets] +version = "=0.54.5" + +[dependencies.serde] +version = "1.0" +features = ["derive"] + + + diff --git a/common/interactor/src/constants.rs b/common/interactor/src/constants.rs new file mode 100644 index 00000000..c2add14a --- /dev/null +++ b/common/interactor/src/constants.rs @@ -0,0 +1,4 @@ +pub const TOKEN_ID: &[u8] = b"SVT-805b28"; +pub const WHITELIST_TOKEN_ID: &[u8] = b"CHOCOLATE-daf625"; +pub const TOKEN_ID_FOR_EXECUTE: &[u8] = b"x-SOV-101252"; +pub const WHITELISTED_TOKEN_ID: &[u8] = b"CHOCOLATE-daf625"; diff --git a/enshrine-esdt-safe/interactor/src/config.rs b/common/interactor/src/interactor_config.rs similarity index 94% rename from enshrine-esdt-safe/interactor/src/config.rs rename to common/interactor/src/interactor_config.rs index 4bf7c7d1..c78c4fcf 100644 --- a/enshrine-esdt-safe/interactor/src/config.rs +++ b/common/interactor/src/interactor_config.rs @@ -3,29 +3,26 @@ use serde::Deserialize; use std::io::Read; - /// Config file const CONFIG_FILE: &str = "config.toml"; - #[derive(Debug, Deserialize)] #[serde(rename_all = "lowercase")] pub enum ChainType { Real, Simulator, - } +} /// Contract Interact configuration #[derive(Debug, Deserialize)] pub struct Config { pub gateway_uri: String, pub chain_type: ChainType, - } - +} impl Config { // Deserializes config from file - pub fn new() -> Self { + pub fn load_config() -> Self { let mut file = std::fs::File::open(CONFIG_FILE).unwrap(); let mut content = String::new(); file.read_to_string(&mut content).unwrap(); @@ -36,7 +33,7 @@ impl Config { Config { gateway_uri: "http://localhost:8085".to_owned(), chain_type: ChainType::Simulator, - } + } } // Returns the gateway URI @@ -49,8 +46,6 @@ impl Config { match self.chain_type { ChainType::Real => false, ChainType::Simulator => true, + } } - } - } - - +} diff --git a/common/interactor/src/interactor_state.rs b/common/interactor/src/interactor_state.rs new file mode 100644 index 00000000..b67adb93 --- /dev/null +++ b/common/interactor/src/interactor_state.rs @@ -0,0 +1,90 @@ +use multiversx_sc_snippets::imports::*; +use serde::{Deserialize, Serialize}; +use std::{ + io::{Read, Write}, + path::Path, +}; + +const STATE_FILE: &str = "state.toml"; + +#[derive(Debug, Default, Serialize, Deserialize)] +pub struct State { + esdt_safe_address: Option, + header_verifier_address: Option, + fee_market_address: Option, + token_handler_address: Option, + testing_sc_address: Option, +} + +impl State { + // Deserializes state from file + pub fn load_state() -> Self { + if Path::new(STATE_FILE).exists() { + let mut file = std::fs::File::open(STATE_FILE).unwrap(); + let mut content = String::new(); + file.read_to_string(&mut content).unwrap(); + toml::from_str(&content).unwrap() + } else { + Self::default() + } + } + + /// Sets the contract address + pub fn set_esdt_safe_address(&mut self, address: Bech32Address) { + self.esdt_safe_address = Some(address); + } + + pub fn set_header_verifier_address(&mut self, address: Bech32Address) { + self.header_verifier_address = Some(address); + } + + pub fn set_fee_market_address(&mut self, address: Bech32Address) { + self.fee_market_address = Some(address); + } + + pub fn set_token_handler_address(&mut self, address: Bech32Address) { + self.token_handler_address = Some(address); + } + + pub fn set_testing_sc_address(&mut self, address: Bech32Address) { + self.testing_sc_address = Some(address); + } + + /// Returns the contract address + pub fn esdt_safe_address(&self) -> &Bech32Address { + self.esdt_safe_address + .as_ref() + .expect("no known esdt_safe contract, deploy first") + } + + pub fn get_header_verifier_address(&self) -> &Bech32Address { + self.header_verifier_address + .as_ref() + .expect("no known header verifier, deploy first") + } + + pub fn get_fee_market_address(&self) -> &Bech32Address { + self.fee_market_address + .as_ref() + .expect("no known fee market, deploy first") + } + + pub fn get_token_handler_address(&self) -> &Bech32Address { + self.token_handler_address + .as_ref() + .expect("no known token handler, deploy first") + } + + pub fn get_testing_sc_address(&self) -> Address { + self.testing_sc_address.clone().unwrap().to_address() + } +} + +impl Drop for State { + // Serializes state to file + fn drop(&mut self) { + let mut file = std::fs::File::create(STATE_FILE).unwrap(); + file.write_all(toml::to_string(self).unwrap().as_bytes()) + .unwrap(); + } +} diff --git a/common/interactor/src/lib.rs b/common/interactor/src/lib.rs new file mode 100644 index 00000000..9dc2742c --- /dev/null +++ b/common/interactor/src/lib.rs @@ -0,0 +1,3 @@ +pub mod interactor_config; +pub mod interactor_state; +pub mod constants; \ No newline at end of file diff --git a/enshrine-esdt-safe/interactor/.gitignore b/enshrine-esdt-safe/interactor/.gitignore index 5a64d09a..2864adf8 100644 --- a/enshrine-esdt-safe/interactor/.gitignore +++ b/enshrine-esdt-safe/interactor/.gitignore @@ -1,2 +1,4 @@ # Pem files are used for interactions, but shouldn't be committed *.pem +# State files are used for interactions, but shouldn't be committed +*state.toml \ No newline at end of file diff --git a/enshrine-esdt-safe/interactor/Cargo.toml b/enshrine-esdt-safe/interactor/Cargo.toml index 654c3bcb..a269581a 100644 --- a/enshrine-esdt-safe/interactor/Cargo.toml +++ b/enshrine-esdt-safe/interactor/Cargo.toml @@ -1,14 +1,17 @@ [[bin]] -name = "rust-interact-esdt-safe" -path = "src/interactor_main.rs" +name = "enshrine_esdt_safe_interactor" +path = "src/enshrine_esdt_safe_interactor_main.rs" [package] -name = "rust-interact-esdt-safe" +name = "enshrine_esdt_safe_interactor" version = "0.0.0" authors = ["you"] edition = "2021" publish = false +[lib] +path = "src/enshrine_esdt_safe_interactor.rs" + [dependencies] toml = "0.8.6" @@ -30,6 +33,9 @@ path = "../../common/setup-phase" [dependencies.token-whitelist] path = "../../common/token-whitelist" +[dependencies.interactor] +path = "../../common/interactor" + [dependencies.utils] path = "../../common/utils" @@ -58,3 +64,6 @@ features = ["derive"] [dependencies.serde] version = "1.0" features = ["derive"] + +[features] +chain-simulator-tests = [] diff --git a/enshrine-esdt-safe/interactor/src/interactor_main.rs b/enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor.rs similarity index 63% rename from enshrine-esdt-safe/interactor/src/interactor_main.rs rename to enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor.rs index 9c7bd7ba..2a673bef 100644 --- a/enshrine-esdt-safe/interactor/src/interactor_main.rs +++ b/enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor.rs @@ -1,23 +1,14 @@ #![allow(non_snake_case)] -// TO DO: remove when all tests are implemented -#![allow(dead_code)] +#![allow(unused)] -mod config; - -use config::Config; use fee_market_proxy::*; +use interactor::constants::{TOKEN_ID, WHITELIST_TOKEN_ID}; +use interactor::interactor_config::Config; +use interactor::interactor_state::State; use multiversx_sc_snippets::imports::*; use proxies::*; -use serde::{Deserialize, Serialize}; -use std::{ - io::{Read, Write}, - path::Path, -}; use transaction::*; -const STATE_FILE: &str = "state.toml"; -const TOKEN_ID: &[u8] = b"SVT-805b28"; -const WHITELIST_TOKEN_ID: &[u8] = b"CHOCOLATE-daf625"; const FEE_MARKET_CODE_PATH: &str = "../fee-market/output/fee-market.mxsc.json"; const HEADER_VERIFIER_CODE_PATH: &str = "../header-verifier/output/header-verifier.mxsc.json"; const ENSHRINE_ESDT_SAFE_CODE_PATH: &str = "output/enshrine-esdt-safe.mxsc.json"; @@ -26,14 +17,15 @@ const TOKEN_HANDLER_CODE_PATH: &str = "../token-handler/output/token-handler.mxs type OptionalTransferData = OptionalValue, ManagedVec>>>; -#[tokio::main] -async fn main() { +pub async fn enshrine_esdt_safe_cli() { env_logger::init(); let mut args = std::env::args(); let _ = args.next(); let cmd = args.next().expect("at least one argument required"); - let mut interact = ContractInteract::new().await; + + let config = Config::load_config(); + let mut interact = ContractInteract::new(config).await; match cmd.as_str() { "deploy" => interact.deploy(false).await, "upgrade" => interact.upgrade().await, @@ -63,79 +55,25 @@ async fn main() { } } -#[derive(Debug, Default, Serialize, Deserialize)] -struct State { - contract_address: Option, - header_verifier_address: Option, - fee_market_address: Option, - token_handler_address: Option, -} - -impl State { - // Deserializes state from file - pub fn load_state() -> Self { - if Path::new(STATE_FILE).exists() { - let mut file = std::fs::File::open(STATE_FILE).unwrap(); - let mut content = String::new(); - file.read_to_string(&mut content).unwrap(); - toml::from_str(&content).unwrap() - } else { - Self::default() - } - } - - /// Sets the contract address - pub fn set_address(&mut self, address: Bech32Address) { - self.contract_address = Some(address); - } - - pub fn set_header_verifier_address(&mut self, address: Bech32Address) { - self.header_verifier_address = Some(address); - } - - pub fn set_fee_market_address(&mut self, address: Bech32Address) { - self.fee_market_address = Some(address); - } - - pub fn set_token_handler_address(&mut self, address: Bech32Address) { - self.token_handler_address = Some(address); - } - - /// Returns the contract address - pub fn current_address(&self) -> &Bech32Address { - self.contract_address - .as_ref() - .expect("no known contract, deploy first") - } -} - -impl Drop for State { - // Serializes state to file - fn drop(&mut self) { - let mut file = std::fs::File::create(STATE_FILE).unwrap(); - file.write_all(toml::to_string(self).unwrap().as_bytes()) - .unwrap(); - } -} - -struct ContractInteract { - interactor: Interactor, - wallet_address: Address, - bob_address: Address, - alice_address: Address, - mike_address: Address, - judy_address: Address, +pub struct ContractInteract { + pub interactor: Interactor, + pub wallet_address: Address, + pub bob_address: Address, + pub alice_address: Address, + pub mike_address: Address, + pub judy_address: Address, enshrine_esdt_safe_code: String, token_handler_code: String, fee_market_code: String, header_verifier_code: String, - state: State, + pub state: State, } impl ContractInteract { - async fn new() -> Self { - let config = Config::new(); - let mut interactor = Interactor::new(config.gateway_uri()).await; + pub async fn new(config: Config) -> Self { + let mut interactor = Interactor::new(config.gateway_uri()) + .await + .use_chain_simulator(config.use_chain_simulator()); interactor.set_current_dir_from_workspace("enshrine-esdt-safe"); let wallet_address = interactor.register_wallet(test_wallets::frank()).await; @@ -159,16 +97,12 @@ impl ContractInteract { } } - async fn deploy(&mut self, is_sovereign_chain: bool) { + pub async fn deploy(&mut self, is_sovereign_chain: bool) { let opt_wegld_identifier = Option::Some(TokenIdentifier::from_esdt_bytes(WHITELIST_TOKEN_ID)); let opt_sov_token_prefix = Option::Some(ManagedBuffer::new_from_bytes(&b"sov"[..])); - let token_handler_address = managed_address!(self - .state - .token_handler_address - .clone() - .unwrap() - .as_address()); + let token_handler_address = + managed_address!(self.state.get_token_handler_address().as_address()); let code_path = MxscPath::new(self.enshrine_esdt_safe_code.as_ref()); let new_address = self @@ -188,14 +122,15 @@ impl ContractInteract { .run() .await; let new_address_bech32 = bech32::encode(&new_address); - self.state.set_address(Bech32Address::from_bech32_string( - new_address_bech32.clone(), - )); + self.state + .set_esdt_safe_address(Bech32Address::from_bech32_string( + new_address_bech32.clone(), + )); println!("new address: {new_address_bech32}"); } - async fn deploy_header_verifier(&mut self) { + pub async fn deploy_header_verifier(&mut self) { let bls_pub_key: ManagedBuffer = ManagedBuffer::new(); let mut bls_pub_keys = MultiValueEncoded::new(); bls_pub_keys.push(bls_pub_key); @@ -220,7 +155,7 @@ impl ContractInteract { println!("new header_verifier_address: {new_address_bech32}"); } - async fn deploy_fee_market(&mut self) { + pub async fn deploy_fee_market(&mut self) { let fee = FeeStruct { base_token: TokenIdentifier::from_esdt_bytes(TOKEN_ID), fee_type: FeeType::Fixed { @@ -238,7 +173,7 @@ impl ContractInteract { .from(&self.wallet_address) .gas(100_000_000u64) .typed(fee_market_proxy::FeeMarketProxy) - .init(self.state.current_address(), Option::Some(fee)) + .init(self.state.esdt_safe_address(), Option::Some(fee)) .code(fee_market_code_path) .returns(ReturnsNewAddress) .run() @@ -251,7 +186,7 @@ impl ContractInteract { println!("new fee_market_address: {new_address_bech32}"); } - async fn deploy_token_handler(&mut self) { + pub async fn deploy_token_handler(&mut self) { let token_handler_code_path = MxscPath::new(&self.token_handler_code); let new_address = self @@ -273,7 +208,7 @@ impl ContractInteract { println!("new token_handler_address: {new_address_bech32}"); } - async fn deploy_all(&mut self, is_sov_chain: bool) { + pub async fn deploy_all(&mut self, is_sov_chain: bool) { self.deploy_token_handler().await; self.deploy(is_sov_chain).await; self.deploy_header_verifier().await; @@ -281,18 +216,18 @@ impl ContractInteract { self.unpause_endpoint().await; } - async fn deploy_setup(&mut self) { + pub async fn deploy_setup(&mut self) { self.deploy_token_handler().await; self.deploy(false).await; self.unpause_endpoint().await; } - async fn upgrade(&mut self) { + pub async fn upgrade(&mut self) { let code_path = MxscPath::new(&self.enshrine_esdt_safe_code); let response = self .interactor .tx() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .from(&self.wallet_address) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) @@ -306,14 +241,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_fee_market_address(&mut self) { - let fee_market_address = self.state.fee_market_address.clone().unwrap(); + pub async fn set_fee_market_address(&mut self) { + let fee_market_address = self.state.get_fee_market_address(); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .set_fee_market_address(fee_market_address) @@ -324,14 +259,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_header_verifier_address(&mut self) { - let header_verifier_address = self.state.header_verifier_address.clone().unwrap(); + pub async fn set_header_verifier_address(&mut self) { + let header_verifier_address = self.state.get_header_verifier_address(); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .set_header_verifier_address(header_verifier_address) @@ -342,14 +277,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_max_user_tx_gas_limit(&mut self) { + pub async fn set_max_user_tx_gas_limit(&mut self) { let max_user_tx_gas_limit = 0u64; let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .set_max_user_tx_gas_limit(max_user_tx_gas_limit) @@ -360,14 +295,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_banned_endpoint(&mut self) { + pub async fn set_banned_endpoint(&mut self) { let endpoint_name = ManagedBuffer::new_from_bytes(&b""[..]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .set_banned_endpoint(endpoint_name) @@ -378,7 +313,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn deposit( + pub async fn deposit( &mut self, transfer_data: OptionalTransferData, error_wanted: Option>, @@ -404,7 +339,7 @@ impl ContractInteract { self.interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .deposit(to, transfer_data) @@ -417,7 +352,7 @@ impl ContractInteract { self.interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .deposit(to, transfer_data) @@ -428,7 +363,7 @@ impl ContractInteract { } } } - async fn execute_operations(&mut self) { + pub async fn execute_operations(&mut self) { let hash_of_hashes = ManagedBuffer::new_from_bytes(&b""[..]); let operation = Operation::new( ManagedAddress::zero(), @@ -440,7 +375,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .execute_operations(hash_of_hashes, operation) @@ -451,7 +386,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn register_new_token_id(&mut self) { + pub async fn register_new_token_id(&mut self) { let token_id = String::new(); let token_nonce = 0u64; let token_amount = BigUint::::from(0u128); @@ -462,7 +397,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .register_new_token_id(tokens) @@ -478,7 +413,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_max_bridged_amount(&mut self) { + pub async fn set_max_bridged_amount(&mut self) { let token_id = TokenIdentifier::from_esdt_bytes(&b""[..]); let max_amount = BigUint::::from(0u128); @@ -486,7 +421,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .set_max_bridged_amount(token_id, max_amount) @@ -497,13 +432,13 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn max_bridged_amount(&mut self) { + pub async fn max_bridged_amount(&mut self) { let token_id = TokenIdentifier::from_esdt_bytes(&b""[..]); let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .max_bridged_amount(token_id) .returns(ReturnsResultUnmanaged) @@ -513,7 +448,7 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn add_tokens_to_whitelist(&mut self, token_id: &[u8]) { + pub async fn add_tokens_to_whitelist(&mut self, token_id: &[u8]) { let tokens; match token_id { @@ -534,7 +469,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .add_tokens_to_whitelist(tokens) @@ -545,14 +480,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn remove_tokens_from_whitelist(&mut self) { + pub async fn remove_tokens_from_whitelist(&mut self) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(&b""[..])]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .remove_tokens_from_whitelist(tokens) @@ -563,14 +498,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn add_tokens_to_blacklist(&mut self) { + pub async fn add_tokens_to_blacklist(&mut self) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(&b""[..])]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .add_tokens_to_blacklist(tokens) @@ -581,14 +516,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn remove_tokens_from_blacklist(&mut self) { + pub async fn remove_tokens_from_blacklist(&mut self) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(&b""[..])]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .remove_tokens_from_blacklist(tokens) @@ -599,11 +534,11 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn token_whitelist(&mut self) { + pub async fn token_whitelist(&mut self) { let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .token_whitelist() .returns(ReturnsResultUnmanaged) @@ -613,11 +548,11 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn token_blacklist(&mut self) { + pub async fn token_blacklist(&mut self) { let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .token_blacklist() .returns(ReturnsResultUnmanaged) @@ -627,12 +562,12 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn pause_endpoint(&mut self) { + pub async fn pause_endpoint(&mut self) { let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .pause_endpoint() @@ -643,12 +578,12 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn unpause_endpoint(&mut self) { + pub async fn unpause_endpoint(&mut self) { let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .unpause_endpoint() @@ -659,11 +594,11 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn paused_status(&mut self) { + pub async fn paused_status(&mut self) { let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) .paused_status() .returns(ReturnsResultUnmanaged) @@ -673,186 +608,3 @@ impl ContractInteract { println!("Result: {result_value:?}"); } } - -#[tokio::test] -#[ignore] -async fn test_deploy() { - let mut interact = ContractInteract::new().await; - interact.deploy(false).await; -} - -#[tokio::test] -#[ignore] -async fn test_deposit_paused() { - let mut interact = ContractInteract::new().await; - interact.deploy_token_handler().await; - interact.deploy(false).await; - interact - .deposit( - OptionalTransferData::None, - Some(ExpectError(4, "Cannot create transaction while paused")), - ) - .await; -} - -#[tokio::test] -#[ignore] -async fn test_deposit_no_payment() { - let mut interact = ContractInteract::new().await; - let to = interact.bob_address.clone(); - let from = interact.wallet_address.clone(); - let to_contract = interact.state.current_address().clone(); - let transfer_data = OptionalTransferData::None; - - interact.deploy_setup().await; - - interact - .interactor - .tx() - .from(from) - .to(to_contract) - .gas(30_000_000u64) - .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) - .deposit(to, transfer_data) - .returns(ExpectError(4, "Nothing to transfer")) - .run() - .await; -} - -#[tokio::test] -#[ignore] -async fn test_deposit_too_many_payments() { - let mut interact = ContractInteract::new().await; - let to = interact.bob_address.clone(); - let from = interact.wallet_address.clone(); - let to_contract = interact.state.current_address().clone(); - let transfer_data = OptionalTransferData::None; - let payments = ManagedVec::from(vec![ - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ( - TokenIdentifier::from_esdt_bytes(TOKEN_ID), - 0u64, - BigUint::from(10u64), - ), - ]); - - interact.deploy_setup().await; - - interact - .interactor - .tx() - .from(from) - .to(to_contract) - .gas(30_000_000u64) - .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) - .deposit(to, transfer_data) - .payment(payments) - .returns(ExpectError(4, "Too many tokens")) - .run() - .await; -} - -#[tokio::test] -#[ignore] -async fn test_deposit_not_whitelisted() { - let mut interact = ContractInteract::new().await; - interact.deploy_setup().await; - interact.deploy_fee_market().await; - interact.add_tokens_to_whitelist(WHITELIST_TOKEN_ID).await; - interact.set_fee_market_address().await; - interact.deposit(OptionalTransferData::None, None).await; -} - -#[tokio::test] -#[ignore] -async fn test_deposit_happy_path() { - let mut interact = ContractInteract::new().await; - interact.deploy_setup().await; - interact.deploy_fee_market().await; - interact.add_tokens_to_whitelist(TOKEN_ID).await; - interact.set_fee_market_address().await; - interact.deposit(OptionalTransferData::None, None).await; -} - -// FAILS => Waiting for fixes (initiator address not set) -#[tokio::test] -#[ignore] -async fn test_deposit_sov_chain() { - let mut interact = ContractInteract::new().await; - let transfer_data = OptionalTransferData::None; - let mut payments = PaymentsVec::new(); - payments.push(EsdtTokenPayment::new( - TokenIdentifier::from(TOKEN_ID), - 0, - BigUint::from(10u64), - )); - payments.push(EsdtTokenPayment::new( - TokenIdentifier::from(TOKEN_ID), - 0, - BigUint::from(30u64), - )); - interact.deploy_all(true).await; - interact.add_tokens_to_whitelist(TOKEN_ID).await; - interact.set_fee_market_address().await; - interact - .interactor - .tx() - .from(interact.wallet_address) - .to(interact.state.current_address()) - .gas(30_000_000u64) - .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) - .deposit(interact.state.current_address(), transfer_data) - .payment(payments) - .returns(ReturnsResultUnmanaged) - .run() - .await; -} diff --git a/enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor_main.rs b/enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor_main.rs new file mode 100644 index 00000000..758010e7 --- /dev/null +++ b/enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor_main.rs @@ -0,0 +1,7 @@ +use multiversx_sc_snippets::imports::*; +use enshrine_esdt_safe_interactor::enshrine_esdt_safe_cli; + +#[tokio::main] +async fn main() { + enshrine_esdt_safe_cli().await; +} \ No newline at end of file diff --git a/enshrine-esdt-safe/interactor/src/proxy.rs b/enshrine-esdt-safe/interactor/src/proxy.rs deleted file mode 100644 index a87a274a..00000000 --- a/enshrine-esdt-safe/interactor/src/proxy.rs +++ /dev/null @@ -1,319 +0,0 @@ -// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -#![allow(dead_code)] -#![allow(clippy::all)] - -use multiversx_sc::proxy_imports::*; - -pub struct EnshrineEsdtSafeProxy; - -impl TxProxyTrait for EnshrineEsdtSafeProxy -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - type TxProxyMethods = EnshrineEsdtSafeProxyMethods; - - fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { - EnshrineEsdtSafeProxyMethods { wrapped_tx: tx } - } -} - -pub struct EnshrineEsdtSafeProxyMethods -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - wrapped_tx: Tx, -} - -#[rustfmt::skip] -impl EnshrineEsdtSafeProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - Gas: TxGas, -{ - pub fn init< - Arg0: ProxyArg, - Arg1: ProxyArg>, - Arg2: ProxyArg>>, - Arg3: ProxyArg>>, - >( - self, - is_sovereign_chain: Arg0, - token_handler_address: Arg1, - opt_wegld_identifier: Arg2, - opt_sov_token_prefix: Arg3, - ) -> TxTypedDeploy { - self.wrapped_tx - .payment(NotPayable) - .raw_deploy() - .argument(&is_sovereign_chain) - .argument(&token_handler_address) - .argument(&opt_wegld_identifier) - .argument(&opt_sov_token_prefix) - .original_result() - } -} - -#[rustfmt::skip] -impl EnshrineEsdtSafeProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn upgrade( - self, - ) -> TxTypedUpgrade { - self.wrapped_tx - .payment(NotPayable) - .raw_upgrade() - .original_result() - } -} - -#[rustfmt::skip] -impl EnshrineEsdtSafeProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn set_fee_market_address< - Arg0: ProxyArg>, - >( - self, - fee_market_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setFeeMarketAddress") - .argument(&fee_market_address) - .original_result() - } - - pub fn set_header_verifier_address< - Arg0: ProxyArg>, - >( - self, - header_verifier_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setHeaderVerifierAddress") - .argument(&header_verifier_address) - .original_result() - } - - pub fn set_max_user_tx_gas_limit< - Arg0: ProxyArg, - >( - self, - max_user_tx_gas_limit: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setMaxTxGasLimit") - .argument(&max_user_tx_gas_limit) - .original_result() - } - - pub fn set_banned_endpoint< - Arg0: ProxyArg>, - >( - self, - endpoint_name: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setBannedEndpoint") - .argument(&endpoint_name) - .original_result() - } - - pub fn deposit< - Arg0: ProxyArg>, - Arg1: ProxyArg, ManagedVec>>>>, - >( - self, - to: Arg0, - optional_transfer_data: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("deposit") - .argument(&to) - .argument(&optional_transfer_data) - .original_result() - } - - pub fn execute_operations< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - hash_of_hashes: Arg0, - operation: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("executeBridgeOps") - .argument(&hash_of_hashes) - .argument(&operation) - .original_result() - } - - pub fn register_new_token_id< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("registerNewTokenID") - .argument(&tokens) - .original_result() - } - - pub fn set_max_bridged_amount< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - token_id: Arg0, - max_amount: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setMaxBridgedAmount") - .argument(&token_id) - .argument(&max_amount) - .original_result() - } - - pub fn max_bridged_amount< - Arg0: ProxyArg>, - >( - self, - token_id: Arg0, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getMaxBridgedAmount") - .argument(&token_id) - .original_result() - } - - /// Tokens in the whitelist can be transferred without fees - pub fn add_tokens_to_whitelist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("addTokensToWhitelist") - .argument(&tokens) - .original_result() - } - - pub fn remove_tokens_from_whitelist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("removeTokensFromWhitelist") - .argument(&tokens) - .original_result() - } - - /// Tokens in blacklist cannot be transferred - pub fn add_tokens_to_blacklist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("addTokensToBlacklist") - .argument(&tokens) - .original_result() - } - - pub fn remove_tokens_from_blacklist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("removeTokensFromBlacklist") - .argument(&tokens) - .original_result() - } - - pub fn token_whitelist( - self, - ) -> TxTypedCall>> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getTokenWhitelist") - .original_result() - } - - pub fn token_blacklist( - self, - ) -> TxTypedCall>> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getTokenBlacklist") - .original_result() - } - - pub fn pause_endpoint( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("pause") - .original_result() - } - - pub fn unpause_endpoint( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("unpause") - .original_result() - } - - pub fn paused_status( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("isPaused") - .original_result() - } -} diff --git a/enshrine-esdt-safe/interactor/state.toml b/enshrine-esdt-safe/interactor/state.toml deleted file mode 100644 index 7bfeb9dd..00000000 --- a/enshrine-esdt-safe/interactor/state.toml +++ /dev/null @@ -1,4 +0,0 @@ -contract_address = "erd1qqqqqqqqqqqqqpgqv9hjetsqgz3smzv9hjd8sgp5sl5r0mm7t7as8gpl7v" -header_verifier_address = "erd1qqqqqqqqqqqqqpgqq83sadqyln9mlydwx87yznfz8rnduvkat7asgpej29" -fee_market_address = "erd1qqqqqqqqqqqqqpgqyztpp6zsdygld3sjcrrsdnjmduqrlkn2t7ases8slc" -token_handler_address = "erd1qqqqqqqqqqqqqpgq9n7uw2dauhhwd7xqqvt7x7ahkpswnhstt7asdr8ejx" diff --git a/enshrine-esdt-safe/interactor/tests/enshrine-esdt-safe_interactor_tests.rs b/enshrine-esdt-safe/interactor/tests/enshrine-esdt-safe_interactor_tests.rs new file mode 100644 index 00000000..6ec9d646 --- /dev/null +++ b/enshrine-esdt-safe/interactor/tests/enshrine-esdt-safe_interactor_tests.rs @@ -0,0 +1,136 @@ +use std::vec; + +use enshrine_esdt_safe_interactor::ContractInteract; +use interactor::constants::{TOKEN_ID, WHITELIST_TOKEN_ID}; +use interactor::interactor_config::Config; +use multiversx_sc_snippets::imports::*; +use proxies::*; +use transaction::*; + +type OptionalTransferData = + OptionalValue, ManagedVec>>>; + +#[tokio::test] +#[ignore] +async fn test_deposit_paused() { + let mut interact = ContractInteract::new(Config::load_config()).await; + interact.deploy_token_handler().await; + interact.deploy(false).await; + interact + .deposit( + OptionalTransferData::None, + Some(ExpectError(4, "Cannot create transaction while paused")), + ) + .await; +} + +#[tokio::test] +#[ignore] +async fn test_deposit_no_payment() { + let mut interact = ContractInteract::new(Config::load_config()).await; + let to = interact.bob_address.clone(); + let from = interact.wallet_address.clone(); + let to_contract = interact.state.esdt_safe_address().clone(); + let transfer_data = OptionalTransferData::None; + + interact.deploy_setup().await; + + interact + .interactor + .tx() + .from(from) + .to(to_contract) + .gas(30_000_000u64) + .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) + .deposit(to, transfer_data) + .returns(ExpectError(4, "Nothing to transfer")) + .run() + .await; +} + +#[tokio::test] +#[ignore] +async fn test_deposit_too_many_payments() { + let mut interact = ContractInteract::new(Config::load_config()).await; + let to = interact.bob_address.clone(); + let from = interact.wallet_address.clone(); + let to_contract = interact.state.esdt_safe_address().clone(); + let transfer_data = OptionalTransferData::None; + let payment = EsdtTokenPayment::new( + TokenIdentifier::from_esdt_bytes(TOKEN_ID), + 0u64, + BigUint::from(10u64), + ); + let payments = ManagedVec::from(vec![payment; 11]); + + interact.deploy_setup().await; + + interact + .interactor + .tx() + .from(from) + .to(to_contract) + .gas(30_000_000u64) + .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) + .deposit(to, transfer_data) + .payment(payments) + .returns(ExpectError(4, "Too many tokens")) + .run() + .await; +} + +#[tokio::test] +#[ignore] +async fn test_deposit_not_whitelisted() { + let mut interact = ContractInteract::new(Config::load_config()).await; + interact.deploy_setup().await; + interact.deploy_fee_market().await; + interact.add_tokens_to_whitelist(WHITELIST_TOKEN_ID).await; + interact.set_fee_market_address().await; + interact.deposit(OptionalTransferData::None, None).await; +} + +#[tokio::test] +#[ignore] +async fn test_deposit_happy_path() { + let mut interact = ContractInteract::new(Config::load_config()).await; + interact.deploy_setup().await; + interact.deploy_fee_market().await; + interact.add_tokens_to_whitelist(TOKEN_ID).await; + interact.set_fee_market_address().await; + interact.deposit(OptionalTransferData::None, None).await; +} + +// FAILS => Waiting for fixes (initiator address not set) +#[tokio::test] +#[ignore] +async fn test_deposit_sov_chain() { + let mut interact = ContractInteract::new(Config::load_config()).await; + let transfer_data = OptionalTransferData::None; + let mut payments = PaymentsVec::new(); + payments.push(EsdtTokenPayment::new( + TokenIdentifier::from(TOKEN_ID), + 0, + BigUint::from(10u64), + )); + payments.push(EsdtTokenPayment::new( + TokenIdentifier::from(TOKEN_ID), + 0, + BigUint::from(30u64), + )); + interact.deploy_all(true).await; + interact.add_tokens_to_whitelist(TOKEN_ID).await; + interact.set_fee_market_address().await; + interact + .interactor + .tx() + .from(interact.wallet_address) + .to(interact.state.esdt_safe_address()) + .gas(30_000_000u64) + .typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy) + .deposit(interact.state.esdt_safe_address(), transfer_data) + .payment(payments) + .returns(ReturnsResultUnmanaged) + .run() + .await; +} diff --git a/esdt-safe/interactor/.gitignore b/esdt-safe/interactor/.gitignore index 5a64d09a..2864adf8 100644 --- a/esdt-safe/interactor/.gitignore +++ b/esdt-safe/interactor/.gitignore @@ -1,2 +1,4 @@ # Pem files are used for interactions, but shouldn't be committed *.pem +# State files are used for interactions, but shouldn't be committed +*state.toml \ No newline at end of file diff --git a/esdt-safe/interactor/Cargo.toml b/esdt-safe/interactor/Cargo.toml index 52f3e346..c3ee7b51 100644 --- a/esdt-safe/interactor/Cargo.toml +++ b/esdt-safe/interactor/Cargo.toml @@ -1,14 +1,17 @@ [[bin]] -name = "rust-interact" -path = "src/interactor_main.rs" +name = "esdt-safe-interactor" +path = "src/esdt_safe_interactor_main.rs" [package] -name = "rust-interact" +name = "esdt-safe-interactor" version = "0.0.0" authors = ["you"] edition = "2021" publish = false +[lib] +path = "src/esdt_safe_interactor.rs" + [dependencies] toml = "0.8.6" @@ -24,6 +27,9 @@ path = "../../common/proxies" [dependencies.tx-batch-module] path = "../../common/tx-batch-module" +[dependencies.interactor] +path = "../../common/interactor" + [dependencies.fee-market] path = "../../fee-market" diff --git a/esdt-safe/interactor/config.toml b/esdt-safe/interactor/config.toml new file mode 100644 index 00000000..97acd5a5 --- /dev/null +++ b/esdt-safe/interactor/config.toml @@ -0,0 +1,7 @@ + +# chain_type = 'simulator' +# gateway_uri = 'http://localhost:8085' + +chain_type = 'real' +gateway_uri = 'https://devnet-gateway.multiversx.com' + diff --git a/esdt-safe/interactor/src/interactor_main.rs b/esdt-safe/interactor/src/esdt_safe_interactor.rs similarity index 74% rename from esdt-safe/interactor/src/interactor_main.rs rename to esdt-safe/interactor/src/esdt_safe_interactor.rs index 19fe784b..c19afc95 100644 --- a/esdt-safe/interactor/src/interactor_main.rs +++ b/esdt-safe/interactor/src/esdt_safe_interactor.rs @@ -1,7 +1,9 @@ #![allow(non_snake_case)] -// TODO: Remove this when interactor setup is complete -#![allow(dead_code)] +#![allow(unused)] +use interactor::constants::{TOKEN_ID, TOKEN_ID_FOR_EXECUTE}; +use interactor::interactor_config::*; +use interactor::interactor_state::State; use multiversx_sc_scenario::multiversx_chain_vm::crypto_functions::{sha256, SHA256_RESULT_LEN}; use multiversx_sc_scenario::scenario_model::TxResponseStatus; use multiversx_sc_snippets::imports::*; @@ -10,19 +12,9 @@ use proxies::esdt_safe_proxy::EsdtSafeProxy; use proxies::fee_market_proxy::{FeeMarketProxy, FeeStruct, FeeType}; use proxies::header_verifier_proxy::HeaderverifierProxy; use proxies::testing_sc_proxy::TestingScProxy; -use serde::{Deserialize, Serialize}; -use std::{ - io::{Read, Write}, - path::Path, -}; use transaction::{GasLimit, Operation, OperationData, PaymentsVec}; use transaction::{OperationEsdtPayment, TransferData}; -const GATEWAY: &str = sdk::gateway::DEVNET_GATEWAY; -const STATE_FILE: &str = "state.toml"; -const TOKEN_ID: &[u8] = b"SOV-101252"; -const TOKEN_ID_FOR_EXECUTE: &[u8] = b"x-SOV-101252"; -const WHITELISTED_TOKEN_ID: &[u8] = b"CHOCOLATE-daf625"; -const INTERACTOR_SCENARIO_TRACE_PATH: &str = "interactor_trace.scen.json"; + const FEE_MARKET_CODE_PATH: &str = "../../fee-market/output/fee-market.mxsc.json"; const HEADER_VERIFIER_CODE_PATH: &str = "../../header-verifier/output/header-verifier.mxsc.json"; const ESDT_SAFE_CODE_PATH: &str = "../output/esdt-safe.mxsc.json"; @@ -31,14 +23,14 @@ const TESTING_SC_CODE_PATH: &str = "../../testing-sc/output/testing-sc.mxsc.json type OptionalTransferData = OptionalValue, ManagedVec>>>; -#[tokio::main] -async fn main() { +pub async fn esdt_safe_cli() { env_logger::init(); let mut args = std::env::args(); let _ = args.next(); let cmd = args.next().expect("at least one argument required"); - let mut interact = ContractInteract::new().await; + let config = Config::load_config(); + let mut interact = ContractInteract::new(config).await; match cmd.as_str() { "deploy" => interact.deploy(false).await, "upgrade" => interact.upgrade().await, @@ -61,77 +53,10 @@ async fn main() { } } -#[derive(Debug, Default, Serialize, Deserialize)] -struct State { - contract_address: Option, - fee_market_address: Option, - header_verifier_address: Option, - testing_sc_address: Option, -} - -impl State { - // Deserializes state from file - pub fn load_state() -> Self { - if Path::new(STATE_FILE).exists() { - let mut file = std::fs::File::open(STATE_FILE).unwrap(); - let mut content = String::new(); - file.read_to_string(&mut content).unwrap(); - toml::from_str(&content).unwrap() - } else { - Self::default() - } - } - - /// Sets the contract address - pub fn set_address(&mut self, address: Bech32Address) { - self.contract_address = Some(address); - } - - pub fn set_fee_market_address(&mut self, address: Bech32Address) { - self.fee_market_address = Some(address); - } - - pub fn set_header_verifier_address(&mut self, address: Bech32Address) { - self.header_verifier_address = Some(address); - } - - pub fn set_testing_sc_address(&mut self, address: Bech32Address) { - self.testing_sc_address = Some(address); - } - - /// Returns the contract address - pub fn current_address(&self) -> &Bech32Address { - self.contract_address - .as_ref() - .expect("no known contract, deploy first") - } - - pub fn get_header_verifier_address(&self) -> Address { - self.header_verifier_address.clone().unwrap().to_address() - } - - pub fn get_fee_market_address(&self) -> Address { - self.fee_market_address.clone().unwrap().to_address() - } - - pub fn get_testing_sc_address(&self) -> Address { - self.testing_sc_address.clone().unwrap().to_address() - } -} - -impl Drop for State { - // Serializes state to file - fn drop(&mut self) { - let mut file = std::fs::File::create(STATE_FILE).unwrap(); - file.write_all(toml::to_string(self).unwrap().as_bytes()) - .unwrap(); - } -} - -struct ContractInteract { +pub struct ContractInteract { interactor: Interactor, wallet_address: Address, - frank_address: Address, + bob_address: Address, alice_address: Address, mike_address: Address, judy_address: Address, @@ -143,13 +68,15 @@ struct ContractInteract { } impl ContractInteract { - async fn new() -> Self { - let mut interactor = Interactor::new(GATEWAY).await; + pub async fn new(config: Config) -> Self { + let mut interactor = Interactor::new(config.gateway_uri()) + .await + .use_chain_simulator(config.use_chain_simulator()); interactor.set_current_dir_from_workspace("esdt-safe/interactor"); - let wallet_address = interactor.register_wallet(test_wallets::bob()).await; - let frank_address = interactor.register_wallet(test_wallets::frank()).await; + let wallet_address = interactor.register_wallet(test_wallets::frank()).await; + let bob_address = interactor.register_wallet(test_wallets::bob()).await; let alice_address = interactor.register_wallet(test_wallets::alice()).await; let mike_address = interactor.register_wallet(test_wallets::mike()).await; let judy_address = interactor.register_wallet(test_wallets::judy()).await; @@ -157,7 +84,7 @@ impl ContractInteract { ContractInteract { interactor, wallet_address, - frank_address, + bob_address, alice_address, mike_address, judy_address, @@ -169,7 +96,7 @@ impl ContractInteract { } } - async fn deploy(&mut self, is_sov_chain: bool) { + pub async fn deploy(&mut self, is_sov_chain: bool) { let code_path = MxscPath::new(self.esdt_safe_code.as_ref()); let new_address = self @@ -185,14 +112,14 @@ impl ContractInteract { .await; let new_address_bech32 = bech32::encode(&new_address); - self.state.set_address(Bech32Address::from_bech32_string( + self.state.set_esdt_safe_address(Bech32Address::from_bech32_string( new_address_bech32.clone(), )); println!("new address: {new_address_bech32}"); } - async fn deploy_fee_market(&mut self) { + pub async fn deploy_fee_market(&mut self) { let fee = FeeStruct { base_token: TokenIdentifier::from_esdt_bytes(TOKEN_ID), fee_type: FeeType::Fixed { @@ -209,7 +136,7 @@ impl ContractInteract { .from(&self.wallet_address) .gas(100_000_000u64) .typed(FeeMarketProxy) - .init(self.state.current_address(), Option::Some(fee)) + .init(self.state.esdt_safe_address(), Option::Some(fee)) .code(fee_market_code_path) .returns(ReturnsNewAddress) .run() @@ -223,7 +150,7 @@ impl ContractInteract { println!("new fee_market_address: {new_address_bech32}"); } - async fn deploy_header_verifier_contract(&mut self) { + pub async fn deploy_header_verifier_contract(&mut self) { let header_verifier_code_path = MxscPath::new(&self.header_verifier_code); let new_address = self @@ -247,7 +174,7 @@ impl ContractInteract { println!("new header_verifier_address: {new_address_bech32}"); } - async fn deploy_testing_contract(&mut self) { + pub async fn deploy_testing_contract(&mut self) { let testing_sc_code_path = MxscPath::new(&self.testing_sc_code); let new_address = self @@ -287,13 +214,13 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn upgrade(&mut self) { + pub async fn upgrade(&mut self) { let code_path = MxscPath::new(&self.esdt_safe_code); let response = self .interactor .tx() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .from(&self.wallet_address) .gas(30_000_000u64) .typed(EsdtSafeProxy) @@ -307,13 +234,13 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_fee_market_address(&mut self) { - let fee_market_address = self.state.fee_market_address.clone().unwrap(); + pub async fn set_fee_market_address(&mut self) { + let fee_market_address = self.state.get_fee_market_address(); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .set_fee_market_address(fee_market_address) @@ -324,14 +251,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_header_verifier_address(&mut self) { - let header_verifier_address = self.state.header_verifier_address.clone().unwrap(); + pub async fn set_header_verifier_address(&mut self) { + let header_verifier_address = self.state.get_header_verifier_address(); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .set_header_verifier_address(header_verifier_address) @@ -342,7 +269,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn deposit( + pub async fn deposit( &mut self, transfer_data: OptionalTransferData, expect_error: Option>, @@ -351,7 +278,7 @@ impl ContractInteract { let token_nonce = 0u64; let token_amount = BigUint::::from(20u64); - let to = &self.frank_address; + let to = &self.bob_address; let mut payments = PaymentsVec::new(); payments.push(EsdtTokenPayment::new( TokenIdentifier::from(token_id), @@ -364,7 +291,7 @@ impl ContractInteract { self.interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(90_000_000u64) .typed(EsdtSafeProxy) .deposit(to, transfer_data) @@ -377,7 +304,7 @@ impl ContractInteract { self.interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(90_000_000u64) .typed(EsdtSafeProxy) .deposit(to, transfer_data) @@ -389,7 +316,7 @@ impl ContractInteract { } } - async fn register_token(&mut self) { + pub async fn register_token(&mut self) { let egld_amount = BigUint::::from(50_000_000_000_000_000u64); let sov_token_id = TokenIdentifier::from_esdt_bytes(b"x-SOV-101252"); @@ -402,7 +329,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(90_000_000u64) .typed(EsdtSafeProxy) .register_token( @@ -420,7 +347,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn execute_operations( + pub async fn execute_operations( &mut self, operation: &Operation, expect_error: Option, @@ -431,7 +358,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(70_000_000u64) .typed(EsdtSafeProxy) .execute_operations(&hash_of_hashes, operation) @@ -444,10 +371,10 @@ impl ContractInteract { } } - async fn execute_operations_with_error(&mut self, error_msg: ExpectError<'_>) { + pub async fn execute_operations_with_error(&mut self, error_msg: ExpectError<'_>) { let tokens = self.setup_payments().await; let operation_data = self.setup_operation_data(false).await; - let to = managed_address!(&self.frank_address); + let to = managed_address!(&self.bob_address); //TO DO: make the "to" address a parameter let operation = Operation::new(to, tokens, operation_data); let operation_hash = self.get_operation_hash(&operation); @@ -455,7 +382,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .execute_operations(&operation_hash, operation) @@ -466,7 +393,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn set_max_bridged_amount(&mut self) { + pub async fn set_max_bridged_amount(&mut self) { let token_id = TokenIdentifier::from_esdt_bytes(&b""[..]); let max_amount = BigUint::::from(0u128); @@ -474,7 +401,7 @@ impl ContractInteract { .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .set_max_bridged_amount(token_id, max_amount) @@ -485,13 +412,13 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn max_bridged_amount(&mut self) { + pub async fn max_bridged_amount(&mut self) { let token_id = TokenIdentifier::from_esdt_bytes(&b""[..]); let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(EsdtSafeProxy) .max_bridged_amount(token_id) .returns(ReturnsResultUnmanaged) @@ -501,14 +428,14 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn add_tokens_to_whitelist(&mut self, token_id: &[u8]) { + pub async fn add_tokens_to_whitelist(&mut self, token_id: &[u8]) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(token_id)]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .add_tokens_to_whitelist(tokens) @@ -519,14 +446,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn remove_tokens_from_whitelist(&mut self) { + pub async fn remove_tokens_from_whitelist(&mut self) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(&b""[..])]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .remove_tokens_from_whitelist(tokens) @@ -537,14 +464,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn add_tokens_to_blacklist(&mut self, token_id: &[u8]) { + pub async fn add_tokens_to_blacklist(&mut self, token_id: &[u8]) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(token_id)]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .add_tokens_to_blacklist(tokens) @@ -555,14 +482,14 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn remove_tokens_from_blacklist(&mut self) { + pub async fn remove_tokens_from_blacklist(&mut self) { let tokens = MultiValueVec::from(vec![TokenIdentifier::from_esdt_bytes(&b""[..])]); let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .remove_tokens_from_blacklist(tokens) @@ -573,11 +500,11 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn token_whitelist(&mut self) { + pub async fn token_whitelist(&mut self) { let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(EsdtSafeProxy) .token_whitelist() .returns(ReturnsResultUnmanaged) @@ -587,11 +514,11 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn token_blacklist(&mut self) { + pub async fn token_blacklist(&mut self) { let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(EsdtSafeProxy) .token_blacklist() .returns(ReturnsResultUnmanaged) @@ -601,12 +528,12 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn pause_endpoint(&mut self) { + pub async fn pause_endpoint(&mut self) { let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .pause_endpoint() @@ -617,12 +544,12 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn unpause_endpoint(&mut self) { + pub async fn unpause_endpoint(&mut self) { let response = self .interactor .tx() .from(&self.wallet_address) - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .gas(30_000_000u64) .typed(EsdtSafeProxy) .unpause_endpoint() @@ -633,11 +560,11 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn paused_status(&mut self) { + pub async fn paused_status(&mut self) { let result_value = self .interactor .query() - .to(self.state.current_address()) + .to(self.state.esdt_safe_address()) .typed(EsdtSafeProxy) .paused_status() .returns(ReturnsResultUnmanaged) @@ -647,7 +574,7 @@ impl ContractInteract { println!("Result: {result_value:?}"); } - async fn remove_fee(&mut self) { + pub async fn remove_fee(&mut self) { let response = self .interactor .tx() @@ -663,7 +590,7 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn header_verifier_set_esdt_address(&mut self) { + pub async fn header_verifier_set_esdt_address(&mut self) { let response = self .interactor .tx() @@ -671,14 +598,14 @@ impl ContractInteract { .to(self.state.get_header_verifier_address()) .gas(30_000_000u64) .typed(HeaderverifierProxy) - .set_esdt_safe_address(self.state.current_address()) + .set_esdt_safe_address(self.state.esdt_safe_address()) .run() .await; println!("Result: {response:?}"); } - async fn setup_operation(&mut self, has_transfer_data: bool) -> Operation { + pub async fn setup_operation(&mut self, has_transfer_data: bool) -> Operation { let to = managed_address!(&self.state.get_testing_sc_address()); let payments = self.setup_payments().await; @@ -687,7 +614,10 @@ impl ContractInteract { Operation::new(to, payments, operation_data) } - async fn setup_operation_data(&mut self, has_transfer_data: bool) -> OperationData { + pub async fn setup_operation_data( + &mut self, + has_transfer_data: bool, + ) -> OperationData { let op_sender = managed_address!(&self.wallet_address); let transfer_data = if has_transfer_data { @@ -713,7 +643,7 @@ impl ContractInteract { operation_data } - async fn register_operations(&mut self, operation: &Operation) { + pub async fn register_operations(&mut self, operation: &Operation) { let bls_signature = ManagedBuffer::new(); let operation_hash = self.get_operation_hash(operation); let hash_of_hashes = sha256(&operation_hash); @@ -746,7 +676,9 @@ impl ContractInteract { println!("Result: {response:?}"); } - async fn setup_payments(&mut self) -> ManagedVec> { + pub async fn setup_payments( + &mut self, + ) -> ManagedVec> { let mut tokens: ManagedVec> = ManagedVec::new(); let token_ids = vec![TOKEN_ID_FOR_EXECUTE]; @@ -761,7 +693,7 @@ impl ContractInteract { hash: ManagedBuffer::new(), name: ManagedBuffer::from("SovToken"), attributes: ManagedBuffer::new(), - creator: managed_address!(&self.frank_address), + creator: managed_address!(&self.bob_address), royalties: BigUint::zero(), uris: ManagedVec::new(), }, @@ -773,13 +705,16 @@ impl ContractInteract { tokens } - fn get_operation_hash(&mut self, operation: &Operation) -> [u8; SHA256_RESULT_LEN] { + pub fn get_operation_hash( + &mut self, + operation: &Operation, + ) -> [u8; SHA256_RESULT_LEN] { let mut serialized_operation: ManagedBuffer = ManagedBuffer::new(); let _ = operation.top_encode(&mut serialized_operation); sha256(&serialized_operation.to_vec()) } - fn get_hash(&mut self, operation: &ManagedBuffer) -> ManagedBuffer { + pub fn get_hash(&mut self, operation: &ManagedBuffer) -> ManagedBuffer { let mut array = [0; 1024]; let len = { @@ -793,31 +728,3 @@ impl ContractInteract { ManagedBuffer::from(&hash) } } - -#[tokio::test] -#[ignore] -async fn test_deploy_sov() { - let mut interact = ContractInteract::new().await; - interact.deploy(false).await; - interact.deploy_fee_market().await; - interact.set_fee_market_address().await; - interact.remove_fee().await; - interact.deploy_header_verifier_contract().await; - interact.set_header_verifier_address().await; - interact.unpause_endpoint().await; - interact.header_verifier_set_esdt_address().await; - interact.deploy_testing_contract().await; - interact.register_token().await; - - let operation = interact.setup_operation(true).await; - interact.register_operations(&operation).await; - interact - .execute_operations( - &operation, - Some(TxResponseStatus::new( - ReturnCode::UserError, - "Value should be greater than 0", - )), - ) - .await; -} diff --git a/esdt-safe/interactor/src/esdt_safe_interactor_main.rs b/esdt-safe/interactor/src/esdt_safe_interactor_main.rs new file mode 100644 index 00000000..d6c7b406 --- /dev/null +++ b/esdt-safe/interactor/src/esdt_safe_interactor_main.rs @@ -0,0 +1,7 @@ +use esdt_safe_interactor::esdt_safe_cli; +use multiversx_sc_snippets::imports::*; + +#[tokio::main] +async fn main() { + esdt_safe_cli().await; +} diff --git a/esdt-safe/interactor/src/proxy.rs b/esdt-safe/interactor/src/proxy.rs deleted file mode 100644 index 6bbef655..00000000 --- a/esdt-safe/interactor/src/proxy.rs +++ /dev/null @@ -1,322 +0,0 @@ -// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -#![allow(dead_code)] -#![allow(clippy::all)] - -use multiversx_sc::proxy_imports::*; - -pub struct EsdtSafeProxy; - -impl TxProxyTrait for EsdtSafeProxy -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - type TxProxyMethods = EsdtSafeProxyMethods; - - fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { - EsdtSafeProxyMethods { wrapped_tx: tx } - } -} - -pub struct EsdtSafeProxyMethods -where - Env: TxEnv, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - wrapped_tx: Tx, -} - -#[rustfmt::skip] -impl EsdtSafeProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - Gas: TxGas, -{ - pub fn init< - Arg0: ProxyArg, - >( - self, - is_sovereign_chain: Arg0, - ) -> TxTypedDeploy { - self.wrapped_tx - .payment(NotPayable) - .raw_deploy() - .argument(&is_sovereign_chain) - .original_result() - } -} - -#[rustfmt::skip] -impl EsdtSafeProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn upgrade( - self, - ) -> TxTypedUpgrade { - self.wrapped_tx - .payment(NotPayable) - .raw_upgrade() - .original_result() - } -} - -#[rustfmt::skip] -impl EsdtSafeProxyMethods -where - Env: TxEnv, - Env::Api: VMApi, - From: TxFrom, - To: TxTo, - Gas: TxGas, -{ - pub fn set_fee_market_address< - Arg0: ProxyArg>, - >( - self, - fee_market_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setFeeMarketAddress") - .argument(&fee_market_address) - .original_result() - } - - pub fn set_header_verifier_address< - Arg0: ProxyArg>, - >( - self, - header_verifier_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setHeaderVerifierAddress") - .argument(&header_verifier_address) - .original_result() - } - - pub fn set_max_user_tx_gas_limit< - Arg0: ProxyArg, - >( - self, - max_user_tx_gas_limit: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setMaxTxGasLimit") - .argument(&max_user_tx_gas_limit) - .original_result() - } - - pub fn set_banned_endpoint< - Arg0: ProxyArg>, - >( - self, - endpoint_name: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setBannedEndpoint") - .argument(&endpoint_name) - .original_result() - } - - pub fn deposit< - Arg0: ProxyArg>, - Arg1: ProxyArg, ManagedVec>>>>, - >( - self, - to: Arg0, - optional_transfer_data: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("deposit") - .argument(&to) - .argument(&optional_transfer_data) - .original_result() - } - - pub fn register_token< - Arg0: ProxyArg>, - Arg1: ProxyArg, - Arg2: ProxyArg>, - Arg3: ProxyArg>, - Arg4: ProxyArg, - >( - self, - sov_token_id: Arg0, - token_type: Arg1, - token_display_name: Arg2, - token_ticker: Arg3, - num_decimals: Arg4, - ) -> TxTypedCall { - self.wrapped_tx - .raw_call("registerToken") - .argument(&sov_token_id) - .argument(&token_type) - .argument(&token_display_name) - .argument(&token_ticker) - .argument(&num_decimals) - .original_result() - } - - pub fn execute_operations< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - hash_of_hashes: Arg0, - operation: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("executeBridgeOps") - .argument(&hash_of_hashes) - .argument(&operation) - .original_result() - } - - pub fn set_max_bridged_amount< - Arg0: ProxyArg>, - Arg1: ProxyArg>, - >( - self, - token_id: Arg0, - max_amount: Arg1, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setMaxBridgedAmount") - .argument(&token_id) - .argument(&max_amount) - .original_result() - } - - pub fn max_bridged_amount< - Arg0: ProxyArg>, - >( - self, - token_id: Arg0, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getMaxBridgedAmount") - .argument(&token_id) - .original_result() - } - - /// Tokens in the whitelist can be transferred without fees - pub fn add_tokens_to_whitelist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("addTokensToWhitelist") - .argument(&tokens) - .original_result() - } - - pub fn remove_tokens_from_whitelist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("removeTokensFromWhitelist") - .argument(&tokens) - .original_result() - } - - /// Tokens in blacklist cannot be transferred - pub fn add_tokens_to_blacklist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("addTokensToBlacklist") - .argument(&tokens) - .original_result() - } - - pub fn remove_tokens_from_blacklist< - Arg0: ProxyArg>>, - >( - self, - tokens: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("removeTokensFromBlacklist") - .argument(&tokens) - .original_result() - } - - pub fn token_whitelist( - self, - ) -> TxTypedCall>> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getTokenWhitelist") - .original_result() - } - - pub fn token_blacklist( - self, - ) -> TxTypedCall>> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getTokenBlacklist") - .original_result() - } - - pub fn pause_endpoint( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("pause") - .original_result() - } - - pub fn unpause_endpoint( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("unpause") - .original_result() - } - - pub fn paused_status( - self, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("isPaused") - .original_result() - } -} diff --git a/esdt-safe/interactor/state.toml b/esdt-safe/interactor/state.toml deleted file mode 100644 index de90ec35..00000000 --- a/esdt-safe/interactor/state.toml +++ /dev/null @@ -1,5 +0,0 @@ -contract_address = "erd1qqqqqqqqqqqqqpgq3hmludfct68ucec93vdlw0ajdwrlyeetrruqaagvw9" -fee_market_address = "erd1qqqqqqqqqqqqqpgqna3dvxa8tz2556lr9jhsznpf6wf4la92rruqc6lgk4" -price_aggregator_address = "erd1qqqqqqqqqqqqqpgq4sshr5wx4ch5gd8847dsavahytt732kut7as6z3mv6" -header_verifier_address = "erd1qqqqqqqqqqqqqpgqe9lhyncklzx2lnruz8t4gdukpujn75w4rruqk0jdwr" -testing_sc_address = "erd1qqqqqqqqqqqqqpgq023jpszns80u0n5a5nuz09u7z87s4yx3rruqp2qryk" diff --git a/esdt-safe/interactor/tests/esdt_safe_interactor_tests.rs b/esdt-safe/interactor/tests/esdt_safe_interactor_tests.rs new file mode 100644 index 00000000..c9af7054 --- /dev/null +++ b/esdt-safe/interactor/tests/esdt_safe_interactor_tests.rs @@ -0,0 +1,33 @@ +use esdt_safe_interactor::ContractInteract; +use interactor::interactor_config::Config; +use multiversx_sc_scenario::imports::*; +use multiversx_sc_scenario::scenario_model::TxResponseStatus; +use multiversx_sc_snippets::imports::*; + +#[tokio::test] +#[ignore] +async fn test_deploy_sov() { + let mut interact = ContractInteract::new(Config::load_config()).await; + interact.deploy(false).await; + interact.deploy_fee_market().await; + interact.set_fee_market_address().await; + interact.remove_fee().await; + interact.deploy_header_verifier_contract().await; + interact.set_header_verifier_address().await; + interact.unpause_endpoint().await; + interact.header_verifier_set_esdt_address().await; + interact.deploy_testing_contract().await; + interact.register_token().await; + + let operation = interact.setup_operation(true).await; + interact.register_operations(&operation).await; + interact + .execute_operations( + &operation, + Some(TxResponseStatus::new( + ReturnCode::UserError, + "Value should be greater than 0", + )), + ) + .await; +}