Skip to content

Commit 5abcef1

Browse files
committed
Fixed issues with the state getter
1 parent b6d05a1 commit 5abcef1

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

packages/protocol/src/state/protocol/ProtocolState.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,30 @@ export function createStateGetter<TargetModule extends StatefulModule>(
3434
prefix: string,
3535
debugInfo: { parentName: string; baseModuleNames: string }
3636
) {
37-
return () => {
37+
return function getter(this: TargetModule) {
38+
// const self = this;
3839
const { value } = valueReference;
3940
// Short-circuit this to return the state in case its already initialized
4041
if (value !== undefined && value.path !== undefined) {
4142
return value;
4243
}
4344

44-
if (target.name === undefined) {
45-
throw errors.missingName(target.constructor.name);
45+
if (this.name === undefined) {
46+
throw errors.missingName(this.constructor.name);
4647
}
4748

48-
if (!target.parent) {
49+
if (!this.parent) {
4950
throw errors.missingParent(
50-
target.constructor.name,
51+
this.constructor.name,
5152
debugInfo.parentName,
5253
debugInfo.baseModuleNames
5354
);
5455
}
5556

56-
const path = Path.fromProperty(target.name, propertyKey, prefix);
57+
const path = Path.fromProperty(this.name, propertyKey, prefix);
5758
if (value) {
5859
value.path = path;
59-
value.stateServiceProvider = target.parent.stateServiceProvider;
60+
value.stateServiceProvider = this.parent.stateServiceProvider;
6061
}
6162
return value;
6263
};

packages/sdk/test/networkstate/Balance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
TokenId,
66
UInt64,
77
} from "@proto-kit/library";
8-
import { runtimeMethod, runtimeModule, state } from "@proto-kit/module";
8+
import { runtimeMethod, runtimeModule } from "@proto-kit/module";
99
import { log, Presets, range, mapSequential } from "@proto-kit/common";
1010
import { Bool, Field, PublicKey } from "o1js";
1111
import { Admin } from "@proto-kit/module/test/modules/Admin";
12-
import { State, assert } from "@proto-kit/protocol";
12+
import { State, assert, state } from "@proto-kit/protocol";
1313

1414
@runtimeModule()
1515
export class BalanceChild extends Balances {

packages/sequencer/test/integration/BlockProduction.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
MandatoryProtocolModulesRecord,
1919
Path,
2020
Protocol,
21+
PROTOKIT_PREFIXES,
2122
} from "@proto-kit/protocol";
2223
import { AppChain } from "@proto-kit/sdk";
2324
import { Bool, Field, PrivateKey, PublicKey, Struct, UInt64 } from "o1js";
@@ -595,7 +596,11 @@ describe("block production", () => {
595596
expect(batch!.blockHashes).toHaveLength(1);
596597
expect(batch!.proof.proof).toBe(MOCK_PROOF);
597598

598-
const supplyPath = Path.fromProperty("Balance", "totalSupply");
599+
const supplyPath = Path.fromProperty(
600+
"Balance",
601+
"totalSupply",
602+
PROTOKIT_PREFIXES.STATE_RUNTIME
603+
);
599604
const newState = await test.getState(supplyPath, "block");
600605

601606
expect(newState).toBeDefined();

packages/sequencer/test/integration/mocks/Balance.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ import {
33
runtimeMethod,
44
runtimeModule,
55
RuntimeModule,
6-
state,
76
} from "@proto-kit/module";
87
import { log, Presets, range, mapSequential } from "@proto-kit/common";
98
import { Bool, Field, PublicKey, UInt64 } from "o1js";
109
import { Admin } from "@proto-kit/module/test/modules/Admin";
11-
import { Option, State, StateMap, assert, Deposit } from "@proto-kit/protocol";
10+
import {
11+
Option,
12+
State,
13+
StateMap,
14+
assert,
15+
Deposit,
16+
state,
17+
} from "@proto-kit/protocol";
1218

1319
@runtimeModule()
1420
export class Balance extends RuntimeModule<object> {

packages/sequencer/test/integration/mocks/ProtocolStateTestHook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
AfterTransactionHookArguments,
33
BeforeTransactionHookArguments,
4-
protocolState,
54
ProvableTransactionHook,
65
StateMap,
6+
state,
77
} from "@proto-kit/protocol";
88
import { Field } from "o1js";
99
import { noop } from "@proto-kit/common";
@@ -12,7 +12,7 @@ import { noop } from "@proto-kit/common";
1212
* A hook used to test protocolstate inside the blockproduction tests
1313
*/
1414
export class ProtocolStateTestHook extends ProvableTransactionHook {
15-
@protocolState() methodIdInvocations = StateMap.from(Field, Field);
15+
@state() methodIdInvocations = StateMap.from(Field, Field);
1616

1717
public async beforeTransaction(
1818
executionData: BeforeTransactionHookArguments

packages/sequencer/test/merkle/MerkleTree.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "reflect-metadata";
12
import { Field } from "o1js";
23
import { RollupMerkleTree, log } from "@proto-kit/common";
34

packages/sequencer/test/settlement/mocks/Balances.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { NoConfig } from "@proto-kit/common";
22
import {
33
RuntimeModule,
44
runtimeMethod,
5-
state,
65
runtimeModule,
76
runtimeMessage,
87
} from "@proto-kit/module";
9-
import { StateMap, assert, Deposit } from "@proto-kit/protocol";
8+
import { StateMap, assert, Deposit, state } from "@proto-kit/protocol";
109
import { Field, PublicKey, Struct, Provable, UInt64 } from "o1js";
1110

1211
export const errors = {

0 commit comments

Comments
 (0)