diff --git a/docs-test-gen/Cargo.toml b/docs-test-gen/Cargo.toml index 1e44a142..1c99253b 100644 --- a/docs-test-gen/Cargo.toml +++ b/docs-test-gen/Cargo.toml @@ -13,4 +13,4 @@ strum = { version = "0.26.2", features = ["derive"] } [dev-dependencies] cosmwasm-schema = "*" -cosmwasm-std = "*" +cosmwasm-std = { version = "*", features = ["stargate", "staking", "cosmwasm_2_0"] } diff --git a/docs-test-gen/src/main.rs b/docs-test-gen/src/main.rs index 149c6180..30a4aba0 100644 --- a/docs-test-gen/src/main.rs +++ b/docs-test-gen/src/main.rs @@ -7,6 +7,7 @@ use strum::{AsRefStr, EnumIter, IntoEnumIterator}; static TEMPLATES: phf::Map<&'static str, &'static str> = phf_map! { "core" => include_str!("../templates/core.tpl"), + "execute" => include_str!("../templates/execute.tpl"), }; #[inline] diff --git a/docs-test-gen/templates/execute.tpl b/docs-test-gen/templates/execute.tpl new file mode 100644 index 00000000..6258d88a --- /dev/null +++ b/docs-test-gen/templates/execute.tpl @@ -0,0 +1,32 @@ +use cosmwasm_std::*; +use cosmwasm_schema::cw_serde; + +#[cw_serde] +struct ExecuteMsg {} + +#[entry_point] +pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult { + // this weird construction allows us to return a StdResult or () in the code + // it tricks the compiler into infering the correct generics + trait ValidReturn {} + impl ValidReturn for StdResult> {} + impl ValidReturn for () {} + fn assert_valid_return(_: &impl ValidReturn) {} + + let ret = { {{code}} }; + assert_valid_return(&ret); + + Ok(Response::default()) +} + +#[test] +fn doctest() { + use cosmwasm_std::testing::*; + + let mut deps = mock_dependencies(); + let env = mock_env(); + let info = mock_info("sender", &[]); + let msg = ExecuteMsg {}; + + let res = execute(deps.as_mut(), env, info, msg).unwrap(); +} diff --git a/scripts/test-rust.sh b/scripts/test-rust.sh new file mode 100755 index 00000000..4c78c933 --- /dev/null +++ b/scripts/test-rust.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -o errexit -o nounset -o pipefail + +( + cd docs-test-gen && \ + rm -rf ./tests && \ + cargo run && + cargo test +) \ No newline at end of file