@proto-kit/module 0.1.1-develop.600 → 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/method/MethodParameterDecoder.d.ts +10 -10
- package/dist/method/MethodParameterDecoder.js +40 -40
- package/dist/method/MethodParameterEncoder.d.ts +15 -8
- package/dist/method/MethodParameterEncoder.d.ts.map +1 -1
- package/dist/method/MethodParameterEncoder.js +122 -48
- package/dist/method/runtimeMethod.d.ts +6 -5
- package/dist/method/runtimeMethod.d.ts.map +1 -1
- package/dist/method/runtimeMethod.js +13 -26
- package/dist/runtime/MethodIdResolver.d.ts +7 -0
- package/dist/runtime/MethodIdResolver.d.ts.map +1 -1
- package/dist/runtime/MethodIdResolver.js +35 -2
- package/dist/runtime/Runtime.d.ts +6 -5
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +29 -22
- package/dist/runtime/RuntimeEnvironment.d.ts +2 -2
- package/dist/runtime/RuntimeEnvironment.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.d.ts +2 -2
- package/dist/runtime/RuntimeModule.d.ts.map +1 -1
- package/dist/runtime/RuntimeModule.js +10 -8
- package/dist/src/factories/MethodIdFactory.d.ts +10 -0
- package/dist/src/factories/MethodIdFactory.d.ts.map +1 -0
- package/dist/src/factories/MethodIdFactory.js +10 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/method/MethodParameterEncoder.d.ts +22 -0
- package/dist/src/method/MethodParameterEncoder.d.ts.map +1 -0
- package/dist/src/method/MethodParameterEncoder.js +103 -0
- package/dist/src/method/runtimeMethod.d.ts +26 -0
- package/dist/src/method/runtimeMethod.d.ts.map +1 -0
- package/dist/src/method/runtimeMethod.js +164 -0
- package/dist/src/module/decorator.d.ts +8 -0
- package/dist/src/module/decorator.d.ts.map +1 -0
- package/dist/src/module/decorator.js +15 -0
- package/dist/src/runtime/MethodIdResolver.d.ts +20 -0
- package/dist/src/runtime/MethodIdResolver.d.ts.map +1 -0
- package/dist/src/runtime/MethodIdResolver.js +100 -0
- package/dist/src/runtime/Runtime.d.ts +71 -0
- package/dist/src/runtime/Runtime.d.ts.map +1 -0
- package/dist/src/runtime/Runtime.js +215 -0
- package/dist/src/runtime/RuntimeEnvironment.d.ts +10 -0
- package/dist/src/runtime/RuntimeEnvironment.d.ts.map +1 -0
- package/dist/src/runtime/RuntimeEnvironment.js +1 -0
- package/dist/src/runtime/RuntimeModule.d.ts +26 -0
- package/dist/src/runtime/RuntimeModule.d.ts.map +1 -0
- package/dist/src/runtime/RuntimeModule.js +85 -0
- package/dist/src/state/InMemoryStateService.d.ts +15 -0
- package/dist/src/state/InMemoryStateService.d.ts.map +1 -0
- package/dist/src/state/InMemoryStateService.js +28 -0
- package/dist/src/state/decorator.d.ts +7 -0
- package/dist/src/state/decorator.d.ts.map +1 -0
- package/dist/src/state/decorator.js +39 -0
- package/dist/state/InMemoryStateService.d.ts +10 -6
- package/dist/state/InMemoryStateService.d.ts.map +1 -1
- package/dist/state/InMemoryStateService.js +10 -8
- package/dist/state/decorator.d.ts.map +1 -1
- package/dist/state/decorator.js +0 -3
- package/dist/test/Runtime.test.d.ts +2 -0
- package/dist/test/Runtime.test.d.ts.map +1 -0
- package/dist/test/Runtime.test.js +24 -0
- package/dist/test/TestingRuntime.d.ts +7 -0
- package/dist/test/TestingRuntime.d.ts.map +1 -0
- package/dist/test/TestingRuntime.js +29 -0
- package/dist/test/method/runtimeMethod.test.d.ts +2 -0
- package/dist/test/method/runtimeMethod.test.d.ts.map +1 -0
- package/dist/test/method/runtimeMethod.test.js +30 -0
- package/dist/test/modules/Admin.d.ts +10 -0
- package/dist/test/modules/Admin.d.ts.map +1 -0
- package/dist/test/modules/Admin.js +29 -0
- package/dist/test/modules/Balances.d.ts +23 -0
- package/dist/test/modules/Balances.d.ts.map +1 -0
- package/dist/test/modules/Balances.js +98 -0
- package/dist/test/modules/Balances.test.d.ts +2 -0
- package/dist/test/modules/Balances.test.d.ts.map +1 -0
- package/dist/test/modules/Balances.test.js +201 -0
- package/dist/test/modules/MethodIdResolver.test.d.ts +2 -0
- package/dist/test/modules/MethodIdResolver.test.d.ts.map +1 -0
- package/dist/test/modules/MethodIdResolver.test.js +67 -0
- package/dist/test/modules/State.test.d.ts +2 -0
- package/dist/test/modules/State.test.d.ts.map +1 -0
- package/dist/test/modules/State.test.js +42 -0
- package/dist/test/runtimeMethod.test.d.ts +2 -0
- package/dist/test/runtimeMethod.test.d.ts.map +1 -0
- package/dist/test/runtimeMethod.test.js +50 -0
- package/package.json +5 -5
- package/src/method/MethodParameterEncoder.ts +192 -81
- package/src/method/runtimeMethod.ts +29 -44
- package/src/runtime/MethodIdResolver.ts +51 -1
- package/src/runtime/Runtime.ts +48 -29
- package/src/runtime/RuntimeEnvironment.ts +4 -7
- package/src/runtime/RuntimeModule.ts +13 -15
- package/src/state/InMemoryStateService.ts +13 -13
- package/src/state/decorator.ts +1 -3
- package/test/Runtime.test.ts +68 -41
- package/test/TestingRuntime.ts +45 -0
- package/test/method/MethodParameterEncoder.test.ts +152 -0
- package/{src/method/decorator.test.ts → test/method/runtimeMethod.test.ts} +2 -2
- package/test/modules/Admin.ts +3 -3
- package/test/modules/Balances.test.ts +57 -61
- package/test/modules/Balances.ts +15 -18
- package/test/modules/{methodId.test.ts → MethodIdResolver.test.ts} +14 -23
- package/test/modules/State.test.ts +41 -50
- package/test/runtimeMethod.test.ts +19 -32
- package/test/tsconfig.json +7 -0
- package/tsconfig.json +2 -2
- package/test/transaction.test.ts +0 -82
- package/tsconfig.test.json +0 -9
package/test/transaction.test.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { PrivateKey, Proof, PublicKey, UInt64 } from "o1js";
|
|
3
|
-
import { container } from "tsyringe";
|
|
4
|
-
import {
|
|
5
|
-
InMemoryStateService,
|
|
6
|
-
MethodPublicOutput,
|
|
7
|
-
Runtime,
|
|
8
|
-
runtimeMethod,
|
|
9
|
-
RuntimeMethodExecutionContext,
|
|
10
|
-
} from "../src";
|
|
11
|
-
import { runtimeModule } from "../src/module/decorator";
|
|
12
|
-
import { RuntimeModule } from "../src/runtime/RuntimeModule";
|
|
13
|
-
import { state } from "../../protocol/src/state/decorator";
|
|
14
|
-
import { StateMap } from "@proto-kit/protocol";
|
|
15
|
-
|
|
16
|
-
interface BalancesConfig {}
|
|
17
|
-
@runtimeModule()
|
|
18
|
-
class Balances extends RuntimeModule<BalancesConfig> {
|
|
19
|
-
@state() public balances = StateMap.from<PublicKey, UInt64>(
|
|
20
|
-
PublicKey,
|
|
21
|
-
UInt64
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
@runtimeMethod()
|
|
25
|
-
public setBalance(to: PublicKey, amount: UInt64) {
|
|
26
|
-
this.balances.set(to, amount);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@runtimeMethod()
|
|
30
|
-
public transfer(from: PublicKey, to: PublicKey, amount: UInt64) {
|
|
31
|
-
const fromBalance = this.balances.get(from);
|
|
32
|
-
const toBalance = this.balances.get(to);
|
|
33
|
-
|
|
34
|
-
this.balances.set(from, fromBalance.value.sub(amount));
|
|
35
|
-
this.balances.set(to, toBalance.value.add(amount));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
describe("transaction", () => {
|
|
40
|
-
it("should update the state", async () => {
|
|
41
|
-
expect.assertions(0);
|
|
42
|
-
|
|
43
|
-
const runtime = Runtime.from({
|
|
44
|
-
modules: {
|
|
45
|
-
Balances,
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
config: {
|
|
49
|
-
Balances: {},
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
state: new InMemoryStateService(),
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const alice = PrivateKey.random().toPublicKey();
|
|
56
|
-
const bob = PrivateKey.random().toPublicKey();
|
|
57
|
-
|
|
58
|
-
const balances = runtime.resolve("Balances");
|
|
59
|
-
|
|
60
|
-
runtime.transaction(() => {
|
|
61
|
-
balances.setBalance(alice, UInt64.from(1000));
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
runtime.transaction(() => {
|
|
65
|
-
balances.transfer(alice, bob, UInt64.from(100));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const executionContext = container.resolve<RuntimeMethodExecutionContext>(
|
|
69
|
-
RuntimeMethodExecutionContext
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const balanceAlice = balances.balances.get(alice);
|
|
73
|
-
const balanceBob = balances.balances.get(bob);
|
|
74
|
-
|
|
75
|
-
console.log("balances", {
|
|
76
|
-
// 900
|
|
77
|
-
alice: balanceAlice.value.toString(),
|
|
78
|
-
// 100
|
|
79
|
-
bob: balanceBob.value.toString(),
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|