Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes and refinements #10

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/check-build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: just check

Expand All @@ -34,6 +35,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- uses: actions/setup-python@v5
with:
python-version: '3.12'
Expand All @@ -43,12 +45,8 @@ jobs:
sudo apt update
sudo apt install -y protobuf-compiler curl
npm ci
- name: Install and configure nilup
run: |
curl https://nilup.nilogy.xyz/install.sh | bash
$HOME/.nilup/bin/nilup use 0.5.0
$HOME/.nilup/bin/nilup init
echo "$HOME/.nilup/bin" >> $GITHUB_PATH
- uses: NillionNetwork/nillion-setup-action@main
version: latest
- run: |
just test-${{ matrix.package }}-ci
- uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
with:
node-version: '22'
registry-url: "https://registry.npmjs.org"
cache: 'npm'
- env:
NODE_AUTH_TOKEN:
${{ secrets.NPM_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion packages/fixture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"dependencies": {
"@types/debug": "^4.1.12",
"date-fns": "^3.6.0",
"debug": "^4.3.5",
"dotenv": "^16.4.5",
"execa": "^9.3.0",
Expand Down
8 changes: 5 additions & 3 deletions packages/fixture/src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import debug from "debug";
import { format } from "date-fns";
import fs from "node:fs";
import path from "node:path";

debug.enable("nillion:*");
export const Log = debug("nillion:fixture");
Log.log = console.log.bind(console);

const formattedDate = format(new Date(), "yyyy-MM-dd_HH-mm-ss");
export const LOG_RUN_DIR = path.resolve(`./logs/${formattedDate}`);
export const LOG_RUN_DIR = path.resolve("./logs");

export const setupLoggingDir = () => {
fs.mkdirSync(LOG_RUN_DIR, { recursive: true });

const runTimestamp = new Date().toISOString();
fs.writeFileSync(`${LOG_RUN_DIR}/timestamp.log`, runTimestamp);

fs.writeFileSync(getDevnetLogFile(), "");
fs.writeFileSync(getTestLogFile(), "");
fs.writeFileSync(getPrepareProgramsLogFile(), "");
Expand Down
2 changes: 1 addition & 1 deletion packages/fixture/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { createProgramFixtures } from "./prepare-programs";
import { runDevnet } from "./run-devnet";
import { runTests } from "./run-tests";

// partyId: "12D3KooWEnWNWnuzuckMhAEKKMPvdDacy3K3tdCQDBtctsYMPe5r",
export const TestEnv = {
NILLION_TEST_TARGET: "",
NILLION_TEST_DEVNET_PID: -1,
NILLION_TEST_DEVNET_SEED: "test-fixture",
NILLION_TEST_PROGRAMS_NAMESPACE: "",

NILLION_BOOTNODE_MULTIADDRESS: "",
NILLION_BOOTNODE_WEBSOCKET: "",
NILLION_CLUSTER_ID: "",
NILLION_NILCHAIN_CHAIN_ID: "",
Expand Down
2 changes: 1 addition & 1 deletion packages/fixture/src/prepare-programs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const storeProgram = async (distDir: string, binaryName: string) => {
env: { PATH: process.env.PATH },
extendEnv: false,
})`nillion
-b ${TestEnv.NILLION_BOOTNODE_WEBSOCKET}
-b ${TestEnv.NILLION_BOOTNODE_MULTIADDRESS}
--node-key-seed ${randomUUID().toString()},
--user-key-seed ${TestEnv.NILLION_USER_SEED}
--nilchain-rpc-endpoint ${TestEnv.NILLION_NILCHAIN_JSON_RPC}
Expand Down
67 changes: 32 additions & 35 deletions packages/fixture/src/test-env.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
import { parse } from "dotenv";
import fs from "node:fs";
import { createInterface } from "node:readline";
import { getDevnetLogFile, Log } from "./logging";
import { Log } from "./logging";
import { TestEnv } from "./main";

export const watchFileForLine = (target: string): Promise<string> =>
new Promise((resolve, reject) => {
const filePath = getDevnetLogFile();

if (!fs.existsSync(filePath)) {
console.log(`${filePath} does not exist`);
reject(new Error(`${filePath} does not exist`));
}

let fileProcessedSize = 0;
let done = false;

const watcher = fs.watch(filePath, (eventType) => {
if (done) {
watcher.close();
} else if (eventType === "change") {
const stream = fs.createReadStream(filePath, {
start: fileProcessedSize,
});
const rl = createInterface({ input: stream });
const waitForFileSync = async (path: string): Promise<string> => {
let iteration = 0;
const timeout = 500;
return new Promise((resolve, reject) => {
const interval = setInterval(() => {
if (iteration > 20) {
clearInterval(interval);
reject(
new Error(
`${path} was not detected in ${String(timeout * iteration)}ms`,
),
);
return;
}

rl.on("line", (line) => {
if (line.includes(target)) {
done = true;
resolve(line);
} else {
fileProcessedSize += Buffer.byteLength(line + "\n");
}
});
if (fs.existsSync(path)) {
clearInterval(interval);
const file = fs.readFileSync(path, "utf8");
resolve(file);
return;
}
});

iteration += 1;
}, timeout);
});
};

export const loadEnv = async (): Promise<void> => {
Log("Watching for nillion-devnet environment file.");
const marker = "nillion-devnet.env";
const line = await watchFileForLine(marker);
const path = line.substring(line.indexOf("/")).trim();
const fromEnvFile = parse(fs.readFileSync(path, "utf8"));
const home = process.env.HOME;
if (!home) throw new Error("Env var HOME unset");

const path = `${home}/.config//nillion/nillion-devnet.env`;
const file = await waitForFileSync(path);
const fromEnvFile = parse(file);

TestEnv.NILLION_BOOTNODE_MULTIADDRESS =
fromEnvFile.NILLION_BOOTNODE_MULTIADDRESS;
TestEnv.NILLION_BOOTNODE_WEBSOCKET = fromEnvFile.NILLION_BOOTNODE_WEBSOCKET;
TestEnv.NILLION_CLUSTER_ID = fromEnvFile.NILLION_CLUSTER_ID;
TestEnv.NILLION_NILCHAIN_CHAIN_ID = fromEnvFile.NILLION_NILCHAIN_CHAIN_ID;
Expand Down