Skip to content

Commit c8624a7

Browse files
committed
Added additional tests, reenabled other jobs
1 parent d093d12 commit c8624a7

File tree

3 files changed

+142
-108
lines changed

3 files changed

+142
-108
lines changed

.github/workflows/pull-request-develop.yml

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,89 @@ on:
1212
jobs:
1313
# Installs npm dependencies for the first time,
1414
# caching them in ~/.npm
15-
# install:
16-
# runs-on: ubuntu-latest
17-
# steps:
18-
# - uses: actions/checkout@v3
19-
# - uses: actions/setup-node@v3
20-
# with:
21-
# node-version: 18
22-
# # This only caches ~/.npm, therefore each subsequent
23-
# # job needs to run `npm ci` to install deps from npm cache
24-
# # alternative is to cache `node_modules` directly
25-
# # TODO:
26-
# # https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/
27-
# # Add caching of `node_modules` to speed up this workflow
28-
# cache: npm
29-
#
30-
# # install dependencies from the package-lock.json
31-
# - name: Install dependencies
32-
# run: npm ci --workspaces
33-
#
34-
# # builds all packages
35-
# build:
36-
# runs-on: ubuntu-latest
37-
# needs: install
38-
# steps:
39-
# - uses: actions/checkout@v3
40-
# - uses: actions/setup-node@v3
41-
# with:
42-
# node-version: 18
43-
# cache: npm
44-
#
45-
# - name: "Install dependencies"
46-
# run: npm ci --workspaces --include-workspace-root
47-
#
48-
# - name: "Build"
49-
# run: npm run build
50-
#
51-
# # lints all packages
52-
# lint:
53-
# runs-on: ubuntu-latest
54-
# needs: install
55-
# steps:
56-
# # check out the repository
57-
# - uses: actions/checkout@v3
58-
# - uses: actions/setup-node@v3
59-
# with:
60-
# node-version: 18
61-
# cache: npm
62-
#
63-
# - name: "Install dependencies"
64-
# run: npm ci --workspaces --include-workspace-root
65-
#
66-
# - name: "Build"
67-
# run: npm run build
68-
#
69-
# - name: "Lint"
70-
# run: npm run lint
71-
#
72-
# - name: "Check formatting"
73-
# run: npx prettier ./packages --check
74-
#
75-
# # tests all packages
76-
# test:
77-
# runs-on: ubuntu-latest
78-
# needs: install
79-
# steps:
80-
# - uses: actions/checkout@v3
81-
# - uses: actions/setup-node@v3
82-
# with:
83-
# node-version: 18
84-
# cache: npm
85-
#
86-
# - name: "Install dependencies"
87-
# run: npm ci --workspaces --include-workspace-root
88-
#
89-
# - name: "Build"
90-
# run: npm run build
91-
#
92-
# - name: "Test"
93-
# run: npm run test:ci
15+
install:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- uses: actions/setup-node@v3
20+
with:
21+
node-version: 18
22+
# This only caches ~/.npm, therefore each subsequent
23+
# job needs to run `npm ci` to install deps from npm cache
24+
# alternative is to cache `node_modules` directly
25+
# TODO:
26+
# https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/
27+
# Add caching of `node_modules` to speed up this workflow
28+
cache: npm
29+
30+
# install dependencies from the package-lock.json
31+
- name: Install dependencies
32+
run: npm ci --workspaces
33+
34+
# builds all packages
35+
build:
36+
runs-on: ubuntu-latest
37+
needs: install
38+
steps:
39+
- uses: actions/checkout@v3
40+
- uses: actions/setup-node@v3
41+
with:
42+
node-version: 18
43+
cache: npm
44+
45+
- name: "Install dependencies"
46+
run: npm ci --workspaces --include-workspace-root
47+
48+
- name: "Build"
49+
run: npm run build
50+
51+
# lints all packages
52+
lint:
53+
runs-on: ubuntu-latest
54+
needs: install
55+
steps:
56+
# check out the repository
57+
- uses: actions/checkout@v3
58+
- uses: actions/setup-node@v3
59+
with:
60+
node-version: 18
61+
cache: npm
62+
63+
- name: "Install dependencies"
64+
run: npm ci --workspaces --include-workspace-root
65+
66+
- name: "Build"
67+
run: npm run build
68+
69+
- name: "Lint"
70+
run: npm run lint
71+
72+
- name: "Check formatting"
73+
run: npx prettier ./packages --check
74+
75+
# tests all packages
76+
test:
77+
runs-on: ubuntu-latest
78+
needs: install
79+
steps:
80+
- uses: actions/checkout@v3
81+
- uses: actions/setup-node@v3
82+
with:
83+
node-version: 18
84+
cache: npm
85+
86+
- name: "Install dependencies"
87+
run: npm ci --workspaces --include-workspace-root
88+
89+
- name: "Build"
90+
run: npm run build
91+
92+
- name: "Test"
93+
run: npm run test:ci
9494

9595
integration:
9696
runs-on: ubuntu-latest
97-
# needs: test
97+
needs: test
9898

9999
env:
100100
POSTGRES_URL: localhost

