-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fhenixsdk.initializeWithHHSigner
fixes (#20)
* Update fhenixjs version with sdk fixes * `initializeWithHHSigner` references correct `fhenixsdk` instance, fixes fields * Update tests to use result object instead of raw result * Run localfhenix * Update faucet port * Update container v
- Loading branch information
1 parent
c3defdc
commit 1f9f4c4
Showing
6 changed files
with
137 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import util from "util"; | ||
import { JsonRpcProvider } from "ethers"; | ||
import { exec } from "child_process"; | ||
|
||
const TEST_ENDPOINT_URL = process.env.TEST_ENDPOINT || "http://localhost:8545"; | ||
|
||
const execPromise = util.promisify(exec); | ||
const CONTAINER_NAME = "fhenixjs-test-env"; | ||
|
||
async function runDockerContainerAsync() { | ||
const imageName = "ghcr.io/fhenixprotocol/localfhenix:v0.3.2"; | ||
|
||
const ports = "-p 8545:8547 -p 5000:3000"; | ||
|
||
const removePrevious = `docker kill ${CONTAINER_NAME}`; | ||
|
||
const command = `docker run --rm --env FHEOS_SECURITY_ZONES=2 --name ${CONTAINER_NAME} ${ports} -d ${imageName}`; | ||
|
||
try { | ||
try { | ||
await execPromise(removePrevious); | ||
} catch (_) {} | ||
const result = await execPromise(command); | ||
// console.log(result.stdout); | ||
// console.error(result.stderr); | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error("Failed to start docker container"); | ||
} | ||
} | ||
|
||
async function killDockerContainerAsync() { | ||
const removePrevious = `docker kill ${CONTAINER_NAME}`; | ||
|
||
try { | ||
await execPromise(removePrevious); | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error("Failed to remove docker container"); | ||
} | ||
} | ||
|
||
async function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function waitForChainToStart(url) { | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
try { | ||
const client = new JsonRpcProvider(url); | ||
console.log(`connecting to ${url}...`); | ||
const networkId = await client.getNetwork(); | ||
return Number(networkId.chainId); | ||
} catch (e) { | ||
console.log(`client not ready`); | ||
} | ||
await sleep(250); | ||
} | ||
} | ||
|
||
export async function mochaGlobalSetup() { | ||
if (process.env.SKIP_LOCAL_ENV === "true") { | ||
return; | ||
} | ||
|
||
runDockerContainerAsync(); | ||
|
||
console.log("\nWaiting for Fhenix to start..."); | ||
|
||
await waitForChainToStart(TEST_ENDPOINT_URL); | ||
|
||
console.log("Fhenix is running!"); | ||
} | ||
|
||
// this is a cjs because jest sucks at typescript | ||
|
||
export async function mochaGlobalTeardown() { | ||
if (process.env.SKIP_LOCAL_ENV === "true") { | ||
return; | ||
} | ||
console.log("\nWaiting for Fhenix to stop..."); | ||
|
||
await killDockerContainerAsync(); | ||
|
||
console.log("Stopped test container. Goodbye!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.