Skip to content

Commit

Permalink
Added multiple sender
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed May 22, 2024
2 parents b569702 + 41fc930 commit 04a35b6
Show file tree
Hide file tree
Showing 54 changed files with 774 additions and 287 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Build Artifacts
run: |
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.14.0
cosmwasm/optimizer:0.15.0
tar -zcvf cosmwasm-artifacts.tar.gz artifacts
9 changes: 9 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
id: just
uses: extractions/setup-just@v1

- name: Install static-sitemap-cli
run: npm install static-sitemap-cli

- name: Setup PATH # For using the pre-built mdbook
run: echo $GITHUB_WORKSPACE/bin >> $GITHUB_PATH

Expand All @@ -49,6 +52,12 @@ jobs:
- name: Build 🏗️
run: just build-docs

- name: Generate sitemap
run: |
cd docs/book
npx sscli --no-clean --base https://orchestrator.abstract.money
- name: Upload artifact
if: ${{ github.event_name != 'pull_request' && (github.event_name == 'release' || github.event_name == 'workflow_dispatch' ) }}
uses: actions/upload-pages-artifact@v3
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Unreleased

- Added a test to make sure the derive macros stay compatible with new cw-orch versions
- Changed the derive macros import from cw_orch to cw_orch_core. This allows changing the cw-orch API without breaking the derive macros.
- Cw-orch mock env info doesn't error when using chain ids that don't match the `osmosis-1` pattern

### Breaking

- Daemon : Changed return types on daemon queriers to match Cosmwasm std types
- Cw-orch : Separate osmosis test tube from cw-orch. Its not available in its own crate `cw-orch-osmosis-test-tube`

## 0.22.0

- Updated osmosis test tube to 24.0.1 ,that avoids re-compiling osmosis test tube
- Added `balance` query at the root of QueryHandler
- Added DaemonBuilder configuration for grpc url and fee overwriting
Expand All @@ -14,6 +25,7 @@
## 0.21.2

- Allow cw-orch wasm compilation without features
- Transaction Response now inspects logs and events to find matching events.

## 0.21.1

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ osmosis-test-tube = { version = "24.0.1" }
anyhow = "1.0"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }

cw-orch = { path = "./cw-orch", version = "0.22.0" }
cw-orch-daemon = { path = "./cw-orch-daemon", version = "0.22.0" }
cw-orch-core = { path = "packages/cw-orch-core", version = "1.0.0" }
cw-orch-traits = { path = "packages/cw-orch-traits", version = "0.22.0" }
Expand All @@ -38,6 +39,7 @@ serde_json = "1.0.79"
tonic = { version = "0.10.2" }
prost-types = "0.12.3"
prost = "0.12.3"
cosmrs = { version = "0.15.0" }
# Test deps
speculoos = "0.11.0"

Expand Down
6 changes: 3 additions & 3 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cb8d415822e00facae900ea8155369c527a52a17f3b032d70d49ecea661cf5fa counter_contract.wasm
a10b9eef9e09166b6a5b33db76a93e53bf75f492532f25f28c34170998013970 mock_contract.wasm
8c28381f7ce56a4e662b921ad1b3133e07f1265a53a93f7fc1d9627f888ec5fc mock_contract_u64.wasm
06ff69733298934834d2a6bf55deb089380ec57c5279645085c11d43959b9698 counter_contract.wasm
0df014cb19a0a74905b25b619c0f71e99cb1c11d0630ccfa0ad3bef9df1ef017 mock_contract.wasm
6dea2f6da5be93ce418b02feddf6256440876bb85ff8a464b434e4319a60a02f mock_contract_u64.wasm
Binary file modified artifacts/counter_contract.wasm
Binary file not shown.
Binary file modified artifacts/mock_contract.wasm
Binary file not shown.
Binary file modified artifacts/mock_contract_u64.wasm
Binary file not shown.
29 changes: 29 additions & 0 deletions contracts/compatibility-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "cw-orch-compatibility-test"
version = "0.1.0"
description = "Mock constract for cw-orch macro testing"
keywords = ["cosmwasm", "blockchain"]
edition = { workspace = true }

exclude = [".env"]

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["export"]
export = []
interface = []

