Skip to content

Commit

Permalink
Add cw-orch
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Jul 19, 2024
1 parent 1c181a1 commit 0b883d0
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/babylon_vault.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
push:
branches:
- main
- feat/babylon
- feat/babylon-*
paths:
- 'smart-contracts/contracts/babylon-vault/Cargo.toml'
- 'smart-contracts/contracts/babylon-vault/**.rs'
Expand Down
1 change: 1 addition & 0 deletions smart-contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions smart-contracts/contracts/babylon-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
cw2 = { workspace = true }
cw-orch = { workspace = true }
8 changes: 0 additions & 8 deletions smart-contracts/contracts/babylon-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,3 @@ pub fn execute(_deps: DepsMut, _env: Env, _info: MessageInfo, _msg: ExecuteMsg)
pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> VaultResult<Binary> {
Ok(Binary::default())
}

#[cfg(test)]
mod tests {
#[test]
fn dummy_test() {
assert!(true);
}
}
3 changes: 3 additions & 0 deletions smart-contracts/contracts/babylon-vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ pub mod contract;
mod error;
pub mod msg;

#[cfg(test)]
mod tests;

pub use crate::error::VaultError;
8 changes: 6 additions & 2 deletions smart-contracts/contracts/babylon-vault/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ use cosmwasm_std::{Timestamp, Uint128};
pub struct InstantiateMsg {}

#[cw_serde]
#[derive(cw_orch::ExecuteFns)]
pub enum ExecuteMsg {
// permission-less methods
#[cw_orch(payable)]
Deposit {},
Withdraw {},
Claim {},
// owner methods
RegisterLst { denom: String },
RegisterLst {
denom: String,
},
}

#[cw_serde]
Expand All @@ -21,7 +25,7 @@ pub struct Claim {
}

#[cw_serde]
#[derive(QueryResponses)]
#[derive(cw_orch::QueryFns, QueryResponses)]
pub enum QueryMsg {
#[returns(Vec<Claim>)]
Pending { address: String },
Expand Down
21 changes: 21 additions & 0 deletions smart-contracts/contracts/babylon-vault/src/tests/instantiate.rs
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")
);
}
2 changes: 2 additions & 0 deletions smart-contracts/contracts/babylon-vault/src/tests/mod.rs
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 smart-contracts/contracts/babylon-vault/src/tests/setup.rs
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 }
}

0 comments on commit 0b883d0

Please sign in to comment.