From fd1a6ebe0a7581d0bf3325df7264dc5a5d8828f7 Mon Sep 17 00:00:00 2001 From: notV4l Date: Fri, 23 Jun 2023 15:57:49 +0200 Subject: [PATCH 1/6] fix: warnings caused by err: any --- .gitignore | 3 +++ .../{events.cairo => events1.cairo} | 0 hardhat.config.ts | 6 +++-- test/argent-account-test.ts | 5 ++-- test/cairo0-constructor.test.ts | 7 +++--- test/cairo1/decode-events.test.ts | 2 +- test/function-args-test.ts | 25 ++++++++++--------- test/oz-account-test.ts | 6 +++-- test/path-test.ts | 5 ++-- test/sample-test.ts | 8 +++--- test/wallet-test.ts | 3 ++- 11 files changed, 42 insertions(+), 28 deletions(-) rename cairo1-contracts/{events.cairo => events1.cairo} (100%) diff --git a/.gitignore b/.gitignore index 4cf7bb4..b6749e7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ __pycache__ #Starknet plugin starknet-artifacts + +#build +dist diff --git a/cairo1-contracts/events.cairo b/cairo1-contracts/events1.cairo similarity index 100% rename from cairo1-contracts/events.cairo rename to cairo1-contracts/events1.cairo diff --git a/hardhat.config.ts b/hardhat.config.ts index 4ab0a3a..410f7fc 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -49,8 +49,10 @@ const config: HardhatUserConfig = { // Read about Devnet options here: https://0xSpaceShard.github.io/starknet-devnet/docs/guide/run // // *Account predeployment* - // "--seed", - // "42", + "--seed", + "42", + // "--fork-network", + // "alpha-goerli", // "--accounts", // "1", // "--initial-balance", diff --git a/test/argent-account-test.ts b/test/argent-account-test.ts index 3dc141e..749b965 100644 --- a/test/argent-account-test.ts +++ b/test/argent-account-test.ts @@ -3,6 +3,7 @@ import hardhat, { starknet } from "hardhat"; import { StarknetContract, StarknetContractFactory } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { expectFeeEstimationStructure, getOZAccount, mint } from "./util"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" describe("Argent account", function () { this.timeout(TIMEOUT); @@ -95,7 +96,7 @@ describe("Argent account", function () { const wrongKey = "0x0123"; await starknet.ArgentAccount.getAccountFromAddress(argentAccountAddress, wrongKey); expect.fail("Should have failed on passing an incorrect private key."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal( "The provided private key is not compatible with the public key stored in the contract." ); @@ -143,7 +144,7 @@ describe("Argent account", function () { { maxFee: estimatedFee.amount / 2n } ); expect.fail("Should have failed earlier"); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.contain("Actual fee exceeded max fee"); } diff --git a/test/cairo0-constructor.test.ts b/test/cairo0-constructor.test.ts index 8cee240..2d491a6 100644 --- a/test/cairo0-constructor.test.ts +++ b/test/cairo0-constructor.test.ts @@ -3,6 +3,7 @@ import { starknet } from "hardhat"; import { Account, StarknetContractFactory } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { getOZAccount } from "./util"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" describe("Starknet", function () { this.timeout(TIMEOUT); @@ -32,7 +33,7 @@ describe("Starknet", function () { try { await account.deploy(contractFactory); expect.fail("Should have failed on not passing constructor calldata."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("constructor: Expected 1 argument, got 0."); } }); @@ -41,7 +42,7 @@ describe("Starknet", function () { try { await account.deploy(contractWithEmptyConstructorFactory, { dummy_var: 10n }); expect.fail("Should have failed on providing constructor arguments."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("constructor: Expected 0 arguments, got 1."); } }); @@ -60,7 +61,7 @@ describe("Starknet", function () { try { await account.deploy(contractWithoutConstructorFactory, { dummy_var: 10n }); expect.fail("Should have failed on providing constructor arguments."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("No constructor arguments required but 1 provided"); } }); diff --git a/test/cairo1/decode-events.test.ts b/test/cairo1/decode-events.test.ts index ef47422..ea97204 100644 --- a/test/cairo1/decode-events.test.ts +++ b/test/cairo1/decode-events.test.ts @@ -15,7 +15,7 @@ describe("Cairo 1 - Events", function () { before(async function () { // assumes events.cairo has been compiled account = await getOZAccount(); - contractFactory = await starknet.getContractFactory("events"); + contractFactory = await starknet.getContractFactory("events1"); await account.declare(contractFactory); contract = await account.deploy(contractFactory, { initial_balance: 0n diff --git a/test/function-args-test.ts b/test/function-args-test.ts index 3d144fd..eb09831 100644 --- a/test/function-args-test.ts +++ b/test/function-args-test.ts @@ -3,6 +3,7 @@ import { starknet } from "hardhat"; import { TIMEOUT } from "./constants"; import { Account, StarknetContract, StarknetContractFactory } from "hardhat/types/runtime"; import { expectFeeEstimationStructure, getOZAccount } from "./util"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" describe("Starknet", function () { this.timeout(TIMEOUT); @@ -26,7 +27,7 @@ describe("Starknet", function () { try { await contract.call("sum_array"); expect.fail("Should have failed on passing too few arguments."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("sum_array: Expected 1 argument, got 0."); } }); @@ -35,7 +36,7 @@ describe("Starknet", function () { try { await contract.call("sum_array", { a: [1, 2, 3, 4], b: 4 }); expect.fail("Should have failed on passing extra argument."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("sum_array: Expected 1 argument, got 2."); } }); @@ -49,7 +50,7 @@ describe("Starknet", function () { try { await contract.call("sum_array", { a_len: 4, a: [1, 2, 3, 4] }); expect.fail("Should have failed on passing extra argument."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("sum_array: Expected 1 argument, got 2."); } }); @@ -74,7 +75,7 @@ describe("Starknet", function () { ] }); expect.fail("Should have failed on passing more members than expected."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("\"points\": Expected 2 members, got 3."); } }); @@ -86,7 +87,7 @@ describe("Starknet", function () { points: [{ x: 1, y: 2 }] }); expect.fail("Should have failed on passing less members than expected."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("\"points\": Expected 2 members, got 1."); } }); @@ -98,7 +99,7 @@ describe("Starknet", function () { points: [{ x: 1 }, { x: 3, y: 4, z: 5 }] }); expect.fail("Should have failed on passing less members than expected."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("\"points[0]\": Expected 2 members, got 1."); } }); @@ -113,7 +114,7 @@ describe("Starknet", function () { ] }); expect.fail("Should have failed on passing more members than expected"); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal("\"points[1]\": Expected 2 members, got 3."); } }); @@ -197,7 +198,7 @@ describe("Starknet", function () { nested_tuple_type_alias: [[{ x: 1n, y: 2n }, 3n], 4n, [5n, [{ x: 7n, y: 8n }]]] }); expect.fail("Should have failed on passing too few members."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.eql( "\"nested_tuple_type_alias[2][1]\": Expected 2 members, got 1." ); @@ -214,7 +215,7 @@ describe("Starknet", function () { ] }); expect.fail("Should have failed on passing too few members."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal( "\"nested_tuple_type_alias[2]\": Expected 2 members, got 3." ); @@ -225,7 +226,7 @@ describe("Starknet", function () { it("shouldn't invoke with raw input if not selected", async function () { try { await account.invoke(contract, "increase_balance", ["10", "20"]); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal(OBJECT_EXPECTATION); } }); @@ -233,7 +234,7 @@ describe("Starknet", function () { it("shouldn't estimate fee with raw input if not selected", async function () { try { await account.estimateFee(contract, "increase_balance", ["10", "20"]); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal(OBJECT_EXPECTATION); } }); @@ -243,7 +244,7 @@ describe("Starknet", function () { await contract.call("sum_point_array", [ "can put whatever here since it won't be checked" ]); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal(OBJECT_EXPECTATION); } }); diff --git a/test/oz-account-test.ts b/test/oz-account-test.ts index 88d0022..decdce5 100644 --- a/test/oz-account-test.ts +++ b/test/oz-account-test.ts @@ -9,6 +9,8 @@ import { OZ_ACCOUNT_ADDRESS, OZ_ACCOUNT_PRIVATE_KEY } from "./util"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" + describe("OpenZeppelin account", function () { this.timeout(TIMEOUT); @@ -86,7 +88,7 @@ describe("OpenZeppelin account", function () { try { await starknet.OpenZeppelinAccount.getAccountFromAddress(OZ_ACCOUNT_ADDRESS, "0x0123"); expect.fail("Should have failed on passing an incorrect private key."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal( "The provided private key is not compatible with the public key stored in the contract." ); @@ -111,7 +113,7 @@ describe("OpenZeppelin account", function () { { maxFee: estimatedFee.amount / 2n } ); expect.fail("Should have failed earlier"); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.contain("Actual fee exceeded max fee"); } diff --git a/test/path-test.ts b/test/path-test.ts index 6b0e32a..82b16b2 100644 --- a/test/path-test.ts +++ b/test/path-test.ts @@ -1,6 +1,7 @@ import { expect } from "chai"; import { starknet } from "hardhat"; import { TIMEOUT } from "./constants"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" const AMBIGUOUS_ERR_MSG = "More than one file was found because the path provided is ambiguous, please specify a relative path"; @@ -28,7 +29,7 @@ describe("getContractFactory", function () { try { await starknet.getContractFactory("util"); expect.fail("Should have failed"); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal(AMBIGUOUS_ERR_MSG); } @@ -40,7 +41,7 @@ describe("getContractFactory", function () { try { await starknet.getContractFactory("util.cairo"); expect.fail("Should have failed"); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal(AMBIGUOUS_ERR_MSG); } diff --git a/test/sample-test.ts b/test/sample-test.ts index b4c3cc7..df3601d 100644 --- a/test/sample-test.ts +++ b/test/sample-test.ts @@ -9,6 +9,8 @@ import { expectAddressEquality, getOZAccount } from "./util"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" + describe("Starknet", function () { this.timeout(TIMEOUT); @@ -74,7 +76,7 @@ describe("Starknet", function () { { maxFee: MAX_FEE, overhead: 2 } ); expect.fail("Should have failed on invoking using options with maxFee and overhead."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.deep.contain("maxFee and overhead cannot be specified together"); } }); @@ -177,7 +179,7 @@ describe("Starknet", function () { { maxFee: MAX_FEE } ); expect.fail("Should have failed on invoking with an odd number."); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.deep.contain("Transaction rejected. Error message:"); expect(err.message).to.deep.contain("An ASSERT_EQ instruction failed: 1 != 0."); } @@ -190,7 +192,7 @@ describe("Starknet", function () { try { await account.deploy(contractFactory, { initial_balance: 0 }, { salt }); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.include("CONTRACT_ADDRESS_UNAVAILABLE"); expect(err.message).to.include( `Requested contract address ${contract.address} is unavailable for deployment` diff --git a/test/wallet-test.ts b/test/wallet-test.ts index cd7ad2f..edd01f5 100644 --- a/test/wallet-test.ts +++ b/test/wallet-test.ts @@ -3,6 +3,7 @@ import { starknet } from "hardhat"; import { StarknetContract, StarknetContractFactory, Wallet } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { expectFeeEstimationStructure, getOZAccount } from "./util"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" describe("Starknet", function () { this.timeout(TIMEOUT); @@ -29,7 +30,7 @@ describe("Starknet", function () { expect.fail( "Should have failed on passing a wallet not configured in 'hardhat.config' file." ); - } catch (err: any) { + } catch (err: StarknetPluginError) { expect(err.message).to.equal( "Invalid wallet name provided: invalidWallet.\nValid wallets: OpenZeppelin" ); From 55ad017d91359e89bb69f4d122a6098a18bc6466 Mon Sep 17 00:00:00 2001 From: notV4l Date: Fri, 23 Jun 2023 16:06:39 +0200 Subject: [PATCH 2/6] fix: clean hardhat.config.ts --- hardhat.config.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 410f7fc..4ab0a3a 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -49,10 +49,8 @@ const config: HardhatUserConfig = { // Read about Devnet options here: https://0xSpaceShard.github.io/starknet-devnet/docs/guide/run // // *Account predeployment* - "--seed", - "42", - // "--fork-network", - // "alpha-goerli", + // "--seed", + // "42", // "--accounts", // "1", // "--initial-balance", From 2720b50e5d2641757e3927146665248b278aaea8 Mon Sep 17 00:00:00 2001 From: notV4l Date: Fri, 23 Jun 2023 17:55:47 +0200 Subject: [PATCH 3/6] fix: use HardhatPluginError --- .eslintrc.json | 1 + hardhat.config.ts | 4 +- package-lock.json | 151 +++++++++++++++++--------------- package.json | 6 +- test/argent-account-test.ts | 13 +-- test/cairo0-constructor.test.ts | 11 ++- test/devnet-restart.test.ts | 6 +- test/function-args-test.ts | 38 +++++--- test/oz-account-test.ts | 14 +-- test/path-test.ts | 8 +- test/postman.test.ts | 7 +- test/sample-test.ts | 12 +-- test/wallet-test.ts | 5 +- 13 files changed, 156 insertions(+), 120 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 913e2ca..a2bb510 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -67,6 +67,7 @@ } ], "template-curly-spacing": ["error", "never"], + "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": ["error"] } } diff --git a/hardhat.config.ts b/hardhat.config.ts index 4ab0a3a..73bb92d 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -49,8 +49,8 @@ const config: HardhatUserConfig = { // Read about Devnet options here: https://0xSpaceShard.github.io/starknet-devnet/docs/guide/run // // *Account predeployment* - // "--seed", - // "42", + "--seed", + "42" // "--accounts", // "1", // "--initial-balance", diff --git a/package-lock.json b/package-lock.json index 0e8d4ff..dcda927 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,11 +19,11 @@ "@types/chai": "^4.2.22", "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", - "@typescript-eslint/eslint-plugin": "^5.8.1", - "@typescript-eslint/parser": "^5.8.1", + "@typescript-eslint/eslint-plugin": "^5.60.0", + "@typescript-eslint/parser": "^5.60.0", "chai": "^4.3.4", "dotenv": "^16.0.1", - "eslint": "^8.5.0", + "eslint": "^8.43.0", "ethers": "^5.4.6", "prettier-eslint-cli": "^7.0.0", "ts-node": "^10.4.0", @@ -102,14 +102,14 @@ } }, "node_modules/@eslint/eslintrc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.2.tgz", - "integrity": "sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.3.tgz", + "integrity": "sha512-+5gy6OQfk+xx3q0d6jGZZC3f3KzAkXc/IanVxd1is/VIIziRqqt3ongQz0FiTUXqTk0c7aDB3OaFuKnuSoJicQ==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.5.1", + "espree": "^9.5.2", "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", @@ -125,9 +125,9 @@ } }, "node_modules/@eslint/js": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.39.0.tgz", - "integrity": "sha512-kf9RB0Fg7NZfap83B3QOqOGg9QmD9yBudqQXzzOtn3i4y7ZUXe5ONeW34Gwi+TxhH4mvj72R1Zc300KUMa9Bng==", + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.43.0.tgz", + "integrity": "sha512-s2UHCoiXfxMvmfzqoN+vrQ84ahUSYde9qNO1MdxmoEhyHWsfmwOpFlwYV+ePJEVc7gFnATGUi376WowX1N7tFg==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -805,9 +805,9 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", - "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", + "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.1", @@ -2033,21 +2033,21 @@ } }, "node_modules/@types/semver": { - "version": "7.3.13", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz", - "integrity": "sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", + "integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==", "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.59.2.tgz", - "integrity": "sha512-yVrXupeHjRxLDcPKL10sGQ/QlVrA8J5IYOEWVqk0lJaSZP7X5DfnP7Ns3cc74/blmbipQ1htFNVGsHX6wsYm0A==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.60.0.tgz", + "integrity": "sha512-78B+anHLF1TI8Jn/cD0Q00TBYdMgjdOn980JfAVa9yw5sop8nyTfVOQAv6LWywkOGLclDBtv5z3oxN4w7jxyNg==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.4.0", - "@typescript-eslint/scope-manager": "5.59.2", - "@typescript-eslint/type-utils": "5.59.2", - "@typescript-eslint/utils": "5.59.2", + "@typescript-eslint/scope-manager": "5.60.0", + "@typescript-eslint/type-utils": "5.60.0", + "@typescript-eslint/utils": "5.60.0", "debug": "^4.3.4", "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", @@ -2073,14 +2073,14 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.2.tgz", - "integrity": "sha512-uq0sKyw6ao1iFOZZGk9F8Nro/8+gfB5ezl1cA06SrqbgJAt0SRoFhb9pXaHvkrxUpZaoLxt8KlovHNk8Gp6/HQ==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.60.0.tgz", + "integrity": "sha512-jBONcBsDJ9UoTWrARkRRCgDz6wUggmH5RpQVlt7BimSwaTkTjwypGzKORXbR4/2Hqjk9hgwlon2rVQAjWNpkyQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.59.2", - "@typescript-eslint/types": "5.59.2", - "@typescript-eslint/typescript-estree": "5.59.2", + "@typescript-eslint/scope-manager": "5.60.0", + "@typescript-eslint/types": "5.60.0", + "@typescript-eslint/typescript-estree": "5.60.0", "debug": "^4.3.4" }, "engines": { @@ -2100,13 +2100,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.2.tgz", - "integrity": "sha512-dB1v7ROySwQWKqQ8rEWcdbTsFjh2G0vn8KUyvTXdPoyzSL6lLGkiXEV5CvpJsEe9xIdKV+8Zqb7wif2issoOFA==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.60.0.tgz", + "integrity": "sha512-hakuzcxPwXi2ihf9WQu1BbRj1e/Pd8ZZwVTG9kfbxAMZstKz8/9OoexIwnmLzShtsdap5U/CoQGRCWlSuPbYxQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.59.2", - "@typescript-eslint/visitor-keys": "5.59.2" + "@typescript-eslint/types": "5.60.0", + "@typescript-eslint/visitor-keys": "5.60.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2117,13 +2117,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.59.2.tgz", - "integrity": "sha512-b1LS2phBOsEy/T381bxkkywfQXkV1dWda/z0PhnIy3bC5+rQWQDS7fk9CSpcXBccPY27Z6vBEuaPBCKCgYezyQ==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.60.0.tgz", + "integrity": "sha512-X7NsRQddORMYRFH7FWo6sA9Y/zbJ8s1x1RIAtnlj6YprbToTiQnM6vxcMu7iYhdunmoC0rUWlca13D5DVHkK2g==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "5.59.2", - "@typescript-eslint/utils": "5.59.2", + "@typescript-eslint/typescript-estree": "5.60.0", + "@typescript-eslint/utils": "5.60.0", "debug": "^4.3.4", "tsutils": "^3.21.0" }, @@ -2144,9 +2144,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.2.tgz", - "integrity": "sha512-LbJ/HqoVs2XTGq5shkiKaNTuVv5tTejdHgfdjqRUGdYhjW1crm/M7og2jhVskMt8/4wS3T1+PfFvL1K3wqYj4w==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.60.0.tgz", + "integrity": "sha512-ascOuoCpNZBccFVNJRSC6rPq4EmJ2NkuoKnd6LDNyAQmdDnziAtxbCGWCbefG1CNzmDvd05zO36AmB7H8RzKPA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -2157,13 +2157,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.2.tgz", - "integrity": "sha512-+j4SmbwVmZsQ9jEyBMgpuBD0rKwi9RxRpjX71Brr73RsYnEr3Lt5QZ624Bxphp8HUkSKfqGnPJp1kA5nl0Sh7Q==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.60.0.tgz", + "integrity": "sha512-R43thAuwarC99SnvrBmh26tc7F6sPa2B3evkXp/8q954kYL6Ro56AwASYWtEEi+4j09GbiNAHqYwNNZuNlARGQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.59.2", - "@typescript-eslint/visitor-keys": "5.59.2", + "@typescript-eslint/types": "5.60.0", + "@typescript-eslint/visitor-keys": "5.60.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -2184,17 +2184,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.59.2.tgz", - "integrity": "sha512-kSuF6/77TZzyGPhGO4uVp+f0SBoYxCDf+lW3GKhtKru/L8k/Hd7NFQxyWUeY7Z/KGB2C6Fe3yf2vVi4V9TsCSQ==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.60.0.tgz", + "integrity": "sha512-ba51uMqDtfLQ5+xHtwlO84vkdjrqNzOnqrnwbMHMRY8Tqeme8C2Q8Fc7LajfGR+e3/4LoYiWXUM6BpIIbHJ4hQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.59.2", - "@typescript-eslint/types": "5.59.2", - "@typescript-eslint/typescript-estree": "5.59.2", + "@typescript-eslint/scope-manager": "5.60.0", + "@typescript-eslint/types": "5.60.0", + "@typescript-eslint/typescript-estree": "5.60.0", "eslint-scope": "^5.1.1", "semver": "^7.3.7" }, @@ -2210,12 +2210,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.59.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.2.tgz", - "integrity": "sha512-EEpsO8m3RASrKAHI9jpavNv9NlEUebV4qmF1OWxSTtKSFBpC1NCmWazDQHFivRf0O1DV11BA645yrLEVQ0/Lig==", + "version": "5.60.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.60.0.tgz", + "integrity": "sha512-wm9Uz71SbCyhUKgcaPRauBdTegUyY/ZWl8gLwD/i/ybJqscrrdVSFImpvUz16BLPChIeKBK5Fa9s6KDQjsjyWw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.59.2", + "@typescript-eslint/types": "5.60.0", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -3306,16 +3306,16 @@ } }, "node_modules/eslint": { - "version": "8.39.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.39.0.tgz", - "integrity": "sha512-mwiok6cy7KTW7rBpo05k6+p4YVZByLNjAZ/ACB9DRCu4YDRwjXI01tWHp6KAUWelsBetTxKK/2sHB0vdS8Z2Og==", + "version": "8.43.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.43.0.tgz", + "integrity": "sha512-aaCpf2JqqKesMFGgmRPessmVKjcGXqdlAYLLC3THM8t5nBRZRQ+st5WM/hoJXkdioEXLLbXgclUpM0TXo5HX5Q==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.4.0", - "@eslint/eslintrc": "^2.0.2", - "@eslint/js": "8.39.0", - "@humanwhocodes/config-array": "^0.11.8", + "@eslint/eslintrc": "^2.0.3", + "@eslint/js": "8.43.0", + "@humanwhocodes/config-array": "^0.11.10", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "ajv": "^6.10.0", @@ -3325,8 +3325,8 @@ "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", "eslint-scope": "^7.2.0", - "eslint-visitor-keys": "^3.4.0", - "espree": "^9.5.1", + "eslint-visitor-keys": "^3.4.1", + "espree": "^9.5.2", "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -3334,13 +3334,12 @@ "find-up": "^5.0.0", "glob-parent": "^6.0.2", "globals": "^13.19.0", - "grapheme-splitter": "^1.0.4", + "graphemer": "^1.4.0", "ignore": "^5.2.0", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", - "js-sdsl": "^4.1.4", "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", @@ -3376,9 +3375,9 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz", - "integrity": "sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz", + "integrity": "sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -3413,14 +3412,14 @@ } }, "node_modules/espree": { - "version": "9.5.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.1.tgz", - "integrity": "sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==", + "version": "9.5.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz", + "integrity": "sha512-7OASN1Wma5fum5SrNhFMAMJxOUAbhyfQ8dQ//PJaJbNw0URTPWqIghHWt1MmAANKhHZIYOHruW4Kw4ruUWOdGw==", "dev": true, "dependencies": { "acorn": "^8.8.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.0" + "eslint-visitor-keys": "^3.4.1" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -3991,6 +3990,12 @@ "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", "dev": true }, + "node_modules/graphemer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true + }, "node_modules/hardhat": { "version": "2.14.0", "resolved": "https://registry.npmjs.org/hardhat/-/hardhat-2.14.0.tgz", diff --git a/package.json b/package.json index 0983249..14ebd84 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,11 @@ "@types/chai": "^4.2.22", "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", - "@typescript-eslint/eslint-plugin": "^5.8.1", - "@typescript-eslint/parser": "^5.8.1", + "@typescript-eslint/eslint-plugin": "^5.60.0", + "@typescript-eslint/parser": "^5.60.0", "chai": "^4.3.4", "dotenv": "^16.0.1", - "eslint": "^8.5.0", + "eslint": "^8.43.0", "ethers": "^5.4.6", "prettier-eslint-cli": "^7.0.0", "ts-node": "^10.4.0", diff --git a/test/argent-account-test.ts b/test/argent-account-test.ts index 749b965..0ae43c7 100644 --- a/test/argent-account-test.ts +++ b/test/argent-account-test.ts @@ -3,7 +3,7 @@ import hardhat, { starknet } from "hardhat"; import { StarknetContract, StarknetContractFactory } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { expectFeeEstimationStructure, getOZAccount, mint } from "./util"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" +import { HardhatPluginError } from "hardhat/plugins"; describe("Argent account", function () { this.timeout(TIMEOUT); @@ -96,7 +96,8 @@ describe("Argent account", function () { const wrongKey = "0x0123"; await starknet.ArgentAccount.getAccountFromAddress(argentAccountAddress, wrongKey); expect.fail("Should have failed on passing an incorrect private key."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal( "The provided private key is not compatible with the public key stored in the contract." ); @@ -144,7 +145,8 @@ describe("Argent account", function () { { maxFee: estimatedFee.amount / 2n } ); expect.fail("Should have failed earlier"); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.contain("Actual fee exceeded max fee"); } @@ -191,8 +193,9 @@ describe("Argent account", function () { const account = await getArgentAccount(); try { await account.declare(mainContractFactory, { maxFee: 1 }); - } catch (error: any) { - expect(error.message).to.contain("Actual fee exceeded max fee"); + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); + expect(err.message).to.contain("Actual fee exceeded max fee"); } }); diff --git a/test/cairo0-constructor.test.ts b/test/cairo0-constructor.test.ts index 2d491a6..4265f23 100644 --- a/test/cairo0-constructor.test.ts +++ b/test/cairo0-constructor.test.ts @@ -3,7 +3,7 @@ import { starknet } from "hardhat"; import { Account, StarknetContractFactory } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { getOZAccount } from "./util"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" +import { HardhatPluginError } from "hardhat/plugins"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -33,7 +33,8 @@ describe("Starknet", function () { try { await account.deploy(contractFactory); expect.fail("Should have failed on not passing constructor calldata."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("constructor: Expected 1 argument, got 0."); } }); @@ -42,7 +43,8 @@ describe("Starknet", function () { try { await account.deploy(contractWithEmptyConstructorFactory, { dummy_var: 10n }); expect.fail("Should have failed on providing constructor arguments."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("constructor: Expected 0 arguments, got 1."); } }); @@ -61,7 +63,8 @@ describe("Starknet", function () { try { await account.deploy(contractWithoutConstructorFactory, { dummy_var: 10n }); expect.fail("Should have failed on providing constructor arguments."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("No constructor arguments required but 1 provided"); } }); diff --git a/test/devnet-restart.test.ts b/test/devnet-restart.test.ts index 75d014a..1b4667d 100644 --- a/test/devnet-restart.test.ts +++ b/test/devnet-restart.test.ts @@ -4,6 +4,7 @@ import { Account, StarknetContractFactory } from "hardhat/types"; import { TIMEOUT } from "./constants"; import { getOZAccount } from "./util"; +import { HardhatPluginError } from "hardhat/plugins"; describe("Devnet restart", function () { this.timeout(TIMEOUT); @@ -35,8 +36,9 @@ describe("Devnet restart", function () { try { await account.invoke(contract, "increase_balance", { amount1: 10, amount2: 20 }); expect.fail("Should throw"); - } catch (error: any) { - expect(error.message).to.match( + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); + expect(err.message).to.match( /Requested contract address 0x[a-fA-F0-9]+ is not deployed/ ); } diff --git a/test/function-args-test.ts b/test/function-args-test.ts index eb09831..e1466b0 100644 --- a/test/function-args-test.ts +++ b/test/function-args-test.ts @@ -3,7 +3,7 @@ import { starknet } from "hardhat"; import { TIMEOUT } from "./constants"; import { Account, StarknetContract, StarknetContractFactory } from "hardhat/types/runtime"; import { expectFeeEstimationStructure, getOZAccount } from "./util"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" +import { HardhatPluginError } from "hardhat/plugins"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -27,7 +27,8 @@ describe("Starknet", function () { try { await contract.call("sum_array"); expect.fail("Should have failed on passing too few arguments."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("sum_array: Expected 1 argument, got 0."); } }); @@ -36,7 +37,8 @@ describe("Starknet", function () { try { await contract.call("sum_array", { a: [1, 2, 3, 4], b: 4 }); expect.fail("Should have failed on passing extra argument."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("sum_array: Expected 1 argument, got 2."); } }); @@ -50,7 +52,8 @@ describe("Starknet", function () { try { await contract.call("sum_array", { a_len: 4, a: [1, 2, 3, 4] }); expect.fail("Should have failed on passing extra argument."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("sum_array: Expected 1 argument, got 2."); } }); @@ -75,7 +78,8 @@ describe("Starknet", function () { ] }); expect.fail("Should have failed on passing more members than expected."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("\"points\": Expected 2 members, got 3."); } }); @@ -87,7 +91,8 @@ describe("Starknet", function () { points: [{ x: 1, y: 2 }] }); expect.fail("Should have failed on passing less members than expected."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("\"points\": Expected 2 members, got 1."); } }); @@ -99,7 +104,8 @@ describe("Starknet", function () { points: [{ x: 1 }, { x: 3, y: 4, z: 5 }] }); expect.fail("Should have failed on passing less members than expected."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("\"points[0]\": Expected 2 members, got 1."); } }); @@ -114,7 +120,8 @@ describe("Starknet", function () { ] }); expect.fail("Should have failed on passing more members than expected"); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal("\"points[1]\": Expected 2 members, got 3."); } }); @@ -198,7 +205,8 @@ describe("Starknet", function () { nested_tuple_type_alias: [[{ x: 1n, y: 2n }, 3n], 4n, [5n, [{ x: 7n, y: 8n }]]] }); expect.fail("Should have failed on passing too few members."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.eql( "\"nested_tuple_type_alias[2][1]\": Expected 2 members, got 1." ); @@ -215,7 +223,8 @@ describe("Starknet", function () { ] }); expect.fail("Should have failed on passing too few members."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal( "\"nested_tuple_type_alias[2]\": Expected 2 members, got 3." ); @@ -226,7 +235,8 @@ describe("Starknet", function () { it("shouldn't invoke with raw input if not selected", async function () { try { await account.invoke(contract, "increase_balance", ["10", "20"]); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal(OBJECT_EXPECTATION); } }); @@ -234,7 +244,8 @@ describe("Starknet", function () { it("shouldn't estimate fee with raw input if not selected", async function () { try { await account.estimateFee(contract, "increase_balance", ["10", "20"]); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal(OBJECT_EXPECTATION); } }); @@ -244,7 +255,8 @@ describe("Starknet", function () { await contract.call("sum_point_array", [ "can put whatever here since it won't be checked" ]); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal(OBJECT_EXPECTATION); } }); diff --git a/test/oz-account-test.ts b/test/oz-account-test.ts index decdce5..6463f9e 100644 --- a/test/oz-account-test.ts +++ b/test/oz-account-test.ts @@ -9,8 +9,7 @@ import { OZ_ACCOUNT_ADDRESS, OZ_ACCOUNT_PRIVATE_KEY } from "./util"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" - +import { HardhatPluginError } from "hardhat/plugins"; describe("OpenZeppelin account", function () { this.timeout(TIMEOUT); @@ -88,7 +87,8 @@ describe("OpenZeppelin account", function () { try { await starknet.OpenZeppelinAccount.getAccountFromAddress(OZ_ACCOUNT_ADDRESS, "0x0123"); expect.fail("Should have failed on passing an incorrect private key."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal( "The provided private key is not compatible with the public key stored in the contract." ); @@ -113,7 +113,8 @@ describe("OpenZeppelin account", function () { { maxFee: estimatedFee.amount / 2n } ); expect.fail("Should have failed earlier"); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.contain("Actual fee exceeded max fee"); } @@ -161,8 +162,9 @@ describe("OpenZeppelin account", function () { try { await account.declare(mainContractFactory, { maxFee: 1 }); expect.fail("Should have failed on the previous line"); - } catch (error: any) { - expect(error.message).to.contain("Actual fee exceeded max fee"); + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); + expect(err.message).to.contain("Actual fee exceeded max fee"); } }); diff --git a/test/path-test.ts b/test/path-test.ts index 82b16b2..216b307 100644 --- a/test/path-test.ts +++ b/test/path-test.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import { starknet } from "hardhat"; import { TIMEOUT } from "./constants"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" +import { HardhatPluginError } from "hardhat/plugins"; const AMBIGUOUS_ERR_MSG = "More than one file was found because the path provided is ambiguous, please specify a relative path"; @@ -29,7 +29,8 @@ describe("getContractFactory", function () { try { await starknet.getContractFactory("util"); expect.fail("Should have failed"); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal(AMBIGUOUS_ERR_MSG); } @@ -41,7 +42,8 @@ describe("getContractFactory", function () { try { await starknet.getContractFactory("util.cairo"); expect.fail("Should have failed"); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal(AMBIGUOUS_ERR_MSG); } diff --git a/test/postman.test.ts b/test/postman.test.ts index 3d37ad7..8d8fd12 100644 --- a/test/postman.test.ts +++ b/test/postman.test.ts @@ -16,6 +16,8 @@ import { OK_TX_STATUSES } from "./util"; +import { HardhatPluginError } from "hardhat/plugins"; + /** * Follows the example at https://www.cairo-lang.org/docs/hello_starknet/l1l2.html * Shows the communication between an L2 contract defined in l1l2.cairo @@ -227,8 +229,9 @@ describe("Postman", function () { user }); expect.fail("Should have failed on the previous line"); - } catch (error: any) { - expect(error.message).to.contain( + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); + expect(err.message).to.contain( "Cannot estimate message fee on \"withdraw\" - not an @l1_handler" ); } diff --git a/test/sample-test.ts b/test/sample-test.ts index df3601d..9457346 100644 --- a/test/sample-test.ts +++ b/test/sample-test.ts @@ -9,8 +9,7 @@ import { expectAddressEquality, getOZAccount } from "./util"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" - +import { HardhatPluginError } from "hardhat/plugins"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -76,7 +75,8 @@ describe("Starknet", function () { { maxFee: MAX_FEE, overhead: 2 } ); expect.fail("Should have failed on invoking using options with maxFee and overhead."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.deep.contain("maxFee and overhead cannot be specified together"); } }); @@ -179,7 +179,8 @@ describe("Starknet", function () { { maxFee: MAX_FEE } ); expect.fail("Should have failed on invoking with an odd number."); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.deep.contain("Transaction rejected. Error message:"); expect(err.message).to.deep.contain("An ASSERT_EQ instruction failed: 1 != 0."); } @@ -192,7 +193,8 @@ describe("Starknet", function () { try { await account.deploy(contractFactory, { initial_balance: 0 }, { salt }); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.include("CONTRACT_ADDRESS_UNAVAILABLE"); expect(err.message).to.include( `Requested contract address ${contract.address} is unavailable for deployment` diff --git a/test/wallet-test.ts b/test/wallet-test.ts index edd01f5..bf8ef58 100644 --- a/test/wallet-test.ts +++ b/test/wallet-test.ts @@ -3,7 +3,7 @@ import { starknet } from "hardhat"; import { StarknetContract, StarknetContractFactory, Wallet } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { expectFeeEstimationStructure, getOZAccount } from "./util"; -import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-plugin-error" +import { HardhatPluginError } from "hardhat/plugins"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -30,7 +30,8 @@ describe("Starknet", function () { expect.fail( "Should have failed on passing a wallet not configured in 'hardhat.config' file." ); - } catch (err: StarknetPluginError) { + } catch (err) { + expect(err).to.be.instanceOf(HardhatPluginError); expect(err.message).to.equal( "Invalid wallet name provided: invalidWallet.\nValid wallets: OpenZeppelin" ); From bcbbd150db34ef988c93ba80892178f581d5e00a Mon Sep 17 00:00:00 2001 From: notV4l Date: Wed, 28 Jun 2023 15:46:42 +0200 Subject: [PATCH 4/6] fix: use StarknetPluginError instead of HardhatPluginError --- .../{events1.cairo => events.cairo} | 0 test/argent-account-test.ts | 19 +++++---- test/cairo0-constructor.test.ts | 11 ++--- test/cairo1/decode-events.test.ts | 2 +- test/devnet-restart.test.ts | 5 +-- test/function-args-test.ts | 41 +++++++------------ test/oz-account-test.ts | 13 +++--- test/path-test.ts | 8 ++-- test/postman.test.ts | 7 ++-- test/sample-test.ts | 13 +++--- test/util.ts | 18 +++++++- test/wallet-test.ts | 6 +-- 12 files changed, 73 insertions(+), 70 deletions(-) rename cairo1-contracts/{events1.cairo => events.cairo} (100%) diff --git a/cairo1-contracts/events1.cairo b/cairo1-contracts/events.cairo similarity index 100% rename from cairo1-contracts/events1.cairo rename to cairo1-contracts/events.cairo diff --git a/test/argent-account-test.ts b/test/argent-account-test.ts index 0ae43c7..61d153a 100644 --- a/test/argent-account-test.ts +++ b/test/argent-account-test.ts @@ -2,8 +2,13 @@ import { expect } from "chai"; import hardhat, { starknet } from "hardhat"; import { StarknetContract, StarknetContractFactory } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; -import { expectFeeEstimationStructure, getOZAccount, mint } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; +import { + expectFeeEstimationStructure, + getOZAccount, + mint, + expectStarknetPluginErrorContain, + expectStarknetPluginErrorEqual +} from "./util"; describe("Argent account", function () { this.timeout(TIMEOUT); @@ -97,8 +102,8 @@ describe("Argent account", function () { await starknet.ArgentAccount.getAccountFromAddress(argentAccountAddress, wrongKey); expect.fail("Should have failed on passing an incorrect private key."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal( + expectStarknetPluginErrorEqual( + err, "The provided private key is not compatible with the public key stored in the contract." ); } @@ -146,8 +151,7 @@ describe("Argent account", function () { ); expect.fail("Should have failed earlier"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.contain("Actual fee exceeded max fee"); + expectStarknetPluginErrorContain(err, "Actual fee exceeded max fee"); } await account.invoke( @@ -194,8 +198,7 @@ describe("Argent account", function () { try { await account.declare(mainContractFactory, { maxFee: 1 }); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.contain("Actual fee exceeded max fee"); + expectStarknetPluginErrorContain(err, "Actual fee exceeded max fee"); } }); diff --git a/test/cairo0-constructor.test.ts b/test/cairo0-constructor.test.ts index 4265f23..8e60423 100644 --- a/test/cairo0-constructor.test.ts +++ b/test/cairo0-constructor.test.ts @@ -3,7 +3,7 @@ import { starknet } from "hardhat"; import { Account, StarknetContractFactory } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { getOZAccount } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; +import { expectStarknetPluginErrorEqual } from "./util"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -34,8 +34,7 @@ describe("Starknet", function () { await account.deploy(contractFactory); expect.fail("Should have failed on not passing constructor calldata."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("constructor: Expected 1 argument, got 0."); + expectStarknetPluginErrorEqual(err, "constructor: Expected 1 argument, got 0."); } }); @@ -44,8 +43,7 @@ describe("Starknet", function () { await account.deploy(contractWithEmptyConstructorFactory, { dummy_var: 10n }); expect.fail("Should have failed on providing constructor arguments."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("constructor: Expected 0 arguments, got 1."); + expectStarknetPluginErrorEqual(err, "constructor: Expected 0 arguments, got 1."); } }); @@ -64,8 +62,7 @@ describe("Starknet", function () { await account.deploy(contractWithoutConstructorFactory, { dummy_var: 10n }); expect.fail("Should have failed on providing constructor arguments."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("No constructor arguments required but 1 provided"); + expectStarknetPluginErrorEqual(err, "No constructor arguments required but 1 provided"); } }); }); diff --git a/test/cairo1/decode-events.test.ts b/test/cairo1/decode-events.test.ts index ea97204..9e0429f 100644 --- a/test/cairo1/decode-events.test.ts +++ b/test/cairo1/decode-events.test.ts @@ -15,7 +15,7 @@ describe("Cairo 1 - Events", function () { before(async function () { // assumes events.cairo has been compiled account = await getOZAccount(); - contractFactory = await starknet.getContractFactory("events1"); + contractFactory = await starknet.getContractFactory("cairo1-contracts/events"); await account.declare(contractFactory); contract = await account.deploy(contractFactory, { initial_balance: 0n diff --git a/test/devnet-restart.test.ts b/test/devnet-restart.test.ts index 1b4667d..5f2a028 100644 --- a/test/devnet-restart.test.ts +++ b/test/devnet-restart.test.ts @@ -3,8 +3,7 @@ import { starknet } from "hardhat"; import { Account, StarknetContractFactory } from "hardhat/types"; import { TIMEOUT } from "./constants"; -import { getOZAccount } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; +import { getOZAccount, expectStarknetPluginError } from "./util"; describe("Devnet restart", function () { this.timeout(TIMEOUT); @@ -37,7 +36,7 @@ describe("Devnet restart", function () { await account.invoke(contract, "increase_balance", { amount1: 10, amount2: 20 }); expect.fail("Should throw"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); + expectStarknetPluginError(err); expect(err.message).to.match( /Requested contract address 0x[a-fA-F0-9]+ is not deployed/ ); diff --git a/test/function-args-test.ts b/test/function-args-test.ts index e1466b0..2b7c363 100644 --- a/test/function-args-test.ts +++ b/test/function-args-test.ts @@ -2,8 +2,7 @@ import { expect } from "chai"; import { starknet } from "hardhat"; import { TIMEOUT } from "./constants"; import { Account, StarknetContract, StarknetContractFactory } from "hardhat/types/runtime"; -import { expectFeeEstimationStructure, getOZAccount } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; +import { expectFeeEstimationStructure, getOZAccount, expectStarknetPluginErrorEqual } from "./util"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -28,8 +27,7 @@ describe("Starknet", function () { await contract.call("sum_array"); expect.fail("Should have failed on passing too few arguments."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("sum_array: Expected 1 argument, got 0."); + expectStarknetPluginErrorEqual(err, "sum_array: Expected 1 argument, got 0."); } }); @@ -38,8 +36,7 @@ describe("Starknet", function () { await contract.call("sum_array", { a: [1, 2, 3, 4], b: 4 }); expect.fail("Should have failed on passing extra argument."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("sum_array: Expected 1 argument, got 2."); + expectStarknetPluginErrorEqual(err, "sum_array: Expected 1 argument, got 2."); } }); @@ -53,8 +50,7 @@ describe("Starknet", function () { await contract.call("sum_array", { a_len: 4, a: [1, 2, 3, 4] }); expect.fail("Should have failed on passing extra argument."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("sum_array: Expected 1 argument, got 2."); + expectStarknetPluginErrorEqual(err, "sum_array: Expected 1 argument, got 2."); } }); @@ -79,8 +75,7 @@ describe("Starknet", function () { }); expect.fail("Should have failed on passing more members than expected."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("\"points\": Expected 2 members, got 3."); + expectStarknetPluginErrorEqual(err, "\"points\": Expected 2 members, got 3."); } }); @@ -92,8 +87,7 @@ describe("Starknet", function () { }); expect.fail("Should have failed on passing less members than expected."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("\"points\": Expected 2 members, got 1."); + expectStarknetPluginErrorEqual(err, "\"points\": Expected 2 members, got 1."); } }); @@ -105,8 +99,7 @@ describe("Starknet", function () { }); expect.fail("Should have failed on passing less members than expected."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("\"points[0]\": Expected 2 members, got 1."); + expectStarknetPluginErrorEqual(err, "\"points[0]\": Expected 2 members, got 1."); } }); @@ -121,8 +114,7 @@ describe("Starknet", function () { }); expect.fail("Should have failed on passing more members than expected"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal("\"points[1]\": Expected 2 members, got 3."); + expectStarknetPluginErrorEqual(err, "\"points[1]\": Expected 2 members, got 3."); } }); @@ -206,8 +198,8 @@ describe("Starknet", function () { }); expect.fail("Should have failed on passing too few members."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.eql( + expectStarknetPluginErrorEqual( + err, "\"nested_tuple_type_alias[2][1]\": Expected 2 members, got 1." ); } @@ -224,8 +216,8 @@ describe("Starknet", function () { }); expect.fail("Should have failed on passing too few members."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal( + expectStarknetPluginErrorEqual( + err, "\"nested_tuple_type_alias[2]\": Expected 2 members, got 3." ); } @@ -236,8 +228,7 @@ describe("Starknet", function () { try { await account.invoke(contract, "increase_balance", ["10", "20"]); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal(OBJECT_EXPECTATION); + expectStarknetPluginErrorEqual(err, OBJECT_EXPECTATION); } }); @@ -245,8 +236,7 @@ describe("Starknet", function () { try { await account.estimateFee(contract, "increase_balance", ["10", "20"]); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal(OBJECT_EXPECTATION); + expectStarknetPluginErrorEqual(err, OBJECT_EXPECTATION); } }); @@ -256,8 +246,7 @@ describe("Starknet", function () { "can put whatever here since it won't be checked" ]); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal(OBJECT_EXPECTATION); + expectStarknetPluginErrorEqual(err, OBJECT_EXPECTATION); } }); diff --git a/test/oz-account-test.ts b/test/oz-account-test.ts index 6463f9e..0f2ae6d 100644 --- a/test/oz-account-test.ts +++ b/test/oz-account-test.ts @@ -4,12 +4,13 @@ import { StarknetContract, StarknetContractFactory } from "hardhat/types/runtime import { TIMEOUT } from "./constants"; import { expectFeeEstimationStructure, + expectStarknetPluginErrorEqual, + expectStarknetPluginErrorContain, getOZAccount, mint, OZ_ACCOUNT_ADDRESS, OZ_ACCOUNT_PRIVATE_KEY } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; describe("OpenZeppelin account", function () { this.timeout(TIMEOUT); @@ -88,8 +89,8 @@ describe("OpenZeppelin account", function () { await starknet.OpenZeppelinAccount.getAccountFromAddress(OZ_ACCOUNT_ADDRESS, "0x0123"); expect.fail("Should have failed on passing an incorrect private key."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal( + expectStarknetPluginErrorEqual( + err, "The provided private key is not compatible with the public key stored in the contract." ); } @@ -114,8 +115,7 @@ describe("OpenZeppelin account", function () { ); expect.fail("Should have failed earlier"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.contain("Actual fee exceeded max fee"); + expectStarknetPluginErrorContain(err, "Actual fee exceeded max fee"); } await account.invoke( @@ -163,8 +163,7 @@ describe("OpenZeppelin account", function () { await account.declare(mainContractFactory, { maxFee: 1 }); expect.fail("Should have failed on the previous line"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.contain("Actual fee exceeded max fee"); + expectStarknetPluginErrorContain(err, "Actual fee exceeded max fee"); } }); diff --git a/test/path-test.ts b/test/path-test.ts index 216b307..45e6878 100644 --- a/test/path-test.ts +++ b/test/path-test.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import { starknet } from "hardhat"; import { TIMEOUT } from "./constants"; -import { HardhatPluginError } from "hardhat/plugins"; +import { expectStarknetPluginErrorEqual } from "./util"; const AMBIGUOUS_ERR_MSG = "More than one file was found because the path provided is ambiguous, please specify a relative path"; @@ -30,8 +30,7 @@ describe("getContractFactory", function () { await starknet.getContractFactory("util"); expect.fail("Should have failed"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal(AMBIGUOUS_ERR_MSG); + expectStarknetPluginErrorEqual(err, AMBIGUOUS_ERR_MSG); } await starknet.getContractFactory("contracts/util"); @@ -43,8 +42,7 @@ describe("getContractFactory", function () { await starknet.getContractFactory("util.cairo"); expect.fail("Should have failed"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal(AMBIGUOUS_ERR_MSG); + expectStarknetPluginErrorEqual(err, AMBIGUOUS_ERR_MSG); } await starknet.getContractFactory("contracts/util.cairo"); diff --git a/test/postman.test.ts b/test/postman.test.ts index 8d8fd12..cd553bc 100644 --- a/test/postman.test.ts +++ b/test/postman.test.ts @@ -12,12 +12,11 @@ import { TIMEOUT } from "./constants"; import { expectAddressEquality, expectFeeEstimationStructure, + expectStarknetPluginErrorContain, getOZAccount, OK_TX_STATUSES } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; - /** * Follows the example at https://www.cairo-lang.org/docs/hello_starknet/l1l2.html * Shows the communication between an L2 contract defined in l1l2.cairo @@ -230,8 +229,8 @@ describe("Postman", function () { }); expect.fail("Should have failed on the previous line"); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.contain( + expectStarknetPluginErrorContain( + err, "Cannot estimate message fee on \"withdraw\" - not an @l1_handler" ); } diff --git a/test/sample-test.ts b/test/sample-test.ts index 9457346..aa8e0f6 100644 --- a/test/sample-test.ts +++ b/test/sample-test.ts @@ -5,11 +5,12 @@ import { TIMEOUT } from "./constants"; import { BigNumber } from "ethers"; import { expectFeeEstimationStructure, + expectStarknetPluginError, + expectStarknetPluginErrorContain, OK_TX_STATUSES, expectAddressEquality, getOZAccount } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -76,8 +77,10 @@ describe("Starknet", function () { ); expect.fail("Should have failed on invoking using options with maxFee and overhead."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.deep.contain("maxFee and overhead cannot be specified together"); + expectStarknetPluginErrorContain( + err, + "maxFee and overhead cannot be specified together" + ); } }); @@ -180,7 +183,7 @@ describe("Starknet", function () { ); expect.fail("Should have failed on invoking with an odd number."); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); + expectStarknetPluginError(err); expect(err.message).to.deep.contain("Transaction rejected. Error message:"); expect(err.message).to.deep.contain("An ASSERT_EQ instruction failed: 1 != 0."); } @@ -194,7 +197,7 @@ describe("Starknet", function () { try { await account.deploy(contractFactory, { initial_balance: 0 }, { salt }); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); + expectStarknetPluginError(err); expect(err.message).to.include("CONTRACT_ADDRESS_UNAVAILABLE"); expect(err.message).to.include( `Requested contract address ${contract.address} is unavailable for deployment` diff --git a/test/util.ts b/test/util.ts index 15ab67d..ee38fbc 100644 --- a/test/util.ts +++ b/test/util.ts @@ -3,13 +3,15 @@ import { PredeployedAccount } from "@shardlabs/starknet-hardhat-plugin/dist/src/ import axios from "axios"; import { expect } from "chai"; import { starknet } from "hardhat"; +import { FeeEstimation } from "@shardlabs/starknet-hardhat-plugin/dist/src/starknet-types"; +import { StarknetPluginError } from "@shardlabs/starknet-hardhat-plugin"; export const OK_TX_STATUSES = ["PENDING", "ACCEPTED_ON_L2", "ACCEPTED_ON_L1"]; export const OZ_ACCOUNT_ADDRESS = ensureEnvVar("OZ_ACCOUNT_ADDRESS"); export const OZ_ACCOUNT_PRIVATE_KEY = ensureEnvVar("OZ_ACCOUNT_PRIVATE_KEY"); -export function expectFeeEstimationStructure(fee: any) { +export function expectFeeEstimationStructure(fee: FeeEstimation) { console.log("Estimated fee:", fee); expect(fee).to.haveOwnProperty("amount"); expect(typeof fee.amount).to.equal("bigint"); @@ -18,6 +20,20 @@ export function expectFeeEstimationStructure(fee: any) { expect(typeof fee.gas_usage).to.equal("bigint"); } +export function expectStarknetPluginError(err: Error) { + expect(err).to.be.instanceOf(StarknetPluginError); +} + +export function expectStarknetPluginErrorEqual(err: Error, expectedMessage: string) { + expect(err).to.be.instanceOf(StarknetPluginError); + expect(err.message).to.equal(expectedMessage); +} + +export function expectStarknetPluginErrorContain(err: Error, expectedMessage: string) { + expect(err).to.be.instanceOf(StarknetPluginError); + expect(err.message).to.equal(expectedMessage); +} + export function ensureEnvVar(varName: string): string { if (!process.env[varName]) { throw new Error(`Env var ${varName} not set or empty`); diff --git a/test/wallet-test.ts b/test/wallet-test.ts index bf8ef58..19531a0 100644 --- a/test/wallet-test.ts +++ b/test/wallet-test.ts @@ -3,7 +3,7 @@ import { starknet } from "hardhat"; import { StarknetContract, StarknetContractFactory, Wallet } from "hardhat/types/runtime"; import { TIMEOUT } from "./constants"; import { expectFeeEstimationStructure, getOZAccount } from "./util"; -import { HardhatPluginError } from "hardhat/plugins"; +import { expectStarknetPluginErrorEqual } from "./util"; describe("Starknet", function () { this.timeout(TIMEOUT); @@ -31,8 +31,8 @@ describe("Starknet", function () { "Should have failed on passing a wallet not configured in 'hardhat.config' file." ); } catch (err) { - expect(err).to.be.instanceOf(HardhatPluginError); - expect(err.message).to.equal( + expectStarknetPluginErrorEqual( + err, "Invalid wallet name provided: invalidWallet.\nValid wallets: OpenZeppelin" ); } From 1b1b42f1401f1ca142faf52ec5c75a53ebff0009 Mon Sep 17 00:00:00 2001 From: notV4l Date: Wed, 28 Jun 2023 16:51:14 +0200 Subject: [PATCH 5/6] fix: copy pasta smol brain error --- test/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/util.ts b/test/util.ts index ee38fbc..a249d2d 100644 --- a/test/util.ts +++ b/test/util.ts @@ -31,7 +31,7 @@ export function expectStarknetPluginErrorEqual(err: Error, expectedMessage: stri export function expectStarknetPluginErrorContain(err: Error, expectedMessage: string) { expect(err).to.be.instanceOf(StarknetPluginError); - expect(err.message).to.equal(expectedMessage); + expect(err.message).to.contain(expectedMessage); } export function ensureEnvVar(varName: string): string { From d393a7fc53e15113264cdf801ad3ae18f1a397cd Mon Sep 17 00:00:00 2001 From: notV4l Date: Wed, 28 Jun 2023 18:18:57 +0200 Subject: [PATCH 6/6] fix: error type --- test/devnet-restart.test.ts | 4 ++-- test/sample-test.ts | 12 ++++++------ test/util.ts | 15 ++++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/test/devnet-restart.test.ts b/test/devnet-restart.test.ts index 5f2a028..d614a87 100644 --- a/test/devnet-restart.test.ts +++ b/test/devnet-restart.test.ts @@ -36,8 +36,8 @@ describe("Devnet restart", function () { await account.invoke(contract, "increase_balance", { amount1: 10, amount2: 20 }); expect.fail("Should throw"); } catch (err) { - expectStarknetPluginError(err); - expect(err.message).to.match( + const error = expectStarknetPluginError(err); + expect(error.message).to.match( /Requested contract address 0x[a-fA-F0-9]+ is not deployed/ ); } diff --git a/test/sample-test.ts b/test/sample-test.ts index aa8e0f6..6a3decd 100644 --- a/test/sample-test.ts +++ b/test/sample-test.ts @@ -183,9 +183,9 @@ describe("Starknet", function () { ); expect.fail("Should have failed on invoking with an odd number."); } catch (err) { - expectStarknetPluginError(err); - expect(err.message).to.deep.contain("Transaction rejected. Error message:"); - expect(err.message).to.deep.contain("An ASSERT_EQ instruction failed: 1 != 0."); + const error = expectStarknetPluginError(err); + expect(error.message).to.deep.contain("Transaction rejected. Error message:"); + expect(error.message).to.deep.contain("An ASSERT_EQ instruction failed: 1 != 0."); } }); @@ -197,9 +197,9 @@ describe("Starknet", function () { try { await account.deploy(contractFactory, { initial_balance: 0 }, { salt }); } catch (err) { - expectStarknetPluginError(err); - expect(err.message).to.include("CONTRACT_ADDRESS_UNAVAILABLE"); - expect(err.message).to.include( + const error = expectStarknetPluginError(err); + expect(error.message).to.include("CONTRACT_ADDRESS_UNAVAILABLE"); + expect(error.message).to.include( `Requested contract address ${contract.address} is unavailable for deployment` ); } diff --git a/test/util.ts b/test/util.ts index a249d2d..71df897 100644 --- a/test/util.ts +++ b/test/util.ts @@ -20,18 +20,19 @@ export function expectFeeEstimationStructure(fee: FeeEstimation) { expect(typeof fee.gas_usage).to.equal("bigint"); } -export function expectStarknetPluginError(err: Error) { +export function expectStarknetPluginError(err: unknown): StarknetPluginError { expect(err).to.be.instanceOf(StarknetPluginError); + return err; } -export function expectStarknetPluginErrorEqual(err: Error, expectedMessage: string) { - expect(err).to.be.instanceOf(StarknetPluginError); - expect(err.message).to.equal(expectedMessage); +export function expectStarknetPluginErrorEqual(err: unknown, expectedMessage: string) { + const error = expectStarknetPluginError(err); + expect(error.message).to.equal(expectedMessage); } -export function expectStarknetPluginErrorContain(err: Error, expectedMessage: string) { - expect(err).to.be.instanceOf(StarknetPluginError); - expect(err.message).to.contain(expectedMessage); +export function expectStarknetPluginErrorContain(err: unknown, expectedMessage: string) { + const error = expectStarknetPluginError(err); + expect(error.message).to.contain(expectedMessage); } export function ensureEnvVar(varName: string): string {