Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Baltariu <[email protected]>
  • Loading branch information
andreiblt1304 committed Jan 8, 2025
1 parent 8ee18f1 commit 06c17a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 101 deletions.
60 changes: 15 additions & 45 deletions enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ pub async fn enshrine_esdt_safe_cli() {
let config = Config::load_config();
let mut interact = ContractInteract::new(config).await;
match cmd.as_str() {
"deploy" => interact.deploy(false, BridgeConfig::default_config()).await,
"deploy" => interact.deploy(false, None).await,
"upgrade" => interact.upgrade().await,
"setFeeMarketAddress" => interact.set_fee_market_address().await,
"setHeaderVerifierAddress" => interact.set_header_verifier_address().await,
"setMaxTxGasLimit" => interact.set_max_user_tx_gas_limit().await,
"setBannedEndpoint" => interact.set_banned_endpoint().await,
"deposit" => interact.deposit(None.into(), Option::None).await,
"executeBridgeOps" => interact.execute_operations().await,
"registerNewTokenID" => interact.register_new_token_id().await,
Expand Down Expand Up @@ -91,7 +89,11 @@ impl ContractInteract {
}
}

pub async fn deploy(&mut self, is_sovereign_chain: bool, config: BridgeConfig<StaticApi>) {
pub async fn deploy(
&mut self,
is_sovereign_chain: bool,
opt_config: Option<BridgeConfig<StaticApi>>,
) {
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"[..]));
Expand All @@ -110,7 +112,7 @@ impl ContractInteract {
token_handler_address,
opt_wegld_identifier,
opt_sov_token_prefix,
config,
opt_config,
)
.code(code_path)
.returns(ReturnsNewAddress)
Expand Down Expand Up @@ -204,17 +206,21 @@ impl ContractInteract {
println!("new token_handler_address: {new_address_bech32}");
}

pub async fn deploy_all(&mut self, is_sov_chain: bool, config: BridgeConfig<StaticApi>) {
pub async fn deploy_all(
&mut self,
is_sov_chain: bool,
opt_config: Option<BridgeConfig<StaticApi>>,
) {
self.deploy_token_handler().await;
self.deploy(is_sov_chain, config).await;
self.deploy(is_sov_chain, opt_config).await;
self.deploy_header_verifier().await;
self.deploy_fee_market().await;
self.unpause_endpoint().await;
}

pub async fn deploy_setup(&mut self, config: BridgeConfig<StaticApi>) {
pub async fn deploy_setup(&mut self, opt_config: Option<BridgeConfig<StaticApi>>) {
self.deploy_token_handler().await;
self.deploy(false, config).await;
self.deploy(false, opt_config).await;
self.unpause_endpoint().await;
}

Expand Down Expand Up @@ -273,42 +279,6 @@ impl ContractInteract {
println!("Result: {response:?}");
}

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.esdt_safe_address())
.gas(30_000_000u64)
.typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy)
.set_max_user_tx_gas_limit(max_user_tx_gas_limit)
.returns(ReturnsResultUnmanaged)
.run()
.await;

println!("Result: {response:?}");
}

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.esdt_safe_address())
.gas(30_000_000u64)
.typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy)
.set_banned_endpoint(endpoint_name)
.returns(ReturnsResultUnmanaged)
.run()
.await;

println!("Result: {response:?}");
}

pub async fn deposit(
&mut self,
transfer_data: OptionalTransferData<StaticApi>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type OptionalTransferData<M> =
async fn test_deposit_paused() {
let mut interact = ContractInteract::new(Config::load_config()).await;
interact.deploy_token_handler().await;
interact.deploy(false, BridgeConfig::default_config()).await;
interact.deploy(false, None).await;
interact
.deposit(
OptionalTransferData::None,
Expand All @@ -34,7 +34,7 @@ async fn test_deposit_no_payment() {
let to_contract = interact.state.esdt_safe_address().clone();
let transfer_data = OptionalTransferData::None;

interact.deploy_setup(BridgeConfig::default_config()).await;
interact.deploy_setup(None).await;

interact
.interactor
Expand Down Expand Up @@ -64,7 +64,7 @@ async fn test_deposit_too_many_payments() {
);
let payments = ManagedVec::from(vec![payment; 11]);

interact.deploy_setup(BridgeConfig::default_config()).await;
interact.deploy_setup(None).await;

interact
.interactor
Expand All @@ -84,7 +84,7 @@ async fn test_deposit_too_many_payments() {
#[ignore]
async fn test_deposit_not_whitelisted() {
let mut interact = ContractInteract::new(Config::load_config()).await;
interact.deploy_setup(BridgeConfig::default_config()).await;
interact.deploy_setup(None).await;
interact.deploy_fee_market().await;
interact.add_tokens_to_whitelist(WHITELIST_TOKEN_ID).await;
interact.set_fee_market_address().await;
Expand All @@ -95,7 +95,7 @@ async fn test_deposit_not_whitelisted() {
#[ignore]
async fn test_deposit_happy_path() {
let mut interact = ContractInteract::new(Config::load_config()).await;
interact.deploy_setup(BridgeConfig::default_config()).await;
interact.deploy_setup(None).await;
interact.deploy_fee_market().await;
interact.add_tokens_to_whitelist(TOKEN_ID).await;
interact.set_fee_market_address().await;
Expand All @@ -119,9 +119,7 @@ async fn test_deposit_sov_chain() {
0,
BigUint::from(30u64),
));
interact
.deploy_all(true, BridgeConfig::default_config())
.await;
interact.deploy_all(true, None).await;
interact.add_tokens_to_whitelist(TOKEN_ID).await;
interact.set_fee_market_address().await;
interact
Expand Down
Loading

0 comments on commit 06c17a3

Please sign in to comment.