wasm-ast-types 0.19.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- package/main/client/client.js +16 -7
- package/main/client/test/ts-client.issue-101.spec.js +27 -0
- package/main/client/test/ts-client.issue-103.test.js +48 -0
- package/main/message-composer/message-composer.js +13 -4
- package/main/message-composer/message-composer.spec.js +14 -4
- package/main/msg-builder/msg-builder.js +21 -7
- package/main/msg-builder/msg-builder.spec.js +7 -1
- package/main/react-query/react-query.spec.js +11 -0
- package/main/utils/types.js +10 -2
- package/module/client/client.js +18 -9
- package/module/client/test/ts-client.issue-101.spec.js +20 -0
- package/module/client/test/ts-client.issue-103.test.js +41 -0
- package/module/message-composer/message-composer.js +13 -4
- package/module/message-composer/message-composer.spec.js +16 -7
- package/module/msg-builder/msg-builder.js +26 -12
- package/module/msg-builder/msg-builder.spec.js +6 -1
- package/module/react-query/react-query.spec.js +10 -0
- package/module/utils/types.js +10 -3
- package/package.json +2 -2
- package/src/client/client.ts +29 -24
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +47 -0
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +79 -0
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +8 -8
- package/src/client/test/ts-client.issue-101.spec.ts +37 -0
- package/src/client/test/ts-client.issue-103.test.ts +106 -0
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +60 -0
- package/src/message-composer/message-composer.spec.ts +41 -20
- package/src/message-composer/message-composer.ts +13 -5
- package/src/msg-builder/__snapshots__/msg-builder.spec.ts.snap +21 -0
- package/src/msg-builder/msg-builder.spec.ts +9 -1
- package/src/msg-builder/msg-builder.ts +36 -24
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +45 -0
- package/src/react-query/react-query.spec.ts +17 -1
- package/src/utils/types.ts +11 -4
package/src/client/client.ts
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { camel
|
2
|
+
import { camel } from 'case';
|
3
3
|
import {
|
4
|
+
arrowFunctionExpression,
|
4
5
|
bindMethod,
|
5
|
-
typedIdentifier,
|
6
|
-
promiseTypeAnnotation,
|
7
6
|
classDeclaration,
|
8
7
|
classProperty,
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
getMessageProperties,
|
9
|
+
promiseTypeAnnotation,
|
10
|
+
typedIdentifier
|
11
|
+
} from '../utils';
|
12
12
|
|
13
|
-
import {
|
14
|
-
QueryMsg,
|
15
|
-
ExecuteMsg
|
16
|
-
} from '../types';
|
13
|
+
import { ExecuteMsg, JSONSchema, QueryMsg } from '../types';
|
17
14
|
|
18
|
-
import {
|
15
|
+
import { createTypedObjectParams, getPropertyType, getResponseType, getType } from '../utils/types';
|
19
16
|
import { RenderContext } from '../context';
|
20
|
-
import { JSONSchema } from '../types';
|
21
17
|
import { identifier, propertySignature } from '../utils/babel';
|
22
18
|
|
23
19
|
export const CONSTANT_EXEC_PARAMS = [
|
@@ -89,7 +85,7 @@ export const createWasmQueryMethod = (
|
|
89
85
|
const methodName = camel(underscoreName);
|
90
86
|
const responseType = getResponseType(context, underscoreName);
|
91
87
|
|
92
|
-
const
|
88
|
+
const param = createTypedObjectParams(
|
93
89
|
context,
|
94
90
|
jsonschema.properties[underscoreName]
|
95
91
|
);
|
@@ -99,13 +95,14 @@ export const createWasmQueryMethod = (
|
|
99
95
|
jsonschema.properties[underscoreName]
|
100
96
|
);
|
101
97
|
|
102
|
-
const
|
103
|
-
|
98
|
+
const msgAction = t.identifier(underscoreName);
|
99
|
+
// If the param is an identifier, we can just use it as is
|
100
|
+
const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args)
|
104
101
|
|
105
102
|
return t.classProperty(
|
106
103
|
t.identifier(methodName),
|
107
104
|
arrowFunctionExpression(
|
108
|
-
|
105
|
+
param ? [param] : [],
|
109
106
|
t.blockStatement(
|
110
107
|
[
|
111
108
|
t.returnStatement(
|
@@ -120,7 +117,7 @@ export const createWasmQueryMethod = (
|
|
120
117
|
[
|
121
118
|
t.memberExpression(t.thisExpression(), t.identifier('contractAddress')),
|
122
119
|
t.objectExpression([
|
123
|
-
|
120
|
+
t.objectProperty(msgAction, msgActionValue)
|
124
121
|
])
|
125
122
|
]
|
126
123
|
)
|
@@ -237,9 +234,15 @@ export const getWasmMethodArgs = (
|
|
237
234
|
// only 1 degree $ref-lookup
|
238
235
|
if (!keys.length && jsonschema.$ref) {
|
239
236
|
const obj = context.refLookup(jsonschema.$ref);
|
237
|
+
// properties
|
240
238
|
if (obj) {
|
241
239
|
keys = Object.keys(obj.properties ?? {})
|
242
240
|
}
|
241
|
+
|
242
|
+
// tuple struct or otherwise, use the name of the reference
|
243
|
+
if (!keys.length && obj?.oneOf) {
|
244
|
+
// TODO????? ADAIR
|
245
|
+
}
|
243
246
|
}
|
244
247
|
|
245
248
|
const args = keys.map(prop => {
|
@@ -265,7 +268,7 @@ export const createWasmExecMethod = (
|
|
265
268
|
|
266
269
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
267
270
|
const methodName = camel(underscoreName);
|
268
|
-
const
|
271
|
+
const param = createTypedObjectParams(
|
269
272
|
context,
|
270
273
|
jsonschema.properties[underscoreName]
|
271
274
|
);
|
@@ -274,12 +277,16 @@ export const createWasmExecMethod = (
|
|
274
277
|
jsonschema.properties[underscoreName]
|
275
278
|
);
|
276
279
|
|
280
|
+
const msgAction = t.identifier(underscoreName);
|
281
|
+
// If the param is an identifier, we can just use it as is
|
282
|
+
const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args)
|
283
|
+
|
277
284
|
return t.classProperty(
|
278
285
|
t.identifier(methodName),
|
279
286
|
arrowFunctionExpression(
|
280
|
-
|
287
|
+
param ? [
|
281
288
|
// props
|
282
|
-
|
289
|
+
param,
|
283
290
|
...CONSTANT_EXEC_PARAMS
|
284
291
|
] : CONSTANT_EXEC_PARAMS,
|
285
292
|
t.blockStatement(
|
@@ -306,10 +313,8 @@ export const createWasmExecMethod = (
|
|
306
313
|
t.objectExpression(
|
307
314
|
[
|
308
315
|
t.objectProperty(
|
309
|
-
|
310
|
-
|
311
|
-
...args
|
312
|
-
])
|
316
|
+
msgAction,
|
317
|
+
msgActionValue
|
313
318
|
)
|
314
319
|
|
315
320
|
]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`execute interfaces no extends 1`] = `
|
4
|
+
"export interface OwnershipInstance {
|
5
|
+
contractAddress: string;
|
6
|
+
sender: string;
|
7
|
+
setFactory: ({
|
8
|
+
newFactory
|
9
|
+
}: {
|
10
|
+
newFactory: string;
|
11
|
+
}, fee?: number | StdFee | \\"auto\\", memo?: string, funds?: Coin[]) => Promise<ExecuteResult>;
|
12
|
+
updateOwnership: (action: Action, fee?: number | StdFee | \\"auto\\", memo?: string, funds?: Coin[]) => Promise<ExecuteResult>;
|
13
|
+
}"
|
14
|
+
`;
|
15
|
+
|
16
|
+
exports[`ownership client with tuple 1`] = `
|
17
|
+
"export class OwnershipClient implements OwnershipInstance {
|
18
|
+
client: SigningCosmWasmClient;
|
19
|
+
sender: string;
|
20
|
+
contractAddress: string;
|
21
|
+
|
22
|
+
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
|
23
|
+
this.client = client;
|
24
|
+
this.sender = sender;
|
25
|
+
this.contractAddress = contractAddress;
|
26
|
+
this.setFactory = this.setFactory.bind(this);
|
27
|
+
this.updateOwnership = this.updateOwnership.bind(this);
|
28
|
+
}
|
29
|
+
|
30
|
+
setFactory = async ({
|
31
|
+
newFactory
|
32
|
+
}: {
|
33
|
+
newFactory: string;
|
34
|
+
}, fee: number | StdFee | \\"auto\\" = \\"auto\\", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
|
35
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
36
|
+
set_factory: {
|
37
|
+
new_factory: newFactory
|
38
|
+
}
|
39
|
+
}, fee, memo, funds);
|
40
|
+
};
|
41
|
+
updateOwnership = async (action: Action, fee: number | StdFee | \\"auto\\" = \\"auto\\", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
|
42
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
43
|
+
update_ownership: action
|
44
|
+
}, fee, memo, funds);
|
45
|
+
};
|
46
|
+
}"
|
47
|
+
`;
|
@@ -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;"`;
|
@@ -193,9 +193,9 @@ exports[`query classes 1`] = `
|
|
193
193
|
this.wasm = this.wasm.bind(this);
|
194
194
|
}
|
195
195
|
|
196
|
-
bank = async (): Promise<BankResponse> => {
|
196
|
+
bank = async (bankMsg: BankMsg): Promise<BankResponse> => {
|
197
197
|
return this.client.queryContractSmart(this.contractAddress, {
|
198
|
-
bank:
|
198
|
+
bank: bankMsg
|
199
199
|
});
|
200
200
|
};
|
201
201
|
custom = async (): Promise<CustomResponse> => {
|
@@ -203,19 +203,19 @@ exports[`query classes 1`] = `
|
|
203
203
|
custom: {}
|
204
204
|
});
|
205
205
|
};
|
206
|
-
staking = async (): Promise<StakingResponse> => {
|
206
|
+
staking = async (stakingMsg: StakingMsg): Promise<StakingResponse> => {
|
207
207
|
return this.client.queryContractSmart(this.contractAddress, {
|
208
|
-
staking:
|
208
|
+
staking: stakingMsg
|
209
209
|
});
|
210
210
|
};
|
211
|
-
distribution = async (): Promise<DistributionResponse> => {
|
211
|
+
distribution = async (distributionMsg: DistributionMsg): Promise<DistributionResponse> => {
|
212
212
|
return this.client.queryContractSmart(this.contractAddress, {
|
213
|
-
distribution:
|
213
|
+
distribution: distributionMsg
|
214
214
|
});
|
215
215
|
};
|
216
|
-
wasm = async (): Promise<WasmResponse> => {
|
216
|
+
wasm = async (wasmMsg: WasmMsg): Promise<WasmResponse> => {
|
217
217
|
return this.client.queryContractSmart(this.contractAddress, {
|
218
|
-
wasm:
|
218
|
+
wasm: wasmMsg
|
219
219
|
});
|
220
220
|
};
|
221
221
|
}"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { createExecuteClass, createExecuteInterface } from '../client';
|
2
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
3
|
+
import ownership from '../../../../../__fixtures__/basic/ownership.json';
|
4
|
+
|
5
|
+
|
6
|
+
// it('query classes', () => {
|
7
|
+
// const ctx = makeContext(cosmos_msg_for__empty);
|
8
|
+
// expectCode(createQueryClass(
|
9
|
+
// ctx,
|
10
|
+
// 'SG721QueryClient',
|
11
|
+
// 'SG721ReadOnlyInstance',
|
12
|
+
// cosmos_msg_for__empty
|
13
|
+
// ))
|
14
|
+
// });
|
15
|
+
|
16
|
+
it('execute interfaces no extends', () => {
|
17
|
+
const ctx = makeContext(ownership);
|
18
|
+
expectCode(createExecuteInterface(
|
19
|
+
ctx,
|
20
|
+
'OwnershipInstance',
|
21
|
+
null,
|
22
|
+
ownership
|
23
|
+
))
|
24
|
+
});
|
25
|
+
|
26
|
+
it('ownership client with tuple', () => {
|
27
|
+
const ctx = makeContext(ownership);
|
28
|
+
expectCode(createExecuteClass(
|
29
|
+
ctx,
|
30
|
+
'OwnershipClient',
|
31
|
+
'OwnershipInstance',
|
32
|
+
null,
|
33
|
+
ownership
|
34
|
+
))
|
35
|
+
});
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import contract from '../../../../../__fixtures__/issues/103/schema.json';
|
2
|
+
|
3
|
+
import {
|
4
|
+
createQueryClass,
|
5
|
+
createExecuteClass,
|
6
|
+
createExecuteInterface,
|
7
|
+
createTypeInterface
|
8
|
+
} from '../client'
|
9
|
+
import { expectCode, printCode, makeContext } from '../../../test-utils';
|
10
|
+
|
11
|
+
const queryMessage = contract.query
|
12
|
+
const executeMessage = contract.execute
|
13
|
+
const queryCtx = makeContext(queryMessage);
|
14
|
+
const executeCtx = makeContext(executeMessage);
|
15
|
+
|
16
|
+
describe('query', () => {
|
17
|
+
it('execute_msg_for__empty', () => {
|
18
|
+
expectCode(createTypeInterface(
|
19
|
+
queryCtx,
|
20
|
+
queryMessage
|
21
|
+
))
|
22
|
+
})
|
23
|
+
|
24
|
+
|
25
|
+
it('query classes', () => {
|
26
|
+
expectCode(createQueryClass(
|
27
|
+
queryCtx,
|
28
|
+
'QueryClient',
|
29
|
+
'ReadOnlyInstance',
|
30
|
+
queryMessage
|
31
|
+
))
|
32
|
+
});
|
33
|
+
|
34
|
+
it('query classes response', () => {
|
35
|
+
expectCode(createTypeInterface(
|
36
|
+
queryCtx,
|
37
|
+
contract.query
|
38
|
+
))
|
39
|
+
});
|
40
|
+
|
41
|
+
it('execute classes array types', () => {
|
42
|
+
expectCode(createExecuteClass(
|
43
|
+
queryCtx,
|
44
|
+
'Client',
|
45
|
+
'Instance',
|
46
|
+
null,
|
47
|
+
queryMessage
|
48
|
+
))
|
49
|
+
});
|
50
|
+
|
51
|
+
it('execute interfaces no extends', () => {
|
52
|
+
expectCode(createExecuteInterface(
|
53
|
+
queryCtx,
|
54
|
+
'SG721Instance',
|
55
|
+
null,
|
56
|
+
queryMessage
|
57
|
+
))
|
58
|
+
});
|
59
|
+
|
60
|
+
});
|
61
|
+
|
62
|
+
describe('execute', () => {
|
63
|
+
it('execute_msg_for__empty', () => {
|
64
|
+
expectCode(createTypeInterface(
|
65
|
+
executeCtx,
|
66
|
+
executeMessage
|
67
|
+
))
|
68
|
+
})
|
69
|
+
|
70
|
+
|
71
|
+
it('query classes', () => {
|
72
|
+
expectCode(createQueryClass(
|
73
|
+
executeCtx,
|
74
|
+
'QueryClient',
|
75
|
+
'ReadOnlyInstance',
|
76
|
+
executeMessage
|
77
|
+
))
|
78
|
+
});
|
79
|
+
|
80
|
+
it('query classes response', () => {
|
81
|
+
expectCode(createTypeInterface(
|
82
|
+
executeCtx,
|
83
|
+
contract.query
|
84
|
+
))
|
85
|
+
});
|
86
|
+
|
87
|
+
it('execute classes array types', () => {
|
88
|
+
expectCode(createExecuteClass(
|
89
|
+
executeCtx,
|
90
|
+
'Client',
|
91
|
+
'Instance',
|
92
|
+
null,
|
93
|
+
executeMessage
|
94
|
+
))
|
95
|
+
});
|
96
|
+
|
97
|
+
it('execute interfaces no extends', () => {
|
98
|
+
expectCode(createExecuteInterface(
|
99
|
+
executeCtx,
|
100
|
+
'SG721Instance',
|
101
|
+
null,
|
102
|
+
executeMessage
|
103
|
+
))
|
104
|
+
});
|
105
|
+
|
106
|
+
});
|
@@ -269,3 +269,63 @@ exports[`execute classes 1`] = `
|
|
269
269
|
};
|
270
270
|
}"
|
271
271
|
`;
|
272
|
+
|
273
|
+
exports[`ownershipClass 1`] = `
|
274
|
+
"export class OwnershipMessageComposer implements OwnershipMessage {
|
275
|
+
sender: string;
|
276
|
+
contractAddress: string;
|
277
|
+
|
278
|
+
constructor(sender: string, contractAddress: string) {
|
279
|
+
this.sender = sender;
|
280
|
+
this.contractAddress = contractAddress;
|
281
|
+
this.setFactory = this.setFactory.bind(this);
|
282
|
+
this.updateOwnership = this.updateOwnership.bind(this);
|
283
|
+
}
|
284
|
+
|
285
|
+
setFactory = ({
|
286
|
+
newFactory
|
287
|
+
}: {
|
288
|
+
newFactory: string;
|
289
|
+
}, funds?: Coin[]): MsgExecuteContractEncodeObject => {
|
290
|
+
return {
|
291
|
+
typeUrl: \\"/cosmwasm.wasm.v1.MsgExecuteContract\\",
|
292
|
+
value: MsgExecuteContract.fromPartial({
|
293
|
+
sender: this.sender,
|
294
|
+
contract: this.contractAddress,
|
295
|
+
msg: toUtf8(JSON.stringify({
|
296
|
+
set_factory: {
|
297
|
+
new_factory: newFactory
|
298
|
+
}
|
299
|
+
})),
|
300
|
+
funds
|
301
|
+
})
|
302
|
+
};
|
303
|
+
};
|
304
|
+
updateOwnership = (action: Action, funds?: Coin[]): MsgExecuteContractEncodeObject => {
|
305
|
+
return {
|
306
|
+
typeUrl: \\"/cosmwasm.wasm.v1.MsgExecuteContract\\",
|
307
|
+
value: MsgExecuteContract.fromPartial({
|
308
|
+
sender: this.sender,
|
309
|
+
contract: this.contractAddress,
|
310
|
+
msg: toUtf8(JSON.stringify({
|
311
|
+
update_ownership: action
|
312
|
+
})),
|
313
|
+
funds
|
314
|
+
})
|
315
|
+
};
|
316
|
+
};
|
317
|
+
}"
|
318
|
+
`;
|
319
|
+
|
320
|
+
exports[`ownershipInterface 1`] = `
|
321
|
+
"export interface OwnershipMessage {
|
322
|
+
contractAddress: string;
|
323
|
+
sender: string;
|
324
|
+
setFactory: ({
|
325
|
+
newFactory
|
326
|
+
}: {
|
327
|
+
newFactory: string;
|
328
|
+
}, funds?: Coin[]) => MsgExecuteContractEncodeObject;
|
329
|
+
updateOwnership: (action: Action, funds?: Coin[]) => MsgExecuteContractEncodeObject;
|
330
|
+
}"
|
331
|
+
`;
|
@@ -1,25 +1,46 @@
|
|
1
|
-
import execute_msg from
|
1
|
+
import execute_msg from "../../../../__fixtures__/basic/execute_msg_for__empty.json";
|
2
|
+
import ownership from "../../../../__fixtures__/basic/ownership.json";
|
3
|
+
|
2
4
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
} from
|
6
|
-
import { expectCode, makeContext } from
|
5
|
+
createMessageComposerClass,
|
6
|
+
createMessageComposerInterface,
|
7
|
+
} from "./message-composer";
|
8
|
+
import { expectCode, makeContext } from "../../test-utils";
|
9
|
+
import * as t from "@babel/types";
|
10
|
+
import { createReactQueryMutationHooks } from "../react-query";
|
11
|
+
|
12
|
+
it("execute classes", () => {
|
13
|
+
const ctx = makeContext(execute_msg);
|
14
|
+
expectCode(
|
15
|
+
createMessageComposerClass(
|
16
|
+
ctx,
|
17
|
+
"SG721MessageComposer",
|
18
|
+
"SG721Message",
|
19
|
+
execute_msg
|
20
|
+
)
|
21
|
+
);
|
22
|
+
});
|
23
|
+
|
24
|
+
it("createMessageComposerInterface", () => {
|
25
|
+
const ctx = makeContext(execute_msg);
|
26
|
+
expectCode(createMessageComposerInterface(ctx, "SG721Message", execute_msg));
|
27
|
+
});
|
7
28
|
|
8
|
-
it(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
29
|
+
it("ownershipClass", () => {
|
30
|
+
const ctx = makeContext(ownership);
|
31
|
+
expectCode(
|
32
|
+
createMessageComposerClass(
|
33
|
+
ctx,
|
34
|
+
"OwnershipMessageComposer",
|
35
|
+
"OwnershipMessage",
|
36
|
+
ownership
|
37
|
+
)
|
38
|
+
);
|
16
39
|
});
|
17
40
|
|
18
|
-
it(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
execute_msg
|
24
|
-
))
|
41
|
+
it("ownershipInterface", () => {
|
42
|
+
const ownershipCtx = makeContext(ownership);
|
43
|
+
expectCode(
|
44
|
+
createMessageComposerInterface(ownershipCtx, "OwnershipMessage", ownership)
|
45
|
+
);
|
25
46
|
});
|
@@ -14,6 +14,7 @@ import { JSONSchema } from '../types';
|
|
14
14
|
import { RenderContext } from '../context';
|
15
15
|
import { identifier } from '../utils/babel';
|
16
16
|
import { getWasmMethodArgs } from '../client/client';
|
17
|
+
import { Expression } from '@babel/types';
|
17
18
|
|
18
19
|
const createWasmExecMethodMessageComposer = (
|
19
20
|
context: RenderContext,
|
@@ -27,12 +28,20 @@ const createWasmExecMethodMessageComposer = (
|
|
27
28
|
|
28
29
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
29
30
|
const methodName = camel(underscoreName);
|
30
|
-
const
|
31
|
+
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
31
32
|
const args = getWasmMethodArgs(
|
32
33
|
context,
|
33
34
|
jsonschema.properties[underscoreName]
|
34
35
|
);
|
35
36
|
|
37
|
+
// what the underscore named property in the message is assigned to
|
38
|
+
let actionValue: Expression
|
39
|
+
if (param?.type === 'Identifier') {
|
40
|
+
actionValue = t.identifier(param.name);
|
41
|
+
} else {
|
42
|
+
actionValue = t.objectExpression(args)
|
43
|
+
}
|
44
|
+
|
36
45
|
const constantParams = [
|
37
46
|
identifier('funds', t.tsTypeAnnotation(
|
38
47
|
t.tsArrayType(
|
@@ -46,9 +55,9 @@ const createWasmExecMethodMessageComposer = (
|
|
46
55
|
return t.classProperty(
|
47
56
|
t.identifier(methodName),
|
48
57
|
arrowFunctionExpression(
|
49
|
-
|
58
|
+
param ? [
|
50
59
|
// props
|
51
|
-
|
60
|
+
param,
|
52
61
|
...constantParams
|
53
62
|
] : constantParams,
|
54
63
|
t.blockStatement(
|
@@ -95,10 +104,9 @@ const createWasmExecMethodMessageComposer = (
|
|
95
104
|
),
|
96
105
|
[
|
97
106
|
t.objectExpression(
|
98
|
-
|
99
107
|
[
|
100
108
|
t.objectProperty(
|
101
|
-
t.identifier(underscoreName),
|
109
|
+
t.identifier(underscoreName), actionValue
|
102
110
|
)
|
103
111
|
]
|
104
112
|
|
@@ -113,6 +113,27 @@ exports[`execute class 1`] = `
|
|
113
113
|
}"
|
114
114
|
`;
|
115
115
|
|
116
|
+
exports[`ownership 1`] = `
|
117
|
+
"export abstract class Ownership {
|
118
|
+
static setFactory = ({
|
119
|
+
newFactory
|
120
|
+
}: CamelCasedProperties<Extract<ExecuteMsg, {
|
121
|
+
set_factory: unknown;
|
122
|
+
}>[\\"set_factory\\"]>): ExecuteMsg => {
|
123
|
+
return {
|
124
|
+
set_factory: ({
|
125
|
+
new_factory: newFactory
|
126
|
+
} as const)
|
127
|
+
};
|
128
|
+
};
|
129
|
+
static updateOwnership = (action: Action): ExecuteMsg => {
|
130
|
+
return {
|
131
|
+
update_ownership: action
|
132
|
+
};
|
133
|
+
};
|
134
|
+
}"
|
135
|
+
`;
|
136
|
+
|
116
137
|
exports[`query class 1`] = `
|
117
138
|
"export abstract class SG721MsgBuilder {
|
118
139
|
static ownerOf = ({
|
@@ -1,9 +1,12 @@
|
|
1
1
|
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
2
2
|
import query_msg from '../../../../__fixtures__/basic/query_msg.json';
|
3
|
+
import ownership from '../../../../__fixtures__/basic/ownership.json';
|
4
|
+
|
3
5
|
import {
|
4
6
|
createMsgBuilderClass,
|
5
7
|
} from './msg-builder'
|
6
8
|
import { expectCode, makeContext } from '../../test-utils';
|
9
|
+
import { findExecuteMsg } from '@cosmwasm/ts-codegen/src';
|
7
10
|
|
8
11
|
it('execute class', () => {
|
9
12
|
const ctx = makeContext(execute_msg);
|
@@ -12,6 +15,11 @@ it('execute class', () => {
|
|
12
15
|
|
13
16
|
|
14
17
|
it('query class', () => {
|
15
|
-
const ctx = makeContext(
|
18
|
+
const ctx = makeContext(query_msg);
|
16
19
|
expectCode(createMsgBuilderClass(ctx, 'SG721MsgBuilder', query_msg))
|
17
20
|
});
|
21
|
+
|
22
|
+
it('ownership', () => {
|
23
|
+
const ctx = makeContext(ownership);
|
24
|
+
expectCode(createMsgBuilderClass(ctx, 'Ownership', ownership))
|
25
|
+
});
|