Skip to content
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
3 changes: 0 additions & 3 deletions clijs/test/commands/abi/encode-decode.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { describe, expect } from "vitest";
import { CliTest } from "../../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("abi:encode-decode", () => {
CliTest("tests abi encoding and decoding", async ({ runCommand }) => {
const encoded = (
Expand Down
3 changes: 0 additions & 3 deletions clijs/test/commands/block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Block } from "@nilfoundation/niljs";
import { describe, expect } from "vitest";
import { CliTest } from "../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("block:get blocks", () => {
CliTest("tests getting blocks", async ({ runCommand }) => {
const block1 = (await runCommand(["block", "latest", "-s", "1"])).result as Block<boolean>;
Expand Down
2 changes: 0 additions & 2 deletions clijs/test/commands/receipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { Hex, ProcessedReceipt } from "@nilfoundation/niljs";
import { describe, expect } from "vitest";
import { CliTest } from "../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
describe("receipt:get_receipt", () => {
CliTest("tests getting receipts", async ({ runCommand, smartAccount }) => {
const txHash = (
Expand Down
3 changes: 0 additions & 3 deletions clijs/test/commands/smart-account/balance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import ConfigManager from "../../../src/common/config.js";
import { ConfigKeys } from "../../../src/common/config.js";
import { CliTest } from "../../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("smart-account:balance", () => {
CliTest("runs smart-account:balance cmd", async ({ cfgPath, runCommand }) => {
const { result } = await runCommand(["smart-account", "new"]);
Expand Down
3 changes: 0 additions & 3 deletions clijs/test/commands/smart-account/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Hex } from "@nilfoundation/niljs";
import { describe, expect } from "vitest";
import { CliTest } from "../../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("smart-account:deploy", () => {
CliTest("tests smart account deploy and send-transaction", async ({ runCommand }) => {
const smartAccountAddress = (await runCommand(["smart-account", "new"])).result as Hex;
Expand Down
3 changes: 0 additions & 3 deletions clijs/test/commands/smart-account/estimate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Hex } from "@nilfoundation/niljs";
import { describe, expect } from "vitest";
import { CliTest } from "../../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("smart-account:estimate", () => {
CliTest("tests smart account deploy and estimate tx", async ({ runCommand }) => {
const smartAccountAddress = (await runCommand(["smart-account", "new"])).result as Hex;
Expand Down
3 changes: 0 additions & 3 deletions clijs/test/commands/smart-account/new.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import ConfigManager from "../../../src/common/config.js";
import { ConfigKeys } from "../../../src/common/config.js";
import { CliTest } from "../../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("smart-account:new", () => {
CliTest("runs smart-account:new cmd", async ({ cfgPath, runCommand }) => {
const { result } = await runCommand(["smart-account", "new"]);
Expand Down
3 changes: 0 additions & 3 deletions clijs/test/commands/smart-account/send-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Hex } from "@nilfoundation/niljs";
import { describe, expect } from "vitest";
import { CliTest } from "../../setup.js";

// To run this test you need to run the nild:
// nild run --http-port 8529
// TODO: Setup nild automatically before running the tests
describe("smart-account:send-token", () => {
CliTest("tests smart account send tokens", async ({ runCommand }) => {
const smartAccountAddress = (await runCommand(["smart-account", "new"])).result as Hex;
Expand Down
46 changes: 46 additions & 0 deletions clijs/test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { type ChildProcess, spawn } from "node:child_process";
import { closeSync, openSync } from "node:fs";
import { testEnv } from "./testEnv.js";

interface Nild {
pid: number;
process: ChildProcess;
logFd: number;
}

let nildInstance: Nild;

export async function setup() {
console.log("launching nild:", testEnv.nild);
const logFd = openSync("nild.log", "w");
const nild = spawn(testEnv.nild, ["run", "--http-port", "8529", "--collator-tick-ms", "100"], {
stdio: ["ignore", logFd, logFd],
});

await new Promise((resolve, reject) => {
nild.once("error", reject);
nild.once("spawn", resolve);
});

if (!nild.pid) {
throw new Error("Failed to start nild");
}

nildInstance = {
pid: nild.pid,
process: nild,
logFd: logFd,
};
}

export async function teardown() {
console.log("stopping nild");

nildInstance.process.kill("SIGTERM");
await new Promise<void>((resolve) => {
nildInstance.process.once("exit", () => {
closeSync(nildInstance.logFd);
resolve();
});
});
}
2 changes: 2 additions & 0 deletions clijs/test/testEnv.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const defaultRpcEndpoint = "http://127.0.0.1:8529";
const defaultFaucetServiceEndpoint = "http://127.0.0.1:8529";
const defaultCometaServiceEndpoint = "http://127.0.0.1:8529";
const defaultNildBinary = "nild";
const testEnv = {
endpoint: process.env.RPC_ENDPOINT ?? defaultRpcEndpoint,
faucetServiceEndpoint: process.env.FAUCET_SERVICE_ENDPOINT ?? defaultFaucetServiceEndpoint,
cometaServiceEndpoint: process.env.COMETA_SERVICE_ENDPOINT ?? defaultCometaServiceEndpoint,
nild: process.env.NILD ?? defaultNildBinary,
} as const;

export { testEnv };
3 changes: 3 additions & 0 deletions clijs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ export default defineConfig({
provider: "v8",
reportOnFailure: true,
},
globalSetup: [
"./test/globalSetup.ts",
],
},
});
11 changes: 5 additions & 6 deletions nix/clijs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ stdenv.mkDerivation rec {

echo "smoke check passed"


nohup nild run --http-port 8529 --collator-tick-ms=100 > nild.log 2>&1 & echo $! > nild_pid &

pnpm run test:ci

kill `cat nild_pid` && rm nild_pid
env NILD=nild pnpm run test:ci || {
echo "tests failed. nild.log:"
cat nild.log
exit 1
}

echo "tests finished successfully"
'';
Expand Down
Loading