diff --git a/package.json b/package.json index 094cbafd..603e43e6 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,9 @@ "prettier": "prettier '**/*.{ts,json,sol,md}' --check", "prettier:fix": "npm run prettier -- --write", "format": "npm run prettier:fix && npm run lint:fix", - "test": "npx lerna run test:ci --stream", - "build": "npx lerna run build" + "test": "HARDHAT_CLEAN=true npx lerna run test:ci --stream", + "build": "npx lerna run build", + "pub": "lerna publish from-package" }, "devDependencies": { "@types/chai": "^4.3.5", diff --git a/packages/local/src/main.ts b/packages/local/src/main.ts index 3dc3a9f4..4213d30c 100644 --- a/packages/local/src/main.ts +++ b/packages/local/src/main.ts @@ -154,11 +154,17 @@ class LocalTableland { // wait until initialization is done await waitForReady(registryReadyEvent, this.initEmitter); - await new Promise((resolve) => setTimeout(resolve, 5000)); + if (process.env.HARDHAT_CLEAN) { + console.log("HARDHAT_CLEAN env set, cleaning hardhat"); + await new Promise((resolve) => setTimeout(resolve, 1)); + this.#_cleanHardhat(); + } this._deployRegistry(); const deployed = await this.#_ensureRegistry(); + + // If the deploy process failed silently we will try to clean hardhat and re-deploy if (!deployed) { throw new Error( "deploying registry contract failed, cannot start network" @@ -241,6 +247,20 @@ class LocalTableland { ); } + #_cleanHardhat(): void { + // Deploy the Registry to the Hardhat node + logSync( + spawnSync( + isWindows() ? "npx.cmd" : "npx", + ["hardhat", "clean", "--global"], + { + cwd: this.registryDir, + } + ), + !inDebugMode() + ); + } + async #_ensureRegistry(): Promise { const provider = getDefaultProvider( `http://127.0.0.1:${this.registryPort}`