-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
69 additions
and
11 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -2,4 +2,7 @@ pub mod contract; | |
mod error; | ||
pub mod msg; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub use crate::error::VaultError; |
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
21 changes: 21 additions & 0 deletions
21
smart-contracts/contracts/babylon-vault/src/tests/instantiate.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,21 @@ | ||
use crate::msg::InstantiateMsg; | ||
use crate::tests::setup::create_test_vault; | ||
use cosmwasm_std::Event; | ||
use cw_orch::contract::interface_traits::CwOrchInstantiate; | ||
|
||
#[test] | ||
fn test_instantiate() { | ||
let env = create_test_vault(); | ||
let vault = env.vault; | ||
|
||
let result = vault.instantiate(&InstantiateMsg {}, None, None); | ||
assert!(result.is_ok()); | ||
let response = result.unwrap(); | ||
assert_eq!(response.events.len(), 1); | ||
assert_eq!( | ||
response.events[0], | ||
Event::new("instantiate") | ||
.add_attribute("_contract_address", "contract0") | ||
.add_attribute("code_id", "1") | ||
); | ||
} |
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,2 @@ | ||
pub mod instantiate; | ||
pub mod setup; |
34 changes: 34 additions & 0 deletions
34
smart-contracts/contracts/babylon-vault/src/tests/setup.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,34 @@ | ||
use crate::{ | ||
contract::{execute, instantiate, query}, | ||
msg::{ExecuteMsg, InstantiateMsg, QueryMsg}, | ||
}; | ||
use cosmwasm_std::{testing::MockApi, Addr, Empty}; | ||
use cw_orch::interface; | ||
use cw_orch::mock::Mock; | ||
use cw_orch::prelude::*; | ||
use cw_orch::{contract::interface_traits::CwOrchUpload, mock::MockBase}; | ||
|
||
pub const SENDER: &str = "sender"; | ||
|
||
#[interface(InstantiateMsg, ExecuteMsg, QueryMsg, Empty)] | ||
pub struct Vault; | ||
|
||
impl<Chain> Uploadable for Vault<Chain> { | ||
fn wrapper() -> Box<dyn MockContract<Empty>> { | ||
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query)) | ||
} | ||
} | ||
|
||
pub struct TestEnv<T: cosmwasm_std::Api> { | ||
pub chain: MockBase<T>, | ||
pub vault: Vault<MockBase<T>>, | ||
} | ||
|
||
pub fn create_test_vault() -> TestEnv<MockApi> { | ||
let sender = Addr::unchecked(SENDER); | ||
let chain = Mock::new(&sender); | ||
|
||
let vault: Vault<Mock> = Vault::new("vault", chain.clone()); | ||
vault.upload().unwrap(); | ||
TestEnv { chain, vault } | ||
} |