Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better UX for defining query response types and schema generation #1339

Merged
merged 41 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1be774c
schema: add a way to tie queries to responses
uint Jun 27, 2022
f793c24
schema: derive macro for QueryResponses
uint Jun 27, 2022
21b3ef3
schema-derive: don't gen trait when compiling to wasm
uint Jun 27, 2022
27579ed
schema-derive: fix query names in api file
uint Jun 27, 2022
1612747
Update contracts
uint Jun 27, 2022
94d1513
update codecov.yaml with schema-derive
uint Jun 27, 2022
82d06d9
schema-derive: remove unnecessary dep
uint Jun 27, 2022
e279d8a
circleci: build schema-derive
uint Jun 27, 2022
1a66e17
schema-derive: add some tests
uint Jun 27, 2022
a5605f6
schema-derive: style
uint Jun 29, 2022
a955db0
schema: owned strings only for simplicity
uint Jun 29, 2022
b495a6c
schema: rename query_responses -> response_schemas
uint Jun 29, 2022
4a3caa0
schema: update IDL tests
uint Jun 29, 2022
17b6308
schema-derive: more tests
uint Jun 29, 2022
7faefd3
schema-derive: verify `rename_all = "snake_case"` is used
uint Jun 29, 2022
aebf859
Revert "schema-derive: verify `rename_all = "snake_case"` is used"
uint Jun 29, 2022
7e9ea3d
idl: integrity check for query names in generated JSON
uint Jul 4, 2022
ef970e7
contracts: update Cargo.lock
uint Jul 4, 2022
6a27aaf
schema-derive: remove unused dep
uint Jul 4, 2022
6308461
schema, schema-derive: refactor
uint Jul 4, 2022
23e638b
schema: better errors for the integrity check
uint Jul 4, 2022
57f20d2
schema: make `responses` in IDL optional
uint Jul 4, 2022
8ed00f5
schema-derive: introduce generate_api!()
uint Jul 4, 2022
de786c4
schema-derive: Cargo.toml fix
uint Jul 4, 2022
c238af7
hackatom: migrate to the generate_api!() macro
uint Jul 4, 2022
11022aa
clippy
uint Jul 4, 2022
6c8a7e6
schema: simplify tests
uint Jul 4, 2022
c0e2c07
schema: QueryResponse tests
uint Jul 5, 2022
09c55ad
schema-derive: refactor
uint Jul 5, 2022
ba50c97
schema: doc comments for proc macros
uint Jul 5, 2022
5c89ee9
schema-derive: go nuts with boilerplate removal
uint Jul 5, 2022
3a35507
schema-derive: assorted fixes
uint Jul 5, 2022
998dfbe
schema: improve proc macro doc comments
uint Jul 5, 2022
90d8355
schema: doc comment style
uint Jul 5, 2022
163a9d7
schema-derive: panic msg tests
uint Jul 6, 2022
88a8f59
put `schema-derive` in separate codecov flag
uint Jul 11, 2022
ce17cf4
schema: rename API generation macros for clarity
uint Jul 11, 2022
ff89d44
format codecov.yml file
uint Jul 11, 2022
da722a4
schema: fix failing doc test
uint Jul 11, 2022
c203560
CI: run clippy for schema-derive
uint Jul 11, 2022
4e0985a
Update codecov.yml
uint Jul 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ workflows:
- arm64
- package_crypto
- package_schema
- package_schema_derive
- package_std
- package_storage
- package_vm
Expand Down Expand Up @@ -186,6 +187,33 @@ jobs:
- target/debug/deps
key: cargocache-v2-package_schema-rust:1.56.1-{{ checksum "Cargo.lock" }}

