-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test verifying that all funds are properly visible on contract execution
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
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
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,5 +1,6 @@ | ||
//! Module for simple contracts to be used in tests | ||
|
||
pub mod error; | ||
pub mod hackatom; | ||
pub mod payout; | ||
pub mod reflect; |
52 changes: 52 additions & 0 deletions
52
packages/multi-test/src/test_helpers/contracts/hackatom.rs
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,52 @@ | ||
//! Simplified contract which when executed releases the funds to beneficiary | ||
|
||
use cosmwasm_std::{ | ||
to_binary, BankMsg, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdError, | ||
}; | ||
use cw_storage_plus::Item; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{test_helpers::EmptyMsg, Contract, ContractWrapper}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct InitMsg { | ||
pub beneficiary: String, | ||
} | ||
|
||
const HACKATOM: Item<InitMsg> = Item::new("hackatom"); | ||
|
||
fn instantiate( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
msg: InitMsg, | ||
) -> Result<Response, StdError> { | ||
HACKATOM.save(deps.storage, &msg)?; | ||
Ok(Response::default()) | ||
} | ||
|
||
fn execute( | ||
deps: DepsMut, | ||
env: Env, | ||
_info: MessageInfo, | ||
_msg: EmptyMsg, | ||
) -> Result<Response, StdError> { | ||
let init = HACKATOM.load(deps.storage)?; | ||
let balance = deps.querier.query_all_balances(env.contract.address)?; | ||
|
||
let resp = Response::new().add_message(BankMsg::Send { | ||
to_address: init.beneficiary, | ||
amount: balance, | ||
}); | ||
|
||
Ok(resp) | ||
} | ||
|
||
fn query(_deps: Deps, _env: Env, msg: EmptyMsg) -> Result<Binary, StdError> { | ||
to_binary(&msg) | ||
} | ||
|
||
pub fn contract() -> Box<dyn Contract<Empty>> { | ||
let contract = ContractWrapper::new(execute, instantiate, query); | ||
Box::new(contract) | ||
} |