Skip to content

Commit

Permalink
ping pong interactor - fix template
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaIalangi committed Oct 23, 2024
1 parent 5b4d37b commit 44b24f1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 52 deletions.
1 change: 0 additions & 1 deletion contracts/examples/ping-pong-egld/interactor/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Pem files are used for interactions, but shouldn't be committed
*.pem
*.json
!ping-pong-owner.pem

# Temporary storage of deployed contract address, so we can preserve the context between executions.
state.toml
Expand Down

This file was deleted.

67 changes: 27 additions & 40 deletions contracts/examples/ping-pong-egld/interactor/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod interact_state;
use crate::interact_state::State;
use clap::Parser;
pub use interact_config::Config;
use ping_pong_egld::ping_pong_egld_proxy::{self, ContractState, UserStatus};
use ping_pong_egld::proxy_ping_pong_egld::{self, ContractState, UserStatus};

use multiversx_sc_snippets::imports::*;

Expand Down Expand Up @@ -103,8 +103,7 @@ pub async fn ping_pong_egld_cli() {
pub struct PingPongEgldInteract {
pub interactor: Interactor,
pub ping_pong_owner_address: Bech32Address,
pub wallet_address_1: Bech32Address,
pub wallet_address_2: Bech32Address,
pub wallet_address: Bech32Address,
pub state: State,
}

Expand All @@ -115,39 +114,27 @@ impl PingPongEgldInteract {
.with_tracer(INTERACTOR_SCENARIO_TRACE_PATH)
.await;

let ping_pong_owner_address = interactor
.register_wallet(Wallet::from_pem_file("ping-pong-owner.pem").unwrap())
.await;
let wallet_address_1 = interactor
.register_wallet(Wallet::from_pem_file("wallet-address.pem").unwrap())
.await;
let wallet_address_2 = interactor.register_wallet(test_wallets::mallory()).await;
let ping_pong_owner_address = interactor.register_wallet(test_wallets::eve()).await;
let wallet_address = interactor.register_wallet(test_wallets::mallory()).await;

// generate blocks until ESDTSystemSCAddress is enabled
interactor.generate_blocks_until_epoch(1).await.unwrap();

Self {
interactor,
ping_pong_owner_address: ping_pong_owner_address.into(),
wallet_address_1: wallet_address_1.into(),
wallet_address_2: wallet_address_2.into(),
wallet_address: wallet_address.into(),
state: State::load_state(),
}
}

pub async fn set_state(&mut self) {
println!("ping pong owner address: {}", self.ping_pong_owner_address);
println!("wallet_1 address: {}", self.wallet_address_1);
println!("wallet_2 address: {}", self.wallet_address_2);
println!("wallet address: {}", self.wallet_address);
self.interactor
.retrieve_account(&self.ping_pong_owner_address)
.await;
self.interactor
.retrieve_account(&self.wallet_address_1)
.await;
self.interactor
.retrieve_account(&self.wallet_address_2)
.await;
self.interactor.retrieve_account(&self.wallet_address).await;
}

pub async fn deploy(
Expand All @@ -164,7 +151,7 @@ impl PingPongEgldInteract {
.tx()
.from(&self.ping_pong_owner_address)
.gas(30_000_000u64)
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.init(
ping_amount,
duration_in_seconds,
Expand Down Expand Up @@ -195,9 +182,9 @@ impl PingPongEgldInteract {
.interactor
.tx()
.to(self.state.current_ping_pong_egld_address())
.from(&self.wallet_address_1)
.from(&self.wallet_address)
.gas(30_000_000u64)
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.upgrade(
ping_amount,
duration_in_seconds,
Expand All @@ -223,10 +210,10 @@ impl PingPongEgldInteract {
let response = self
.interactor
.tx()
.from(sender.unwrap_or(&self.wallet_address_1))
.from(sender.unwrap_or(&self.wallet_address))
.to(self.state.current_ping_pong_egld_address())
.gas(30_000_000u64)
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.ping(_data)
.egld(egld_amount)
.returns(ReturnsHandledOrError::new())
Expand All @@ -237,7 +224,7 @@ impl PingPongEgldInteract {
Ok(_) => println!("Ping successful!"),
Err(err) => {
println!("Ping failed with message: {}", err.message);
assert_eq!(err.message, message.unwrap_or_default());
assert_eq!(message.unwrap_or_default(), err.message);
},
}
}
Expand All @@ -246,10 +233,10 @@ impl PingPongEgldInteract {
let response = self
.interactor
.tx()
.from(sender.unwrap_or(&self.wallet_address_1))
.from(sender.unwrap_or(&self.wallet_address))
.to(self.state.current_ping_pong_egld_address())
.gas(30_000_000u64)
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.pong()
.returns(ReturnsHandledOrError::new())
.run()
Expand All @@ -259,7 +246,7 @@ impl PingPongEgldInteract {
Ok(_) => println!("Pong successful!"),
Err(err) => {
println!("Pong failed with message: {}", err.message);
assert_eq!(err.message, message.unwrap_or_default());
assert_eq!(message.unwrap_or_default(), err.message);
},
}
}
Expand All @@ -268,10 +255,10 @@ impl PingPongEgldInteract {
let response = self
.interactor
.tx()
.from(sender.unwrap_or(&self.wallet_address_1))
.from(sender.unwrap_or(&self.wallet_address))
.to(self.state.current_ping_pong_egld_address())
.gas(30_000_000u64)
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.pong_all()
.returns(ReturnsHandledOrError::new())
.run()
Expand All @@ -281,7 +268,7 @@ impl PingPongEgldInteract {
Ok(_) => println!("Pong All successful!"),
Err(err) => {
println!("Pong All failed with message: {}", err.message);
assert_eq!(err.message, message.unwrap_or_default());
assert_eq!(message.unwrap_or_default(), err.message);
},
}
}
Expand All @@ -291,7 +278,7 @@ impl PingPongEgldInteract {
.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.get_user_addresses()
.returns(ReturnsResult)
.run()
Expand All @@ -309,7 +296,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.get_contract_state()
.returns(ReturnsResult)
.run()
Expand All @@ -320,7 +307,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.ping_amount()
.returns(ReturnsResultUnmanaged)
.run()
Expand All @@ -331,7 +318,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.deadline()
.returns(ReturnsResultUnmanaged)
.run()
Expand All @@ -342,7 +329,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.activation_timestamp()
.returns(ReturnsResultUnmanaged)
.run()
Expand All @@ -353,7 +340,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.max_funds()
.returns(ReturnsResultUnmanaged)
.run()
Expand All @@ -364,7 +351,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.user_status(user_id)
.returns(ReturnsResultUnmanaged)
.run()
Expand All @@ -375,7 +362,7 @@ impl PingPongEgldInteract {
self.interactor
.query()
.to(self.state.current_ping_pong_egld_address())
.typed(ping_pong_egld_proxy::PingPongProxy)
.typed(proxy_ping_pong_egld::PingPongProxy)
.pong_all_last_user()
.returns(ReturnsResultUnmanaged)
.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn test_ping() {
let mut interact = PingPongEgldInteract::init(Config::chain_simulator_config()).await;

let ping_amount = 1u64;
let duration_in_seconds = 100u64;
let duration_in_seconds = 20u64;
let max_funds = 100_000u64;

interact
Expand Down Expand Up @@ -130,7 +130,7 @@ async fn test_pong_all() {
let mut interact = PingPongEgldInteract::init(Config::chain_simulator_config()).await;

let ping_amount = 1u64;
let duration_in_seconds = 50u64;
let duration_in_seconds = 18u64;
let max_funds = 100_000u64;

interact
Expand All @@ -143,18 +143,18 @@ async fn test_pong_all() {
.await;

interact
.ping(1u64, None, Some(&interact.wallet_address_2.clone()))
.ping(1u64, None, Some(&interact.ping_pong_owner_address.clone()))
.await;

interact
.ping(1u64, None, Some(&interact.wallet_address_1.clone()))
.ping(1u64, None, Some(&interact.wallet_address.clone()))
.await;

interact.pong_all(None, None).await;
interact
.pong(
Some("already withdrawn"),
Some(&interact.wallet_address_1.clone()),
Some(&interact.wallet_address.clone()),
)
.await;
}
2 changes: 1 addition & 1 deletion contracts/examples/ping-pong-egld/src/ping_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use multiversx_sc::imports::*;

pub mod ping_pong_egld_proxy;
pub mod proxy_ping_pong_egld;
mod types;

use types::{ContractState, UserStatus};
Expand Down

0 comments on commit 44b24f1

Please sign in to comment.