diff --git a/test/consts.ts b/test/consts.ts index 16ac522..d3b3803 100644 --- a/test/consts.ts +++ b/test/consts.ts @@ -16,3 +16,11 @@ export const CHAIN_PRIVATE_KEY = "0x3cc23e0227bd17ea5d6ea9d42b5eaa53ad41b1974de4755c79fe236d361a6fd5"; + +export const LOCAL_PEER_IDS = [ + "12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR", + "12D3KooWQdpukY3p2DhDfUfDgphAqsGu5ZUrmQ4mcHSGrRag6gQK", + "12D3KooWRT8V5awYdEZm6aAV9HWweCEbhWd7df4wehqHZXAB7yMZ", +]; + +export const FLUENCE_ENV = "local"; diff --git a/test/fRPC.integration-test.ts b/test/fRPC.integration-test.ts index 018c9f8..1158de6 100644 --- a/test/fRPC.integration-test.ts +++ b/test/fRPC.integration-test.ts @@ -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); @@ -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) => { @@ -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) => { diff --git a/test/utils.ts b/test/utils.ts index 17fd82d..c469982 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -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 { + await fs.rename(path, `${path}.back`).catch((err) => { + if (err.code !== "ENOENT") { + throw err; + } + }); +} + export async function execute( cmd: string, ...args: string[] @@ -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 {