@proto-kit/common 0.1.1-develop.153
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.
- package/LICENSE.md +201 -0
- package/dist/Constants.d.ts +4 -0
- package/dist/Constants.d.ts.map +1 -0
- package/dist/Constants.js +3 -0
- package/dist/config/ConfigurableModule.d.ts +21 -0
- package/dist/config/ConfigurableModule.d.ts.map +1 -0
- package/dist/config/ConfigurableModule.js +19 -0
- package/dist/config/ConfigurationAggregator.d.ts +10 -0
- package/dist/config/ConfigurationAggregator.d.ts.map +1 -0
- package/dist/config/ConfigurationAggregator.js +35 -0
- package/dist/config/ConfigurationReceiver.d.ts +25 -0
- package/dist/config/ConfigurationReceiver.d.ts.map +1 -0
- package/dist/config/ConfigurationReceiver.js +36 -0
- package/dist/config/ModuleContainer.d.ts +103 -0
- package/dist/config/ModuleContainer.d.ts.map +1 -0
- package/dist/config/ModuleContainer.js +163 -0
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/model/MethodPublicInput.d.ts +51 -0
- package/dist/model/MethodPublicInput.d.ts.map +1 -0
- package/dist/model/MethodPublicInput.js +11 -0
- package/dist/model/Option.d.ts +89 -0
- package/dist/model/Option.d.ts.map +1 -0
- package/dist/model/Option.js +86 -0
- package/dist/model/Path.d.ts +31 -0
- package/dist/model/Path.d.ts.map +1 -0
- package/dist/model/Path.js +44 -0
- package/dist/model/StateTransition.d.ts +85 -0
- package/dist/model/StateTransition.d.ts.map +1 -0
- package/dist/model/StateTransition.js +58 -0
- package/dist/model/StateTransitionProvableBatch.d.ts +56 -0
- package/dist/model/StateTransitionProvableBatch.d.ts.map +1 -0
- package/dist/model/StateTransitionProvableBatch.js +20 -0
- package/dist/prover/block/BlockProver.d.ts +199 -0
- package/dist/prover/block/BlockProver.d.ts.map +1 -0
- package/dist/prover/block/BlockProver.js +119 -0
- package/dist/prover/block/BlockScopedModule.d.ts +3 -0
- package/dist/prover/block/BlockScopedModule.d.ts.map +1 -0
- package/dist/prover/block/BlockScopedModule.js +6 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts +92 -0
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -0
- package/dist/prover/statetransition/StateTransitionProver.js +127 -0
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +16 -0
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +1 -0
- package/dist/prover/statetransition/StateTransitionWitnessProvider.js +17 -0
- package/dist/src/model/Option.d.ts +158 -0
- package/dist/src/model/Option.d.ts.map +1 -0
- package/dist/src/model/Option.js +53 -0
- package/dist/src/model/Path.d.ts +35 -0
- package/dist/src/model/Path.d.ts.map +1 -0
- package/dist/src/model/Path.js +51 -0
- package/dist/src/model/StateTransition.d.ts +201 -0
- package/dist/src/model/StateTransition.d.ts.map +1 -0
- package/dist/src/model/StateTransition.js +43 -0
- package/dist/src/utils/PrefixedHashList.d.ts +15 -0
- package/dist/src/utils/PrefixedHashList.d.ts.map +1 -0
- package/dist/src/utils/PrefixedHashList.js +28 -0
- package/dist/src/utils/ProvableHashList.d.ts +30 -0
- package/dist/src/utils/ProvableHashList.d.ts.map +1 -0
- package/dist/src/utils/ProvableHashList.js +43 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils/PrefixedHashList.d.ts +14 -0
- package/dist/utils/PrefixedHashList.d.ts.map +1 -0
- package/dist/utils/PrefixedHashList.js +12 -0
- package/dist/utils/PrefixedProvableHashList.d.ts +8 -0
- package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -0
- package/dist/utils/PrefixedProvableHashList.js +12 -0
- package/dist/utils/ProvableHashList.d.ts +26 -0
- package/dist/utils/ProvableHashList.d.ts.map +1 -0
- package/dist/utils/ProvableHashList.js +35 -0
- package/dist/utils/Utils.d.ts +22 -0
- package/dist/utils/Utils.d.ts.map +1 -0
- package/dist/utils/Utils.js +41 -0
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +26 -0
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +79 -0
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +143 -0
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +1 -0
- package/dist/utils/merkletree/RollupMerkleTree.js +246 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +53 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +98 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts +32 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -0
- package/dist/zkProgrammable/ZkProgrammable.js +60 -0
- package/dist/zkProgrammable/provableMethod.d.ts +16 -0
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -0
- package/dist/zkProgrammable/provableMethod.js +69 -0
- package/jest.config.cjs +1 -0
- package/package.json +35 -0
- package/src/config/ConfigurableModule.ts +44 -0
- package/src/config/ModuleContainer.ts +265 -0
- package/src/index.ts +9 -0
- package/src/types.ts +17 -0
- package/src/utils.ts +10 -0
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +122 -0
- package/src/zkProgrammable/ZkProgrammable.ts +119 -0
- package/src/zkProgrammable/provableMethod.ts +109 -0
- package/test/config/ModuleContainer.test.ts +82 -0
- package/test/tsconfig.json +4 -0
- package/test/zkProgrammable/ZkProgrammable.test.ts +283 -0
- package/tsconfig.json +8 -0
- package/tsconfig.test.json +9 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import { ConfigurableModule } from "../../src/config/ConfigurableModule";
|
|
3
|
+
import {
|
|
4
|
+
ModuleContainerErrors,
|
|
5
|
+
ModuleContainer,
|
|
6
|
+
ModulesRecord,
|
|
7
|
+
} from "../../src/config/ModuleContainer";
|
|
8
|
+
import { TypedClass } from "../../src/types";
|
|
9
|
+
|
|
10
|
+
// module container will accept modules that extend this type
|
|
11
|
+
class BaseTestModule<Config> extends ConfigurableModule<Config> {}
|
|
12
|
+
|
|
13
|
+
type TestModulesRecord = ModulesRecord<TypedClass<BaseTestModule<unknown>>>;
|
|
14
|
+
|
|
15
|
+
interface TestModuleConfig {
|
|
16
|
+
testConfigProperty: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class TestModule extends BaseTestModule<TestModuleConfig> {}
|
|
20
|
+
|
|
21
|
+
interface OtherTestModuleConfig {
|
|
22
|
+
otherTestConfigProperty: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class OtherTestModule extends BaseTestModule<OtherTestModuleConfig> {}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Showcases a wrongly typed/defined module as
|
|
29
|
+
* per the TestModuleContainer requirements
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line max-len
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class, @typescript-eslint/no-unused-vars
|
|
33
|
+
class WrongTestModule {}
|
|
34
|
+
|
|
35
|
+
class TestModuleContainer<
|
|
36
|
+
Modules extends TestModulesRecord
|
|
37
|
+
> extends ModuleContainer<Modules> {}
|
|
38
|
+
|
|
39
|
+
describe("moduleContainer", () => {
|
|
40
|
+
let container: TestModuleContainer<{
|
|
41
|
+
TestModule: typeof TestModule;
|
|
42
|
+
OtherTestModule: typeof OtherTestModule;
|
|
43
|
+
}>;
|
|
44
|
+
const testConfigProperty = 0;
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
container = new TestModuleContainer({
|
|
48
|
+
modules: {
|
|
49
|
+
TestModule,
|
|
50
|
+
OtherTestModule,
|
|
51
|
+
// this module would not be assignable to TestModuleContainer
|
|
52
|
+
// WrongTestModule,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should throw on resolution, if config was not provided", () => {
|
|
58
|
+
expect.assertions(1);
|
|
59
|
+
|
|
60
|
+
expect(() => {
|
|
61
|
+
container.resolve("TestModule");
|
|
62
|
+
}).toThrow(ModuleContainerErrors.configNotSetInContainer("TestModule"));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should resolve the registered module with the provided config", () => {
|
|
66
|
+
expect.assertions(1);
|
|
67
|
+
|
|
68
|
+
container.configure({
|
|
69
|
+
TestModule: {
|
|
70
|
+
testConfigProperty,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
OtherTestModule: {
|
|
74
|
+
otherTestConfigProperty: testConfigProperty,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const testModule = container.resolve("TestModule");
|
|
79
|
+
|
|
80
|
+
expect(testModule.config.testConfigProperty).toBe(testConfigProperty);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
4
|
+
import { jest } from "@jest/globals";
|
|
5
|
+
import { container } from "tsyringe";
|
|
6
|
+
import { Experimental, Field, Struct, Proof } from "snarkyjs";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
mockProof,
|
|
10
|
+
provableMethod,
|
|
11
|
+
} from "../../src/zkProgrammable/provableMethod";
|
|
12
|
+
import {
|
|
13
|
+
AreProofsEnabled,
|
|
14
|
+
CompileArtifact,
|
|
15
|
+
mockVerificationKey,
|
|
16
|
+
PlainZkProgram,
|
|
17
|
+
ZkProgrammable,
|
|
18
|
+
} from "../../src/zkProgrammable/ZkProgrammable";
|
|
19
|
+
import { ProvableMethodExecutionContext } from "../../src/zkProgrammable/ProvableMethodExecutionContext";
|
|
20
|
+
import { Pickles } from "snarkyjs/dist/node/snarky";
|
|
21
|
+
|
|
22
|
+
const appChainMock: AreProofsEnabled = {
|
|
23
|
+
areProofsEnabled: false,
|
|
24
|
+
|
|
25
|
+
setProofsEnabled(areProofsEnabled: boolean) {
|
|
26
|
+
this.areProofsEnabled = areProofsEnabled;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
class TestPublicInput extends Struct({
|
|
31
|
+
foo: Field,
|
|
32
|
+
}) {}
|
|
33
|
+
|
|
34
|
+
class TestPublicOutput extends Struct({
|
|
35
|
+
bar: Field,
|
|
36
|
+
}) {}
|
|
37
|
+
|
|
38
|
+
const failErrorMessage = "test failure";
|
|
39
|
+
|
|
40
|
+
class TestProgrammable extends ZkProgrammable<
|
|
41
|
+
TestPublicInput,
|
|
42
|
+
TestPublicOutput
|
|
43
|
+
> {
|
|
44
|
+
public appChain: AreProofsEnabled = appChainMock;
|
|
45
|
+
|
|
46
|
+
@provableMethod()
|
|
47
|
+
public foo(publicInput: TestPublicInput, bar: Field) {
|
|
48
|
+
// expose the private input as public output again for testing purposes
|
|
49
|
+
return new TestPublicOutput({
|
|
50
|
+
bar,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@provableMethod()
|
|
55
|
+
public fail(publicInput: TestPublicInput) {
|
|
56
|
+
publicInput.foo.assertEquals(1, failErrorMessage);
|
|
57
|
+
|
|
58
|
+
return new TestPublicOutput({
|
|
59
|
+
bar: Field(0),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public zkProgramFactory() {
|
|
64
|
+
const program = Experimental.ZkProgram({
|
|
65
|
+
publicInput: TestPublicInput,
|
|
66
|
+
publicOutput: TestPublicOutput,
|
|
67
|
+
|
|
68
|
+
methods: {
|
|
69
|
+
foo: {
|
|
70
|
+
privateInputs: [Field],
|
|
71
|
+
method: this.foo.bind(this),
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
fail: {
|
|
75
|
+
privateInputs: [],
|
|
76
|
+
method: this.fail.bind(this),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const SelfProof = Experimental.ZkProgram.Proof(program);
|
|
82
|
+
|
|
83
|
+
const methods = {
|
|
84
|
+
foo: program.foo.bind(program),
|
|
85
|
+
fail: program.fail.bind(program),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
compile: program.compile.bind(program),
|
|
90
|
+
verify: program.verify.bind(program),
|
|
91
|
+
Proof: SelfProof,
|
|
92
|
+
methods,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class OtherTestProgrammable extends ZkProgrammable {
|
|
98
|
+
public appChain: AreProofsEnabled = appChainMock;
|
|
99
|
+
|
|
100
|
+
public constructor(public testProgrammable: TestProgrammable) {
|
|
101
|
+
super();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@provableMethod()
|
|
105
|
+
public bar(
|
|
106
|
+
testProgrammableProof: InstanceType<
|
|
107
|
+
typeof this.testProgrammable.zkProgram.Proof
|
|
108
|
+
>
|
|
109
|
+
) {
|
|
110
|
+
testProgrammableProof.verify();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public zkProgramFactory(): PlainZkProgram {
|
|
114
|
+
const program = Experimental.ZkProgram({
|
|
115
|
+
methods: {
|
|
116
|
+
bar: {
|
|
117
|
+
privateInputs: [this.testProgrammable.zkProgram.Proof],
|
|
118
|
+
method: this.bar.bind(this),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const methods = {
|
|
124
|
+
bar: program.bar.bind(program),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const SelfProof = Experimental.ZkProgram.Proof(program);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
compile: program.compile.bind(program),
|
|
131
|
+
verify: program.verify.bind(program),
|
|
132
|
+
Proof: SelfProof,
|
|
133
|
+
methods,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
describe("zkProgrammable", () => {
|
|
139
|
+
let testProgrammable: TestProgrammable;
|
|
140
|
+
let artifact: CompileArtifact;
|
|
141
|
+
let zkProgramFactorySpy: ReturnType<typeof jest.spyOn>;
|
|
142
|
+
|
|
143
|
+
describe.each([
|
|
144
|
+
[
|
|
145
|
+
false,
|
|
146
|
+
{
|
|
147
|
+
verificationKey: mockVerificationKey,
|
|
148
|
+
shouldVerifyMockProofs: true,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
true,
|
|
153
|
+
{
|
|
154
|
+
verificationKey:
|
|
155
|
+
"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",
|
|
156
|
+
|
|
157
|
+
shouldVerifyMockProofs: false,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
])(
|
|
161
|
+
"areProofsEnabled",
|
|
162
|
+
(areProofsEnabled, { verificationKey, shouldVerifyMockProofs }) => {
|
|
163
|
+
beforeAll(async () => {
|
|
164
|
+
testProgrammable = new TestProgrammable();
|
|
165
|
+
testProgrammable.appChain.setProofsEnabled(areProofsEnabled);
|
|
166
|
+
zkProgramFactorySpy = jest.spyOn(testProgrammable, "zkProgramFactory");
|
|
167
|
+
artifact = await testProgrammable.zkProgram.compile();
|
|
168
|
+
}, 500_000);
|
|
169
|
+
|
|
170
|
+
describe("zkProgramFactory", () => {
|
|
171
|
+
it("should create and cache a ZkProgram", () => {
|
|
172
|
+
expect.assertions(1);
|
|
173
|
+
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
175
|
+
const programs = {
|
|
176
|
+
1: testProgrammable.zkProgram,
|
|
177
|
+
2: testProgrammable.zkProgram,
|
|
178
|
+
3: testProgrammable.zkProgram,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
expect(zkProgramFactorySpy).toHaveBeenCalledTimes(1);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("compile should return the correct verification key", () => {
|
|
186
|
+
expect.assertions(1);
|
|
187
|
+
|
|
188
|
+
expect(artifact.verificationKey).toBe(verificationKey);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("if proofs are disabled, it should successfully verify mock proofs", async () => {
|
|
192
|
+
expect.assertions(1);
|
|
193
|
+
|
|
194
|
+
const proof = new testProgrammable.zkProgram.Proof({
|
|
195
|
+
proof: mockProof,
|
|
196
|
+
|
|
197
|
+
publicInput: new TestPublicInput({
|
|
198
|
+
foo: Field(0),
|
|
199
|
+
}),
|
|
200
|
+
|
|
201
|
+
publicOutput: new TestPublicOutput({
|
|
202
|
+
bar: Field(0),
|
|
203
|
+
}),
|
|
204
|
+
|
|
205
|
+
maxProofsVerified: 0,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const verified = await testProgrammable.zkProgram.verify(proof);
|
|
209
|
+
|
|
210
|
+
expect(verified).toBe(shouldVerifyMockProofs);
|
|
211
|
+
|
|
212
|
+
// Check if toJSON works on mockproofs
|
|
213
|
+
// const json = proof.toJSON();
|
|
214
|
+
// expect(json).toBeDefined();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
describe("provableMethod", () => {
|
|
220
|
+
const executionContext = container.resolve<ProvableMethodExecutionContext>(
|
|
221
|
+
ProvableMethodExecutionContext
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
let otherTestProgrammable: OtherTestProgrammable;
|
|
225
|
+
|
|
226
|
+
const testPublicInput = new TestPublicInput({
|
|
227
|
+
foo: Field(0),
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("zkProgram interoperability", () => {
|
|
231
|
+
beforeAll(async () => {
|
|
232
|
+
otherTestProgrammable = new OtherTestProgrammable(testProgrammable);
|
|
233
|
+
await otherTestProgrammable.zkProgram.compile();
|
|
234
|
+
}, 500_000);
|
|
235
|
+
|
|
236
|
+
it("should successfully pass proof of one zkProgram as input to another zkProgram", async () => {
|
|
237
|
+
expect.assertions(3);
|
|
238
|
+
|
|
239
|
+
// execute foo
|
|
240
|
+
testProgrammable.foo(testPublicInput, Field(0));
|
|
241
|
+
|
|
242
|
+
// prove foo
|
|
243
|
+
const testProof = await executionContext
|
|
244
|
+
.current()
|
|
245
|
+
.result.prove<Proof<TestPublicInput, TestPublicOutput>>();
|
|
246
|
+
const testProofVerified = await testProgrammable.zkProgram.verify(
|
|
247
|
+
testProof
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
// execute bar
|
|
251
|
+
otherTestProgrammable.bar(testProof);
|
|
252
|
+
|
|
253
|
+
// proof bar
|
|
254
|
+
const otherTestProof = await executionContext
|
|
255
|
+
.current()
|
|
256
|
+
.result.prove<Proof<undefined, void>>();
|
|
257
|
+
const otherTestProofVerified =
|
|
258
|
+
await otherTestProgrammable.zkProgram.verify(otherTestProof);
|
|
259
|
+
|
|
260
|
+
expect(testProof.publicOutput.bar.toString()).toBe(
|
|
261
|
+
testPublicInput.foo.toString()
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
expect(testProofVerified).toBe(true);
|
|
265
|
+
expect(otherTestProofVerified).toBe(true);
|
|
266
|
+
}, 500_000);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe("failed method execution", () => {
|
|
270
|
+
it("if the method fails, it should fail to execute and prove", async () => {
|
|
271
|
+
expect.assertions(2);
|
|
272
|
+
|
|
273
|
+
expect(() => {
|
|
274
|
+
testProgrammable.fail(testPublicInput);
|
|
275
|
+
}).toThrow(failErrorMessage);
|
|
276
|
+
|
|
277
|
+
await expect(async () => {
|
|
278
|
+
await executionContext.current().result.prove();
|
|
279
|
+
}).rejects.toThrow(failErrorMessage);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
});
|
package/tsconfig.json
ADDED