[dependencies]
cosmwasm-std = { workspace = true }
serde = { workspace = true }
schemars = "0.8.10"
serde_json = "1.0.79"
thiserror = { version = "1.0.21" }
cosmwasm-schema = "1.2"
# This version should not be a path dependency and be kept to the last cw-orch version (beyond v0.23)
# Keeping a different package until v0.23 to avoid package conflicts
cw-orch = { package = "aaa-test-cw-orch", version = "0.22" }
# Keep the old-cw-orch version to 0.22 for backwards compatibility
old-cw-orch = { package = "cw-orch", version = "0.22" }
2 changes: 2 additions & 0 deletions contracts/compatibility-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This folder is used for testing backwards compatibility of cw-orch macros with the older macro versions.
The cw-orch version needs to stay at 0.22 for this test because it's the first stable version of cw-orch-core.
139 changes: 139 additions & 0 deletions contracts/compatibility-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
mod msg_tests;

use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{
to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult,
};

#[cw_serde]
pub struct InstantiateMsg {}

#[cw_serde]
#[derive(old_cw_orch::ExecuteFns)]
pub enum ExecuteMsg {
FirstMessage {},
#[payable]
SecondMessage {
/// test doc-comment
t: String,
},
}

#[cw_serde]
#[derive(old_cw_orch::QueryFns, QueryResponses)]
pub enum QueryMsg {
#[returns(String)]
/// test-doc-comment
FirstQuery {},
#[returns(u64)]
SecondQuery {
/// test doc-comment
t: String,
},
}

#[cw_serde]
pub struct MigrateMsg {
pub t: String,
}

#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
pub fn instantiate(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: InstantiateMsg,
) -> StdResult<Response> {
Ok(Response::new().add_attribute("action", "instantiate"))
}

#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
pub fn execute(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: ExecuteMsg,
) -> StdResult<Response> {
match msg {
ExecuteMsg::FirstMessage {} => {
Ok(Response::new().add_attribute("action", "first message passed"))
}
ExecuteMsg::SecondMessage { t: _ } => {
Ok(Response::new().add_attribute("action", "first message passed"))
}
}
}

#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
pub fn query(_deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::FirstQuery {} => to_json_binary("first query passed"),
QueryMsg::SecondQuery { .. } => to_json_binary(&89u64),
}
}

#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult<Response> {
if msg.t.eq("success") {
Ok(Response::new())
} else {
Err(StdError::generic_err(
"migrate endpoint reached but no test implementation",
))
}
}

#[cw_orch::interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)]
pub struct MockContract;

#[cfg(not(target_arch = "wasm32"))]
pub mod interface {
use old_cw_orch::environment::ChainInfoOwned;

use crate::{execute, instantiate, migrate, query, MockContract};

impl<Chain> old_cw_orch::prelude::Uploadable for MockContract<Chain> {
fn wrapper(
) -> Box<dyn old_cw_orch::prelude::MockContract<cosmwasm_std::Empty, cosmwasm_std::Empty>>
{
Box::new(
old_cw_orch::prelude::ContractWrapper::new(execute, instantiate, query)
.with_migrate(migrate),
)
}

fn wasm(_chain: &ChainInfoOwned) -> old_cw_orch::prelude::WasmPath {
use old_cw_orch::prelude::*;
artifacts_dir_from_workspace!()
.find_wasm_path("mock_contract")
.unwrap()
}
}
}

#[cfg(test)]
mod test {
use super::MockContract as LocalMockContract;
use super::*;
use cosmwasm_std::coins;
use cw_orch::prelude::*;

#[test]
fn compiles() -> Result<(), CwOrchError> {
// We need to check we can still call the execute msgs conveniently
let sender = Addr::unchecked("sender");
let mock = Mock::new(&sender);
mock.set_balance(&sender, coins(156 * 2, "ujuno"))?;
let contract = LocalMockContract::new("mock-contract", mock.clone());

contract.upload()?;
contract.instantiate(&InstantiateMsg {}, None, None)?;
contract.first_message()?;
contract.second_message("s".to_string(), &coins(156, "ujuno"))?;

contract.first_query()?;
contract.second_query("arg".to_string())?;

Ok(())
}
}
103 changes: 103 additions & 0 deletions contracts/compatibility-test/src/msg_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Here we implement some tests for the interface macros to make sure everything works and keeps working
// This is a contract not exposed, only used for compilation test (necessary)

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};