packages/persistance/test-integration/PrismaBlockProduction.test.ts

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import "reflect-metadata";
22
import {
33
afterAll,
4-
afterEach,
54
beforeAll,
65
describe,
76
expect,
87
} from "@jest/globals";
98
import { expectDefined, equalProvable } from "@proto-kit/common";
10-
import { Balance, TokenId } from "@proto-kit/library";
9+
import { BalancesKey, TokenId } from "@proto-kit/library";
1110
import { NetworkState } from "@proto-kit/protocol";
1211
import { AppChainTransaction } from "@proto-kit/sdk";
1312
import { ComputedBlock, UnprovenBlock } from "@proto-kit/sequencer";
1413
import { PrivateKey, PublicKey } from "o1js";
1514
import { container } from "tsyringe";
15+
1616
import {
1717
PrismaBatchStore,
1818
PrismaBlockStorage,
19-
PrismaTransactionStorage
19+
PrismaTransactionStorage,
2020
} from "../src";
21+
2122
import {
2223
createPrismaAppchain,
2324
IntegrationTestDBConfig,
24-
prepareBlock
25+
prepareBlock,
2526
} from "./utils";
2627

27-
describe("Prisma integration", () => {
28+
describe("prisma integration", () => {
2829
let appChain: ReturnType<typeof createPrismaAppchain>;
2930

3031
const sender = PrivateKey.random();
@@ -145,6 +146,49 @@ describe("Prisma integration", () => {
145146

146147
expect(accountState).toBeUndefined();
147148
});
149+
150+
it("should fetch balance change", async () => {
151+
const balance = await appChain.query.runtime.Balances.balances.get(
152+
BalancesKey.from(TokenId.from(0), sender.toPublicKey())
153+
);
154+
155+
expectDefined(balance);
156+
157+
expect(balance.toString()).toStrictEqual("100");
158+
});
159+
160+
describe("add balance to second account", () => {
161+
const sender2 = PrivateKey.random();
162+
163+
beforeAll(async () => {
164+
appChain.configurePartial({
165+
Signer: {
166+
signer: sender2,
167+
},
168+
});
169+
await prepareBlock(appChain, sender2.toPublicKey(), 0);
170+
});
171+
172+
it("should produce the block", async () => {
173+
const [block, batch] = await appChain.sequencer
174+
.resolve("BlockTrigger")
175+
.produceBlock();
176+
177+
expectDefined(block);
178+
expectDefined(batch);
179+
expect(block.transactions).toHaveLength(1);
180+
}, 30000);
181+
182+
it("should retrieve correct balance for account 2", async () => {
183+
const balance = await appChain.query.runtime.Balances.balances.get(
184+
BalancesKey.from(TokenId.from(0), sender2.toPublicKey())
185+
);
186+
187+
expectDefined(balance);
188+
189+
expect(balance.toString()).toStrictEqual("100");
190+
});
191+
});
148192
});
149193

150194
describe("persisted mempool", () => {
@@ -153,7 +197,11 @@ describe("Prisma integration", () => {
153197
beforeAll(async () => {
154198
await setup();
155199

156-
transaction = await prepareBlock(appChain, sender.toPublicKey(), senderNonce);
200+
transaction = await prepareBlock(
201+
appChain,
202+
sender.toPublicKey(),
203+
senderNonce
204+
);
157205
senderNonce++;
158206
});
159207

@@ -174,7 +222,10 @@ describe("Prisma integration", () => {
174222
});
175223

176224
it("should resolve transaction from storage as pending", async () => {
177-
const txResolver = appChain.sequencer.resolveOrFail("TransactionStorage", PrismaTransactionStorage);
225+
const txResolver = appChain.sequencer.resolveOrFail(
226+
"TransactionStorage",
227+
PrismaTransactionStorage
228+
);
178229

179230
const txs = await txResolver.getPendingUserTransactions();
180231

packages/persistance/test-integration/SequencerRestart.test.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import "reflect-metadata";
22
import { afterAll, beforeAll, expect } from "@jest/globals";
3-
import { expectDefined, log } from "@proto-kit/common";
4-
import { Field, Poseidon, PrivateKey } from "o1js";
3+
import { expectDefined } from "@proto-kit/common";
4+
import { PrivateKey } from "o1js";
55
import { container } from "tsyringe";
6+
67
import {
78
createPrismaAppchain,
89
IntegrationTestDBConfig,
910
prepareBlock,
1011
} from "./utils";
11-
import { Prisma } from "@prisma/client";
12-
13-
log.setLevel("TRACE")
14-
15-
// describe("Decimal", () => {
16-
//
17-
// it("decimal", () => {
18-
// const f = Poseidon.hash([Field(5)])
19-
//
20-
// const Decimal = Prisma.Decimal.clone({
21-
// precision: 78,
22-
// });
23-
//
24-
// const d = new Decimal(f.toString());
25-
// expect(d.toFixed()).toStrictEqual(f.toString())
26-
// })
27-
//
28-
// })
2912

3013
describe("sequencer restart", () => {
3114
let appChain: ReturnType<typeof createPrismaAppchain>;
@@ -64,7 +47,7 @@ describe("sequencer restart", () => {
6447

6548
const blockTrigger = appChain.sequencer.resolve("BlockTrigger");
6649

67-
console.log(sender.toPublicKey().toBase58())
50+
console.log(sender.toPublicKey().toBase58());
6851

6952
for (let block = 0; block < 2; block++) {
7053
await prepareBlock(appChain, sender.toPublicKey(), senderNonce);

0 commit comments

Comments
 (0)