Skip to content

Commit 3a5d764

Browse files
authored
Merge pull request #106 from CosmWasm/issue-103
test
2 parents d2edba3 + b5d8d50 commit 3a5d764

File tree

8 files changed

+482
-1
lines changed

8 files changed

+482
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"contract_name": "something-in-raw-folder"
3+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"contract_name": "cw1-whitelist",
3+
"contract_version": "0.3.0",
4+
"idl_version": "1.0.0",
5+
"instantiate": {
6+
"$schema": "http://json-schema.org/draft-07/schema#",
7+
"title": "InstantiateMsg",
8+
"type": "object",
9+
"required": [
10+
"admins",
11+
"mutable"
12+
],
13+
"properties": {
14+
"admins": {
15+
"type": "array",
16+
"items": {
17+
"type": "string"
18+
}
19+
},
20+
"mutable": {
21+
"type": "boolean"
22+
}
23+
}
24+
},
25+
"execute": {
26+
"$schema": "http://json-schema.org/draft-07/schema#",
27+
"title": "ExecuteMsg",
28+
"anyOf": [
29+
{
30+
"$ref": "#/definitions/ExecMsg"
31+
}
32+
],
33+
"definitions": {
34+
"ExecMsg": {
35+
"type": "string",
36+
"enum": []
37+
}
38+
}
39+
},
40+
"query": {
41+
"$schema": "http://json-schema.org/draft-07/schema#",
42+
"title": "QueryMsg",
43+
"anyOf": [
44+
{
45+
"$ref": "#/definitions/QueryMsg"
46+
}
47+
],
48+
"definitions": {
49+
"QueryMsg": {
50+
"type": "string",
51+
"enum": []
52+
}
53+
}
54+
},
55+
"migrate": null,
56+
"sudo": null,
57+
"responses": {}
58+
}

__output__/issues/103/clean.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"schemas": [
3+
{
4+
"$schema": "http://json-schema.org/draft-07/schema#",
5+
"title": "InstantiateMsg",
6+
"type": "object",
7+
"required": [
8+
"admins",
9+
"mutable"
10+
],
11+
"properties": {
12+
"admins": {
13+
"type": "array",
14+
"items": {
15+
"type": "string"
16+
}
17+
},
18+
"mutable": {
19+
"type": "boolean"
20+
}
21+
}
22+
},
23+
{
24+
"$schema": "http://json-schema.org/draft-07/schema#",
25+
"title": "ExecuteMsg",
26+
"anyOf": [
27+
{
28+
"$ref": "#/definitions/ExecMsg"
29+
}
30+
],
31+
"definitions": {
32+
"ExecMsg": {
33+
"type": "string"
34+
}
35+
}
36+
},
37+
{
38+
"$schema": "http://json-schema.org/draft-07/schema#",
39+
"title": "QueryMsg",
40+
"anyOf": [
41+
{
42+
"$ref": "#/definitions/QueryMsg"
43+
}
44+
],
45+
"definitions": {
46+
"QueryMsg": {
47+
"type": "string"
48+
}
49+
}
50+
}
51+
],
52+
"responses": {},
53+
"idlObject": {
54+
"contract_name": "cw1-whitelist",
55+
"contract_version": "0.3.0",
56+
"idl_version": "1.0.0",
57+
"instantiate": {
58+
"$schema": "http://json-schema.org/draft-07/schema#",
59+
"title": "InstantiateMsg",
60+
"type": "object",
61+
"required": [
62+
"admins",
63+
"mutable"
64+
],
65+
"properties": {
66+
"admins": {
67+
"type": "array",
68+
"items": {
69+
"type": "string"
70+
}
71+
},
72+
"mutable": {
73+
"type": "boolean"
74+
}
75+
}
76+
},
77+
"execute": {
78+
"$schema": "http://json-schema.org/draft-07/schema#",
79+
"title": "ExecuteMsg",
80+
"anyOf": [
81+
{
82+
"$ref": "#/definitions/ExecMsg"
83+
}
84+
],
85+
"definitions": {
86+
"ExecMsg": {
87+
"type": "string"
88+
}
89+
}
90+
},
91+
"query": {
92+
"$schema": "http://json-schema.org/draft-07/schema#",
93+
"title": "QueryMsg",
94+
"anyOf": [
95+
{
96+
"$ref": "#/definitions/QueryMsg"
97+
}
98+
],
99+
"definitions": {
100+
"QueryMsg": {
101+
"type": "string"
102+
}
103+
}
104+
},
105+
"migrate": null,
106+
"sudo": null,
107+
"responses": {}
108+
}
109+
}

