@gala-chain/launchpad 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/.dev-env +7 -0
  2. package/.dockerignore +9 -0
  3. package/.eslintignore +4 -0
  4. package/.eslintrc.json +37 -0
  5. package/.github/workflows/publish-on-tag.yml +72 -0
  6. package/.github/workflows/test-on-push.yml +32 -0
  7. package/.nvmrc +1 -0
  8. package/.prettierignore +4 -0
  9. package/.prettierrc +12 -0
  10. package/Dockerfile +31 -0
  11. package/LICENSE +201 -0
  12. package/README.md +2 -0
  13. package/api-config.json +16 -0
  14. package/e2e/__snapshots__/api.spec.ts.snap +2482 -0
  15. package/e2e/api-config.json +17 -0
  16. package/e2e/api.spec.ts +48 -0
  17. package/e2e/jest.config.js +42 -0
  18. package/e2e/tsconfig.json +10 -0
  19. package/jest.config.ts +27 -0
  20. package/lib/jest.config.d.ts +13 -0
  21. package/lib/jest.config.d.ts.map +1 -0
  22. package/lib/jest.config.js +28 -0
  23. package/lib/jest.config.js.map +1 -0
  24. package/lib/package.json +54 -0
  25. package/lib/src/api/index.d.ts +4 -0
  26. package/lib/src/api/index.d.ts.map +1 -0
  27. package/lib/src/api/index.js +21 -0
  28. package/lib/src/api/index.js.map +1 -0
  29. package/lib/src/api/types/LaunchpadDtos.d.ts +102 -0
  30. package/lib/src/api/types/LaunchpadDtos.d.ts.map +1 -0
  31. package/lib/src/api/types/LaunchpadDtos.js +410 -0
  32. package/lib/src/api/types/LaunchpadDtos.js.map +1 -0
  33. package/lib/src/api/types/LaunchpadFeeConfig.d.ts +9 -0
  34. package/lib/src/api/types/LaunchpadFeeConfig.d.ts.map +1 -0
  35. package/lib/src/api/types/LaunchpadFeeConfig.js +56 -0
  36. package/lib/src/api/types/LaunchpadFeeConfig.js.map +1 -0
  37. package/lib/src/api/types/LaunchpadFinalizeAllocation.d.ts +10 -0
  38. package/lib/src/api/types/LaunchpadFinalizeAllocation.d.ts.map +1 -0
  39. package/lib/src/api/types/LaunchpadFinalizeAllocation.js +70 -0
  40. package/lib/src/api/types/LaunchpadFinalizeAllocation.js.map +1 -0
  41. package/lib/src/api/types/LaunchpadSale.d.ts +35 -0
  42. package/lib/src/api/types/LaunchpadSale.d.ts.map +1 -0
  43. package/lib/src/api/types/LaunchpadSale.js +195 -0
  44. package/lib/src/api/types/LaunchpadSale.js.map +1 -0
  45. package/lib/src/api/types/index.d.ts +5 -0
  46. package/lib/src/api/types/index.d.ts.map +1 -0
  47. package/lib/src/api/types/index.js +22 -0
  48. package/lib/src/api/types/index.js.map +1 -0
  49. package/lib/src/api/utils/error.d.ts +20 -0
  50. package/lib/src/api/utils/error.d.ts.map +1 -0
  51. package/lib/src/api/utils/error.js +35 -0
  52. package/lib/src/api/utils/error.js.map +1 -0
  53. package/lib/src/api/utils/index.d.ts +2 -0
  54. package/lib/src/api/utils/index.d.ts.map +1 -0
  55. package/lib/src/api/utils/index.js +19 -0
  56. package/lib/src/api/utils/index.js.map +1 -0
  57. package/lib/src/api/validators/decorators.d.ts +19 -0
  58. package/lib/src/api/validators/decorators.d.ts.map +1 -0
  59. package/lib/src/api/validators/decorators.js +391 -0
  60. package/lib/src/api/validators/decorators.js.map +1 -0
  61. package/lib/src/api/validators/index.d.ts +2 -0
  62. package/lib/src/api/validators/index.d.ts.map +1 -0
  63. package/lib/src/api/validators/index.js +19 -0
  64. package/lib/src/api/validators/index.js.map +1 -0
  65. package/lib/src/chaincode/LaunchpadContract.d.ts +20 -0
  66. package/lib/src/chaincode/LaunchpadContract.d.ts.map +1 -0
  67. package/lib/src/chaincode/LaunchpadContract.js +217 -0
  68. package/lib/src/chaincode/LaunchpadContract.js.map +1 -0
  69. package/lib/src/chaincode/dexLaunchpadFeeGate.d.ts +14 -0
  70. package/lib/src/chaincode/dexLaunchpadFeeGate.d.ts.map +1 -0
  71. package/lib/src/chaincode/dexLaunchpadFeeGate.js +47 -0
  72. package/lib/src/chaincode/dexLaunchpadFeeGate.js.map +1 -0
  73. package/lib/src/chaincode/index.d.ts +2 -0
  74. package/lib/src/chaincode/index.d.ts.map +1 -0
  75. package/lib/src/chaincode/index.js +19 -0
  76. package/lib/src/chaincode/index.js.map +1 -0
  77. package/lib/src/chaincode/launchpad/buyExactToken.d.ts +20 -0
  78. package/lib/src/chaincode/launchpad/buyExactToken.d.ts.map +1 -0
  79. package/lib/src/chaincode/launchpad/buyExactToken.js +113 -0
  80. package/lib/src/chaincode/launchpad/buyExactToken.js.map +1 -0
  81. package/lib/src/chaincode/launchpad/buyWithNative.d.ts +22 -0
  82. package/lib/src/chaincode/launchpad/buyWithNative.d.ts.map +1 -0
  83. package/lib/src/chaincode/launchpad/buyWithNative.js +106 -0
  84. package/lib/src/chaincode/launchpad/buyWithNative.js.map +1 -0
  85. package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts +27 -0
  86. package/lib/src/chaincode/launchpad/callMemeTokenIn.d.ts.map +1 -0
  87. package/lib/src/chaincode/launchpad/callMemeTokenIn.js +76 -0
  88. package/lib/src/chaincode/launchpad/callMemeTokenIn.js.map +1 -0
  89. package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts +25 -0
  90. package/lib/src/chaincode/launchpad/callMemeTokenOut.d.ts.map +1 -0
  91. package/lib/src/chaincode/launchpad/callMemeTokenOut.js +56 -0
  92. package/lib/src/chaincode/launchpad/callMemeTokenOut.js.map +1 -0
  93. package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts +25 -0
  94. package/lib/src/chaincode/launchpad/callNativeTokenIn.d.ts.map +1 -0
  95. package/lib/src/chaincode/launchpad/callNativeTokenIn.js +51 -0
  96. package/lib/src/chaincode/launchpad/callNativeTokenIn.js.map +1 -0
  97. package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts +26 -0
  98. package/lib/src/chaincode/launchpad/callNativeTokenOut.d.ts.map +1 -0
  99. package/lib/src/chaincode/launchpad/callNativeTokenOut.js +60 -0
  100. package/lib/src/chaincode/launchpad/callNativeTokenOut.js.map +1 -0
  101. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts +4 -0
  102. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.d.ts.map +1 -0
  103. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js +58 -0
  104. package/lib/src/chaincode/launchpad/configureLaunchpadFeeConfig.js.map +1 -0
  105. package/lib/src/chaincode/launchpad/createSale.d.ts +26 -0
  106. package/lib/src/chaincode/launchpad/createSale.d.ts.map +1 -0
  107. package/lib/src/chaincode/launchpad/createSale.js +129 -0
  108. package/lib/src/chaincode/launchpad/createSale.js.map +1 -0
  109. package/lib/src/chaincode/launchpad/fees.d.ts +6 -0
  110. package/lib/src/chaincode/launchpad/fees.d.ts.map +1 -0
  111. package/lib/src/chaincode/launchpad/fees.js +85 -0
  112. package/lib/src/chaincode/launchpad/fees.js.map +1 -0
  113. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts +4 -0
  114. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.d.ts.map +1 -0
  115. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js +36 -0
  116. package/lib/src/chaincode/launchpad/fetchLaunchpadAdressConfig.js.map +1 -0
  117. package/lib/src/chaincode/launchpad/fetchSaleDetails.d.ts +19 -0
  118. package/lib/src/chaincode/launchpad/fetchSaleDetails.d.ts.map +1 -0
  119. package/lib/src/chaincode/launchpad/fetchSaleDetails.js +49 -0
  120. package/lib/src/chaincode/launchpad/fetchSaleDetails.js.map +1 -0
  121. package/lib/src/chaincode/launchpad/finaliseSale.d.ts +4 -0
  122. package/lib/src/chaincode/launchpad/finaliseSale.d.ts.map +1 -0
  123. package/lib/src/chaincode/launchpad/finaliseSale.js +144 -0
  124. package/lib/src/chaincode/launchpad/finaliseSale.js.map +1 -0
  125. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.d.ts +4 -0
  126. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.d.ts.map +1 -0
  127. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.js +43 -0
  128. package/lib/src/chaincode/launchpad/finalizeTokenAllocation.js.map +1 -0
  129. package/lib/src/chaincode/launchpad/index.d.ts +15 -0
  130. package/lib/src/chaincode/launchpad/index.d.ts.map +1 -0
  131. package/lib/src/chaincode/launchpad/index.js +32 -0
  132. package/lib/src/chaincode/launchpad/index.js.map +1 -0
  133. package/lib/src/chaincode/launchpad/preMintCalculation.d.ts +17 -0
  134. package/lib/src/chaincode/launchpad/preMintCalculation.d.ts.map +1 -0
  135. package/lib/src/chaincode/launchpad/preMintCalculation.js +56 -0
  136. package/lib/src/chaincode/launchpad/preMintCalculation.js.map +1 -0
  137. package/lib/src/chaincode/launchpad/sellExactToken.d.ts +22 -0
  138. package/lib/src/chaincode/launchpad/sellExactToken.d.ts.map +1 -0
  139. package/lib/src/chaincode/launchpad/sellExactToken.js +102 -0
  140. package/lib/src/chaincode/launchpad/sellExactToken.js.map +1 -0
  141. package/lib/src/chaincode/launchpad/sellWithNative.d.ts +23 -0
  142. package/lib/src/chaincode/launchpad/sellWithNative.d.ts.map +1 -0
  143. package/lib/src/chaincode/launchpad/sellWithNative.js +97 -0
  144. package/lib/src/chaincode/launchpad/sellWithNative.js.map +1 -0
  145. package/lib/src/chaincode/utils/index.d.ts +2 -0
  146. package/lib/src/chaincode/utils/index.d.ts.map +1 -0
  147. package/lib/src/chaincode/utils/index.js +19 -0
  148. package/lib/src/chaincode/utils/index.js.map +1 -0
  149. package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts +11 -0
  150. package/lib/src/chaincode/utils/launchpadSaleUtils.d.ts.map +1 -0
  151. package/lib/src/chaincode/utils/launchpadSaleUtils.js +65 -0
  152. package/lib/src/chaincode/utils/launchpadSaleUtils.js.map +1 -0
  153. package/lib/src/cli.d.ts +3 -0
  154. package/lib/src/cli.d.ts.map +1 -0
  155. package/lib/src/cli.js +41 -0
  156. package/lib/src/cli.js.map +1 -0
  157. package/lib/src/index.d.ts +14 -0
  158. package/lib/src/index.d.ts.map +1 -0
  159. package/lib/src/index.js +32 -0
  160. package/lib/src/index.js.map +1 -0
  161. package/lib/tsconfig.tsbuildinfo +1 -0
  162. package/package.json +54 -0
  163. package/src/api/index.ts +18 -0
  164. package/src/api/types/LaunchpadDtos.ts +362 -0
  165. package/src/api/types/LaunchpadFeeConfig.ts +45 -0
  166. package/src/api/types/LaunchpadFinalizeAllocation.ts +65 -0
  167. package/src/api/types/LaunchpadSale.ts +200 -0
  168. package/src/api/types/index.ts +19 -0
  169. package/src/api/utils/error.ts +32 -0
  170. package/src/api/utils/index.ts +16 -0
  171. package/src/api/validators/decorators.spec.ts +277 -0
  172. package/src/api/validators/decorators.ts +401 -0
  173. package/src/api/validators/index.ts +16 -0
  174. package/src/chaincode/LaunchpadContract.ts +211 -0
  175. package/src/chaincode/dexLaunchpadFeeGate.ts +43 -0
  176. package/src/chaincode/index.ts +16 -0
  177. package/src/chaincode/launchpad/buyExactToken.ts +128 -0
  178. package/src/chaincode/launchpad/buyWithNative.ts +120 -0
  179. package/src/chaincode/launchpad/callMemeTokenIn.ts +82 -0
  180. package/src/chaincode/launchpad/callMemeTokenOut.ts +80 -0
  181. package/src/chaincode/launchpad/callNativeTokenIn.ts +71 -0
  182. package/src/chaincode/launchpad/callNativeTokenOut.ts +81 -0
  183. package/src/chaincode/launchpad/configureLaunchpadFeeConfig.ts +69 -0
  184. package/src/chaincode/launchpad/createSale.ts +157 -0
  185. package/src/chaincode/launchpad/fees.ts +105 -0
  186. package/src/chaincode/launchpad/fetchLaunchpadAdressConfig.ts +38 -0
  187. package/src/chaincode/launchpad/fetchSaleDetails.ts +53 -0
  188. package/src/chaincode/launchpad/finaliseSale.ts +217 -0
  189. package/src/chaincode/launchpad/finalizeTokenAllocation.ts +47 -0
  190. package/src/chaincode/launchpad/index.ts +28 -0
  191. package/src/chaincode/launchpad/preMintCalculation.ts +61 -0
  192. package/src/chaincode/launchpad/sellExactToken.ts +122 -0
  193. package/src/chaincode/launchpad/sellWithNative.ts +112 -0
  194. package/src/chaincode/utils/index.ts +15 -0
  195. package/src/chaincode/utils/launchpadSaleUtils.ts +68 -0
  196. package/src/cli.ts +63 -0
  197. package/src/index.ts +32 -0
  198. package/tsconfig.base.json +29 -0
  199. package/tsconfig.json +19 -0
  200. package/tsconfig.spec.json +11 -0
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { ErrorCode as BaseErrorCode, ChainError } from "@gala-chain/api";
16
+
17
+ export const ErrorCode = {
18
+ ...BaseErrorCode,
19
+ PRECONDITION_FAILED: 412
20
+ };
21
+
22
+ export class SlippageToleranceExceededError extends ChainError {
23
+ constructor(message: string) {
24
+ super(message, 412);
25
+ }
26
+ }
27
+
28
+ export class PreConditionFailedError extends ChainError {
29
+ constructor(message: string) {
30
+ super(message, 412);
31
+ }
32
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ export * from "./error";
@@ -0,0 +1,277 @@
1
+ /*
2
+ * Copyright (c) Gala Games Inc. All rights reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { ArrayUniqueObjects, ChainCallDTO } from "@gala-chain/api";
16
+ import BigNumber from "bignumber.js";
17
+ import { ArrayNotEmpty, validate } from "class-validator";
18
+
19
+ import { BigNumberIsNegative, IsStringArrayRecord, IsStringRecord } from "./decorators";
20
+
21
+ describe("ArrayUniqueObject", () => {
22
+ it("validation should give errors when two users have the same id", async () => {
23
+ // Given
24
+ class MockDto extends ChainCallDTO {
25
+ @ArrayNotEmpty()
26
+ @ArrayUniqueObjects("id")
27
+ users: unknown[];
28
+ }
29
+
30
+ const NewFake = new MockDto();
31
+ NewFake.users = [{ id: 1 }, { id: 1 }, { id: 3 }];
32
+
33
+ // When
34
+ const output = await NewFake.validate();
35
+
36
+ // Then
37
+ expect(output).toEqual([
38
+ expect.objectContaining({
39
+ constraints: expect.objectContaining({
40
+ ArrayUniqueObjects: "users must not contains duplicate entry for id"
41
+ })
42
+ })
43
+ ]);
44
+ });
45
+
46
+ it("validation should give errors when two users have the same id", async () => {
47
+ // Given
48
+ class MockDto extends ChainCallDTO {
49
+ @ArrayNotEmpty()
50
+ @ArrayUniqueObjects("id")
51
+ users: unknown[];
52
+ }
53
+
54
+ const NewFake = new MockDto();
55
+ NewFake.users = [
56
+ { id: 1, other: "yee" },
57
+ { id: 1, other: "wee" },
58
+ { id: 3, other: "hee" }
59
+ ];
60
+
61
+ // When
62
+ const output = await NewFake.validate();
63
+
64
+ // Then
65
+ expect(output).toEqual([
66
+ expect.objectContaining({
67
+ constraints: expect.objectContaining({
68
+ ArrayUniqueObjects: "users must not contains duplicate entry for id"
69
+ })
70
+ })
71
+ ]);
72
+ });
73
+
74
+ it("validation should pass when all users have different ids", async () => {
75
+ // Given
76
+ class MockDto extends ChainCallDTO {
77
+ @ArrayNotEmpty()
78
+ @ArrayUniqueObjects("id")
79
+ users: unknown[];
80
+ }
81
+
82
+ const NewFake = new MockDto();
83
+ NewFake.users = [{ id: 1 }, { id: 2 }, { id: 3 }];
84
+
85
+ // When
86
+ const output = await NewFake.validate();
87
+
88
+ // Then
89
+ expect(output.length).toEqual(0);
90
+ });
91
+ });
92
+
93
+ describe("BigNumberIsNegative", () => {
94
+ it("should return error if BigNumber is positive", async () => {
95
+ // Given
96
+ class MockDto extends ChainCallDTO {
97
+ @BigNumberIsNegative()
98
+ amount: BigNumber;
99
+ }
100
+ const dto = new MockDto();
101
+ dto.amount = new BigNumber(5);
102
+
103
+ // When
104
+ const result = await validate(dto);
105
+
106
+ // Then
107
+ expect(result).toEqual([
108
+ expect.objectContaining({
109
+ constraints: expect.objectContaining({
110
+ BigNumberIsNegative: "amount must be negative but is 5"
111
+ })
112
+ })
113
+ ]);
114
+ });
115
+
116
+ it("should pass validation for negative BigNumber", async () => {
117
+ // Given
118
+ class MockDto extends ChainCallDTO {
119
+ @BigNumberIsNegative()
120
+ amount: BigNumber;
121
+ }
122
+ const dto = new MockDto();
123
+ dto.amount = new BigNumber(-10);
124
+
125
+ // When
126
+ const result = await validate(dto);
127
+
128
+ // then
129
+ expect(result.length).toBe(0);
130
+ });
131
+ });
132
+
133
+ describe("IsStringArrayRecord validator", () => {
134
+ class MockDto {
135
+ @IsStringArrayRecord()
136
+ data!: unknown;
137
+ }
138
+
139
+ it("should pass for a valid non-empty Record<string, string[]>", async () => {
140
+ // Given
141
+ const dto = new MockDto();
142
+ dto.data = {
143
+ key1: ["value1", "value2"],
144
+ key2: ["value3"]
145
+ };
146
+
147
+ // When
148
+ const errors = await validate(dto);
149
+
150
+ // Then
151
+ expect(errors.length).toBe(0);
152
+ });
153
+
154
+ it("should pass for an empty object", async () => {
155
+ // Given
156
+ const dto = new MockDto();
157
+ dto.data = {};
158
+
159
+ // When
160
+ const errors = await validate(dto);
161
+
162
+ // Then
163
+ expect(errors.length).toBe(0);
164
+ });
165
+
166
+ it("should fail if any value is not a string", async () => {
167
+ // Given
168
+ const dto = new MockDto();
169
+ dto.data = {
170
+ key1: "value1",
171
+ key2: 123
172
+ };
173
+
174
+ // When
175
+ const errors = await validate(dto);
176
+
177
+ // Then
178
+ expect(errors.length).toBeGreaterThan(0);
179
+ });
180
+
181
+ it("should fail if input is null", async () => {
182
+ // Given
183
+ const dto = new MockDto();
184
+ dto.data = null;
185
+
186
+ // When
187
+ const errors = await validate(dto);
188
+
189
+ // Then
190
+ expect(errors.length).toBeGreaterThan(0);
191
+ });
192
+
193
+ it("should fail if input is an array", async () => {
194
+ // Given
195
+ const dto = new MockDto();
196
+ dto.data = ["a", "b"];
197
+
198
+ // When
199
+ const errors = await validate(dto);
200
+
201
+ // Then
202
+ expect(errors.length).toBeGreaterThan(0);
203
+ });
204
+ });
205
+
206
+ describe("IsStringRecord validator", () => {
207
+ class MockDto {
208
+ @IsStringRecord()
209
+ data!: unknown;
210
+ }
211
+
212
+ it("should pass for a valid non-empty Record<string, string>", async () => {
213
+ // Given
214
+ const dto = new MockDto();
215
+ dto.data = {
216
+ key1: "value1",
217
+ key2: "value2"
218
+ };
219
+
220
+ // When
221
+ const errors = await validate(dto);
222
+
223
+ // Then
224
+ expect(errors.length).toBe(0);
225
+ });
226
+
227
+ it("should pass for an empty object", async () => {
228
+ // Given
229
+ const dto = new MockDto();
230
+ dto.data = {};
231
+
232
+ // When
233
+ const errors = await validate(dto);
234
+
235
+ // Then
236
+ expect(errors.length).toBe(0);
237
+ });
238
+
239
+ it("should fail if any value is not a string", async () => {
240
+ // Given
241
+ const dto = new MockDto();
242
+ dto.data = {
243
+ key1: "value1",
244
+ key2: 123
245
+ };
246
+
247
+ // When
248
+ const errors = await validate(dto);
249
+
250
+ // Then
251
+ expect(errors.length).toBeGreaterThan(0);
252
+ });
253
+
254
+ it("should fail if input is null", async () => {
255
+ // Given
256
+ const dto = new MockDto();
257
+ dto.data = null;
258
+
259
+ // When
260
+ const errors = await validate(dto);
261
+
262
+ // Then
263
+ expect(errors.length).toBeGreaterThan(0);
264
+ });
265
+
266
+ it("should fail if input is an array", async () => {
267
+ // Given
268
+ const dto = new MockDto();
269
+ dto.data = ["a", "b"];
270
+
271
+ // When
272
+ const errors = await validate(dto);
273
+
274
+ // Then
275
+ expect(errors.length).toBeGreaterThan(0);
276
+ });
277
+ });