Skip to content

Commit

Permalink
fixes after second review
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiuosvat committed Dec 3, 2024
1 parent ba9c32c commit e0d1c94
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 56 deletions.
12 changes: 6 additions & 6 deletions common/interactor/src/interactor_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const STATE_FILE: &str = "state.toml";

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct State {
contract_address: Option<Bech32Address>,
esdt_safe_address: Option<Bech32Address>,
header_verifier_address: Option<Bech32Address>,
fee_market_address: Option<Bech32Address>,
token_handler_address: Option<Bech32Address>,
Expand All @@ -30,8 +30,8 @@ impl State {
}

/// Sets the contract address
pub fn set_address(&mut self, address: Bech32Address) {
self.contract_address = Some(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) {
Expand All @@ -51,10 +51,10 @@ impl State {
}

/// Returns the contract address
pub fn current_address(&self) -> &Bech32Address {
self.contract_address
pub fn esdt_safe_address(&self) -> &Bech32Address {
self.esdt_safe_address
.as_ref()
.expect("no known contract, deploy first")
.expect("no known esdt_safe contract, deploy first")
}

pub fn get_header_verifier_address(&self) -> &Bech32Address {
Expand Down
2 changes: 2 additions & 0 deletions enshrine-esdt-safe/interactor/.gitignore
Original file line number Diff line number Diff line change
@@ -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
49 changes: 25 additions & 24 deletions enshrine-esdt-safe/interactor/src/enshrine_esdt_safe_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ 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}");
}
Expand Down Expand Up @@ -172,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()
Expand Down Expand Up @@ -226,7 +227,7 @@ impl ContractInteract {
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)
Expand All @@ -247,7 +248,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_fee_market_address(fee_market_address)
Expand All @@ -265,7 +266,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_header_verifier_address(header_verifier_address)
Expand All @@ -283,7 +284,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_user_tx_gas_limit(max_user_tx_gas_limit)
Expand All @@ -301,7 +302,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_banned_endpoint(endpoint_name)
Expand Down Expand Up @@ -338,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)
Expand All @@ -351,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)
Expand All @@ -374,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)
Expand All @@ -396,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)
Expand All @@ -420,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)
Expand All @@ -437,7 +438,7 @@ impl ContractInteract {
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)
Expand Down Expand Up @@ -468,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)
Expand All @@ -486,7 +487,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)
.remove_tokens_from_whitelist(tokens)
Expand All @@ -504,7 +505,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_blacklist(tokens)
Expand All @@ -522,7 +523,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)
.remove_tokens_from_blacklist(tokens)
Expand All @@ -537,7 +538,7 @@ impl ContractInteract {
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)
Expand All @@ -551,7 +552,7 @@ impl ContractInteract {
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)
Expand All @@ -566,7 +567,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)
.pause_endpoint()
Expand All @@ -582,7 +583,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)
.unpause_endpoint()
Expand All @@ -597,7 +598,7 @@ impl ContractInteract {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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.current_address().clone();
let to_contract = interact.state.esdt_safe_address().clone();
let transfer_data = OptionalTransferData::None;

interact.deploy_setup().await;
Expand All @@ -54,7 +54,7 @@ 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.current_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),
Expand Down Expand Up @@ -125,10 +125,10 @@ async fn test_deposit_sov_chain() {
.interactor
.tx()
.from(interact.wallet_address)
.to(interact.state.current_address())
.to(interact.state.esdt_safe_address())
.gas(30_000_000u64)
.typed(enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy)
.deposit(interact.state.current_address(), transfer_data)
.deposit(interact.state.esdt_safe_address(), transfer_data)
.payment(payments)
.returns(ReturnsResultUnmanaged)
.run()
Expand Down
2 changes: 2 additions & 0 deletions esdt-safe/interactor/.gitignore
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit e0d1c94

Please sign in to comment.