Skip to content

Commit

Permalink
forwarder interactor setup
Browse files Browse the repository at this point in the history
mihaicalinluca committed Dec 9, 2024

Verified

This commit was signed with the committer’s verified signature.
mihaicalinluca Mihai Calin Luca
1 parent e856a90 commit 9602c10
Showing 15 changed files with 3,457 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -133,6 +133,7 @@ members = [
"contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child",
"contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child/meta",
"contracts/feature-tests/composability/forwarder",
"contracts/feature-tests/composability/forwarder-interactor",
"contracts/feature-tests/composability/forwarder/meta",
"contracts/feature-tests/composability/forwarder-legacy",
"contracts/feature-tests/composability/forwarder-legacy/meta",
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "forwarder-interact"
version = "0.0.0"
authors = ["you"]
edition = "2021"
publish = false

[[bin]]
name = "forwarder-interact"
path = "src/interactor_main.rs"

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

[dependencies.forwarder]
path = "../forwarder"

[dependencies.multiversx-sc-snippets]
version = "0.54.5"
path = "../../../../framework/snippets"

[dependencies.multiversx-sc]
version = "0.54.5"
path = "../../../../framework/base"

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

[features]
chain-simulator-tests = []
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'

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 new() -> 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,
}
}
}
1,944 changes: 1,944 additions & 0 deletions contracts/feature-tests/composability/forwarder-interactor/src/interact.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use forwarder_interact::forwarder_cli;
use multiversx_sc_snippets::imports::*;

#[tokio::main]
async fn main() {
forwarder_cli().await;
}
1,375 changes: 1,375 additions & 0 deletions contracts/feature-tests/composability/forwarder-interactor/src/proxy.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contract_address = "erd1qqqqqqqqqqqqqpgqcr2nq237tg5vr3ezjvr750spkmtsjstjd8ssfp6eun"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use forwarder_interact::ContractInteract;
use multiversx_sc_snippets::imports::*;

// Simple deploy test that runs using the chain simulator configuration.
// In order for this test to work, make sure that the `config.toml` file contains the chain simulator config (or choose it manually)
// The chain simulator should already be installed and running before attempting to run this test.
// The chain-simulator-tests feature should be present in Cargo.toml.
// Can be run with `sc-meta test -c`.
#[tokio::test]
#[cfg_attr(not(feature = "chain-simulator-tests"), ignore)]
async fn deploy_test_forwarder_cs() {
let mut interactor = ContractInteract::new().await;

interactor.deploy().await;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use forwarder_interact::ContractInteract;
use multiversx_sc_snippets::imports::*;

// Simple deploy test that runs on the real blockchain configuration.
// In order for this test to work, make sure that the `config.toml` file contains the real blockchain config (or choose it manually)
// Can be run with `sc-meta test`.
#[tokio::test]
#[ignore = "run on demand, relies on real blockchain state"]
async fn deploy_test_forwarder() {
let mut interactor = ContractInteract::new().await;

interactor.deploy().await;
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[[proxy]]
path = "src/forwarder_proxy.rs"

[[proxy]]
path = "../forwarder-interactor/src/proxy.rs"

Original file line number Diff line number Diff line change
@@ -1354,7 +1354,7 @@ where
}

#[type_abi]
#[derive(TopEncode, TopDecode)]
#[derive(TopEncode, TopDecode, Debug)]
pub struct CallbackData<Api>
where
Api: ManagedTypeApi,
@@ -1367,7 +1367,7 @@ where
}

#[type_abi]
#[derive(TopEncode, TopDecode, Clone, Copy, PartialEq, Debug)]
#[derive(TopEncode, TopDecode, Clone, Copy, PartialEq, Debug, Default)]
pub struct Color {
pub r: u8,
pub g: u8,
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ multiversx_sc::imports!();
multiversx_sc::derive_imports!();

#[type_abi]
#[derive(TopEncode, TopDecode)]
#[derive(TopEncode, TopDecode, Debug)]
pub struct CallbackData<M: ManagedTypeApi> {
callback_name: ManagedBuffer<M>,
token_identifier: EgldOrEsdtTokenIdentifier<M>,
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@ use super::fwd_storage;

// used as mock attributes for NFTs
#[type_abi]
#[derive(TopEncode, TopDecode, Clone, Copy, PartialEq, Debug)]
#[derive(TopEncode, TopDecode, Clone, Copy, PartialEq, Debug, Default)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}

#[type_abi]
#[derive(TopEncode, TopDecode, PartialEq, Eq, Clone)]
#[derive(TopEncode, TopDecode, PartialEq, Eq, Clone, Debug)]
pub struct ComplexAttributes<M: ManagedTypeApi> {
pub biguint: BigUint<M>,
pub vec_u8: ManagedBuffer<M>,

0 comments on commit 9602c10

Please sign in to comment.