Skip to content

Commit

Permalink
WIP [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
FabijanC committed Jun 30, 2022
1 parent 5cb4e02 commit abe9f3e
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/devnet/integrated-devnet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios from "axios";
import { ChildProcess } from "child_process";
import { HardhatPluginError } from "hardhat/plugins";
import { PLUGIN_NAME } from "../constants";

function sleep(amountMillis: number): Promise<void> {
return new Promise((resolve) => {
Expand All @@ -11,6 +13,7 @@ const DEVNET_ALIVE_URL = "is_alive";

export abstract class IntegratedDevnet {
protected childProcess: ChildProcess;
private stderr = "";

constructor(protected host: string, protected port: string) {
IntegratedDevnet.cleanupFns.push(this.cleanup.bind(this));
Expand All @@ -29,6 +32,15 @@ export abstract class IntegratedDevnet {
public async start(): Promise<void> {
this.childProcess = await this.spawnChildProcess();

this.childProcess.stderr.on("data", (chunk) => (this.stderr += chunk.toString()));

this.childProcess.on("close", (code) => {
if (code !== 0) {
const msg = `Integrated devnet exited with code ${code}.\n${this.stderr}`;
throw new HardhatPluginError(PLUGIN_NAME, msg);
}
});

return new Promise((resolve, reject) => {
this.childProcess.on("spawn", async () => {
const maxWaitMillis = 60_000;
Expand Down
17 changes: 17 additions & 0 deletions test/integrated-devnet-tests/with-docker-fail/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

# TODO decide how it will fail - address already in use or invalid cli arg

# TODO change to use ../
source ~/shardlabs/starknet-hardhat-plugin/scripts/check-devnet-is-not-running.sh

check_devnet_is_not_running

# run devnet which will cause integrated-devnet to fail
starknet-devnet --host 127.0.0.1 --port 5050 &

npx hardhat starknet-compile contracts/contract.cairo

npx hardhat test --no-compile test/integrated-devnet.test.ts |
~/shardlabs/starknet-hardhat-plugin/scripts/assert_contains.py "Address already in use"
13 changes: 13 additions & 0 deletions test/integrated-devnet-tests/with-docker-fail/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "../dist/src/index.js";

module.exports = {
starknet: {
network: process.env.NETWORK
},
networks: {
integratedDevnet: {
dockerizedVersion: process.env.STARKNET_DEVNET,
url: "http://127.0.0.1:5050"
}
}
};
4 changes: 4 additions & 0 deletions test/integrated-devnet-tests/with-docker-fail/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "../../network.schema",
"integrated-devnet": true
}
11 changes: 11 additions & 0 deletions test/integrated-devnet-tests/with-venv-fail/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

source ../scripts/check-devnet-is-not-running.sh

check_devnet_is_not_running
starknet-devnet --host 127.0.0.1 --port 5050 &

npx hardhat starknet-compile contracts/contract.cairo
npx hardhat test --no-compile test/integrated-devnet.test.ts |
../scripts/assert_contains.py "address already in use"
13 changes: 13 additions & 0 deletions test/integrated-devnet-tests/with-venv-fail/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "../dist/src/index.js";

module.exports = {
starknet: {
network: process.env.NETWORK
},
networks: {
integratedDevnet: {
venv: process.env.STARKNET_DEVNET_PATH,
url: "http://127.0.0.1:5050"
}
}
};
4 changes: 4 additions & 0 deletions test/integrated-devnet-tests/with-venv-fail/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "../../network.schema",
"integrated-devnet": true
}

0 comments on commit abe9f3e

Please sign in to comment.