Skip to content

Commit dbfc387

Browse files
committed
Add to_schema_files test
1 parent fad8a4a commit dbfc387

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

packages/schema/src/idl.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,55 @@ pub enum EncodeError {
146146

147147
#[cfg(test)]
148148
mod tests {
149+
use crate::schema_for;
150+
149151
use super::*;
150152

151153
#[test]
152154
fn version_is_semver() {
153155
semver::Version::parse(IDL_VERSION).unwrap();
154156
}
157+
158+
#[test]
159+
fn to_schema_files_works() {
160+
let empty = Api {
161+
contract_name: "my_contract".to_string(),
162+
contract_version: "1.2.3".to_string(),
163+
instantiate: None,
164+
execute: None,
165+
query: None,
166+
migrate: None,
167+
sudo: None,
168+
responses: None,
169+
};
170+
171+
let files = empty.render().to_schema_files().unwrap();
172+
assert_eq!(files, []);
173+
174+
#[derive(schemars::JsonSchema)]
175+
struct TestMsg {}
176+
177+
let full = Api {
178+
contract_name: "my_contract".to_string(),
179+
contract_version: "1.2.3".to_string(),
180+
instantiate: Some(schema_for!(TestMsg)),
181+
execute: Some(schema_for!(TestMsg)),
182+
query: Some(schema_for!(TestMsg)),
183+
migrate: Some(schema_for!(TestMsg)),
184+
sudo: Some(schema_for!(TestMsg)),
185+
responses: Some(BTreeMap::from([(
186+
"TestMsg".to_string(),
187+
schema_for!(TestMsg),
188+
)])),
189+
};
190+
191+
let files = full.render().to_schema_files().unwrap();
192+
assert_eq!(files.len(), 6);
193+
assert_eq!(files[0].0, "instantiate.json");
194+
assert_eq!(files[1].0, "execute.json");
195+
assert_eq!(files[2].0, "query.json");
196+
assert_eq!(files[3].0, "migrate.json");
197+
assert_eq!(files[4].0, "sudo.json");
198+
assert_eq!(files[5].0, "response_to_TestMsg.json");
199+
}
155200
}

0 commit comments

Comments
 (0)