Skip to content

Commit

Permalink
chore: migrate trait to contract.rs, dependencies failing
Browse files Browse the repository at this point in the history
  • Loading branch information
maancham committed Feb 7, 2024
1 parent cb469b5 commit 4ba87f5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions integration-tests/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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<T: DeserializeOwned>(&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<AppResponse, Self::Err>
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<AppResponse, Self::Err>
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::<Self::Err>().unwrap()))
}
}
2 changes: 1 addition & 1 deletion integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@

pub mod contract;

This comment has been minimized.

Copy link
@cgorenflo

cgorenflo Feb 12, 2024

Contributor

add a new line at the end

0 comments on commit 4ba87f5

Please sign in to comment.