@proto-kit/common 0.1.1-develop.651 → 0.1.1-develop.833
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 -201
- package/dist/config/ChildContainerFactory.d.ts +10 -0
- package/dist/config/ChildContainerFactory.d.ts.map +1 -0
- package/dist/config/ChildContainerFactory.js +23 -0
- package/dist/config/ChildContainerStartable.d.ts +5 -0
- package/dist/config/ChildContainerStartable.d.ts.map +1 -0
- package/dist/config/ChildContainerStartable.js +1 -0
- package/dist/config/ConfigurableModule.d.ts +1 -1
- package/dist/config/ConfigurableModule.d.ts.map +1 -1
- package/dist/config/ConfigurableModule.js +0 -1
- package/dist/config/ModuleContainer.d.ts +10 -2
- package/dist/config/ModuleContainer.d.ts.map +1 -1
- package/dist/config/ModuleContainer.js +6 -10
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -1
- package/dist/dependencyFactory/injectOptional.d.ts.map +1 -1
- package/dist/dependencyFactory/injectOptional.js +1 -4
- package/dist/events/EventEmitter.d.ts.map +1 -1
- package/dist/events/EventEmitter.js +0 -1
- package/dist/events/EventEmitterProxy.d.ts.map +1 -1
- package/dist/events/EventEmitterProxy.js +2 -0
- package/dist/log.d.ts +3 -2
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +11 -4
- package/dist/quickmaths.d.ts +7 -0
- package/dist/quickmaths.d.ts.map +1 -0
- package/dist/quickmaths.js +24 -0
- package/dist/test/equalProvable.d.ts +20 -0
- package/dist/test/equalProvable.d.ts.map +1 -0
- package/dist/test/equalProvable.js +13 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -1
- package/dist/trees/MockAsyncMerkleStore.js +1 -1
- package/dist/trees/RollupMerkleTree.d.ts +35 -16
- package/dist/trees/RollupMerkleTree.d.ts.map +1 -1
- package/dist/trees/RollupMerkleTree.js +8 -13
- package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.js +17 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +12 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -10
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -1
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +1 -3
- package/dist/zkProgrammable/ZkProgrammable.d.ts +11 -5
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -1
- package/dist/zkProgrammable/ZkProgrammable.js +7 -2
- package/dist/zkProgrammable/provableMethod.d.ts +5 -6
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -1
- package/dist/zkProgrammable/provableMethod.js +2 -5
- package/package.json +5 -5
- package/src/config/ChildContainerCreatable.ts +1 -1
- package/src/config/ConfigurableModule.ts +1 -2
- package/src/config/ModuleContainer.ts +17 -13
- package/src/dependencyFactory/DependencyFactory.ts +5 -4
- package/src/dependencyFactory/injectOptional.ts +0 -1
- package/src/events/EventEmitter.ts +0 -2
- package/src/events/EventEmitterProxy.ts +7 -5
- package/src/log.ts +20 -6
- package/src/trees/MockAsyncMerkleStore.ts +2 -1
- package/src/trees/RollupMerkleTree.ts +11 -17
- package/src/trees/VirtualMerkleTreeStore.ts +2 -3
- package/src/types.ts +2 -4
- package/src/utils.ts +77 -19
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +2 -4
- package/src/zkProgrammable/ZkProgrammable.ts +19 -13
- package/src/zkProgrammable/provableMethod.ts +13 -15
- package/test/config/ContainerEvents.test.ts +6 -25
- package/test/config/ModuleContainer.test.ts +10 -25
- package/test/trees/MerkleTree.test.ts +3 -2
- package/test/tsconfig.json +5 -2
- package/test/zkProgrammable/ZkProgrammable.test.ts +104 -83
- package/tsconfig.json +1 -1
- package/tsconfig.test.json +0 -9
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Field,
|
|
3
|
+
FlexibleProvablePure,
|
|
4
|
+
Poseidon,
|
|
5
|
+
DynamicProof,
|
|
6
|
+
Proof,
|
|
7
|
+
} from "o1js";
|
|
2
8
|
|
|
3
9
|
export function requireTrue(
|
|
4
10
|
condition: boolean,
|
|
@@ -11,17 +17,50 @@ export function requireTrue(
|
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
export function range(
|
|
20
|
+
export function range(
|
|
21
|
+
startOrEnd: number,
|
|
22
|
+
endOrNothing: number | undefined
|
|
23
|
+
): number[] {
|
|
24
|
+
let end = endOrNothing;
|
|
25
|
+
let start = startOrEnd;
|
|
15
26
|
if (end === undefined) {
|
|
16
27
|
end = startOrEnd;
|
|
17
|
-
|
|
28
|
+
start = 0;
|
|
18
29
|
}
|
|
19
|
-
return Array.from(
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
return Array.from({ length: end - start }, (ignored, index) => index + start);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function reduceSequential<T, U>(
|
|
34
|
+
array: T[],
|
|
35
|
+
callbackfn: (
|
|
36
|
+
previousValue: U,
|
|
37
|
+
currentValue: T,
|
|
38
|
+
currentIndex: number,
|
|
39
|
+
array: T[]
|
|
40
|
+
) => Promise<U>,
|
|
41
|
+
initialValue: U
|
|
42
|
+
) {
|
|
43
|
+
return array.reduce<Promise<U>>(
|
|
44
|
+
async (previousPromise, current, index, arr) => {
|
|
45
|
+
const previous = await previousPromise;
|
|
46
|
+
return await callbackfn(previous, current, index, arr);
|
|
47
|
+
},
|
|
48
|
+
Promise.resolve(initialValue)
|
|
22
49
|
);
|
|
23
50
|
}
|
|
24
51
|
|
|
52
|
+
export function mapSequential<T, R>(
|
|
53
|
+
array: T[],
|
|
54
|
+
f: (element: T, index: number, array: T[]) => Promise<R>
|
|
55
|
+
) {
|
|
56
|
+
return array.reduce<Promise<R[]>>(async (r, element, index, a) => {
|
|
57
|
+
const ret = await r;
|
|
58
|
+
const next = await f(element, index, a);
|
|
59
|
+
ret.push(next);
|
|
60
|
+
return ret;
|
|
61
|
+
}, Promise.resolve([]));
|
|
62
|
+
}
|
|
63
|
+
|
|
25
64
|
/**
|
|
26
65
|
* Computes a dummy value for the given value type.
|
|
27
66
|
*
|
|
@@ -38,7 +77,6 @@ export function dummyValue<Value>(
|
|
|
38
77
|
return valueType.fromFields(fields) as Value;
|
|
39
78
|
}
|
|
40
79
|
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
42
80
|
export function noop(): void {}
|
|
43
81
|
|
|
44
82
|
export interface ToFieldable {
|
|
@@ -53,14 +91,19 @@ export interface ToJSONableStatic {
|
|
|
53
91
|
toJSON: (value: unknown) => any;
|
|
54
92
|
}
|
|
55
93
|
|
|
56
|
-
export interface ProofTypes {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
94
|
+
// export interface ProofTypes {
|
|
95
|
+
// publicOutputType?: ToFieldableStatic;
|
|
96
|
+
// publicInputType?: ToFieldableStatic;
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
export type ProofTypes =
|
|
100
|
+
| typeof Proof<unknown, unknown>
|
|
101
|
+
| typeof DynamicProof<unknown, unknown>;
|
|
60
102
|
|
|
61
103
|
export async function sleep(ms: number) {
|
|
62
|
-
|
|
63
|
-
|
|
104
|
+
await new Promise((resolve) => {
|
|
105
|
+
setTimeout(resolve, ms);
|
|
106
|
+
});
|
|
64
107
|
}
|
|
65
108
|
|
|
66
109
|
export function filterNonNull<Type>(value: Type | null): value is Type {
|
|
@@ -73,19 +116,34 @@ export function filterNonUndefined<Type>(
|
|
|
73
116
|
return value !== undefined;
|
|
74
117
|
}
|
|
75
118
|
|
|
76
|
-
|
|
119
|
+
const encoder = new TextEncoder();
|
|
77
120
|
|
|
78
121
|
// Copied from o1js binable.ts:317
|
|
79
122
|
export function prefixToField(prefix: string): Field {
|
|
80
|
-
|
|
123
|
+
const fieldSize = Field.sizeInBytes;
|
|
81
124
|
if (prefix.length >= fieldSize) throw Error("prefix too long");
|
|
82
|
-
|
|
125
|
+
const stringBytes = [...encoder.encode(prefix)];
|
|
83
126
|
return Field.fromBytes(
|
|
84
127
|
stringBytes.concat(Array(fieldSize - stringBytes.length).fill(0))
|
|
85
128
|
);
|
|
86
129
|
}
|
|
87
130
|
|
|
88
131
|
export function hashWithPrefix(prefix: string, input: Field[]) {
|
|
89
|
-
const salt = Poseidon.update(
|
|
90
|
-
|
|
91
|
-
|
|
132
|
+
const salt = Poseidon.update(
|
|
133
|
+
[Field(0), Field(0), Field(0)],
|
|
134
|
+
[prefixToField(prefix)]
|
|
135
|
+
);
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
137
|
+
return Poseidon.update(salt as [Field, Field, Field], input)[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// end copy
|
|
141
|
+
|
|
142
|
+
export function expectDefined<T>(value: T | undefined): asserts value is T {
|
|
143
|
+
expect(value).toBeDefined();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
type NonMethodKeys<Type> = {
|
|
147
|
+
[Key in keyof Type]: Type[Key] extends Function ? never : Key;
|
|
148
|
+
}[keyof Type];
|
|
149
|
+
export type NonMethods<Type> = Pick<Type, NonMethodKeys<Type>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Proof } from "o1js";
|
|
2
2
|
import { singleton } from "tsyringe";
|
|
3
3
|
import uniqueId from "lodash/uniqueId";
|
|
4
4
|
|
|
@@ -23,8 +23,7 @@ export class ProvableMethodExecutionResult {
|
|
|
23
23
|
public prover?: () => Promise<Proof<unknown, unknown>>;
|
|
24
24
|
|
|
25
25
|
public async prove<
|
|
26
|
-
|
|
27
|
-
ProofType extends Proof<unknown, unknown>
|
|
26
|
+
ProofType extends Proof<unknown, unknown>,
|
|
28
27
|
>(): Promise<ProofType> {
|
|
29
28
|
if (!this.prover) {
|
|
30
29
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
@@ -54,7 +53,6 @@ export class ProvableMethodExecutionContext {
|
|
|
54
53
|
public result: ProvableMethodExecutionResult =
|
|
55
54
|
new ProvableMethodExecutionResult();
|
|
56
55
|
|
|
57
|
-
// eslint-disable-next-line no-warning-comments,max-len
|
|
58
56
|
// TODO See if we should make this class generic, bc I think we can persist the type
|
|
59
57
|
/**
|
|
60
58
|
* Adds a method prover to the current execution context,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZkProgram, FlexibleProvablePure, Proof, Field, Provable } from "o1js";
|
|
2
2
|
import { Memoize } from "typescript-memoize";
|
|
3
3
|
|
|
4
|
+
import { log } from "../log";
|
|
5
|
+
|
|
4
6
|
import { MOCK_PROOF } from "./provableMethod";
|
|
5
7
|
|
|
6
8
|
const errors = {
|
|
@@ -9,7 +11,10 @@ const errors = {
|
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
export interface CompileArtifact {
|
|
12
|
-
verificationKey:
|
|
14
|
+
verificationKey: {
|
|
15
|
+
data: string;
|
|
16
|
+
hash: Field;
|
|
17
|
+
};
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
export interface AreProofsEnabled {
|
|
@@ -29,24 +34,22 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
|
|
|
29
34
|
compile: Compile;
|
|
30
35
|
verify: Verify<PublicInput, PublicOutput>;
|
|
31
36
|
Proof: ReturnType<
|
|
32
|
-
typeof
|
|
37
|
+
typeof ZkProgram.Proof<
|
|
33
38
|
FlexibleProvablePure<PublicInput>,
|
|
34
39
|
FlexibleProvablePure<PublicOutput>
|
|
35
40
|
>
|
|
36
41
|
>;
|
|
37
42
|
methods: Record<
|
|
38
43
|
string,
|
|
39
|
-
| ((
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
...args: any
|
|
42
|
-
) => Promise<Proof<PublicInput, PublicOutput>>)
|
|
44
|
+
| ((...args: any) => Promise<Proof<PublicInput, PublicOutput>>)
|
|
43
45
|
| ((
|
|
44
46
|
publicInput: PublicInput,
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
47
|
...args: any
|
|
47
48
|
) => Promise<Proof<PublicInput, PublicOutput>>)
|
|
48
49
|
>;
|
|
49
|
-
analyzeMethods:
|
|
50
|
+
analyzeMethods: () => Promise<
|
|
51
|
+
Record<string, Awaited<ReturnType<typeof Provable.constraintSystem>>>
|
|
52
|
+
>;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
export function verifyToMockable<PublicInput, PublicOutput>(
|
|
@@ -61,7 +64,7 @@ export function verifyToMockable<PublicInput, PublicOutput>(
|
|
|
61
64
|
verified = await verify(proof);
|
|
62
65
|
} catch (error: unknown) {
|
|
63
66
|
// silently fail verification
|
|
64
|
-
|
|
67
|
+
log.error(error);
|
|
65
68
|
verified = false;
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -72,7 +75,10 @@ export function verifyToMockable<PublicInput, PublicOutput>(
|
|
|
72
75
|
};
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
export const MOCK_VERIFICATION_KEY =
|
|
78
|
+
export const MOCK_VERIFICATION_KEY = {
|
|
79
|
+
data: "mock-verification-key",
|
|
80
|
+
hash: Field(0),
|
|
81
|
+
};
|
|
76
82
|
|
|
77
83
|
export function compileToMockable(
|
|
78
84
|
compile: Compile,
|
|
@@ -91,7 +97,7 @@ export function compileToMockable(
|
|
|
91
97
|
|
|
92
98
|
export abstract class ZkProgrammable<
|
|
93
99
|
PublicInput = undefined,
|
|
94
|
-
PublicOutput = void
|
|
100
|
+
PublicOutput = void,
|
|
95
101
|
> {
|
|
96
102
|
public abstract get appChain(): AreProofsEnabled | undefined;
|
|
97
103
|
|
|
@@ -115,7 +121,7 @@ export abstract class ZkProgrammable<
|
|
|
115
121
|
|
|
116
122
|
export interface WithZkProgrammable<
|
|
117
123
|
PublicInput = undefined,
|
|
118
|
-
PublicOutput = void
|
|
124
|
+
PublicOutput = void,
|
|
119
125
|
> {
|
|
120
126
|
zkProgrammable: ZkProgrammable<PublicInput, PublicOutput>;
|
|
121
127
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Proof, DynamicProof } from "o1js";
|
|
2
2
|
import { container } from "tsyringe";
|
|
3
3
|
|
|
4
4
|
import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext";
|
|
5
5
|
import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
|
|
6
|
-
import { ToFieldable } from "../utils";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export type ArgumentTypes = (
|
|
7
|
+
// Now, in o1js provable types are normal js objects, therefore any
|
|
8
|
+
export type O1JSPrimitive = object | string | boolean | number;
|
|
9
|
+
export type ArgumentTypes = (
|
|
10
|
+
| O1JSPrimitive
|
|
11
|
+
| Proof<unknown, unknown>
|
|
12
|
+
| DynamicProof<unknown, unknown>
|
|
13
|
+
)[];
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
export type DecoratedMethod = (...args: ArgumentTypes) => unknown;
|
|
15
|
+
export type DecoratedMethod = (...args: ArgumentTypes) => Promise<unknown>;
|
|
14
16
|
|
|
15
17
|
export const MOCK_PROOF = "mock-proof";
|
|
16
18
|
|
|
@@ -20,7 +22,6 @@ export function toProver(
|
|
|
20
22
|
isFirstParameterPublicInput: boolean,
|
|
21
23
|
...args: ArgumentTypes
|
|
22
24
|
) {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
25
|
return async function prover(this: ZkProgrammable<any, any>) {
|
|
25
26
|
const areProofsEnabled = this.appChain?.areProofsEnabled;
|
|
26
27
|
if (areProofsEnabled ?? false) {
|
|
@@ -29,12 +30,11 @@ export function toProver(
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// create a mock proof by simulating method execution in JS
|
|
32
|
-
const publicOutput = Reflect.apply(simulatedMethod, this, args);
|
|
33
|
+
const publicOutput = await Reflect.apply(simulatedMethod, this, args);
|
|
33
34
|
|
|
34
35
|
return new this.zkProgram.Proof({
|
|
35
36
|
proof: MOCK_PROOF,
|
|
36
37
|
|
|
37
|
-
// eslint-disable-next-line no-warning-comments
|
|
38
38
|
// TODO: provide undefined if public input is not used
|
|
39
39
|
publicInput: isFirstParameterPublicInput ? args[0] : undefined,
|
|
40
40
|
publicOutput,
|
|
@@ -64,17 +64,16 @@ export function provableMethod(
|
|
|
64
64
|
)
|
|
65
65
|
) {
|
|
66
66
|
return <
|
|
67
|
-
|
|
68
|
-
Target extends WithZkProgrammable<any, any> | ZkProgrammable<any, any>
|
|
67
|
+
Target extends WithZkProgrammable<any, any> | ZkProgrammable<any, any>,
|
|
69
68
|
>(
|
|
70
69
|
target: Target,
|
|
71
70
|
methodName: string,
|
|
72
|
-
descriptor:
|
|
71
|
+
descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise<any> | any>
|
|
73
72
|
) => {
|
|
74
73
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
75
74
|
const simulatedMethod = descriptor.value as DecoratedMethod;
|
|
76
75
|
|
|
77
|
-
descriptor.value = function value(
|
|
76
|
+
descriptor.value = async function value(
|
|
78
77
|
this: ZkProgrammable<unknown, unknown>,
|
|
79
78
|
...args: ArgumentTypes
|
|
80
79
|
) {
|
|
@@ -100,7 +99,6 @@ export function provableMethod(
|
|
|
100
99
|
* or not, execute its simulated (Javascript) version and
|
|
101
100
|
* return the result.
|
|
102
101
|
*/
|
|
103
|
-
// eslint-disable-next-line @typescript-eslint/init-declarations
|
|
104
102
|
let result: unknown;
|
|
105
103
|
try {
|
|
106
104
|
result = Reflect.apply(simulatedMethod, this, args);
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import { injectable, container as tsyringeContainer } from "tsyringe";
|
|
3
|
+
|
|
2
4
|
import {
|
|
3
5
|
BaseModuleInstanceType,
|
|
4
|
-
BaseModuleType,
|
|
5
6
|
ConfigurableModule,
|
|
6
7
|
EventEmitter,
|
|
7
8
|
EventEmittingComponent,
|
|
8
|
-
EventsRecord,
|
|
9
9
|
ModuleContainer,
|
|
10
10
|
ModulesRecord,
|
|
11
|
-
TypedClass,
|
|
12
11
|
} from "../../src";
|
|
13
|
-
import { injectable, container as tsyringeContainer } from "tsyringe";
|
|
14
|
-
import {
|
|
15
|
-
CastToEventsRecord,
|
|
16
|
-
ContainerEvents,
|
|
17
|
-
FlattenedContainerEvents,
|
|
18
|
-
FlattenObject,
|
|
19
|
-
} from "../../src/events/EventEmitterProxy";
|
|
20
12
|
|
|
21
13
|
class TestContainer<
|
|
22
|
-
Modules extends ModulesRecord
|
|
14
|
+
Modules extends ModulesRecord,
|
|
23
15
|
> extends ModuleContainer<Modules> {}
|
|
24
16
|
|
|
25
17
|
type TestEvents = {
|
|
26
18
|
test: [string];
|
|
27
|
-
}
|
|
19
|
+
};
|
|
28
20
|
|
|
29
21
|
@injectable()
|
|
30
22
|
class TestModule
|
|
@@ -36,7 +28,7 @@ class TestModule
|
|
|
36
28
|
|
|
37
29
|
type TestEvents2 = {
|
|
38
30
|
test2: [number];
|
|
39
|
-
}
|
|
31
|
+
};
|
|
40
32
|
|
|
41
33
|
class TestModule2
|
|
42
34
|
extends ConfigurableModule<{}>
|
|
@@ -45,17 +37,6 @@ class TestModule2
|
|
|
45
37
|
events = new EventEmitter<TestEvents2>();
|
|
46
38
|
}
|
|
47
39
|
|
|
48
|
-
type X = {
|
|
49
|
-
test: TypedClass<TestModule>;
|
|
50
|
-
test2: TypedClass<TestModule2>;
|
|
51
|
-
};
|
|
52
|
-
type Y = FlattenObject<ContainerEvents<X>>;
|
|
53
|
-
type Z = CastToEventsRecord<FlattenedContainerEvents<X>>;
|
|
54
|
-
// const y: Y = {
|
|
55
|
-
// test: ["asd"],
|
|
56
|
-
// // test2: [2]
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
40
|
describe("test event propagation", () => {
|
|
60
41
|
it("should propagate events up", () => {
|
|
61
42
|
expect.assertions(1);
|
|
@@ -69,7 +50,7 @@ describe("test event propagation", () => {
|
|
|
69
50
|
|
|
70
51
|
container.configure({
|
|
71
52
|
test: {},
|
|
72
|
-
test2: {}
|
|
53
|
+
test2: {},
|
|
73
54
|
});
|
|
74
55
|
|
|
75
56
|
container.create(() => tsyringeContainer.createChildContainer());
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
1
|
import "reflect-metadata";
|
|
3
2
|
import { container as tsyringeContainer, inject, injectable } from "tsyringe";
|
|
4
3
|
|
|
@@ -9,10 +8,9 @@ import {
|
|
|
9
8
|
import {
|
|
10
9
|
ModuleContainer,
|
|
11
10
|
ModulesRecord,
|
|
12
|
-
DependenciesFromModules,
|
|
13
11
|
} from "../../src/config/ModuleContainer";
|
|
14
12
|
import { TypedClass } from "../../src/types";
|
|
15
|
-
import {
|
|
13
|
+
import { DependencyFactory } from "../../src";
|
|
16
14
|
|
|
17
15
|
// module container will accept modules that extend this type
|
|
18
16
|
class BaseTestModule<Config> extends ConfigurableModule<Config> {}
|
|
@@ -63,27 +61,12 @@ class OtherTestModule extends BaseTestModule<OtherTestModuleConfig> {
|
|
|
63
61
|
* Showcases a wrongly typed/defined module as
|
|
64
62
|
* per the TestModuleContainer requirements
|
|
65
63
|
*/
|
|
66
|
-
// eslint-disable-next-line
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class, @typescript-eslint/no-unused-vars
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
68
65
|
class WrongTestModule {}
|
|
69
66
|
|
|
70
67
|
class TestModuleContainer<
|
|
71
|
-
Modules extends TestModulesRecord
|
|
72
|
-
> extends ModuleContainer<Modules> {
|
|
73
|
-
public create(childContainerProvider: ChildContainerProvider) {
|
|
74
|
-
super.create(childContainerProvider);
|
|
75
|
-
this.registerDependencyFactories(["TestModule" as any]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type inferred = DependenciesFromModules<{
|
|
80
|
-
TestModule: typeof TestModule;
|
|
81
|
-
OtherTestModule: typeof OtherTestModule;
|
|
82
|
-
}>;
|
|
83
|
-
|
|
84
|
-
// const merged2T: merged2 = {
|
|
85
|
-
// dependencyModule1: ""
|
|
86
|
-
// }
|
|
68
|
+
Modules extends TestModulesRecord,
|
|
69
|
+
> extends ModuleContainer<Modules> {}
|
|
87
70
|
|
|
88
71
|
describe("moduleContainer", () => {
|
|
89
72
|
let container: TestModuleContainer<{
|
|
@@ -103,7 +86,7 @@ describe("moduleContainer", () => {
|
|
|
103
86
|
});
|
|
104
87
|
});
|
|
105
88
|
|
|
106
|
-
it
|
|
89
|
+
it("should resolve dependency factory dependencies correctly", () => {
|
|
107
90
|
container.configure({
|
|
108
91
|
TestModule: {
|
|
109
92
|
testConfigProperty,
|
|
@@ -116,7 +99,9 @@ describe("moduleContainer", () => {
|
|
|
116
99
|
|
|
117
100
|
container.create(() => tsyringeContainer.createChildContainer());
|
|
118
101
|
|
|
119
|
-
|
|
102
|
+
// Unfortunately we still need this so that the dependencies are registered
|
|
103
|
+
container.resolve("TestModule");
|
|
104
|
+
const dm = container.resolve("DependencyModule1");
|
|
120
105
|
|
|
121
106
|
expect(dm.x()).toBe("dependency factory works");
|
|
122
107
|
expect(dm.testModule).toBeDefined();
|
|
@@ -150,7 +135,7 @@ describe("moduleContainer", () => {
|
|
|
150
135
|
|
|
151
136
|
expect(testModule.config.testConfigProperty).toBe(testConfigProperty);
|
|
152
137
|
|
|
153
|
-
const dependency = container.resolve("
|
|
138
|
+
const dependency = container.resolve("DependencyModule1");
|
|
154
139
|
dependency.x();
|
|
155
140
|
});
|
|
156
141
|
|
|
@@ -178,7 +163,7 @@ describe("moduleContainer", () => {
|
|
|
178
163
|
|
|
179
164
|
container.create(() => tsyringeContainer.createChildContainer());
|
|
180
165
|
|
|
181
|
-
const config = container.resolve("TestModule")
|
|
166
|
+
const { config } = container.resolve("TestModule");
|
|
182
167
|
|
|
183
168
|
expect(config.testConfigProperty).toBe(3);
|
|
184
169
|
expect(config.testConfigProperty2).toBe(2);
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { beforeEach } from "@jest/globals";
|
|
2
|
-
import { Field
|
|
2
|
+
import { Field } from "o1js";
|
|
3
3
|
|
|
4
4
|
import { createMerkleTree, InMemoryMerkleTreeStorage, log } from "../../src";
|
|
5
5
|
|
|
6
6
|
describe.each([4, 16, 256])("cachedMerkleTree - %s", (height) => {
|
|
7
7
|
class RollupMerkleTree extends createMerkleTree(height) {}
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
9
|
class RollupMerkleTreeWitness extends RollupMerkleTree.WITNESS {}
|
|
9
10
|
|
|
10
11
|
let store: InMemoryMerkleTreeStorage;
|
|
11
12
|
let tree: RollupMerkleTree;
|
|
12
13
|
|
|
13
14
|
beforeEach(() => {
|
|
14
|
-
log.setLevel("
|
|
15
|
+
log.setLevel("INFO");
|
|
15
16
|
|
|
16
17
|
store = new InMemoryMerkleTreeStorage();
|
|
17
18
|
tree = new RollupMerkleTree(store);
|
package/test/tsconfig.json
CHANGED