generated from multiversx/mx-template-sc
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from multiversx/add-interactor-tests
Add interactor chain-simulator tests
- Loading branch information
Showing
16 changed files
with
3,358 additions
and
229 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
} |
Oops, something went wrong.