Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promises-features - interactor #1942

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ members = [
"contracts/feature-tests/composability/local-esdt-and-nft/meta",
"contracts/feature-tests/composability/promises-features",
"contracts/feature-tests/composability/promises-features/meta",
"contracts/feature-tests/composability/promises-features/interactor",
"contracts/feature-tests/composability/proxy-test-first",
"contracts/feature-tests/composability/proxy-test-first/meta",
"contracts/feature-tests/composability/proxy-test-second",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Pem files are used for interactions, but shouldn't be committed
*.pem
state.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "rust-interact"
version = "0.0.0"
authors = ["you"]
edition = "2021"
publish = false

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

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

[dependencies.promises-features]
path = ".."

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

[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,5 @@
# 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 {

Check warning on line 25 in contracts/feature-tests/composability/promises-features/interactor/src/config.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/feature-tests/composability/promises-features/interactor/src/config.rs#L25

warning: you should consider adding a `Default` implementation for `Config` --> contracts/feature-tests/composability/promises-features/interactor/src/config.rs:25:5 | 25 | / pub fn new() -> Self { 26 | | let mut file = std::fs::File::open(CONFIG_FILE).unwrap(); 27 | | let mut content = String::new(); 28 | | file.read_to_string(&mut content).unwrap(); 29 | | toml::from_str(&content).unwrap() 30 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default = note: `#[warn(clippy::new_without_default)]` on by default help: try adding this | 23 + impl Default for Config { 24 + fn default() -> Self { 25 + Self::new() 26 + } 27 + } |
Raw output
contracts/feature-tests/composability/promises-features/interactor/src/config.rs:25:5:w:warning: you should consider adding a `Default` implementation for `Config`
  --> contracts/feature-tests/composability/promises-features/interactor/src/config.rs:25:5
   |
25 | /     pub fn new() -> Self {
26 | |         let mut file = std::fs::File::open(CONFIG_FILE).unwrap();
27 | |         let mut content = String::new();
28 | |         file.read_to_string(&mut content).unwrap();
29 | |         toml::from_str(&content).unwrap()
30 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
   = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
   |
23 + impl Default for Config {
24 +     fn default() -> Self {
25 +         Self::new()
26 +     }
27 + }
   |


__END__

Check warning on line 25 in contracts/feature-tests/composability/promises-features/interactor/src/config.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/feature-tests/composability/promises-features/interactor/src/config.rs#L25

warning: you should consider adding a `Default` implementation for `Config` --> contracts/feature-tests/composability/promises-features/interactor/src/config.rs:25:5 | 25 | / pub fn new() -> Self { 26 | | let mut file = std::fs::File::open(CONFIG_FILE).unwrap(); 27 | | let mut content = String::new(); 28 | | file.read_to_string(&mut content).unwrap(); 29 | | toml::from_str(&content).unwrap() 30 | | } | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default = note: `#[warn(clippy::new_without_default)]` on by default help: try adding this | 23 + impl Default for Config { 24 + fn default() -> Self { 25 + Self::new() 26 + } 27 + } |
Raw output
contracts/feature-tests/composability/promises-features/interactor/src/config.rs:25:5:w:warning: you should consider adding a `Default` implementation for `Config`
  --> contracts/feature-tests/composability/promises-features/interactor/src/config.rs:25:5
   |
25 | /     pub fn new() -> Self {
26 | |         let mut file = std::fs::File::open(CONFIG_FILE).unwrap();
27 | |         let mut content = String::new();
28 | |         file.read_to_string(&mut content).unwrap();
29 | |         toml::from_str(&content).unwrap()
30 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
   = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
   |
23 + impl Default for Config {
24 +     fn default() -> Self {
25 +         Self::new()
26 +     }
27 + }
   |


__END__
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
Loading