Skip to content

Commit

Permalink
Replace StarknetPluginError with assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-SL committed Nov 24, 2022
1 parent fb0c77a commit f4cedb1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 45 deletions.
11 changes: 3 additions & 8 deletions test/general-tests/starknet-new-account/check.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { readFileSync } from "fs";
import path from "path";
import { StarknetPluginError } from "../../../src/starknet-plugin-error";
import { hardhatStarknetNewAccount } from "../../utils/cli-functions";
import { ensureEnvVar, extractAddress } from "../../utils/utils";
import { assertEqual, ensureEnvVar, extractAddress } from "../../utils/utils";

const network = ensureEnvVar("NETWORK");
const home = ensureEnvVar("HOME");
Expand All @@ -22,9 +21,5 @@ const accountAddressFile = JSON.parse(accountFile.toString())[network].OpenZeppe
const addressStd = parseInt(accountAddressStd, 16);
const addressFile = parseInt(accountAddressFile, 16);

// If address_one and address_two are equal then success
if (addressStd === addressFile) {
console.log("Success");
} else {
throw new StarknetPluginError("Addresses are not equal");
}
// If addressStd and addressFile are equal then success
assertEqual(addressStd, addressFile, "Account address mismatch");
15 changes: 6 additions & 9 deletions test/general-tests/starknet-verify/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ensureEnvVar, exec, extractAddress } from "../../utils/utils";
import { StarknetPluginError } from "../../../src/starknet-plugin-error";
import { assertEqual, ensureEnvVar, exec, extractAddress } from "../../utils/utils";
import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions";
import axios from "axios";

console.log("The starknet-verify test is too flaky so it is temporarily suspended. Make sure it's working!");
process.exit(0);
Expand All @@ -24,10 +24,7 @@ exec(`npx hardhat starknet-verify --starknet-network ${network} --path ${mainCon
console.log("Sleeping to allow Voyager to register the verification");
exec("sleep 15s");

const is_verified = exec(`curl "https://goerli.voyager.online/api/contract/${address}/code" | jq ".abiVerified"`);
if (is_verified == "true") {
console.log("Successfully verified!");
} else {
console.log("Error: Not verified!");
throw new StarknetPluginError("Error: Not verified!");
}
(async () => {
const { data } = await axios.get(`https://goerli.voyager.online/api/contract/${address}/code`);
assertEqual(data.abiVerified, "true", "Contract is not verified");
})();
14 changes: 4 additions & 10 deletions test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { existsSync, readFileSync } from "fs";
import { checkDevnetIsNotRunning, contains } from "../../utils/utils";
import { StarknetPluginError } from "../../../src/starknet-plugin-error";
import { assertExists, checkDevnetIsNotRunning, contains } from "../../utils/utils";
import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions";

(async () => {
Expand All @@ -14,14 +13,9 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun
contains(execution.stderr, expectedWarning);

// Checks if file logs/stderr.log exists and contains the expected warning string
if (existsSync("logs/stdout.log")) {
const stdout = readFileSync("logs/stdout.log", "utf-8");
if (!stdout.includes(expectedStdout)) {
throw new StarknetPluginError(`Expected stderr to contain ${expectedStdout}`);
}
} else {
throw new StarknetPluginError("Expected logs/stdout.log to exist");
}
assertExists("logs/stdout.log", "Expected logs/stdout.log to exist");
const stdout = readFileSync("logs/stdout.log", "utf-8");
contains(stdout, expectedStdout);

console.log("Success");
await checkDevnetIsNotRunning();
Expand Down
18 changes: 5 additions & 13 deletions test/integrated-devnet-tests/with-stderr-to-file/check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { existsSync, readFileSync } from "fs";
import { checkDevnetIsNotRunning } from "../../utils/utils";
import { StarknetPluginError } from "../../../src/starknet-plugin-error";
import { assertExists, checkDevnetIsNotRunning, contains } from "../../utils/utils";
import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions";

(async () => {
Expand All @@ -12,19 +11,12 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun

const output = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "));
// Checks if output contains the expected string from stdout
if (!output.includes(expectedStdout)) {
throw new StarknetPluginError(`Expected output to contain ${expectedStdout}`);
}
contains(output.stdout, expectedStdout);

// Checks if file logs/stderr.log exists and contains the expected warning string
if (existsSync("logs/stderr.log")) {
const stderr = readFileSync("logs/stderr.log", "utf-8");
if (!stderr.includes(expectedWarning)) {
throw new StarknetPluginError(`Expected stderr to contain ${expectedWarning}`);
}
} else {
throw new StarknetPluginError("Expected logs/stderr.log to exist");
}
assertExists("logs/stderr.log", "Expected logs/stderr.log to exist");
const stderr = readFileSync("logs/stderr.log", "utf-8");
contains(stderr, expectedWarning);

console.log("Success");
await checkDevnetIsNotRunning();
Expand Down
7 changes: 2 additions & 5 deletions test/recompilation-tests/hardhat-test/check.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { copyFileSync, readFileSync, appendFileSync } from "fs";
import path from "path";
import { StarknetPluginError } from "../../../src/starknet-plugin-error";
import { hardhatStarknetTest } from "../../utils/cli-functions";
import { rmrfSync } from "../../utils/utils";
import { assertNotEqual, rmrfSync } from "../../utils/utils";

const prefix = path.join(__dirname);
const contractName = "contract_test_cache.cairo";
Expand Down Expand Up @@ -44,9 +43,7 @@ hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts"
// Check that the cache file was updated using diff
const cacheContentAfter = readFileSync("cache/cairo-files-cache.json");
const cacheContentBefore = readFileSync("cache-content-before.json");
if (cacheContentAfter.equals(cacheContentBefore)) {
throw new StarknetPluginError("Cache file was not updated");
}
assertNotEqual(cacheContentAfter, cacheContentBefore, "Cache file was not updated.");

console.log("Testing Recompilation one contract added another deleted");
rmrfSync("contracts/contract_test_cache.cairo");
Expand Down

0 comments on commit f4cedb1

Please sign in to comment.