Skip to content

Commit d960e0c

Browse files
committed
refactor: move TestBalances to a helpers folder in src
1 parent f253ca7 commit d960e0c

7 files changed

Lines changed: 10 additions & 47 deletions

File tree

packages/stack/src/scripts/graphql/server.ts

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import {
55
InMemoryTransactionSender,
66
StateServiceQueryModule,
77
} from "@proto-kit/sdk";
8-
import { PrivateKey, PublicKey } from "o1js";
9-
import { Runtime, runtimeMethod, runtimeModule } from "@proto-kit/module";
10-
import { Protocol, State, state } from "@proto-kit/protocol";
8+
import { PrivateKey } from "o1js";
9+
import { Runtime } from "@proto-kit/module";
10+
import { Protocol } from "@proto-kit/protocol";
1111
import {
12-
Balance,
13-
Balances,
14-
BalancesKey,
1512
TokenId,
1613
VanillaProtocolModules,
1714
VanillaRuntimeModules,
@@ -44,42 +41,7 @@ import {
4441
} from "@proto-kit/api";
4542
import { container } from "tsyringe";
4643

47-
@runtimeModule()
48-
export class TestBalances extends Balances {
49-
/**
50-
* We use `satisfies` here in order to be able to access
51-
* presets by key in a type safe way.
52-
*/
53-
// public static presets = {} satisfies Presets<object>;
54-
55-
@state() public totalSupply = State.from<UInt64>(UInt64);
56-
57-
@runtimeMethod()
58-
public async getBalanceForUser(
59-
tokenId: TokenId,
60-
address: PublicKey
61-
): Promise<Balance> {
62-
return await super.getBalance(tokenId, address);
63-
}
64-
65-
@runtimeMethod()
66-
public async addBalance(
67-
tokenId: TokenId,
68-
address: PublicKey,
69-
balance: UInt64
70-
) {
71-
const totalSupply = await this.totalSupply.get();
72-
await this.totalSupply.set(totalSupply.orElse(UInt64.zero).add(balance));
73-
74-
const previous = await this.balances.get(
75-
new BalancesKey({ tokenId, address })
76-
);
77-
await this.balances.set(
78-
new BalancesKey({ tokenId, address }),
79-
previous.orElse(UInt64.zero).add(balance)
80-
);
81-
}
82-
}
44+
import { TestBalances } from "../../helpers/TestBalance";
8345

8446
export async function startServer() {
8547
log.setLevel("DEBUG");

packages/stack/src/scripts/worker/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { Protocol } from "@proto-kit/protocol";
77
import { ModulesConfig, ModuleContainer, TypedClass } from "@proto-kit/common";
88

9-
import { TestBalances } from "../graphql/server";
9+
import { TestBalances } from "../../helpers/TestBalance";
1010

1111
const runtime = Runtime.from(
1212
VanillaRuntimeModules.with({

packages/stack/src/scripts/worker/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { Runtime } from "@proto-kit/module";
77
import { Protocol } from "@proto-kit/protocol";
88

9-
import { TestBalances } from "../graphql/server";
9+
import { TestBalances } from "../../helpers/TestBalance";
1010

1111
const client = ClientAppChain.fromRemoteEndpoint(
1212
Runtime.from(

packages/stack/test-integration/caching/caching.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import { container } from "tsyringe";
3232
import { S3RemoteCache } from "@proto-kit/deployment";
3333

34-
import { TestBalances } from "../../src";
34+
import { TestBalances } from "../../src/helpers/TestBalance";
3535
import * as fs from "node:fs";
3636
import cachedir from "cachedir";
3737

packages/stack/test/graphql/graphql-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
} from "@proto-kit/api";
4242
import { container } from "tsyringe";
4343

44-
import { TestBalances } from "./utils";
44+
import { TestBalances } from "../../src/helpers/TestBalance";
4545

4646
export async function startGraphqlServer() {
4747
log.setLevel("DEBUG");

packages/stack/test/graphql/graphql.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import {
2727
import { beforeAll } from "@jest/globals";
2828
import { container } from "tsyringe";
2929

30+
import { TestBalances } from "../../src/helpers/TestBalance";
31+
3032
import { startGraphqlServer } from "./graphql-server";
31-
import { TestBalances } from "./utils";
3233

3334
const pk = PrivateKey.random();
3435

0 commit comments

Comments
 (0)