Skip to content

Commit

Permalink
Tests with local env
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Oct 20, 2023
1 parent 8b82b5a commit 28c78d6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
8 changes: 8 additions & 0 deletions test/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@

export const CHAIN_PRIVATE_KEY =
"0x3cc23e0227bd17ea5d6ea9d42b5eaa53ad41b1974de4755c79fe236d361a6fd5";

export const LOCAL_PEER_IDS = [
"12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
"12D3KooWQdpukY3p2DhDfUfDgphAqsGu5ZUrmQ4mcHSGrRag6gQK",
"12D3KooWRT8V5awYdEZm6aAV9HWweCEbhWd7df4wehqHZXAB7yMZ",
];

export const FLUENCE_ENV = "local";
59 changes: 46 additions & 13 deletions test/fRPC.integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* limitations under the License.
*/

import { promises as fs } from "fs";

import { startGateway, fluence } from "./utils";
import { CHAIN_PRIVATE_KEY } from "./consts";
import { startGateway, fluence, backupFile } from "./utils";
import { CHAIN_PRIVATE_KEY, LOCAL_PEER_IDS, FLUENCE_ENV } from "./consts";

async function testGateway(mode?: string) {
const gateway = await startGateway(mode);
Expand All @@ -42,6 +40,16 @@ async function testGateway(mode?: string) {
}
}

async function fluenceKeyEnv(...args: string[]) {
return fluence(
...args,
"--env",
FLUENCE_ENV,
"--priv-key",
CHAIN_PRIVATE_KEY,
);
}

describe("fRPC", () => {
describe("quickstart", () => {
[undefined, "random", "round-robin", "quorum"].forEach((mode) => {
Expand All @@ -51,20 +59,45 @@ describe("fRPC", () => {
});
});

describe("deploy", () => {
it("should deploy the deal", async () => {
await fs.rename(".fluence/workers.yaml", ".fluence/workers.yaml.bak");
describe.only("deploy", () => {
beforeAll(async () => {
const [register, stderrReg] = await fluenceKeyEnv("provider", "register");

// Here CLI writes success to stdout
if (!register.includes("Successfully")) {
throw new Error(`Failed to register provider:
stdout: ${register}
stderr: ${stderrReg}`);
}

const [stdout, _] = await fluence(
"deal",
"deploy",
"--priv-key",
CHAIN_PRIVATE_KEY,
const [stdoutAdd, addPeers] = await fluenceKeyEnv(
"provider",
"add-peer",
...LOCAL_PEER_IDS.flatMap((id) => ["--peer-id", id]),
"--units",
"1",
);

console.log(stdout);
// Here CLI writes results to stderr
const added = addPeers.match(/Added/g)?.length ?? 0;
if (added != 3) {
throw new Error(`Failed to add peers:
stdout: ${stdoutAdd}
stderr: ${addPeers}`);
}
});

it("should deploy the deal", async () => {
await backupFile(".fluence/workers.yaml");

const [stdout, _] = await fluenceKeyEnv("deal", "deploy");

expect(stdout.includes("Success!")).toBeTruthy();

// Wait until workers are deployed
// TODO: Make this gracefully,
// call aqua subnet resolution
await new Promise((resolve) => setTimeout(resolve, 10000));
});

["random", "round-robin", "quorum"].forEach((mode) => {
Expand Down
11 changes: 10 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
*/

import { relative } from "path";
import { promises as fs } from "fs";
import { execFile, ChildProcess } from "child_process";

import treeKill from "tree-kill";

import { CONFIG_PATH, readConfig, updateConfig } from "./config";

export async function backupFile(path: string): Promise<void> {
await fs.rename(path, `${path}.back`).catch((err) => {
if (err.code !== "ENOENT") {
throw err;
}
});
}

export async function execute(
cmd: string,
...args: string[]
Expand All @@ -37,7 +46,7 @@ export async function execute(
}

export async function fluence(...args: string[]): Promise<[string, string]> {
return execute("fluence", ...args);
return execute("fluence", ...args, "--no-input");
}

export class Gateway {
Expand Down

0 comments on commit 28c78d6

Please sign in to comment.