Skip to content

Commit

Permalink
Fixed cs test
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Baltariu <[email protected]>
  • Loading branch information
andreiblt1304 committed Dec 11, 2024
1 parent 769c41f commit b42d94a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
46 changes: 39 additions & 7 deletions sovereign-forge/interactor/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use config::Config;
use multiversx_sc_snippets::{imports::*, sdk::bech32};
use proxies::{
chain_config_proxy::ChainConfigContractProxy, chain_factory_proxy::ChainFactoryContractProxy,
header_verifier_proxy::HeaderverifierProxy, sovereign_forge_proxy::SovereignForgeProxy,
esdt_safe_proxy::EsdtSafeProxy, header_verifier_proxy::HeaderverifierProxy,
sovereign_forge_proxy::SovereignForgeProxy,
};
use serde::{Deserialize, Serialize};
use std::{
Expand All @@ -18,6 +19,7 @@ const STATE_FILE: &str = "state.toml";
const CHAIN_CONFIG_CODE_PATH: &str = "../../chain-config/output/chain-config.mxsc.json";
const CHAIN_FACTORY_CODE_PATH: &str = "../../chain-factory/output/chain-factory.mxsc.json";
const HEADER_VERIFIER_CODE_PATH: &str = "../../header-verifier/output/header-verifier.mxsc.json";
const ESDT_SAFE_CODE_PATH: &str = "../../esdt-safe/output/esdt-safe.mxsc.json";

pub async fn sovereign_forge_cli() {
env_logger::init();
Expand Down Expand Up @@ -47,6 +49,7 @@ pub struct State {
config_address: Option<Bech32Address>,
factory_address: Option<Bech32Address>,
header_verifier_address: Option<Bech32Address>,
esdt_safe_address: Option<Bech32Address>,
}

impl State {
Expand Down Expand Up @@ -82,6 +85,10 @@ impl State {
self.header_verifier_address = Some(address);
}

pub fn set_esdt_safe_address(&mut self, address: Bech32Address) {
self.esdt_safe_address = Some(address);
}

/// Returns the contract address
pub fn current_address(&self) -> &Bech32Address {
self.contract_address
Expand Down Expand Up @@ -161,6 +168,10 @@ impl ContractInteract {
self.convert_address_to_managed(self.state.header_verifier_address.clone());
let forge_managed_address =
self.convert_address_to_managed(self.state.contract_address.clone());
let config_managed_address =
self.convert_address_to_managed(self.state.config_address.clone());
let esdt_safe_managed_address =
self.convert_address_to_managed(self.state.esdt_safe_address.clone());

let new_address = self
.interactor
Expand All @@ -169,11 +180,11 @@ impl ContractInteract {
.gas(50_000_000u64)
.typed(ChainFactoryContractProxy)
.init(
forge_managed_address,
header_verifier_managed_address.clone(),
header_verifier_managed_address.clone(),
header_verifier_managed_address.clone(),
forge_managed_address.clone(),
config_managed_address,
header_verifier_managed_address,
esdt_safe_managed_address,
forge_managed_address, // USE ACTUAL FEE-MARKET TEMPLATE
)
.code(MxscPath::new(CHAIN_FACTORY_CODE_PATH))
.returns(ReturnsNewAddress)
Expand Down Expand Up @@ -248,6 +259,27 @@ impl ContractInteract {
println!("new Header-Verifier address: {new_address_bech32}");
}

pub async fn deploy_esdt_safe_template(&mut self) {
let new_address = self
.interactor
.tx()
.from(&self.wallet_address)
.gas(80_000_000u64)
.typed(EsdtSafeProxy)
.init(false)
.returns(ReturnsNewAddress)
.code(MxscPath::new(ESDT_SAFE_CODE_PATH))
.run()
.await;

let new_address_bech32 = bech32::encode(&new_address);
self.state
.set_esdt_safe_address(Bech32Address::from_bech32_string(
new_address_bech32.clone(),
));

println!("new Header-Verifier address: {new_address_bech32}");
}
pub async fn upgrade(&mut self) {
let response = self
.interactor
Expand All @@ -267,7 +299,7 @@ impl ContractInteract {
}

pub async fn register_token_handler(&mut self, shard_id: u32) {
let bech32 = &self.state.header_verifier_address.as_ref().unwrap();
let bech32 = &self.state.contract_address.as_ref().unwrap();
let address = bech32.to_address();
let token_handler_address = ManagedAddress::from(address);

Expand Down Expand Up @@ -383,7 +415,7 @@ impl ContractInteract {
.tx()
.from(&self.wallet_address)
.to(self.state.current_address())
.gas(30_000_000u64)
.gas(80_000_000u64)
.typed(SovereignForgeProxy)
.deploy_phase_three(is_sovereign_chain)
.returns(ReturnsResultUnmanaged)
Expand Down
9 changes: 5 additions & 4 deletions sovereign-forge/interactor/state.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
contract_address = "erd1qqqqqqqqqqqqqpgqp7savykx0n380r5fykpfg629dumcqm6ud8ss2rkes5"
config_address = "erd1qqqqqqqqqqqqqpgq4f6lm4mppra83zrz5r68f8ysutx7xqlrd8ssu2a8gu"
factory_address = "erd1qqqqqqqqqqqqqpgq55shtd9738tvtcndca46utay5wfqm84sd8sskm267y"
header_verifier_address = "erd1qqqqqqqqqqqqqpgqsl0phg7xmzhqmk768h9agrrscgm7qwudd8ssls3aq2"
contract_address = "erd1qqqqqqqqqqqqqpgqt54uz2y2frvy7fqet479a6efarnyw3yud8ssj6kyuz"
config_address = "erd1qqqqqqqqqqqqqpgqd3sm30pzrsqs2y7ct6368tlt94d6xvl6d8ssqhckfm"
factory_address = "erd1qqqqqqqqqqqqqpgq9xqda668zt76c8tvfqe9t39g7pz0j9t2d8sss3w65z"
header_verifier_address = "erd1qqqqqqqqqqqqqpgqlmtayq49qt94dj7gghagd7ap3d3htj76d8sszr0t7z"
esdt_safe_address = "erd1qqqqqqqqqqqqqpgqvxvmyp2fgr6qekksx8n6t8netkpweh28d8ssw9gwh8"
5 changes: 3 additions & 2 deletions sovereign-forge/interactor/tests/interact_cs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ async fn deploy_test_sovereign_forge_cs() {
let mut interactor = ContractInteract::new().await;
interactor.deploy().await;

interactor.deploy_chain_factory().await;
interactor.deploy_chain_config_template().await;
interactor.deploy_header_verifier_template().await;
interactor.deploy_chain_config_template().await;
interactor.deploy_esdt_safe_template().await;
interactor.deploy_chain_factory().await;

interactor.register_token_handler(1).await;
interactor.register_token_handler(2).await;
Expand Down

0 comments on commit b42d94a

Please sign in to comment.