__output__/issues/103/orig.json

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"schemas": [
3+
{
4+
"$schema": "http://json-schema.org/draft-07/schema#",
5+
"title": "InstantiateMsg",
6+
"type": "object",
7+
"required": [
8+
"admins",
9+
"mutable"
10+
],
11+
"properties": {
12+
"admins": {
13+
"type": "array",
14+
"items": {
15+
"type": "string"
16+
}
17+
},
18+
"mutable": {
19+
"type": "boolean"
20+
}
21+
}
22+
},
23+
{
24+
"$schema": "http://json-schema.org/draft-07/schema#",
25+
"title": "ExecuteMsg",
26+
"anyOf": [
27+
{
28+
"$ref": "#/definitions/ExecMsg"
29+
}
30+
],
31+
"definitions": {
32+
"ExecMsg": {
33+
"type": "string",
34+
"enum": []
35+
}
36+
}
37+
},
38+
{
39+
"$schema": "http://json-schema.org/draft-07/schema#",
40+
"title": "QueryMsg",
41+
"anyOf": [
42+
{
43+
"$ref": "#/definitions/QueryMsg"
44+
}
45+
],
46+
"definitions": {
47+
"QueryMsg": {
48+
"type": "string",
49+
"enum": []
50+
}
51+
}
52+
}
53+
],
54+
"responses": {},
55+
"idlObject": {
56+
"contract_name": "cw1-whitelist",
57+
"contract_version": "0.3.0",
58+
"idl_version": "1.0.0",
59+
"instantiate": {
60+
"$schema": "http://json-schema.org/draft-07/schema#",
61+
"title": "InstantiateMsg",
62+
"type": "object",
63+
"required": [
64+
"admins",
65+
"mutable"
66+
],
67+
"properties": {
68+
"admins": {
69+
"type": "array",
70+
"items": {
71+
"type": "string"
72+
}
73+
},
74+
"mutable": {
75+
"type": "boolean"
76+
}
77+
}
78+
},
79+
"execute": {
80+
"$schema": "http://json-schema.org/draft-07/schema#",
81+
"title": "ExecuteMsg",
82+
"anyOf": [
83+
{
84+
"$ref": "#/definitions/ExecMsg"
85+
}
86+
],
87+
"definitions": {
88+
"ExecMsg": {
89+
"type": "string",
90+
"enum": []
91+
}
92+
}
93+
},
94+
"query": {
95+
"$schema": "http://json-schema.org/draft-07/schema#",
96+
"title": "QueryMsg",
97+
"anyOf": [
98+
{
99+
"$ref": "#/definitions/QueryMsg"
100+
}
101+
],
102+
"definitions": {
103+
"QueryMsg": {
104+
"type": "string",
105+
"enum": []
106+
}
107+
}
108+
},
109+
"migrate": null,
110+
"sudo": null,
111+
"responses": {}
112+
}
113+
}

packages/ts-codegen/__tests__/cleanse.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ it('daodao/cw-code-id-registry', async () => {
2929
mkdirp(out);
3030
writeFileSync(out + '/orig.json', JSON.stringify(orig, null, 2));
3131
writeFileSync(out + '/clean.json', JSON.stringify(clean, null, 2));
32+
})
33+
34+
it('issues/103', async () => {
35+
const out = OUTPUT_DIR + '/issues/103';
36+
const schemaDir = FIXTURE_DIR + '/issues/103/';
37+
38+
const clean = await readSchemas({ schemaDir, clean: true });
39+
const orig = await readSchemas({ schemaDir, clean: false });
3240

41+
mkdirp(out);
42+
writeFileSync(out + '/orig.json', JSON.stringify(orig, null, 2));
43+
writeFileSync(out + '/clean.json', JSON.stringify(clean, null, 2));
3344
})
3445

packages/ts-codegen/src/utils/schemas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const readSchemas = async ({
1313
schemaDir, clean = true
1414
}: ReadSchemaOpts): Promise<ContractInfo> => {
1515
const fn = clean ? cleanse : (str) => str;
16-
const files = glob(schemaDir + '/**/*.json');
16+
const files = glob(schemaDir + '/**/*.json')
17+
.filter(file => !file.match(/\/raw\//));
18+
1719
const schemas = files
1820
.map(file => JSON.parse(readFileSync(file, 'utf-8')));
1921

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`execute execute classes array types 1`] = `
4+
"export class Client implements Instance {
5+
client: SigningCosmWasmClient;
6+
sender: string;
7+
contractAddress: string;
8+
9+
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
10+
this.client = client;
11+
this.sender = sender;
12+
this.contractAddress = contractAddress;
13+
}
14+
15+
}"
16+
`;
17+
18+
exports[`execute execute interfaces no extends 1`] = `
19+
"export interface SG721Instance {
20+
contractAddress: string;
21+
sender: string;
22+
}"
23+
`;
24+
25+
exports[`execute execute_msg_for__empty 1`] = `"export type ExecuteMsg = ExecuteMsg;"`;
26+
27+
exports[`execute query classes 1`] = `
28+
"export class QueryClient implements ReadOnlyInstance {
29+
client: CosmWasmClient;
30+
contractAddress: string;
31+
32+
constructor(client: CosmWasmClient, contractAddress: string) {
33+
this.client = client;
34+
this.contractAddress = contractAddress;
35+
}
36+
37+
}"
38+
`;
39+
40+
exports[`execute query classes response 1`] = `"export type QueryMsg = QueryMsg;"`;
41+
42+
exports[`query execute classes array types 1`] = `
43+
"export class Client implements Instance {
44+
client: SigningCosmWasmClient;
45+
sender: string;
46+
contractAddress: string;
47+
48+
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
49+
this.client = client;
50+
this.sender = sender;
51+
this.contractAddress = contractAddress;
52+
}
53+
54+
}"
55+
`;
56+
57+
exports[`query execute interfaces no extends 1`] = `
58+
"export interface SG721Instance {
59+
contractAddress: string;
60+
sender: string;
61+
}"
62+
`;
63+
64+
exports[`query execute_msg_for__empty 1`] = `"export type QueryMsg = QueryMsg;"`;
65+
66+
exports[`query query classes 1`] = `
67+
"export class QueryClient implements ReadOnlyInstance {
68+
client: CosmWasmClient;
69+
contractAddress: string;
70+
71+
constructor(client: CosmWasmClient, contractAddress: string) {
72+
this.client = client;
73+
this.contractAddress = contractAddress;
74+
}
75+
76+
}"
77+
`;
78+
79+
exports[`query query classes response 1`] = `"export type QueryMsg = QueryMsg;"`;

0 commit comments

Comments
 (0)