Skip to content

Commit

Permalink
WIP: spin up local notary server
Browse files Browse the repository at this point in the history
  • Loading branch information
heeckhau committed Feb 29, 2024
1 parent bf72640 commit 59a575b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
branches: [ main ]

env:
LOCAL: true
LOCAL-NOTARY: true
LOCAL-WS: false
HEADLESS: true
PUPPETEER_SKIP_DOWNLOAD: true

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build": "NODE_ENV=production concurrently npm:build:src npm:build:types",
"update:wasm": "sh utils/check-wasm.sh -f",
"build:wasm": "wasm-pack build --target web wasm/prover",
"build:server-fixture": "sh utils/build-server-fixture.sh",
"build:tlsn-binaries": "sh utils/build-tlsn-binaries.sh",
"watch:dev": "webpack --config webpack.web.dev.config.js --watch",
"predev": "sh utils/check-wasm.sh",
"lint:wasm": "cd wasm/prover; cargo clippy --target wasm32-unknown-unknown",
Expand All @@ -28,7 +28,7 @@
"lint:tsc": "tsc --noEmit",
"lint": "concurrently npm:lint:tsc npm:lint:eslint",
"run:test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' mocha -r ts-node/register 'test/testRunner.ts'",
"test": "npm run build:server-fixture && npm run build:test && npm run run:test"
"test": "npm run build:tlsn-binaries && npm run build:test && npm run run:test"
},
"dependencies": {
"comlink": "^4.4.1"
Expand Down
8 changes: 4 additions & 4 deletions test/full-integration-swapi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { prove, verify } from '../src';
// @ts-ignore
console.log('test start');
console.time('prove');
const proof = await prove('https://localhost:3000/formats/json', {
const proof = await prove('https://swapi.dev/api/people/1', {
method: 'GET',
headers: { secret: 'test_secret' },
maxTranscriptSize: 16384,
notaryUrl: process.env.LOCAL
notaryUrl: process.env.LOCAL_NOTARY
? 'http://localhost:7047'
: 'https://notary.pse.dev',
websocketProxyUrl: process.env.LOCAL
websocketProxyUrl: process.env.LOCAL_WS
? 'ws://localhost:55688'
: 'wss://notary.pse.dev/proxy?token=swapi.dev',
secretHeaders: ['test_secret'],
Expand All @@ -34,4 +34,4 @@ import { prove, verify } from '../src';
console.log('caught error from wasm');
console.error(err);
}
})();
})();
31 changes: 22 additions & 9 deletions test/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, before, after } from 'mocha';
const assert = require('assert');
import { exec, spawn, ChildProcess } from 'node:child_process';
import * as fs from 'fs';
import * as yaml from 'js-yaml';
const yaml = require('js-yaml');

const timeout = 60000;

Expand All @@ -29,10 +29,10 @@ let server: ChildProcess;

let tlsnServerFixture: ChildProcess;
const spawnTlsnServerFixture = () => {
const tlsnServerFixturePath = './utils/tlsn/tlsn/tlsn-server-fixture/Cargo.toml';
const tlsnServerFixturePath = './utils/tlsn/tlsn/tlsn-server-fixture/';
// Spawn the server process
// tlsnServerFixture = spawn(tlsnServerFixturePath, []);
tlsnServerFixture = exec(`cargo run --release --manifest-path ${tlsnServerFixturePath}`)
tlsnServerFixture = exec(`../target/release/notary-server`, { cwd: tlsnServerFixturePath });

tlsnServerFixture.stdout?.on('data', (data) => {
console.log(`Server: ${data}`);
Expand All @@ -44,17 +44,29 @@ const spawnTlsnServerFixture = () => {
}

let localNotaryServer: ChildProcess;
const spawnLocalNotaryServer = () => {
const localNotaryServerPath = './utils/tlsn/notary-server/Cargo.toml';
localNotaryServer = exec(`cargo run --release --manifest-path ${localNotaryServerPath}`)

const spawnLocalNotaryServer = async () => {
const localNotaryServerPath = './utils/tlsn/notary-server/';
localNotaryServer = exec(`target/release/notary-server`, { cwd: localNotaryServerPath });
localNotaryServer.stdout?.on('data', (data) => {
console.log(`Server: ${data}`);
});

localNotaryServer.stderr?.on('data', (data) => {
console.error(`Server Error: ${data}`);
});

// wait for the notary server to be ready
while (true) {
try {
const response = await fetch("http://127.0.0.1:7047/info");
if (response.ok) {
return;
}
} catch (error) {
console.error('Waiting for local notary server...');
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
}

const configureNotarySerer = () => {
Expand All @@ -76,7 +88,7 @@ before(async function () {
server = exec('serve --config ../serve.json ./test-build -l 3001');
spawnTlsnServerFixture();
configureNotarySerer();
spawnLocalNotaryServer();
await spawnLocalNotaryServer();
browser = await puppeteer.launch(opts);
page = await browser.newPage();
await page.goto('http://localhost:3001');
Expand All @@ -85,7 +97,8 @@ before(async function () {

// close browser and reset global variables
after(async function () {
await tlsnServerFixture.kill();
// await tlsnServerFixture.kill();
await localNotaryServer.kill('SIGTERM');
await server.kill();
// @ts-ignore
await browser.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ git checkout "v0.1.0-alpha.4"

for dir in "tlsn/tlsn-server-fixture/" "notary-server"; do
# Change to the specific subdirectory
cd tlsn/tlsn-server-fixture/
pushd ${dir}

# Build the project
cargo build --release
popd
done
3 changes: 2 additions & 1 deletion webpack.web.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const isProd = process.env.NODE_ENV === 'production';

const envPlugin = new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
LOCAL: false,
LOCAL_NOTARY: true,
LOCAL_WS: false,
HEADLESS: false,
});

Expand Down

0 comments on commit 59a575b

Please sign in to comment.