// ANCHOR: unordered_msg_def
#[cw_serde]
#[derive(cw_orch::ExecuteFns)]
#[disable_fields_sorting]
pub enum ExecuteMsg {
Test { b: u64, a: String },
}
// ANCHOR_END: unordered_msg_def

// ANCHOR: ordered_msg_def
#[cw_serde]
#[derive(cw_orch::ExecuteFns)]
pub enum ExecuteMsgOrdered {
Test { b: u64, a: String },
}
// ANCHOR_END: ordered_msg_def

#[cw_orch::interface(Empty, ExecuteMsg, Empty, Empty)]
pub struct TestContract;

#[cw_orch::interface(Empty, ExecuteMsgOrdered, Empty, Empty)]
pub struct OrderedTestContract;

pub fn instantiate(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: Empty,
) -> StdResult<Response> {
Ok(Response::new())
}

pub fn execute(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: ExecuteMsg,
) -> StdResult<Response> {
Ok(Response::new())
}

pub fn execute_ordered(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: ExecuteMsgOrdered,
) -> StdResult<Response> {
Ok(Response::new())
}

pub fn query(_deps: Deps, _env: Env, _msg: Empty) -> StdResult<Binary> {
Ok(vec![].into())
}
#[cfg(not(target_arch = "wasm32"))]
mod interface {
use super::*;
use cw_orch::prelude::*;

impl<Chain> Uploadable for TestContract<Chain> {
fn wrapper() -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new_with_empty(execute, instantiate, query))
}
}

impl<Chain> Uploadable for OrderedTestContract<Chain> {
fn wrapper() -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new_with_empty(
execute_ordered,
instantiate,
query,
))
}
}
}

#[cfg(test)]
mod test {
use super::*;
use cw_orch::prelude::*;
#[test]
pub fn test() -> Result<(), CwOrchError> {
let chain = Mock::new("sender");

let contract = TestContract::new("test", chain.clone());
let contract_ordered = OrderedTestContract::new("test-ordered", chain.clone());

contract.upload()?;
contract_ordered.upload()?;
contract.instantiate(&Empty {}, None, None)?;
contract_ordered.instantiate(&Empty {}, None, None)?;

contract.test(5, "test".to_string())?;
contract_ordered.test("test".to_string(), 5)?;

Ok(())
}
}
3 changes: 2 additions & 1 deletion contracts/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ name = "deploy"
# Deps for deployment
dotenv = { version = "0.15.0" }
pretty_env_logger = { version = "0.5.0" }
cw-orch = { path = "../../cw-orch", features = ["daemon", "osmosis-test-tube"] }
cw-orch = { path = "../../cw-orch", features = ["daemon"] }
cw-orch-osmosis-test-tube = { version = "0.1.0", path = "../../packages/cw-orch-osmosis-test-tube" }
anyhow.workspace = true
1 change: 1 addition & 0 deletions contracts/counter/examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use counter_contract::{
};
use cw_orch::{anyhow, prelude::*};

// From https://github.com/CosmosContracts/juno/blob/32568dba828ff7783aea8cb5bb4b8b5832888255/docker/test-user.env#L2
const LOCAL_MNEMONIC: &str = "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose";
pub fn main() -> anyhow::Result<()> {
std::env::set_var("LOCAL_MNEMONIC", LOCAL_MNEMONIC);
Expand Down
5 changes: 2 additions & 3 deletions contracts/counter/tests/checksum.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use counter_contract::CounterContract;
use cw_orch::{
contract::interface_traits::Uploadable, mock::Mock, osmosis_test_tube::MOCK_CHAIN_INFO,
};
use cw_orch::{contract::interface_traits::Uploadable, mock::Mock};
use cw_orch_osmosis_test_tube::MOCK_CHAIN_INFO;

#[test]
fn checksum() {
Expand Down
2 changes: 1 addition & 1 deletion contracts/counter/tests/osmosis-test-tube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use counter_contract::{
msg::{GetCountResponse, InstantiateMsg, QueryMsg},
CounterContract,
};
use cw_orch::osmosis_test_tube::OsmosisTestTube;
// Use prelude to get all the necessary imports
use cw_orch::prelude::*;
use cw_orch_osmosis_test_tube::OsmosisTestTube;

// ANCHOR: integration_test
// ANCHOR: setup
Expand Down
Loading

0 comments on commit 04a35b6

Please sign in to comment.