package_schema_derive:
docker:
- image: rust:1.56.1
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
- restore_cache:
keys:
- cargocache-v2-package_schema_derive-rust:1.56.1-{{ checksum "Cargo.lock" }}
- run:
name: Build
working_directory: ~/project/packages/schema-derive
command: cargo build --locked
- run:
name: Run tests
working_directory: ~/project/packages/schema-derive
command: cargo test --locked
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargocache-v2-package_schema_derive-rust:1.56.1-{{ checksum "Cargo.lock" }}
uint marked this conversation as resolved.
Show resolved Hide resolved

package_std:
docker:
- image: rust:1.56.1
Expand Down Expand Up @@ -938,6 +966,10 @@ jobs:
name: Clippy linting on schema
working_directory: ~/project/packages/schema
command: cargo clippy --all-targets -- -D warnings
- run:
name: Clippy linting on schema-derive
working_directory: ~/project/packages/schema-derive
command: cargo clippy --all-targets -- -D warnings
- run:
name: Clippy linting on std (no feature flags)
working_directory: ~/project/packages/std
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ flags:
cosmwasm-schema:
paths:
- packages/schema/
cosmwasm-schema-derive:
paths:
- packages/schema-derive/
uint marked this conversation as resolved.
Show resolved Hide resolved
cosmwasm-std:
paths:
- packages/std/
Expand Down
10 changes: 10 additions & 0 deletions contracts/burner/Cargo.lock

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

10 changes: 10 additions & 0 deletions contracts/crypto-verify/Cargo.lock

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

10 changes: 10 additions & 0 deletions contracts/floaty/Cargo.lock

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

10 changes: 10 additions & 0 deletions contracts/hackatom/Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/hackatom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cranelift = ["cosmwasm-vm/cranelift"]
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = ["abort"] }
rust-argon2 = "0.8"
schemars = "0.8.1"
Expand All @@ -39,6 +40,5 @@ sha2 = "0.9.1"
thiserror = "1.0"

[dev-dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-storage = { path = "../../packages/storage", default-features = false }
cosmwasm-vm = { path = "../../packages/vm", default-features = false }
59 changes: 8 additions & 51 deletions contracts/hackatom/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,13 @@
use std::collections::BTreeMap;
use std::env::current_dir;
use std::fs::{create_dir_all, write};
use cosmwasm_schema::write_api;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for, Api};
use cosmwasm_std::{AllBalanceResponse, BalanceResponse};

use hackatom::msg::{
ExecuteMsg, InstantiateMsg, IntResponse, MigrateMsg, QueryMsg, RecurseResponse, SudoMsg,
VerifierResponse,
};
use hackatom::state::State;
use hackatom::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

// messages
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
export_schema(&schema_for!(SudoMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(VerifierResponse), &out_dir);
export_schema(&schema_for!(BalanceResponse), &out_dir);

// state
export_schema(&schema_for!(State), &out_dir);

let contract_name = env!("CARGO_PKG_NAME");
let contract_version = env!("CARGO_PKG_VERSION");

// The new IDL
let path = out_dir.join(format!("{}.json", contract_name));
let api = Api {
contract_name: contract_name.to_string(),
contract_version: contract_version.to_string(),
instantiate: schema_for!(InstantiateMsg),
execute: Some(schema_for!(ExecuteMsg)),
query: Some(schema_for!(QueryMsg)),
migrate: Some(schema_for!(MigrateMsg)),
sudo: Some(schema_for!(SudoMsg)),
responses: BTreeMap::from([
("verifier".to_string(), schema_for!(VerifierResponse)),
("other_balance".to_string(), schema_for!(AllBalanceResponse)),
("recurse".to_string(), schema_for!(RecurseResponse)),
("get_int".to_string(), schema_for!(IntResponse)),
]),
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
sudo: SudoMsg,
migrate: MigrateMsg,
}
.render();
let json = api.to_string().unwrap();
write(&path, json + "\n").unwrap();
println!("Exported the full API as {}", path.to_str().unwrap());
}
39 changes: 0 additions & 39 deletions contracts/hackatom/schema/balance_response.json

This file was deleted.

Loading