Skip to content

Commit

Permalink
Merge pull request #13 from multiversx/add-interactor-tests
Browse files Browse the repository at this point in the history
Add interactor chain-simulator tests
  • Loading branch information
sergiuosvat authored Nov 28, 2024
2 parents e69c421 + 7585eca commit 0752251
Show file tree
Hide file tree
Showing 16 changed files with 3,358 additions and 229 deletions.
1,927 changes: 1,710 additions & 217 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[workspace]
resolver = "2"

members = [
"liquid-staking",
"liquid-staking/meta",
"liquid-staking/interactor",
"delegation-mock",
"delegation-mock/meta"
]
12 changes: 6 additions & 6 deletions delegation-mock/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions liquid-staking/interactor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Pem files are used for interactions, but shouldn't be committed
*.pem
30 changes: 30 additions & 0 deletions liquid-staking/interactor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "liquid-staking-interactor"
version = "0.0.0"
authors = ["you"]
edition = "2021"
publish = false

[[bin]]
name = "liquid-staking-interactor"
path = "src/liquid_staking_interactor_main.rs"

[lib]
path = "src/liquid_staking_interactor.rs"

[dependencies.liquid-staking]
path = ".."

[dependencies.multiversx-sc-snippets]
version = "0.54.4"

[dependencies.multiversx-sc]
version = "0.54.4"

[dependencies]
clap = { version = "4.4.7", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
toml = "0.8.6"

[features]
chain-simulator-tests = []
7 changes: 7 additions & 0 deletions liquid-staking/interactor/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

chain_type = 'simulator'
gateway_uri = 'http://localhost:8085'

# chain_type = 'real'
# gateway_uri = 'https://devnet-gateway.multiversx.com'

111 changes: 111 additions & 0 deletions liquid-staking/interactor/src/delegation_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// 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 DelegationMockProxy;

impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for DelegationMockProxy
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
type TxProxyMethods = DelegationMockProxyMethods<Env, From, To, Gas>;

fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods {
DelegationMockProxyMethods { wrapped_tx: tx }
}
}

pub struct DelegationMockProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>,
}

#[rustfmt::skip]
impl<Env, From, Gas> DelegationMockProxyMethods<Env, From, (), Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
Gas: TxGas<Env>,
{
pub fn init(
self,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> DelegationMockProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn deposit_egld(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("depositEGLD")
.original_result()
}

pub fn delegate(
self,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("delegate")
.original_result()
}

pub fn undelegate<
Arg0: ProxyArg<BigUint<Env::Api>>,
>(
self,
egld_to_undelegate: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("unDelegate")
.argument(&egld_to_undelegate)
.original_result()
}

pub fn withdraw(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("withdraw")
.original_result()
}

pub fn claim_rewards(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("claimRewards")
.original_result()
}
}
51 changes: 51 additions & 0 deletions liquid-staking/interactor/src/liquid_staking_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![allow(unused)]

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 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();
toml::from_str(&content).unwrap()
}

pub fn chain_simulator_config() -> Self {
Config {
gateway_uri: "http://localhost:8085".to_owned(),
chain_type: ChainType::Simulator,
}
}

// Returns the gateway URI
pub fn gateway_uri(&self) -> &str {
&self.gateway_uri
}

// Returns if chain type is chain simulator
pub fn use_chain_simulator(&self) -> bool {
match self.chain_type {
ChainType::Real => false,
ChainType::Simulator => true,
}
}
}
Loading

0 comments on commit 0752251

Please sign in to comment.