Skip to content

Commit

Permalink
fix: Expect , in :custom(msg, query)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Oct 27, 2023
1 parent cb15d56 commit dffa571
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions examples/Cargo.lock

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

5 changes: 4 additions & 1 deletion examples/contracts/custom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ crate-type = ["cdylib", "rlib"]

[features]
library = []
mt = ["library"]
mt = ["library", "anyhow", "cw-multi-test"]

[dependencies]
cw1 = { path = "../../interfaces/cw1" }
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.3", features = ["staking"] }
cw-storage-plus = "1.0"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
cw-multi-test = { version = "0.16", optional = true }
anyhow = { version = "1.0", optional = true }

[dev-dependencies]
anyhow = "1.0"
Expand Down
8 changes: 6 additions & 2 deletions examples/contracts/custom/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use cosmwasm_std::{CosmosMsg, QueryRequest, Response, StdResult};
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx};
use sylvia::{contract, entry_points, schemars};
use sylvia::{contract, schemars};

#[cfg(not(feature = "library"))]
use sylvia::entry_points;

use crate::messages::{CountResponse, CounterMsg, CounterQuery};

pub struct CustomContract;

#[cfg_attr(not(feature = "mt"), entry_points)]
#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
#[messages(cw1 as Cw1: custom(msg, query))]
#[sv::custom(query=CounterQuery, msg=CounterMsg)]
impl CustomContract {
pub const fn new() -> Self {
Expand Down
29 changes: 29 additions & 0 deletions examples/contracts/custom/src/cw1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::messages::CounterMsg;
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use cw1::{CanExecuteResp, Cw1};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

use crate::contract::CustomContract;

#[contract(module=crate::contract)]
#[messages(cw1 as Cw1)]
#[sv::custom(query=CounterQuery, msg=CounterMsg)]
impl Cw1 for CustomContract {
type Error = StdError;

#[msg(exec)]
fn execute(&self, _ctx: ExecCtx, _msgs: Vec<CosmosMsg>) -> StdResult<Response> {
Ok(Response::new())
}

#[msg(query)]
fn can_execute(
&self,
_ctx: QueryCtx,
_sender: String,
_msg: CosmosMsg,
) -> StdResult<CanExecuteResp> {
Ok(CanExecuteResp::default())
}
}
1 change: 1 addition & 0 deletions examples/contracts/custom/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod contract;
pub mod cw1;
pub mod messages;
#[cfg(any(test, feature = "mt"))]
pub mod multitest;
3 changes: 2 additions & 1 deletion examples/contracts/custom/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod custom_module;
pub mod custom_module;
#[cfg(test)]
mod tests;
11 changes: 1 addition & 10 deletions examples/contracts/custom/src/multitest/custom_module.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
use cosmwasm_schema::schemars::JsonSchema;
use cosmwasm_std::testing::{MockApi, MockStorage};
use cosmwasm_std::{
to_binary, Addr, Api, Binary, BlockInfo, CustomQuery, Empty, Querier, StdError, StdResult,
Storage,
};
use cw_multi_test::{AppResponse, BankKeeper, CosmosRouter, Module, WasmKeeper};
use cw_multi_test::{AppResponse, CosmosRouter, Module};
use cw_storage_plus::Item;
use serde::de::DeserializeOwned;
use std::fmt::Debug;

use crate::messages::{CountResponse, CounterMsg, CounterQuery};

pub type CustomApp = cw_multi_test::App<
BankKeeper,
MockApi,
MockStorage,
CustomModule,
WasmKeeper<CounterMsg, CounterQuery>,
>;

pub struct CustomModule {
pub counter: Item<'static, u64>,
}
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/custom/src/multitest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use sylvia::multitest::App;

use crate::contract::multitest_utils::CodeId;

use super::custom_module::{CustomApp, CustomModule};
use super::custom_module::CustomModule;

#[test]
fn test_custom() {
Expand All @@ -14,7 +14,7 @@ fn test_custom() {
router.custom.save_counter(storage, 0).unwrap();
});

let app = App::<CustomApp>::new(mt_app);
let app = App::new(mt_app);

let code_id = CodeId::store_code(&app);

Expand Down
4 changes: 4 additions & 0 deletions sylvia-derive/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ fn interface_has_custom(content: ParseStream) -> Result<Customs> {
))
}
}
if !custom_content.peek(Token![,]) {
break;
}
let _: Token![,] = custom_content.parse()?;

Check warning on line 305 in sylvia-derive/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/parser.rs#L305

Added line #L305 was not covered by tests
}
Ok(customs)
}
Expand Down

0 comments on commit dffa571

Please sign in to comment.