Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check to getBlockUtil #183

Merged
merged 1 commit into from Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -28,7 +28,8 @@
"test-recompilation-tests": "TEST_SUBDIR=recompilation-tests ./scripts/test.sh",
"build": "rm -rf dist && tsc && npm run copy-files",
"copy-files": "cp src/starknet_cli_wrapper.py dist/src/",
"lint": "eslint src test"
"lint": "eslint src test",
"format": "prettier -wl src test"
},
"author": "Shard-Labs",
"license": "ISC",
Expand Down
5 changes: 5 additions & 0 deletions src/extend-utils.ts
Expand Up @@ -187,6 +187,11 @@ export async function getBlockUtil(
hash: identifier?.blockHash
};

if (identifier && typeof identifier !== "object") {
const msg = `Invalid identifier provided to getBlock: ${identifier}`;
throw new HardhatPluginError(PLUGIN_NAME, msg);
}

if (blockOptions.number == null && !blockOptions.hash) {
blockOptions.number = "latest";
}
Expand Down
11 changes: 8 additions & 3 deletions src/recompiler.ts
Expand Up @@ -22,7 +22,7 @@ export class Cache {
protected cache: Record<string, ContractData> = {};
public fsPromises = fs.promises;

constructor(protected hre: HardhatRuntimeEnvironment) { }
constructor(protected hre: HardhatRuntimeEnvironment) {}

// Returns the contract data from the cache
public async getCache(): Promise<Record<string, ContractData>> {
Expand Down Expand Up @@ -66,7 +66,10 @@ export class Cache {
// Saves the cache to the file
public async saveCache(): Promise<void> {
const cacheFilePath = this.getCacheFilePath();
await this.fsPromises.writeFile(cacheFilePath, JSON.stringify(this.cache, null, " ") + "\n");
await this.fsPromises.writeFile(
cacheFilePath,
JSON.stringify(this.cache, null, " ") + "\n"
);
}
}

Expand All @@ -80,7 +83,9 @@ export class Recompiler {
}

// Gets hash of each .cairo file inside source
private async getContractHash(paths: ProjectPathsConfig): Promise<Record<string, ContractData>> {
private async getContractHash(
paths: ProjectPathsConfig
): Promise<Record<string, ContractData>> {
const { starknetSources: defaultSourcesPath } = paths;

const sourceRegex = new RegExp("^" + defaultSourcesPath + "/");
Expand Down
1 change: 0 additions & 1 deletion src/task-actions.ts
Expand Up @@ -26,7 +26,6 @@ import { getWalletUtil } from "./extend-utils";
import { createIntegratedDevnet } from "./devnet";
import { Recompiler } from "./recompiler";


function checkSourceExists(sourcePath: string): void {
if (!fs.existsSync(sourcePath)) {
const msg = `Source expected to be at ${sourcePath}, but not found.`;
Expand Down