Skip to content

Commit

Permalink
Convert project to use ESM (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov authored Feb 18, 2024
1 parent 5be4393 commit 21643f2
Show file tree
Hide file tree
Showing 40 changed files with 5,945 additions and 8,864 deletions.
13 changes: 0 additions & 13 deletions .env.example

This file was deleted.

13 changes: 0 additions & 13 deletions .env2

This file was deleted.

2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ tests
benchmark/*.js
*/resolvers-types.ts
codegen.ts
/zkapp
/benchmark
38 changes: 13 additions & 25 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,30 @@ on:
jobs:
Run-Tests:
runs-on: ubuntu-latest
container: node:latest
services:
postgres:
image: postgres:latest
mina-local-network:
image: o1labs/mina-local-network:o1js-main-latest-lightnet
env:
POSTGRES_DB: archive
POSTGRES_PASSWORD: password
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
NETWORK_TYPE: 'single-node'
PROOF_LEVEL: 'none'
ports:
- 3085:3085
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
- 8080:8080
- 8181:8181
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: npm ci

- name: Download nightly Berkeley dump
run: bash ./scripts/download_db.sh

- name: Install PostgreSQL client
run: |
apt-get update
apt-get install --yes postgresql-client
- name: Create Archive Node database
run: psql -h postgres -U postgres archive < ./data/berkeley-archive.sql
env:
PGPASSWORD: password
- name: Wait for Mina network readiness
uses: o1-labs/wait-for-mina-network-action@v1
with:
mina-graphql-port: 8080
max-attempts: 60
polling-interval-ms: 10000

- name: Run tests
run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ coverage/**/*

# Ignore benchmark results
benchmark/*.json
benchmark/*.csv
51 changes: 0 additions & 51 deletions benchmark/data.csv

This file was deleted.

14 changes: 2 additions & 12 deletions benchmark/graphql.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
config:
target: 'http://localhost:8080'
target: 'http://localhost:3000'
phases:
- duration: 180
arrivalRate: 25
Expand All @@ -13,17 +13,14 @@ config:
arrivalRate: 100
rampTo: 1000
name: 'heavy phase'
processor: 'processor.js'
payload:
path: 'data.csv'
path: 'zkapp.csv'
skipHeader: true
fields:
- 'address'
- 'tokenId'
scenarios:
- name: 'Get Events'
flow:
- function: 'generateRandomBlockRange'
- post:
url: '/'
json:
Expand Down Expand Up @@ -55,14 +52,10 @@ scenarios:
variables:
input:
address: '{{ address }}'
tokenId: '{{ tokenId }}'
to: '{{ to }}'
from: '{{ from }}'
expect:
- statusCode: 200
- name: 'Get Actions'
flow:
- function: 'generateRandomBlockRange'
- post:
url: '/'
json:
Expand Down Expand Up @@ -102,8 +95,5 @@ scenarios:
variables:
input:
address: '{{ address }}'
tokenId: '{{ tokenId }}'
to: '{{ to }}'
from: '{{ from }}'
expect:
- statusCode: 200
22 changes: 0 additions & 22 deletions benchmark/processor.js

This file was deleted.

54 changes: 54 additions & 0 deletions benchmark/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Lightnet, PrivateKey } from 'o1js';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { writeFileSync } from 'node:fs';
import {
setNetworkConfig,
fetchAccountInfo,
deployContract,
updateContractState,
emitSingleEvent,
emitMultipleFieldsEvent,
emitAction,
reduceAction,
} from '../zkapp/utils.js';

(async () => {
setNetworkConfig();

const zkAppKey = PrivateKey.random();
const zkAppKeypair = {
privateKey: zkAppKey,
publicKey: zkAppKey.toPublicKey(),
};

const senderKeypair = await Lightnet.acquireKeyPair();

await fetchAccountInfo(senderKeypair.publicKey);

const zkApp = await deployContract(zkAppKeypair, senderKeypair);

await updateContractState(zkApp, senderKeypair);

await emitSingleEvent(zkApp, senderKeypair);

await emitMultipleFieldsEvent(zkApp, senderKeypair);

await emitAction(zkApp, senderKeypair);

await reduceAction(zkApp, senderKeypair);

await emitAction(zkApp, senderKeypair, { numberOfEmits: 3 });

await reduceAction(zkApp, senderKeypair);

const keyPairReleaseMessage = await Lightnet.releaseKeyPair({
publicKey: senderKeypair.publicKey.toBase58(),
});

if (keyPairReleaseMessage) console.info(keyPairReleaseMessage);

const filePath = join(dirname(fileURLToPath(import.meta.url)), 'zkapp.csv');
writeFileSync(filePath, `address\n${zkAppKeypair.publicKey.toBase58()}\n`);
console.log(`Public key of zkApp keypair written into ${filePath}`);
})();
3 changes: 2 additions & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: 'schema.graphql',
emitLegacyCommonJSImports: false,
generates: {
'./src/resolvers-types.ts': {
config: {
contextType: './context#GraphQLContext',
enumValues: {
BlockStatusFilter: './models/types#BlockStatusFilter',
BlockStatusFilter: './blockchain/types#BlockStatusFilter',
},
},
plugins: ['typescript', 'typescript-resolvers'],
Expand Down
7 changes: 7 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"watch": ["src"],
"ext": "ts",
"execMap": {
"ts": "node --loader ts-node/esm"
}
}
Loading

0 comments on commit 21643f2

Please sign in to comment.