Skip to content

Commit a856242

Browse files
committed
Add in test.
1 parent 7825bc7 commit a856242

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

packages/module/test/method/MethodParameterEncoder.test.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ import {
77
ZkProgram,
88
Proof,
99
} from "o1js";
10-
import { NonMethods, noop } from "@proto-kit/common";
10+
import { NonMethods } from "@proto-kit/common";
1111

12-
import {
13-
MethodParameterEncoder,
14-
RuntimeModule,
15-
runtimeModule,
16-
runtimeMethod,
17-
} from "../../src";
12+
import { MethodParameterEncoder } from "../../src";
1813

1914
class TestStruct extends Struct({
2015
a: Field,
@@ -124,29 +119,3 @@ describe("MethodParameterEncoder", () => {
124119
);
125120
}, 30000);
126121
});
127-
128-
class TieredStruct extends TestStruct {}
129-
130-
@runtimeModule()
131-
class TestModule extends RuntimeModule {
132-
@runtimeMethod()
133-
public async foo(
134-
a: TieredStruct,
135-
b: PublicKey,
136-
c: Field,
137-
d: TestProof,
138-
e: string
139-
) {
140-
noop();
141-
}
142-
}
143-
144-
describe("MethodParameterEncoder construction", () => {
145-
it("should throw on non-provable method signature", () => {
146-
const module = new TestModule();
147-
module.name = "testModule";
148-
expect(() => MethodParameterEncoder.fromMethod(module, "foo")).toThrowError(
149-
"'testModule.foo' are provable types or proofs (indizes: [4])"
150-
);
151-
});
152-
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Bool, Field, PublicKey, Struct, ZkProgram } from "o1js";
2+
import { noop } from "@proto-kit/common";
3+
4+
import { runtimeMethod, RuntimeModule, runtimeModule } from "../../src";
5+
6+
class TestStruct extends Struct({
7+
a: Field,
8+
b: Bool,
9+
}) {}
10+
class TieredStruct extends TestStruct {}
11+
const TestProgram = ZkProgram({
12+
name: "TestProgram",
13+
publicInput: PublicKey,
14+
publicOutput: TestStruct,
15+
methods: {
16+
foo: {
17+
privateInputs: [],
18+
method: async (input: PublicKey) => {
19+
return {
20+
a: Field(input.x),
21+
b: Bool(input.isOdd),
22+
};
23+
},
24+
},
25+
},
26+
});
27+
class TestProof extends ZkProgram.Proof(TestProgram) {}
28+
29+
describe("Creating module with non-provable method argument", () => {
30+
it("should throw on non-provable method signature", () => {
31+
expect(() => {
32+
@runtimeModule()
33+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
34+
class TestModule extends RuntimeModule {
35+
@runtimeMethod()
36+
public async foo(
37+
a: TieredStruct,
38+
b: PublicKey,
39+
c: Field,
40+
d: TestProof,
41+
e: string
42+
) {
43+
noop();
44+
}
45+
}
46+
}).toThrow(
47+
"Not all arguments of method 'undefined.foo' are provable types or proofs (indizes: [3, 4])"
48+
);
49+
});
50+
});

0 commit comments

Comments
 (0)