From 4ba87f53b0f8c0a0555f5770e81454351971bee5 Mon Sep 17 00:00:00 2001 From: maancham Date: Wed, 7 Feb 2024 17:19:53 -0500 Subject: [PATCH] chore: migrate trait to contract.rs, dependencies failing --- integration-tests/src/contract.rs | 56 +++++++++++++++++++++++++++++++ integration-tests/src/lib.rs | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 integration-tests/src/contract.rs diff --git a/integration-tests/src/contract.rs b/integration-tests/src/contract.rs new file mode 100644 index 000000000..304f8ef01 --- /dev/null +++ b/integration-tests/src/contract.rs @@ -0,0 +1,56 @@ +use cosmwasm_std::{Addr, Coin}; +use cw_multi_test::{App, AppResponse, Executor}; +use error_stack::{report, Result}; +use serde::de::DeserializeOwned; +use serde::Serialize; + +pub trait Contract { + type QMsg; + type ExMsg; + type Err; + + fn contract_address(&self) -> Addr; + fn query(&self, app: &App, query_message: &Self::QMsg) -> T + where + Self::QMsg: Serialize, + { + app.wrap() + .query_wasm_smart(self.contract_address(), query_message) + .unwrap() + } + + fn execute( + &self, + app: &mut App, + caller: Addr, + execute_message: &Self::ExMsg, + ) -> Result + where + Self::ExMsg: Serialize, + Self::ExMsg: std::fmt::Debug, + Self::Err: error_stack::Context, + { + self.execute_with_funds(app, caller, execute_message, &[]) + } + + fn execute_with_funds( + &self, + app: &mut App, + caller: Addr, + execute_message: &Self::ExMsg, + funds: &[Coin], + ) -> Result + where + Self::ExMsg: Serialize, + Self::ExMsg: std::fmt::Debug, + Self::Err: error_stack::Context, + { + app.execute_contract( + caller.clone(), + self.contract_address(), + execute_message, + funds, + ) + .map_err(|err| report!(err.downcast::().unwrap())) + } +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 8b1378917..b5eb8421b 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1 +1 @@ - +pub mod contract; \ No newline at end of file