From c6fe5ca3e3ab62e60290a0e9fbf1df07661db86c Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 8 Nov 2022 17:34:04 +0300 Subject: [PATCH 01/41] WIP: Replace bash test to TS using shelljs --- package-lock.json | 88 +++++++++++++++++-- package.json | 2 + scripts/test.sh | 7 +- .../with-account-compilation-option/check.ts | 14 +++ test/general-tests/account-test/check.ts | 19 ++++ .../with-active-venv/check.ts | 4 + test/recompilation-tests/hardhat-run/check.ts | 10 +++ test/utils/utils.ts | 20 +++++ test/venv-tests/with-venv/check.ts | 8 ++ 9 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 test/configuration-tests/with-account-compilation-option/check.ts create mode 100644 test/general-tests/account-test/check.ts create mode 100644 test/integrated-devnet-tests/with-active-venv/check.ts create mode 100644 test/recompilation-tests/hardhat-run/check.ts create mode 100644 test/utils/utils.ts create mode 100644 test/venv-tests/with-venv/check.ts diff --git a/package-lock.json b/package-lock.json index b9d5dd8b..650d1d3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "exit-hook": "2.2.1", "form-data": "^4.0.0", "glob": "^7.2.0", + "shelljs": "^0.8.5", "starknet": "^3.15.0" }, "devDependencies": { @@ -22,6 +23,7 @@ "@types/glob": "^7.2.0", "@types/mocha": "^9.0.0", "@types/node": "^16.11.26", + "@types/shelljs": "^0.8.11", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", "chai": "^4.3.4", @@ -1058,6 +1060,16 @@ "@types/node": "*" } }, + "node_modules/@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "dev": true, + "dependencies": { + "@types/glob": "*", + "@types/node": "*" + } + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.19.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.19.0.tgz", @@ -3527,6 +3539,14 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/io-ts": { "version": "1.10.4", "resolved": "https://registry.npmjs.org/io-ts/-/io-ts-1.10.4.tgz", @@ -4662,8 +4682,7 @@ "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "node_modules/path-type": { "version": "4.0.0", @@ -5266,6 +5285,17 @@ "node": ">=8.10.0" } }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -5312,7 +5342,6 @@ "version": "1.17.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", - "dev": true, "dependencies": { "path-parse": "^1.0.6" }, @@ -5572,6 +5601,22 @@ "node": ">=8" } }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -7094,6 +7139,16 @@ "@types/node": "*" } }, + "@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "dev": true, + "requires": { + "@types/glob": "*", + "@types/node": "*" + } + }, "@typescript-eslint/eslint-plugin": { "version": "5.19.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.19.0.tgz", @@ -8955,6 +9010,11 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, + "interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + }, "io-ts": { "version": "1.10.4", "resolved": "https://registry.npmjs.org/io-ts/-/io-ts-1.10.4.tgz", @@ -9831,8 +9891,7 @@ "path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "path-type": { "version": "4.0.0", @@ -10283,6 +10342,14 @@ "picomatch": "^2.2.1" } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "requires": { + "resolve": "^1.1.6" + } + }, "regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -10317,7 +10384,6 @@ "version": "1.17.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", - "dev": true, "requires": { "path-parse": "^1.0.6" } @@ -10511,6 +10577,16 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, + "shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, "side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", diff --git a/package.json b/package.json index 4fc3dcb6..8a1e4701 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "exit-hook": "2.2.1", "form-data": "^4.0.0", "glob": "^7.2.0", + "shelljs": "^0.8.5", "starknet": "^3.15.0" }, "peerDependencies": { @@ -50,6 +51,7 @@ "@types/glob": "^7.2.0", "@types/mocha": "^9.0.0", "@types/node": "^16.11.26", + "@types/shelljs": "^0.8.11", "@typescript-eslint/eslint-plugin": "^5.8.1", "@typescript-eslint/parser": "^5.8.1", "chai": "^4.3.4", diff --git a/scripts/test.sh b/scripts/test.sh index ac0c863a..92e6f6ec 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -69,7 +69,12 @@ function iterate_dir() { [ "$network" == "devnet" ] && DEVNET_PID=$(../scripts/run-devnet.sh) - NETWORK="$network" "$test_case/check.sh" && success=$((success + 1)) || echo "Test failed!" + # check if test_case/check.ts exists + if [ -f "$test_case/check.ts" ]; then + # run the test + NETWORK="$network" npx hardhat test "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" + fi + # NETWORK="$network" "$test_case/check.sh" && success=$((success + 1)) || echo "Test failed!" rm -rf starknet-artifacts git checkout --force diff --git a/test/configuration-tests/with-account-compilation-option/check.ts b/test/configuration-tests/with-account-compilation-option/check.ts new file mode 100644 index 00000000..7be20706 --- /dev/null +++ b/test/configuration-tests/with-account-compilation-option/check.ts @@ -0,0 +1,14 @@ +import shell from "shelljs"; +import { contains, exec } from "../../utils/utils"; + +const CONTRACT_NAME = "dummy_account.cairo"; +const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); + +const EXPECTED = "Use the --account-contract flag to compile an account contract."; + +shell.echo("Testing rejection of compilation without the account flag"); +shell.cp(CONTRACT_NAME, CONTRACT_PATH); +contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); +shell.echo("Success"); + +exec(`npx hardhat starknet-compile ${CONTRACT_PATH} --account-contract`); diff --git a/test/general-tests/account-test/check.ts b/test/general-tests/account-test/check.ts new file mode 100644 index 00000000..ba81c1f9 --- /dev/null +++ b/test/general-tests/account-test/check.ts @@ -0,0 +1,19 @@ +import { exec } from "../../utils/utils"; +import shell from "shelljs"; + +exec("npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo"); +exec("npx hardhat test --no-compile test/oz-account-test.ts"); + +if (process.env.NETWORK == "devnet") { + exec("npx hardhat test --no-compile scripts/deploy-argent.ts"); + + shell.env.TOKEN_ADDRESS = "0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488"; + shell.env.SENDER_ADDRESS = process.env.OZ_ACCOUNT_ADDRESS; + shell.env.SENDER_PRIVATE_KEY = process.env.OZ_ACCOUNT_PRIVATE_KEY; + shell.env.SENDER_IMPLEMENTATION = "OpenZeppelin"; + shell.env.RECIPIENT_ADDRESS = process.env.ARGENT_ACCOUNT_ADDRESS; + shell.env.TRANSFER_AMOUNT = "0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488"; + exec("npx hardhat test --no-compile scripts/transfer-funds.ts"); +} + +exec("npx hardhat test --no-compile test/argent-account-test.ts"); diff --git a/test/integrated-devnet-tests/with-active-venv/check.ts b/test/integrated-devnet-tests/with-active-venv/check.ts new file mode 100644 index 00000000..8594a21e --- /dev/null +++ b/test/integrated-devnet-tests/with-active-venv/check.ts @@ -0,0 +1,4 @@ +// import { exec } from "../../utils/utils"; + +// exec("npx hardhat starknet-compile contracts/contract.cairo"); +// exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); diff --git a/test/recompilation-tests/hardhat-run/check.ts b/test/recompilation-tests/hardhat-run/check.ts new file mode 100644 index 00000000..b10c79c6 --- /dev/null +++ b/test/recompilation-tests/hardhat-run/check.ts @@ -0,0 +1,10 @@ +import shell from "shelljs"; +import { exec } from "../../utils/utils"; + +shell.echo("should recompile with deleted artifact on hardhat run"); +shell.rm("-rf", "starknet-artifacts/contracts/contract.cairo"); +exec("npx hardhat run scripts/deploy.ts"); + +shell.echo("should recompile with cache file deleted on hardhat run"); +shell.rm("-rf", "cache/cairo-files-cache.json"); +exec("npx hardhat run scripts/deploy.ts"); diff --git a/test/utils/utils.ts b/test/utils/utils.ts new file mode 100644 index 00000000..6afb6597 --- /dev/null +++ b/test/utils/utils.ts @@ -0,0 +1,20 @@ +import shell from "shelljs"; + +export function exec(cmd: string) { + const result = shell.exec(cmd); + if (result.code !== 0) { + shell.exit(1); + } + + return result; +} + +export function contains(cmd: string, pattern: string) { + const res = shell.exec(cmd, { silent: true }).stderr; // Also needed for stdout + if (!res.includes(pattern)) { + console.error("Pattern not in input"); + console.error("Pattern:", pattern); + console.error("Input:", res); + shell.exit(1); + } +} diff --git a/test/venv-tests/with-venv/check.ts b/test/venv-tests/with-venv/check.ts new file mode 100644 index 00000000..f9b86a41 --- /dev/null +++ b/test/venv-tests/with-venv/check.ts @@ -0,0 +1,8 @@ +import { exec } from "../../utils/utils"; + +const INITIAL_VALUE = 10; +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network ${NETWORK} --inputs ${INITIAL_VALUE}`); +exec("npx hardhat test --no-compile test/quick-test.ts"); From b43addae44f3f0fb69799bc2126cde83501b44f1 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 8 Nov 2022 18:39:15 +0300 Subject: [PATCH 02/41] Add no-compile flag to test --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 92e6f6ec..66325d00 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -72,7 +72,7 @@ function iterate_dir() { # check if test_case/check.ts exists if [ -f "$test_case/check.ts" ]; then # run the test - NETWORK="$network" npx hardhat test "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" + NETWORK="$network" npx hardhat --no-compile test "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" fi # NETWORK="$network" "$test_case/check.sh" && success=$((success + 1)) || echo "Test failed!" From 701a9a22c9530ae4f2fb16e8dd44edce5618128d Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 8 Nov 2022 18:43:23 +0300 Subject: [PATCH 03/41] Put no-compile after the task name --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 66325d00..548d86cd 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -72,7 +72,7 @@ function iterate_dir() { # check if test_case/check.ts exists if [ -f "$test_case/check.ts" ]; then # run the test - NETWORK="$network" npx hardhat --no-compile test "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" + NETWORK="$network" npx hardhat test --no-compile "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" fi # NETWORK="$network" "$test_case/check.sh" && success=$((success + 1)) || echo "Test failed!" From 46201c402185b234e861dcd6ac4f0d1b176d6104 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 9 Nov 2022 13:36:45 +0300 Subject: [PATCH 04/41] Update suits for configuration test set --- .../with-account-compilation-option/check.ts | 2 +- .../with-artifacts-path/check.ts | 8 ++++++++ .../with-cairo-version/check.ts | 6 ++++++ .../with-cli-network/check.ts | 9 +++++++++ test/configuration-tests/with-cli-paths/check.ts | 6 ++++++ .../with-deploy-inputs/check.ts | 7 +++++++ .../with-deploy-path/check.ts | 7 +++++++ .../check.ts | 16 ++++++++++++++++ .../with-sources-path/check.ts | 9 +++++++++ test/configuration-tests/with-wait/check.ts | 6 ++++++ 10 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/configuration-tests/with-artifacts-path/check.ts create mode 100644 test/configuration-tests/with-cairo-version/check.ts create mode 100644 test/configuration-tests/with-cli-network/check.ts create mode 100644 test/configuration-tests/with-cli-paths/check.ts create mode 100644 test/configuration-tests/with-deploy-inputs/check.ts create mode 100644 test/configuration-tests/with-deploy-path/check.ts create mode 100644 test/configuration-tests/with-disable-hint-compilation-option/check.ts create mode 100644 test/configuration-tests/with-sources-path/check.ts create mode 100644 test/configuration-tests/with-wait/check.ts diff --git a/test/configuration-tests/with-account-compilation-option/check.ts b/test/configuration-tests/with-account-compilation-option/check.ts index 7be20706..b49d1ff7 100644 --- a/test/configuration-tests/with-account-compilation-option/check.ts +++ b/test/configuration-tests/with-account-compilation-option/check.ts @@ -7,7 +7,7 @@ const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); const EXPECTED = "Use the --account-contract flag to compile an account contract."; shell.echo("Testing rejection of compilation without the account flag"); -shell.cp(CONTRACT_NAME, CONTRACT_PATH); +exec(`cp $(dirname "$0")/${CONTRACT_NAME} ${CONTRACT_PATH}`); contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); shell.echo("Success"); diff --git a/test/configuration-tests/with-artifacts-path/check.ts b/test/configuration-tests/with-artifacts-path/check.ts new file mode 100644 index 00000000..63e520ae --- /dev/null +++ b/test/configuration-tests/with-artifacts-path/check.ts @@ -0,0 +1,8 @@ +import shell from "shelljs"; +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} my-starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +shell.rm("-rf", "my-starknet-artifacts"); diff --git a/test/configuration-tests/with-cairo-version/check.ts b/test/configuration-tests/with-cairo-version/check.ts new file mode 100644 index 00000000..de9f044b --- /dev/null +++ b/test/configuration-tests/with-cairo-version/check.ts @@ -0,0 +1,6 @@ +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo --starknet-network ${NETWORK} --inputs 10`); diff --git a/test/configuration-tests/with-cli-network/check.ts b/test/configuration-tests/with-cli-network/check.ts new file mode 100644 index 00000000..9baad394 --- /dev/null +++ b/test/configuration-tests/with-cli-network/check.ts @@ -0,0 +1,9 @@ +import { exec } from "../../utils/utils"; + +// Test how --starknet-network can be specified through CLI while at the same time +// overriding hardhat.config specification. +// It would be sufficient to run this test just once and not for both alpha and devnet. +// Only tests if --starknet-network is accepted, not if the correct network is targeted. + +exec("npx hardhat run --no-compile scripts/compile-contract.ts"); +exec("npx hardhat test --no-compile --starknet-network devnet test/quick-test.ts"); diff --git a/test/configuration-tests/with-cli-paths/check.ts b/test/configuration-tests/with-cli-paths/check.ts new file mode 100644 index 00000000..255c306c --- /dev/null +++ b/test/configuration-tests/with-cli-paths/check.ts @@ -0,0 +1,6 @@ +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); diff --git a/test/configuration-tests/with-deploy-inputs/check.ts b/test/configuration-tests/with-deploy-inputs/check.ts new file mode 100644 index 00000000..65afebaa --- /dev/null +++ b/test/configuration-tests/with-deploy-inputs/check.ts @@ -0,0 +1,7 @@ +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK}`); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK} --salt 0x10`); diff --git a/test/configuration-tests/with-deploy-path/check.ts b/test/configuration-tests/with-deploy-path/check.ts new file mode 100644 index 00000000..2825959e --- /dev/null +++ b/test/configuration-tests/with-deploy-path/check.ts @@ -0,0 +1,7 @@ +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK}`); +exec(`npx hardhat starknet-deploy contract --inputs "10" --starknet-network ${NETWORK}`); diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts new file mode 100644 index 00000000..965acc1a --- /dev/null +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -0,0 +1,16 @@ +import shell from "shelljs"; +import { contains, exec } from "../../utils/utils"; + +const CONTRACT_NAME = "contract_with_unwhitelisted_hints.cairo"; +const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); + +exec(`cp $(dirname "$0")/${CONTRACT_NAME} ${CONTRACT_PATH}`); + +const EXPECTED = `Hint is not whitelisted. +This may indicate that this library function cannot be used in StarkNet contracts.`; + +shell.echo("Testing rejection of compilation without the --disable-hint-validation flag"); +contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); +shell.echo("Success"); + +exec(`npx hardhat starknet-compile ${CONTRACT_PATH} --disable-hint-validation`); diff --git a/test/configuration-tests/with-sources-path/check.ts b/test/configuration-tests/with-sources-path/check.ts new file mode 100644 index 00000000..593f5d50 --- /dev/null +++ b/test/configuration-tests/with-sources-path/check.ts @@ -0,0 +1,9 @@ +import shell from "shelljs"; +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +shell.mv("contracts", "my-starknet-sources"); + +exec("npx hardhat starknet-compile"); +exec(`npx hardhat starknet-deploy starknet-artifacts/my-starknet-sources/contract.cairo/ --starknet-network ${NETWORK} --inputs 10`); diff --git a/test/configuration-tests/with-wait/check.ts b/test/configuration-tests/with-wait/check.ts new file mode 100644 index 00000000..87ab9f8b --- /dev/null +++ b/test/configuration-tests/with-wait/check.ts @@ -0,0 +1,6 @@ +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/util.cairo"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/util.cairo/ --starknet-network ${NETWORK} --wait`); From 189a496878171b653ebe48ac7e0d9d931bd3e52b Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Mon, 14 Nov 2022 14:14:50 +0300 Subject: [PATCH 05/41] Remove check.sh files --- .../with-account-compilation-option/check.sh | 16 ------ .../with-artifacts-path/check.sh | 6 --- .../with-cairo-version/check.sh | 5 -- .../with-cli-network/check.sh | 10 ---- .../with-cli-paths/check.sh | 5 -- .../with-deploy-inputs/check.sh | 6 --- .../with-deploy-path/check.sh | 6 --- .../check.sh | 17 ------- .../with-networks/check.sh | 29 ----------- .../with-sources-path/check.sh | 7 --- test/configuration-tests/with-wait/check.sh | 5 -- test/general-tests/account-test/check.sh | 20 -------- test/general-tests/cairo-migrate/check.sh | 19 ------- test/general-tests/constructor-test/check.sh | 5 -- test/general-tests/declare-test/check.sh | 5 -- test/general-tests/decode-event-test/check.sh | 5 -- test/general-tests/devnet-block-time/check.sh | 4 -- .../devnet-create-block/check.sh | 4 -- .../devnet-dump-and-load/check.sh | 5 -- test/general-tests/devnet-restart/check.sh | 5 -- .../expect-error-on-compile/check.sh | 13 ----- .../function-argument-number/check.sh | 5 -- .../general-tests/getContractFactory/check.sh | 5 -- test/general-tests/hardhat-run/check.sh | 8 --- test/general-tests/plain/check.sh | 10 ---- test/general-tests/postman/check.sh | 10 ---- .../predeployed-accounts-test/check.sh | 4 -- test/general-tests/proxy-call/check.sh | 4 -- .../relative-artifact-test/check.sh | 8 --- test/general-tests/short-string-test/check.sh | 8 --- test/general-tests/starknet-call/check.sh | 36 ------------- .../starknet-estimate-fee/check.sh | 36 ------------- test/general-tests/starknet-invoke/check.sh | 36 ------------- .../starknet-new-account/check.sh | 25 --------- .../starknet-plugin-version/check.sh | 4 -- test/general-tests/starknet-verify/check.sh | 32 ------------ test/general-tests/wallet-test/check.sh | 17 ------- .../with-active-venv-args/check.sh | 9 ---- .../with-active-venv/check.sh | 11 ---- .../with-default/check.sh | 9 ---- .../with-docker-address-occupied/check.sh | 17 ------- .../with-docker-args/check.sh | 9 ---- .../with-docker-wrong-cli/check.sh | 12 ----- .../with-docker/check.sh | 9 ---- .../with-stderr-to-STDERR/check.sh | 29 ----------- .../with-stderr-to-STDOUT/check.sh | 12 ----- .../with-stderr-to-file/check.sh | 32 ------------ .../with-venv-address-occupied/check.sh | 15 ------ .../with-venv-wrong-cli/check.sh | 12 ----- .../with-venv/check.sh | 9 ---- test/recompilation-tests/hardhat-run/check.sh | 11 ---- .../recompilation-tests/hardhat-test/check.sh | 51 ------------------- .../recompiler-default/check.sh | 10 ---- .../recompiler-off/check.sh | 10 ---- .../starknet-call/check.sh | 11 ---- .../starknet-deploy/check.sh | 7 --- .../starknet-invoke/check.sh | 23 --------- test/venv-tests/with-venv-active/check.sh | 9 ---- test/venv-tests/with-venv/check.sh | 8 --- 59 files changed, 770 deletions(-) delete mode 100755 test/configuration-tests/with-account-compilation-option/check.sh delete mode 100755 test/configuration-tests/with-artifacts-path/check.sh delete mode 100755 test/configuration-tests/with-cairo-version/check.sh delete mode 100755 test/configuration-tests/with-cli-network/check.sh delete mode 100755 test/configuration-tests/with-cli-paths/check.sh delete mode 100755 test/configuration-tests/with-deploy-inputs/check.sh delete mode 100755 test/configuration-tests/with-deploy-path/check.sh delete mode 100755 test/configuration-tests/with-disable-hint-compilation-option/check.sh delete mode 100755 test/configuration-tests/with-networks/check.sh delete mode 100755 test/configuration-tests/with-sources-path/check.sh delete mode 100755 test/configuration-tests/with-wait/check.sh delete mode 100755 test/general-tests/account-test/check.sh delete mode 100755 test/general-tests/cairo-migrate/check.sh delete mode 100755 test/general-tests/constructor-test/check.sh delete mode 100755 test/general-tests/declare-test/check.sh delete mode 100755 test/general-tests/decode-event-test/check.sh delete mode 100755 test/general-tests/devnet-block-time/check.sh delete mode 100755 test/general-tests/devnet-create-block/check.sh delete mode 100755 test/general-tests/devnet-dump-and-load/check.sh delete mode 100755 test/general-tests/devnet-restart/check.sh delete mode 100755 test/general-tests/expect-error-on-compile/check.sh delete mode 100755 test/general-tests/function-argument-number/check.sh delete mode 100755 test/general-tests/getContractFactory/check.sh delete mode 100755 test/general-tests/hardhat-run/check.sh delete mode 100755 test/general-tests/plain/check.sh delete mode 100755 test/general-tests/postman/check.sh delete mode 100755 test/general-tests/predeployed-accounts-test/check.sh delete mode 100755 test/general-tests/proxy-call/check.sh delete mode 100755 test/general-tests/relative-artifact-test/check.sh delete mode 100755 test/general-tests/short-string-test/check.sh delete mode 100755 test/general-tests/starknet-call/check.sh delete mode 100755 test/general-tests/starknet-estimate-fee/check.sh delete mode 100755 test/general-tests/starknet-invoke/check.sh delete mode 100755 test/general-tests/starknet-new-account/check.sh delete mode 100755 test/general-tests/starknet-plugin-version/check.sh delete mode 100755 test/general-tests/starknet-verify/check.sh delete mode 100755 test/general-tests/wallet-test/check.sh delete mode 100755 test/integrated-devnet-tests/with-active-venv-args/check.sh delete mode 100755 test/integrated-devnet-tests/with-active-venv/check.sh delete mode 100755 test/integrated-devnet-tests/with-default/check.sh delete mode 100755 test/integrated-devnet-tests/with-docker-address-occupied/check.sh delete mode 100755 test/integrated-devnet-tests/with-docker-args/check.sh delete mode 100755 test/integrated-devnet-tests/with-docker-wrong-cli/check.sh delete mode 100755 test/integrated-devnet-tests/with-docker/check.sh delete mode 100755 test/integrated-devnet-tests/with-stderr-to-STDERR/check.sh delete mode 100755 test/integrated-devnet-tests/with-stderr-to-STDOUT/check.sh delete mode 100755 test/integrated-devnet-tests/with-stderr-to-file/check.sh delete mode 100755 test/integrated-devnet-tests/with-venv-address-occupied/check.sh delete mode 100755 test/integrated-devnet-tests/with-venv-wrong-cli/check.sh delete mode 100755 test/integrated-devnet-tests/with-venv/check.sh delete mode 100755 test/recompilation-tests/hardhat-run/check.sh delete mode 100755 test/recompilation-tests/hardhat-test/check.sh delete mode 100755 test/recompilation-tests/recompiler-default/check.sh delete mode 100755 test/recompilation-tests/recompiler-off/check.sh delete mode 100755 test/recompilation-tests/starknet-call/check.sh delete mode 100755 test/recompilation-tests/starknet-deploy/check.sh delete mode 100755 test/recompilation-tests/starknet-invoke/check.sh delete mode 100755 test/venv-tests/with-venv-active/check.sh delete mode 100755 test/venv-tests/with-venv/check.sh diff --git a/test/configuration-tests/with-account-compilation-option/check.sh b/test/configuration-tests/with-account-compilation-option/check.sh deleted file mode 100755 index 894c6295..00000000 --- a/test/configuration-tests/with-account-compilation-option/check.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -e - -CONTRACT_NAME=dummy_account.cairo -CONTRACT_PATH="contracts/$CONTRACT_NAME" - -cp "$(dirname "$0")/$CONTRACT_NAME" "$CONTRACT_PATH" - -EXPECTED="Use the --account-contract flag to compile an account contract." - -echo "Testing rejection of compilation without the account flag" -npx hardhat starknet-compile "$CONTRACT_PATH" 2>&1 | - ../scripts/assert-contains.py "$EXPECTED" -echo "Success" - -npx hardhat starknet-compile "$CONTRACT_PATH" --account-contract diff --git a/test/configuration-tests/with-artifacts-path/check.sh b/test/configuration-tests/with-artifacts-path/check.sh deleted file mode 100755 index 5af61b5a..00000000 --- a/test/configuration-tests/with-artifacts-path/check.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat starknet-deploy --starknet-network "$NETWORK" my-starknet-artifacts/contracts/contract.cairo/ --inputs 10 -rm -rf my-starknet-artifacts diff --git a/test/configuration-tests/with-cairo-version/check.sh b/test/configuration-tests/with-cairo-version/check.sh deleted file mode 100755 index 885cc5fd..00000000 --- a/test/configuration-tests/with-cairo-version/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat starknet-deploy contracts/contract.cairo --starknet-network "$NETWORK" --inputs 10 diff --git a/test/configuration-tests/with-cli-network/check.sh b/test/configuration-tests/with-cli-network/check.sh deleted file mode 100755 index fbe422d2..00000000 --- a/test/configuration-tests/with-cli-network/check.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -# Test how --starknet-network can be specified through CLI while at the same time -# overriding hardhat.config specification. -# It would be sufficient to run this test just once and not for both alpha and devnet. -# Only tests if --starknet-network is accepted, not if the correct network is targeted. - -npx hardhat run --no-compile scripts/compile-contract.ts -npx hardhat test --no-compile --starknet-network devnet test/quick-test.ts diff --git a/test/configuration-tests/with-cli-paths/check.sh b/test/configuration-tests/with-cli-paths/check.sh deleted file mode 100755 index 14737fa4..00000000 --- a/test/configuration-tests/with-cli-paths/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10 diff --git a/test/configuration-tests/with-deploy-inputs/check.sh b/test/configuration-tests/with-deploy-inputs/check.sh deleted file mode 100755 index 02631b6d..00000000 --- a/test/configuration-tests/with-deploy-inputs/check.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network "$NETWORK" -npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network "$NETWORK" --salt 0x10 diff --git a/test/configuration-tests/with-deploy-path/check.sh b/test/configuration-tests/with-deploy-path/check.sh deleted file mode 100755 index f6096540..00000000 --- a/test/configuration-tests/with-deploy-path/check.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network "$NETWORK" -npx hardhat starknet-deploy contract --inputs "10" --starknet-network "$NETWORK" diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.sh b/test/configuration-tests/with-disable-hint-compilation-option/check.sh deleted file mode 100755 index adfb030b..00000000 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -e - -CONTRACT_NAME=contract_with_unwhitelisted_hints.cairo -CONTRACT_PATH="contracts/$CONTRACT_NAME" - -cp "$(dirname "$0")/$CONTRACT_NAME" "$CONTRACT_PATH" - -EXPECTED="Hint is not whitelisted. -This may indicate that this library function cannot be used in StarkNet contracts." - -echo "Testing rejection of compilation without the --disable-hint-validation flag" -npx hardhat starknet-compile "$CONTRACT_PATH" 2>&1 | - ../scripts/assert-contains.py "$EXPECTED" -echo "Success" - -npx hardhat starknet-compile "$CONTRACT_PATH" --disable-hint-validation diff --git a/test/configuration-tests/with-networks/check.sh b/test/configuration-tests/with-networks/check.sh deleted file mode 100755 index 42ac64b9..00000000 --- a/test/configuration-tests/with-networks/check.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -ARTIFACT_PATH=starknet-artifacts/contracts/contract.cairo/ -INVALID_NETWORK="foo" -PREFIX=$(dirname "$0") - -echo "Testing no starknet network" -npx hardhat starknet-deploy "$ARTIFACT_PATH" --inputs 10 2>&1 \ - | tail -n +2 \ - | diff - "$PREFIX/without-starknet-network.txt" -echo "Success" - -echo "Testing invalid CLI network" -npx hardhat starknet-deploy --starknet-network "$INVALID_NETWORK" "$ARTIFACT_PATH" --inputs 10 2>&1 \ - | tail -n +2 \ - | diff - "$PREFIX/invalid-cli-network.txt" -echo "Success" - -echo "Testing no mocha network" -NETWORK="" npx hardhat test --no-compile test/contract-factory-test.ts -echo "Success" - -echo "Testing invalid config network" -NETWORK="$INVALID_NETWORK" npx hardhat test --no-compile test/contract-factory-test.ts 2>&1 \ - | tail -n +1 \ - | diff - "$PREFIX/invalid-config-network.txt" -echo "Success" diff --git a/test/configuration-tests/with-sources-path/check.sh b/test/configuration-tests/with-sources-path/check.sh deleted file mode 100755 index 567fb17b..00000000 --- a/test/configuration-tests/with-sources-path/check.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e - -mv contracts my-starknet-sources - -npx hardhat starknet-compile -npx hardhat starknet-deploy starknet-artifacts/my-starknet-sources/contract.cairo/ --starknet-network "$NETWORK" --inputs 10 diff --git a/test/configuration-tests/with-wait/check.sh b/test/configuration-tests/with-wait/check.sh deleted file mode 100755 index a6bab5db..00000000 --- a/test/configuration-tests/with-wait/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/util.cairo -npx hardhat starknet-deploy starknet-artifacts/contracts/util.cairo/ --starknet-network "$NETWORK" --wait diff --git a/test/general-tests/account-test/check.sh b/test/general-tests/account-test/check.sh deleted file mode 100755 index 0dc81e78..00000000 --- a/test/general-tests/account-test/check.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -eu - -npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo - -npx hardhat test --no-compile test/oz-account-test.ts - -if [ "$NETWORK" == "devnet" ]; then - npx hardhat test --no-compile scripts/deploy-argent.ts - - TOKEN_ADDRESS="0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488" \ - SENDER_ADDRESS=$OZ_ACCOUNT_ADDRESS \ - SENDER_PRIVATE_KEY=$OZ_ACCOUNT_PRIVATE_KEY \ - SENDER_IMPLEMENTATION="OpenZeppelin" \ - RECIPIENT_ADDRESS=$ARGENT_ACCOUNT_ADDRESS \ - TRANSFER_AMOUNT="1000000000000000000" \ - npx hardhat test --no-compile scripts/transfer-funds.ts -fi - -npx hardhat test --no-compile test/argent-account-test.ts diff --git a/test/general-tests/cairo-migrate/check.sh b/test/general-tests/cairo-migrate/check.sh deleted file mode 100755 index fa2f35ca..00000000 --- a/test/general-tests/cairo-migrate/check.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -set -e - -CONTRACT_NAME=old_contract.cairo -CONTRACT_PATH="contracts/$CONTRACT_NAME" -NEW_COMMENT="// Declare this file as a StarkNet contract." - -cp "$(dirname "$0")/$CONTRACT_NAME" "$CONTRACT_PATH" - -echo "Testing migration of old cairo contract to a new one" -# Migrate contract to new version. -npx hardhat migrate "$CONTRACT_PATH" 2>&1 | - ../scripts/assert-contains.py "$NEW_COMMENT" - -# Migrate contract to new version with change content in place option. -npx hardhat migrate "$CONTRACT_PATH" --inplace -cat "$CONTRACT_PATH" | ../scripts/assert-contains.py "$NEW_COMMENT" - -echo "Success" diff --git a/test/general-tests/constructor-test/check.sh b/test/general-tests/constructor-test/check.sh deleted file mode 100755 index e383f00f..00000000 --- a/test/general-tests/constructor-test/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo contracts/simple_storage.cairo contracts/empty_constructor.cairo -npx hardhat test --no-compile test/constructor.test.ts diff --git a/test/general-tests/declare-test/check.sh b/test/general-tests/declare-test/check.sh deleted file mode 100755 index 579beb2d..00000000 --- a/test/general-tests/declare-test/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo contracts/deployer.cairo -npx hardhat test --no-compile test/declare-deploy.test.ts diff --git a/test/general-tests/decode-event-test/check.sh b/test/general-tests/decode-event-test/check.sh deleted file mode 100755 index bc918cee..00000000 --- a/test/general-tests/decode-event-test/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/events.cairo -npx hardhat test --no-compile test/decode-events.test.ts diff --git a/test/general-tests/devnet-block-time/check.sh b/test/general-tests/devnet-block-time/check.sh deleted file mode 100755 index 8965add8..00000000 --- a/test/general-tests/devnet-block-time/check.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat test --no-compile test/devnet-time-test.ts diff --git a/test/general-tests/devnet-create-block/check.sh b/test/general-tests/devnet-create-block/check.sh deleted file mode 100755 index 894e4d0e..00000000 --- a/test/general-tests/devnet-create-block/check.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat test --no-compile test/devnet-create-block.test.ts diff --git a/test/general-tests/devnet-dump-and-load/check.sh b/test/general-tests/devnet-dump-and-load/check.sh deleted file mode 100755 index bfe19441..00000000 --- a/test/general-tests/devnet-dump-and-load/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/devnet-dump-and-load.test.ts diff --git a/test/general-tests/devnet-restart/check.sh b/test/general-tests/devnet-restart/check.sh deleted file mode 100755 index 576ec321..00000000 --- a/test/general-tests/devnet-restart/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/devnet-restart.test.ts diff --git a/test/general-tests/expect-error-on-compile/check.sh b/test/general-tests/expect-error-on-compile/check.sh deleted file mode 100755 index 882b1220..00000000 --- a/test/general-tests/expect-error-on-compile/check.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -eu - -CONTRACT_NAME=invalid_contract.cairo -CONTRACT_PATH="contracts/$CONTRACT_NAME" - -cp "$(dirname "$0")/$CONTRACT_NAME" "$CONTRACT_PATH" - -echo "Testing rejection of compilation with correct message" -npx hardhat starknet-compile "$CONTRACT_PATH" 2>&1 | - ../scripts/assert-contains.py "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'" -echo "Success" diff --git a/test/general-tests/function-argument-number/check.sh b/test/general-tests/function-argument-number/check.sh deleted file mode 100755 index cf4382bc..00000000 --- a/test/general-tests/function-argument-number/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/function-args-test.ts diff --git a/test/general-tests/getContractFactory/check.sh b/test/general-tests/getContractFactory/check.sh deleted file mode 100755 index c25f8295..00000000 --- a/test/general-tests/getContractFactory/check.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile -npx hardhat test --no-compile test/path-test.ts diff --git a/test/general-tests/hardhat-run/check.sh b/test/general-tests/hardhat-run/check.sh deleted file mode 100755 index 4160f637..00000000 --- a/test/general-tests/hardhat-run/check.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -e - -echo "$0: Testing hh run with --starknet-network is currently disabled" - -# npx hardhat starknet-compile contracts/contract.cairo -# npx hardhat run --no-compile scripts/quick-script.ts --starknet-network "$NETWORK" diff --git a/test/general-tests/plain/check.sh b/test/general-tests/plain/check.sh deleted file mode 100755 index baeeacc9..00000000 --- a/test/general-tests/plain/check.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -INITIAL_VALUE=10 -PUBLIC_KEY=1628448741648245036800002906075225705100596136133912895015035902954123957052 - -npx hardhat starknet-compile -npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network "$NETWORK" --inputs "$INITIAL_VALUE" -npx hardhat starknet-deploy starknet-artifacts/contracts/auth_contract.cairo/ --inputs "$PUBLIC_KEY $INITIAL_VALUE" --starknet-network "$NETWORK" -npx hardhat test --no-compile test/sample-test.ts diff --git a/test/general-tests/postman/check.sh b/test/general-tests/postman/check.sh deleted file mode 100755 index ff370c73..00000000 --- a/test/general-tests/postman/check.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -trap 'kill $(jobs -p)' EXIT - -npx hardhat starknet-compile contracts/l1l2.cairo -npx hardhat node & -sleep 1 - -npx hardhat test --network localhost test/postman.test.ts diff --git a/test/general-tests/predeployed-accounts-test/check.sh b/test/general-tests/predeployed-accounts-test/check.sh deleted file mode 100755 index 0fe17130..00000000 --- a/test/general-tests/predeployed-accounts-test/check.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat test --no-compile test/get-predeployed-accounts.test.ts diff --git a/test/general-tests/proxy-call/check.sh b/test/general-tests/proxy-call/check.sh deleted file mode 100755 index 89b61136..00000000 --- a/test/general-tests/proxy-call/check.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat test --no-compile scripts/delegate-proxy.ts diff --git a/test/general-tests/relative-artifact-test/check.sh b/test/general-tests/relative-artifact-test/check.sh deleted file mode 100755 index 39aaf47c..00000000 --- a/test/general-tests/relative-artifact-test/check.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo - -cp -a starknet-artifacts/contracts test/test-artifacts - -npx hardhat test --no-compile test/relative-artifacts.test.ts diff --git a/test/general-tests/short-string-test/check.sh b/test/general-tests/short-string-test/check.sh deleted file mode 100755 index b7348958..00000000 --- a/test/general-tests/short-string-test/check.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -cd .. - -# The config file used for running mocha tests is the one in root - -npx hardhat test --no-compile test/general-tests/short-string-test/short-string-test.ts diff --git a/test/general-tests/starknet-call/check.sh b/test/general-tests/starknet-call/check.sh deleted file mode 100755 index 46e59681..00000000 --- a/test/general-tests/starknet-call/check.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10) -echo $output - -ADDRESS=$(echo $output | sed -r "s/.*Contract address: (\w*).*/\1/") -PREFIX=$(dirname "$0") - -echo "Testing no input argument" -npx hardhat starknet-call --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/no-inputs.txt" -echo "Success" - -echo "Testing too few input arguments" -npx hardhat starknet-call --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" --inputs "10 20 30" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/too-few-inputs.txt" -echo "Success" - -echo "Testing too many input arguments" -npx hardhat starknet-call --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" --inputs "10 20 30 40 50" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/too-many-inputs.txt" -echo "Success" - -echo "The success case of starknet-call test is temporarily disabled." -echo "To enable it back, uncomment the lines in its check.sh." -# echo "Testing success case" -# npx hardhat starknet-call --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" --inputs "10 20 30 40" 2>&1 \ -# | tail -n +2 \ -# | head -n -3 \ -# | diff - <(echo "40 60") -# echo "Success" diff --git a/test/general-tests/starknet-estimate-fee/check.sh b/test/general-tests/starknet-estimate-fee/check.sh deleted file mode 100755 index f8a4987a..00000000 --- a/test/general-tests/starknet-estimate-fee/check.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10) -echo $output - -ADDRESS=$(echo $output | sed -r "s/.*Contract address: (\w*).*/\1/") -PREFIX=$(dirname "$0") - -echo "Testing no input argument" -npx hardhat starknet-estimate-fee --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/no-inputs.txt" -echo "Success" - -echo "Testing too few input arguments" -npx hardhat starknet-estimate-fee --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" --inputs "10 20 30" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/too-few-inputs.txt" -echo "Success" - -echo "Testing too many input arguments" -npx hardhat starknet-estimate-fee --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" --inputs "10 20 30 40 50" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/too-many-inputs.txt" -echo "Success" - -echo "The success case of starknet-estimate-fee test is temporarily disabled." -echo "To enable it back, uncomment the lines in its check.sh." -# echo "Testing success case" -# npx hardhat starknet-estimate-fee --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$ADDRESS" --inputs "10 20 30 40" 2>&1 \ -# | tail -n +2 \ -# | head -n -3 \ -# | diff - <(echo "40 60") -# echo "Success" diff --git a/test/general-tests/starknet-invoke/check.sh b/test/general-tests/starknet-invoke/check.sh deleted file mode 100755 index c3045522..00000000 --- a/test/general-tests/starknet-invoke/check.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-compile contracts/contract.cairo -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10) -echo $output - -ADDRESS=$(echo $output | sed -r "s/.*Contract address: (\w*).*/\1/") -PREFIX=$(dirname "$0") - -echo "Testing no input argument" -npx hardhat starknet-invoke --starknet-network "$NETWORK" --contract contract --function increase_balance --address "$ADDRESS" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/no-inputs.txt" -echo "Success" - -echo "Testing too few input arguments" -npx hardhat starknet-invoke --starknet-network "$NETWORK" --contract contract --function increase_balance --address "$ADDRESS" --inputs 10 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/too-few-inputs.txt" -echo "Success" - -echo "Testing too many input arguments" -npx hardhat starknet-invoke --starknet-network "$NETWORK" --contract contract --function increase_balance --address "$ADDRESS" --inputs "10 20 30" 2>&1 \ - | tail -n +6 \ - | diff - "$PREFIX/too-many-inputs.txt" -echo "Success" - -echo "The success case of starknet-invoke test is temporarily disabled." -echo "To enable it back, uncomment the lines in its check.sh." -# echo "Testing success case" -# npx hardhat starknet-invoke --starknet-network "$NETWORK" --contract contract --function increase_balance --address "$ADDRESS" --inputs "10 20" 2>&1 \ -# | tail -n +2\ -# | head -n -5\ -# | diff - <(echo "Invoke transaction was sent.") -# echo "Success" diff --git a/test/general-tests/starknet-new-account/check.sh b/test/general-tests/starknet-new-account/check.sh deleted file mode 100755 index 98e595ec..00000000 --- a/test/general-tests/starknet-new-account/check.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -eu - -export ACCOUNT_DIR="$HOME/.starknet_new_account_test" -ACCOUNT_FILE="$ACCOUNT_DIR/starknet_open_zeppelin_accounts.json" - -output=$(npx hardhat starknet-new-account --wallet OpenZeppelin --starknet-network "$NETWORK") -tail=${output#*$'\n'Account address: } -ACCOUNT_ADDRESS_FROM_STD=${tail%%$'\n'*} - -# Read newly created account and grab the address -ACCOUNT_ADDRESS_FROM_FILE=$(jq -r ."$NETWORK".OpenZeppelin.address $ACCOUNT_FILE) - -# Change hex to int -address_one=$(python -c "print(int('${ACCOUNT_ADDRESS_FROM_STD}', 16))") -address_two=$(python -c "print(int('${ACCOUNT_ADDRESS_FROM_FILE}', 16))") - -# If address_one and address_two are equal then success -if [ ${address_one} == ${address_two} ]; then - echo "Success" -else - echo "Failed" - exit 1 -fi diff --git a/test/general-tests/starknet-plugin-version/check.sh b/test/general-tests/starknet-plugin-version/check.sh deleted file mode 100755 index 92f72ae0..00000000 --- a/test/general-tests/starknet-plugin-version/check.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -npx hardhat starknet-plugin-version diff --git a/test/general-tests/starknet-verify/check.sh b/test/general-tests/starknet-verify/check.sh deleted file mode 100755 index 0202ab5c..00000000 --- a/test/general-tests/starknet-verify/check.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - - -set -e - -echo "The starknet-verify test is too flaky so it is temporarily suspended. Make sure it's working!" -exit 0 - -MAIN_CONTRACT=contracts/contract.cairo -UTIL_CONTRACT=contracts/util.cairo - -npx hardhat starknet-compile $MAIN_CONTRACT $UTIL_CONTRACT - -echo "Waiting for deployment to be accepted" -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" contract --inputs 10 --wait) -address=$(echo $output | sed -r "s/.*Contract address: (\w*).*/\1/") -echo "Verifying contract at $address" - -echo "Sleeping to allow Voyager to index the deployment" -sleep 1m - -npx hardhat starknet-verify --starknet-network "$NETWORK" --path $MAIN_CONTRACT $UTIL_CONTRACT --address $address --compiler-version 0.9.0 --license "No License (None)" --account-contract false -echo "Sleeping to allow Voyager to register the verification" -sleep 15s - -is_verified=$(curl "https://goerli.voyager.online/api/contract/$address/code" | jq ".abiVerified") -if [ "$is_verified" == "true" ]; then - echo "Successfully verified!" -else - echo "$0: Error: Not verified!" - exit 1 -fi diff --git a/test/general-tests/wallet-test/check.sh b/test/general-tests/wallet-test/check.sh deleted file mode 100755 index 14aa9838..00000000 --- a/test/general-tests/wallet-test/check.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -eu - -export ACCOUNT_DIR="$HOME/.starknet_accounts_wallet_test" - -npx hardhat starknet-compile contracts/contract.cairo - -../scripts/deploy-funded-cli-account.sh - -npx hardhat test --no-compile test/wallet-test.ts - -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10) -echo $output -ADDRESS=$(echo $output | sed -r "s/.*Contract address: (\w*).*/\1/") - -npx hardhat starknet-call --contract contract --function get_balance --address "$ADDRESS" --wallet OpenZeppelin --starknet-network "$NETWORK" -npx hardhat starknet-invoke --contract contract --function increase_balance --inputs "10 20" --address "$ADDRESS" --wallet OpenZeppelin --starknet-network "$NETWORK" diff --git a/test/integrated-devnet-tests/with-active-venv-args/check.sh b/test/integrated-devnet-tests/with-active-venv-args/check.sh deleted file mode 100755 index 717b327a..00000000 --- a/test/integrated-devnet-tests/with-active-venv-args/check.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet-args.test.ts -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-active-venv/check.sh b/test/integrated-devnet-tests/with-active-venv/check.sh deleted file mode 100755 index c12e2dbd..00000000 --- a/test/integrated-devnet-tests/with-active-venv/check.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -source ../my-venv/bin/activate - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet.test.ts -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-default/check.sh b/test/integrated-devnet-tests/with-default/check.sh deleted file mode 100755 index b01520aa..00000000 --- a/test/integrated-devnet-tests/with-default/check.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet.test.ts -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.sh b/test/integrated-devnet-tests/with-docker-address-occupied/check.sh deleted file mode 100755 index a60a19fc..00000000 --- a/test/integrated-devnet-tests/with-docker-address-occupied/check.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -trap 'kill $(jobs -p)' EXIT - -source ../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 --accounts 0 & - -npx hardhat starknet-compile contracts/contract.cairo - -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "127.0.0.1:5050 already occupied." diff --git a/test/integrated-devnet-tests/with-docker-args/check.sh b/test/integrated-devnet-tests/with-docker-args/check.sh deleted file mode 100755 index 717b327a..00000000 --- a/test/integrated-devnet-tests/with-docker-args/check.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet-args.test.ts -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-docker-wrong-cli/check.sh b/test/integrated-devnet-tests/with-docker-wrong-cli/check.sh deleted file mode 100755 index 8fb411a6..00000000 --- a/test/integrated-devnet-tests/with-docker-wrong-cli/check.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running - -npx hardhat starknet-compile contracts/contract.cairo - -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value." diff --git a/test/integrated-devnet-tests/with-docker/check.sh b/test/integrated-devnet-tests/with-docker/check.sh deleted file mode 100755 index b01520aa..00000000 --- a/test/integrated-devnet-tests/with-docker/check.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet.test.ts -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.sh b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.sh deleted file mode 100755 index 9d814039..00000000 --- a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running - -EXPECTED_STDOUT="Account #0" -EXPECTED_WARNING="WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS." - -npx hardhat starknet-compile contracts/contract.cairo - -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "$EXPECTED_WARNING" - - -# Checks if file logs/stdout.log exists and contains the expected warning string -if [ -f logs/stdout.log ]; then - if ! grep -q "$EXPECTED_STDOUT" logs/stdout.log; then - echo "Expected warning to contain '$EXPECTED_STDOUT'" - exit 1 - fi -else - echo "Expected logs/stdout.log to exist" - exit 1 -fi - -echo "Success" -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.sh b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.sh deleted file mode 100755 index 8fb411a6..00000000 --- a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running - -npx hardhat starknet-compile contracts/contract.cairo - -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value." diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.sh b/test/integrated-devnet-tests/with-stderr-to-file/check.sh deleted file mode 100755 index 587d517b..00000000 --- a/test/integrated-devnet-tests/with-stderr-to-file/check.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo - -EXPECTED_STDOUT="Account #0" -EXPECTED_WARNING="WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS." - -output=$(npx hardhat test --no-compile test/integrated-devnet.test.ts) -# Checks if output contains the expected string from stdout -if ! echo "$output" | grep -q "$EXPECTED_STDOUT"; then - echo "Expected output to contain '$EXPECTED_STDOUT'" - exit 1 -fi - - -# Checks if file logs/stderr.log exists and contains the expected warning string -if [ -f logs/stderr.log ]; then - if ! grep -q "$EXPECTED_WARNING" logs/stderr.log; then - echo "Expected warning to contain '$EXPECTED_WARNING'" - exit 1 - fi -else - echo "Expected logs/stderr.log to exist" - exit 1 -fi - -echo "Success" -check_devnet_is_not_running diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.sh b/test/integrated-devnet-tests/with-venv-address-occupied/check.sh deleted file mode 100755 index 54e376dd..00000000 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -e - -trap 'kill $(jobs -p)' EXIT - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -starknet-devnet --host 127.0.0.1 --port 5050 --accounts 0 & - -npx hardhat starknet-compile contracts/contract.cairo - -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "127.0.0.1:5050 already occupied." diff --git a/test/integrated-devnet-tests/with-venv-wrong-cli/check.sh b/test/integrated-devnet-tests/with-venv-wrong-cli/check.sh deleted file mode 100755 index 8fb411a6..00000000 --- a/test/integrated-devnet-tests/with-venv-wrong-cli/check.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running - -npx hardhat starknet-compile contracts/contract.cairo - -npx hardhat test --no-compile test/integrated-devnet.test.ts 2>&1 | - ../scripts/assert-contains.py "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value." diff --git a/test/integrated-devnet-tests/with-venv/check.sh b/test/integrated-devnet-tests/with-venv/check.sh deleted file mode 100755 index b01520aa..00000000 --- a/test/integrated-devnet-tests/with-venv/check.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -source ../scripts/check-devnet-is-not-running.sh - -check_devnet_is_not_running -npx hardhat starknet-compile contracts/contract.cairo -npx hardhat test --no-compile test/integrated-devnet.test.ts -check_devnet_is_not_running diff --git a/test/recompilation-tests/hardhat-run/check.sh b/test/recompilation-tests/hardhat-run/check.sh deleted file mode 100755 index 489f04f5..00000000 --- a/test/recompilation-tests/hardhat-run/check.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -# Hardhat run command -echo "Testing Recompilation with deleted artifact on hardhat run" -rm -rf starknet-artifacts/contracts/contract.cairo -npx hardhat run --no-compile scripts/deploy.ts - -echo "Testing Recompilation with cache file deleted on hardhat run" -rm -rf cache/cairo-files-cache.json -npx hardhat run --no-compile scripts/deploy.ts diff --git a/test/recompilation-tests/hardhat-test/check.sh b/test/recompilation-tests/hardhat-test/check.sh deleted file mode 100755 index 3e789826..00000000 --- a/test/recompilation-tests/hardhat-test/check.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -set -e - -CONTRACT_NAME=contract_test_cache.cairo -CONTRACT_PATH="contracts/${CONTRACT_NAME}" - -DEPENDENCY_NAME=dependency.cairo -DEPENDENCY_PATH="contracts/${DEPENDENCY_NAME}" - -rm -rf $DEPENDENCY_PATH $CONTRACT_PATH -# Hardhat test command -echo "Testing Recompilation with new contract added" -cp "$(dirname "$0")/$CONTRACT_NAME" "$CONTRACT_PATH" -cp "$(dirname "$0")/$DEPENDENCY_NAME" "$DEPENDENCY_PATH" -npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts - -echo "Testing Recompilation with artifacts deleted" -rm -rf starknet-artifacts/contracts/contract.cairo -npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts - -echo "Testing Recompilation with updated contract" -# Appending a new function to the contract -cat "$(dirname "$0")/get_balance.cairo" >> contracts/contract_test_cache.cairo -npx hardhat test --no-compile test/recompilation/recompilation-update-test.ts - -echo "Testing Recompilation with cache file deleted" -rm -rf cache/cairo-files-cache.json -npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts - -echo "Testing Recompilation with dependency changed" -echo "//" >> "$DEPENDENCY_PATH" -npx hardhat test --no-compile test/recompilation/recompilation-dependency-test.ts - -echo "Testing Recompilation with source deleted" -cp cache/cairo-files-cache.json cache-content-before.json -rm -rf contracts/contract_test_cache.cairo -npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts -# Check that the cache file was updated using diff -if diff -q cache-content-before.json cache/cairo-files-cache.json; then - echo "Cache file was not updated" - exit 1 -fi - -echo "Testing Recompilation one contract added another deleted" -rm -f contracts/contract_test_cache.cairo -rm -f contracts/dependency.cairo - -CONTRACT_WITH_NO_DEPENDENCY=contract_test_cache_no_dependency.cairo -cp "$(dirname "$0")/$CONTRACT_WITH_NO_DEPENDENCY" "$CONTRACT_PATH" - -npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts diff --git a/test/recompilation-tests/recompiler-default/check.sh b/test/recompilation-tests/recompiler-default/check.sh deleted file mode 100755 index d25e085f..00000000 --- a/test/recompilation-tests/recompiler-default/check.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -EXPECTED='StarknetPluginError: Artifact expected to be at' - -echo "Testing with deleted artifact on recompiler option set to default (off)" -rm -rf starknet-artifacts/contracts/contract.cairo/ -npx hardhat run --no-compile scripts/deploy.ts 2>&1 | - ../scripts/assert-contains.py "$EXPECTED" -echo "Success" diff --git a/test/recompilation-tests/recompiler-off/check.sh b/test/recompilation-tests/recompiler-off/check.sh deleted file mode 100755 index d18160b4..00000000 --- a/test/recompilation-tests/recompiler-off/check.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -EXPECTED='StarknetPluginError: Artifact expected to be at' - -echo "Testing with deleted artifact on recompiler option set to false" -rm -rf starknet-artifacts/contracts/contract.cairo/ -npx hardhat run --no-compile scripts/deploy.ts 2>&1 | - ../scripts/assert-contains.py "$EXPECTED" -echo "Success" diff --git a/test/recompilation-tests/starknet-call/check.sh b/test/recompilation-tests/starknet-call/check.sh deleted file mode 100755 index f3097299..00000000 --- a/test/recompilation-tests/starknet-call/check.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -echo "Testing Recompilation with deleted artifact on starknet-call" -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10) - -tail=${output#*$'\n'Contract address: } -address=${tail%%$'\n'*} - -rm -rf starknet-artifacts/contracts/contract.cairo -npx hardhat starknet-call --starknet-network "$NETWORK" --contract contract --function sum_points_to_tuple --address "$address" --inputs "10 20 30 40" diff --git a/test/recompilation-tests/starknet-deploy/check.sh b/test/recompilation-tests/starknet-deploy/check.sh deleted file mode 100755 index 572c6bf3..00000000 --- a/test/recompilation-tests/starknet-deploy/check.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e - -# Hardhat starknet-deploy command -echo "Testing Recompilation with deleted artifact on starknet-deploy" -rm -rf starknet-artifacts/contracts/contract.cairo -npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10 diff --git a/test/recompilation-tests/starknet-invoke/check.sh b/test/recompilation-tests/starknet-invoke/check.sh deleted file mode 100755 index 42bcbdc2..00000000 --- a/test/recompilation-tests/starknet-invoke/check.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -e - -# Hardhat starknet-invoke command -echo "Testing Recompilation with deleted artifact on hardhat starknet-invoke" -output=$(npx hardhat starknet-deploy --starknet-network "$NETWORK" starknet-artifacts/contracts/contract.cairo/ --inputs 10) -# Grab the output Contract address to a variable using parameter expansion -tail=${output#*$'\n'Contract address: } -address=${tail%%$'\n'*} - -# Remove artifact contract to force recompilation -rm -rf starknet-artifacts/contracts/contract.cairo - -export ACCOUNT_DIR="$HOME/.starknet_accounts_recompile_test" -../scripts/deploy-funded-cli-account.sh - -npx hardhat starknet-invoke \ - --starknet-network "$NETWORK" \ - --contract contract \ - --function increase_balance \ - --address "$address" \ - --inputs "10 20" \ - --wallet OpenZeppelin diff --git a/test/venv-tests/with-venv-active/check.sh b/test/venv-tests/with-venv-active/check.sh deleted file mode 100755 index 699cf021..00000000 --- a/test/venv-tests/with-venv-active/check.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -source ../my-venv/bin/activate - -INITIAL_VALUE=10 - -npx hardhat starknet-compile -npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network "$NETWORK" --inputs "$INITIAL_VALUE" diff --git a/test/venv-tests/with-venv/check.sh b/test/venv-tests/with-venv/check.sh deleted file mode 100755 index d6e02c22..00000000 --- a/test/venv-tests/with-venv/check.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -INITIAL_VALUE=10 - -npx hardhat starknet-compile -npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network "$NETWORK" --inputs "$INITIAL_VALUE" -npx hardhat test --no-compile test/quick-test.ts From 77f9a40e92989cd1872317ae73a4ee4d53096be8 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Mon, 14 Nov 2022 14:30:09 +0300 Subject: [PATCH 06/41] Replace check.sh with check.ts - Use console.log in place of shell.echo - use fs functions to copy, delete and read file --- .../with-account-compilation-option/check.ts | 9 +-- .../with-artifacts-path/check.ts | 4 +- .../with-deploy-inputs/check.ts | 8 ++- .../check.ts | 9 +-- .../with-networks/check.ts | 30 ++++++++++ test/general-tests/account-test/check.ts | 4 +- test/general-tests/cairo-migrate/check.ts | 19 ++++++ test/general-tests/constructor-test/check.ts | 4 ++ test/general-tests/declare-test/check.ts | 4 ++ test/general-tests/decode-event-test/check.ts | 4 ++ test/general-tests/devnet-block-time/check.ts | 3 + .../devnet-create-block/check.ts | 3 + .../devnet-dump-and-load/check.ts | 4 ++ test/general-tests/devnet-restart/check.ts | 4 ++ .../expect-error-on-compile/check.ts | 13 +++++ .../function-argument-number/check.ts | 4 ++ .../general-tests/getContractFactory/check.ts | 4 ++ test/general-tests/hardhat-run/check.ts | 5 ++ test/general-tests/plain/check.ts | 10 ++++ test/general-tests/postman/check.ts | 9 +++ .../predeployed-accounts-test/check.ts | 3 + test/general-tests/proxy-call/check.ts | 3 + .../relative-artifact-test/check.ts | 7 +++ test/general-tests/short-string-test/check.ts | 7 +++ test/general-tests/starknet-call/check.ts | 40 +++++++++++++ .../starknet-estimate-fee/check.ts | 37 ++++++++++++ test/general-tests/starknet-invoke/check.ts | 37 ++++++++++++ .../starknet-new-account/check.ts | 30 ++++++++++ .../starknet-plugin-version/check.ts | 3 + test/general-tests/starknet-verify/check.ts | 32 ++++++++++ test/general-tests/wallet-test/check.ts | 20 +++++++ .../with-active-venv-args/check.ts | 6 ++ .../with-active-venv/check.ts | 10 +++- .../with-active-venv/venv.sh | 4 ++ .../with-default/check.ts | 6 ++ .../with-docker-address-occupied/check.ts | 15 +++++ .../with-docker-args/check.ts | 6 ++ .../with-docker-wrong-cli/check.ts | 7 +++ .../with-docker/check.ts | 6 ++ .../with-stderr-to-STDERR/check.ts | 26 +++++++++ .../with-stderr-to-STDOUT/check.ts | 6 ++ .../with-stderr-to-file/check.ts | 31 ++++++++++ .../with-venv-address-occupied/check.ts | 14 +++++ .../with-venv-wrong-cli/check.ts | 7 +++ .../with-venv/check.ts | 6 ++ test/recompilation-tests/hardhat-run/check.ts | 11 ++-- .../recompilation-tests/hardhat-test/check.ts | 58 +++++++++++++++++++ .../recompiler-default/check.ts | 8 +++ .../recompiler-off/check.ts | 9 +++ .../starknet-call/check.ts | 11 ++++ .../starknet-deploy/check.ts | 9 +++ .../starknet-invoke/check.ts | 26 +++++++++ test/utils/utils.ts | 34 ++++++++++- test/venv-tests/with-venv-active/check.ts | 10 ++++ test/venv-tests/with-venv-active/venv.sh | 4 ++ 55 files changed, 679 insertions(+), 24 deletions(-) create mode 100644 test/configuration-tests/with-networks/check.ts create mode 100644 test/general-tests/cairo-migrate/check.ts create mode 100644 test/general-tests/constructor-test/check.ts create mode 100644 test/general-tests/declare-test/check.ts create mode 100644 test/general-tests/decode-event-test/check.ts create mode 100644 test/general-tests/devnet-block-time/check.ts create mode 100644 test/general-tests/devnet-create-block/check.ts create mode 100644 test/general-tests/devnet-dump-and-load/check.ts create mode 100644 test/general-tests/devnet-restart/check.ts create mode 100644 test/general-tests/expect-error-on-compile/check.ts create mode 100644 test/general-tests/function-argument-number/check.ts create mode 100644 test/general-tests/getContractFactory/check.ts create mode 100644 test/general-tests/hardhat-run/check.ts create mode 100644 test/general-tests/plain/check.ts create mode 100644 test/general-tests/postman/check.ts create mode 100644 test/general-tests/predeployed-accounts-test/check.ts create mode 100644 test/general-tests/proxy-call/check.ts create mode 100644 test/general-tests/relative-artifact-test/check.ts create mode 100644 test/general-tests/short-string-test/check.ts create mode 100644 test/general-tests/starknet-call/check.ts create mode 100644 test/general-tests/starknet-estimate-fee/check.ts create mode 100644 test/general-tests/starknet-invoke/check.ts create mode 100644 test/general-tests/starknet-new-account/check.ts create mode 100644 test/general-tests/starknet-plugin-version/check.ts create mode 100644 test/general-tests/starknet-verify/check.ts create mode 100644 test/general-tests/wallet-test/check.ts create mode 100644 test/integrated-devnet-tests/with-active-venv-args/check.ts create mode 100644 test/integrated-devnet-tests/with-active-venv/venv.sh create mode 100644 test/integrated-devnet-tests/with-default/check.ts create mode 100644 test/integrated-devnet-tests/with-docker-address-occupied/check.ts create mode 100644 test/integrated-devnet-tests/with-docker-args/check.ts create mode 100644 test/integrated-devnet-tests/with-docker-wrong-cli/check.ts create mode 100644 test/integrated-devnet-tests/with-docker/check.ts create mode 100644 test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts create mode 100644 test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts create mode 100644 test/integrated-devnet-tests/with-stderr-to-file/check.ts create mode 100644 test/integrated-devnet-tests/with-venv-address-occupied/check.ts create mode 100644 test/integrated-devnet-tests/with-venv-wrong-cli/check.ts create mode 100644 test/integrated-devnet-tests/with-venv/check.ts create mode 100644 test/recompilation-tests/hardhat-test/check.ts create mode 100644 test/recompilation-tests/recompiler-default/check.ts create mode 100644 test/recompilation-tests/recompiler-off/check.ts create mode 100644 test/recompilation-tests/starknet-call/check.ts create mode 100644 test/recompilation-tests/starknet-deploy/check.ts create mode 100644 test/recompilation-tests/starknet-invoke/check.ts create mode 100644 test/venv-tests/with-venv-active/check.ts create mode 100644 test/venv-tests/with-venv-active/venv.sh diff --git a/test/configuration-tests/with-account-compilation-option/check.ts b/test/configuration-tests/with-account-compilation-option/check.ts index b49d1ff7..de532478 100644 --- a/test/configuration-tests/with-account-compilation-option/check.ts +++ b/test/configuration-tests/with-account-compilation-option/check.ts @@ -1,4 +1,5 @@ -import shell from "shelljs"; +import { copyFileSync } from "fs"; +import path from "path"; import { contains, exec } from "../../utils/utils"; const CONTRACT_NAME = "dummy_account.cairo"; @@ -6,9 +7,9 @@ const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); const EXPECTED = "Use the --account-contract flag to compile an account contract."; -shell.echo("Testing rejection of compilation without the account flag"); -exec(`cp $(dirname "$0")/${CONTRACT_NAME} ${CONTRACT_PATH}`); +console.log("Testing rejection of compilation without the account flag"); +copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); -shell.echo("Success"); +console.log("Success"); exec(`npx hardhat starknet-compile ${CONTRACT_PATH} --account-contract`); diff --git a/test/configuration-tests/with-artifacts-path/check.ts b/test/configuration-tests/with-artifacts-path/check.ts index 63e520ae..ab4dcee7 100644 --- a/test/configuration-tests/with-artifacts-path/check.ts +++ b/test/configuration-tests/with-artifacts-path/check.ts @@ -1,8 +1,8 @@ -import shell from "shelljs"; +import { rmSync } from "fs"; import { exec } from "../../utils/utils"; const NETWORK = process.env.NETWORK; exec("npx hardhat starknet-compile contracts/contract.cairo"); exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} my-starknet-artifacts/contracts/contract.cairo/ --inputs 10`); -shell.rm("-rf", "my-starknet-artifacts"); +rmSync("my-starknet-artifacts", { recursive: true, force: true }); diff --git a/test/configuration-tests/with-deploy-inputs/check.ts b/test/configuration-tests/with-deploy-inputs/check.ts index 65afebaa..20c733f5 100644 --- a/test/configuration-tests/with-deploy-inputs/check.ts +++ b/test/configuration-tests/with-deploy-inputs/check.ts @@ -3,5 +3,9 @@ import { exec } from "../../utils/utils"; const NETWORK = process.env.NETWORK; exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK}`); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK} --salt 0x10`); +exec( + `npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK}` +); +exec( + `npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK} --salt 0x10` +); diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts index 965acc1a..41f413ad 100644 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.ts +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -1,16 +1,17 @@ -import shell from "shelljs"; +import { copyFileSync } from "fs"; +import path from "path"; import { contains, exec } from "../../utils/utils"; const CONTRACT_NAME = "contract_with_unwhitelisted_hints.cairo"; const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); -exec(`cp $(dirname "$0")/${CONTRACT_NAME} ${CONTRACT_PATH}`); +copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); const EXPECTED = `Hint is not whitelisted. This may indicate that this library function cannot be used in StarkNet contracts.`; -shell.echo("Testing rejection of compilation without the --disable-hint-validation flag"); +console.log("Testing rejection of compilation without the --disable-hint-validation flag"); contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); -shell.echo("Success"); +console.log("Success"); exec(`npx hardhat starknet-compile ${CONTRACT_PATH} --disable-hint-validation`); diff --git a/test/configuration-tests/with-networks/check.ts b/test/configuration-tests/with-networks/check.ts new file mode 100644 index 00000000..b3f0a49a --- /dev/null +++ b/test/configuration-tests/with-networks/check.ts @@ -0,0 +1,30 @@ +import { exec } from "../../utils/utils"; +import path from "path"; + + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +const ARTIFACT_PATH = "starknet-artifacts/contracts/contract.cairo/"; +const INVALID_NETWORK = "foo"; +const PREFIX = path.join(__dirname); + +console.log("Testing no starknet network"); +exec(`npx hardhat starknet-deploy ${ARTIFACT_PATH} --inputs 10 2>&1 \ +| tail -n +2 \ +| diff - ${path.join(PREFIX, "without-starknet-network.txt")}`); +console.log("Success"); + +console.log("Testing invalid CLI network"); +exec(`npx hardhat starknet-deploy --starknet-network ${INVALID_NETWORK} ${ARTIFACT_PATH} --inputs 10 2>&1 \ +| tail -n +2 \ +| diff - ${path.join(PREFIX, "invalid-cli-network.txt")}`); +console.log("Success"); + +console.log("Testing no mocha network"); +exec("NETWORK='' npx hardhat test --no-compile test/contract-factory-test.ts"); +console.log("Success"); + +console.log("Testing invalid config network"); +exec(`NETWORK=${INVALID_NETWORK} npx hardhat test --no-compile test/contract-factory-test.ts 2>&1 \ +| tail -n +2 \ +| diff - ${path.join(PREFIX, "invalid-config-network.txt")}`); +console.log("Success"); diff --git a/test/general-tests/account-test/check.ts b/test/general-tests/account-test/check.ts index ba81c1f9..82c3324c 100644 --- a/test/general-tests/account-test/check.ts +++ b/test/general-tests/account-test/check.ts @@ -4,7 +4,7 @@ import shell from "shelljs"; exec("npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo"); exec("npx hardhat test --no-compile test/oz-account-test.ts"); -if (process.env.NETWORK == "devnet") { +if (process.env.NETWORK === "devnet") { exec("npx hardhat test --no-compile scripts/deploy-argent.ts"); shell.env.TOKEN_ADDRESS = "0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488"; @@ -12,7 +12,7 @@ if (process.env.NETWORK == "devnet") { shell.env.SENDER_PRIVATE_KEY = process.env.OZ_ACCOUNT_PRIVATE_KEY; shell.env.SENDER_IMPLEMENTATION = "OpenZeppelin"; shell.env.RECIPIENT_ADDRESS = process.env.ARGENT_ACCOUNT_ADDRESS; - shell.env.TRANSFER_AMOUNT = "0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488"; + shell.env.TRANSFER_AMOUNT = "1000000000000000000"; exec("npx hardhat test --no-compile scripts/transfer-funds.ts"); } diff --git a/test/general-tests/cairo-migrate/check.ts b/test/general-tests/cairo-migrate/check.ts new file mode 100644 index 00000000..94fbd880 --- /dev/null +++ b/test/general-tests/cairo-migrate/check.ts @@ -0,0 +1,19 @@ +import { copyFileSync } from "fs"; +import path from "path"; +import { contains, exec } from "../../utils/utils"; + +const CONTRACT_NAME = "old_contract.cairo"; +const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); +const NEW_COMMENT = "// Declare this file as a StarkNet contract."; + +copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); + +console.log("Testing migration of old cairo contract to a new one"); +// Migrate contract to new version. +contains(`npx hardhat migrate ${CONTRACT_PATH}`, NEW_COMMENT, "stdout"); + +// Migrate contract to new version with change content in place option. +exec(`npx hardhat migrate ${CONTRACT_PATH} --inplace`); +contains(`cat ${CONTRACT_PATH}`, NEW_COMMENT, "stdout"); + +console.log("Success"); diff --git a/test/general-tests/constructor-test/check.ts b/test/general-tests/constructor-test/check.ts new file mode 100644 index 00000000..c9752f05 --- /dev/null +++ b/test/general-tests/constructor-test/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/contract.cairo contracts/simple_storage.cairo contracts/empty_constructor.cairo"); +exec("npx hardhat test --no-compile test/constructor.test.ts"); diff --git a/test/general-tests/declare-test/check.ts b/test/general-tests/declare-test/check.ts new file mode 100644 index 00000000..15d3ddb2 --- /dev/null +++ b/test/general-tests/declare-test/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/contract.cairo contracts/deployer.cairo"); +exec("npx hardhat test --no-compile test/declare-deploy.test.ts"); diff --git a/test/general-tests/decode-event-test/check.ts b/test/general-tests/decode-event-test/check.ts new file mode 100644 index 00000000..8166a8eb --- /dev/null +++ b/test/general-tests/decode-event-test/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/events.cairo"); +exec("npx hardhat test --no-compile test/decode-events.test.ts"); diff --git a/test/general-tests/devnet-block-time/check.ts b/test/general-tests/devnet-block-time/check.ts new file mode 100644 index 00000000..d188ded2 --- /dev/null +++ b/test/general-tests/devnet-block-time/check.ts @@ -0,0 +1,3 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat test --no-compile test/devnet-time-test.ts"); diff --git a/test/general-tests/devnet-create-block/check.ts b/test/general-tests/devnet-create-block/check.ts new file mode 100644 index 00000000..29947da3 --- /dev/null +++ b/test/general-tests/devnet-create-block/check.ts @@ -0,0 +1,3 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat test --no-compile test/devnet-create-block.test.ts"); diff --git a/test/general-tests/devnet-dump-and-load/check.ts b/test/general-tests/devnet-dump-and-load/check.ts new file mode 100644 index 00000000..43330543 --- /dev/null +++ b/test/general-tests/devnet-dump-and-load/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/devnet-dump-and-load.test.ts"); diff --git a/test/general-tests/devnet-restart/check.ts b/test/general-tests/devnet-restart/check.ts new file mode 100644 index 00000000..b044218f --- /dev/null +++ b/test/general-tests/devnet-restart/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/devnet-restart.test.ts"); diff --git a/test/general-tests/expect-error-on-compile/check.ts b/test/general-tests/expect-error-on-compile/check.ts new file mode 100644 index 00000000..ac9c8d93 --- /dev/null +++ b/test/general-tests/expect-error-on-compile/check.ts @@ -0,0 +1,13 @@ +import { copyFileSync } from "fs"; +import path from "path"; +import { contains } from "../../utils/utils"; + + +const CONTRACT_NAME = "invalid_contract.cairo"; +const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); + +copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); + +console.log("Testing rejection of compilation with correct message"); +contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'"); +console.log("Success"); diff --git a/test/general-tests/function-argument-number/check.ts b/test/general-tests/function-argument-number/check.ts new file mode 100644 index 00000000..ffb4538a --- /dev/null +++ b/test/general-tests/function-argument-number/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/function-args-test.ts"); diff --git a/test/general-tests/getContractFactory/check.ts b/test/general-tests/getContractFactory/check.ts new file mode 100644 index 00000000..3ac38b16 --- /dev/null +++ b/test/general-tests/getContractFactory/check.ts @@ -0,0 +1,4 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile"); +exec("npx hardhat test --no-compile test/path-test.ts"); diff --git a/test/general-tests/hardhat-run/check.ts b/test/general-tests/hardhat-run/check.ts new file mode 100644 index 00000000..782e5618 --- /dev/null +++ b/test/general-tests/hardhat-run/check.ts @@ -0,0 +1,5 @@ + +console.log("$0: Testing hh run with --starknet-network is currently disabled"); + +// npx hardhat starknet-compile contracts/contract.cairo +// npx hardhat run --no-compile scripts/quick-script.ts --starknet-network "$NETWORK" diff --git a/test/general-tests/plain/check.ts b/test/general-tests/plain/check.ts new file mode 100644 index 00000000..8113749a --- /dev/null +++ b/test/general-tests/plain/check.ts @@ -0,0 +1,10 @@ +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; +const INITIAL_VALUE = 10; +const PUBLIC_KEY = "1628448741648245036800002906075225705100596136133912895015035902954123957052"; + +exec("npx hardhat starknet-compile"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network ${NETWORK} --inputs ${INITIAL_VALUE}`); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/auth_contract.cairo/ --inputs "${PUBLIC_KEY} ${INITIAL_VALUE}" --starknet-network ${NETWORK}`); +exec("npx hardhat test --no-compile test/sample-test.ts"); diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts new file mode 100644 index 00000000..444ff872 --- /dev/null +++ b/test/general-tests/postman/check.ts @@ -0,0 +1,9 @@ +import { exec } from "../../utils/utils"; + +exec("trap 'kill $(jobs -p)' EXIT"); + +exec("npx hardhat starknet-compile contracts/l1l2.cairo"); +exec(`npx hardhat node & +sleep 1`); + +exec("npx hardhat test --network localhost test/postman.test.ts"); diff --git a/test/general-tests/predeployed-accounts-test/check.ts b/test/general-tests/predeployed-accounts-test/check.ts new file mode 100644 index 00000000..ac99e475 --- /dev/null +++ b/test/general-tests/predeployed-accounts-test/check.ts @@ -0,0 +1,3 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat test --no-compile test/get-predeployed-accounts.test.ts"); diff --git a/test/general-tests/proxy-call/check.ts b/test/general-tests/proxy-call/check.ts new file mode 100644 index 00000000..40b32950 --- /dev/null +++ b/test/general-tests/proxy-call/check.ts @@ -0,0 +1,3 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat test --no-compile scripts/delegate-proxy.ts"); diff --git a/test/general-tests/relative-artifact-test/check.ts b/test/general-tests/relative-artifact-test/check.ts new file mode 100644 index 00000000..19cd122d --- /dev/null +++ b/test/general-tests/relative-artifact-test/check.ts @@ -0,0 +1,7 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo"); + +exec("cp -a starknet-artifacts/contracts test/test-artifacts"); + +exec("npx hardhat test --no-compile test/relative-artifacts.test.ts"); diff --git a/test/general-tests/short-string-test/check.ts b/test/general-tests/short-string-test/check.ts new file mode 100644 index 00000000..507f941f --- /dev/null +++ b/test/general-tests/short-string-test/check.ts @@ -0,0 +1,7 @@ +import { exec } from "../../utils/utils"; + +process.chdir(".."); + +// The config file used for running mocha tests is the one in root + +exec("npx hardhat test --no-compile test/general-tests/short-string-test/short-string-test.ts"); diff --git a/test/general-tests/starknet-call/check.ts b/test/general-tests/starknet-call/check.ts new file mode 100644 index 00000000..05e4ca7d --- /dev/null +++ b/test/general-tests/starknet-call/check.ts @@ -0,0 +1,40 @@ +import path from "path"; +import { exec, extractAddress } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +console.log(output.stdout); + +const ADDRESS = extractAddress(output.stdout, "Contract address: "); +const PREFIX = path.join(__dirname); + + +console.log("Testing no input argument"); +exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} 2>&1 \ +| tail -n +6 \ +| diff - ${path.join(PREFIX, "no-inputs.txt")}`); +console.log("Success"); + +console.log("Testing too few input arguments"); +exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30" 2>&1 \ +| tail -n +6 \ +| diff - ${path.join(PREFIX, "too-few-inputs.txt")}`); +console.log("Success"); + +console.log("Testing too many input arguments"); +exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40 50" 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "too-many-inputs.txt")}`); +console.log("Success"); + +console.log("The success case of starknet-call test is temporarily disabled."); +console.log("To enable it back, uncomment the lines in its check.sh."); +// console.log("Testing success case"); +// exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40" 2>&1 \ +// | tail -n +2 \ +// | head -n -3 \ +// | diff - <(echo "40 60")`); +// console.log("Success"); diff --git a/test/general-tests/starknet-estimate-fee/check.ts b/test/general-tests/starknet-estimate-fee/check.ts new file mode 100644 index 00000000..7efd2095 --- /dev/null +++ b/test/general-tests/starknet-estimate-fee/check.ts @@ -0,0 +1,37 @@ +import path from "path"; +import { exec, extractAddress } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); + +const ADDRESS = extractAddress(output.stdout, "Contract address: "); +const PREFIX = path.join(__dirname); + +console.log("Testing no input argument"); +exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "no-inputs.txt")}`); +console.log("Success"); + +console.log("Testing too few input arguments"); +exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30" 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "too-few-inputs.txt")}`); +console.log("Success"); + +console.log("Testing too many input arguments"); +exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40 50" 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "too-many-inputs.txt")}`); +console.log("Success"); + +console.log("The success case of starknet-estimate-fee test is temporarily disabled."); +console.log("To enable it back, uncomment the lines in its check.sh."); +// console.log("Testing success case"); +// exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40" 2>&1 \ +// | tail -n +2 \ +// | head -n -3 \ +// | diff - <(echo "40 60")`); +// console.log("Success"); diff --git a/test/general-tests/starknet-invoke/check.ts b/test/general-tests/starknet-invoke/check.ts new file mode 100644 index 00000000..ac935ded --- /dev/null +++ b/test/general-tests/starknet-invoke/check.ts @@ -0,0 +1,37 @@ +import path from "path"; +import { exec, extractAddress } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); + +const ADDRESS = extractAddress(output.stdout, "Contract address: "); +const PREFIX = path.join(__dirname); + +console.log("Testing no input argument"); +exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "no-inputs.txt")}`); +console.log("Success"); + +console.log("Testing too few input arguments"); +exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} --inputs 10 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "too-few-inputs.txt")}`); +console.log("Success"); + +console.log("Testing too many input arguments"); +exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} --inputs "10 20 30" 2>&1 \ + | tail -n +6 \ + | diff - ${path.join(PREFIX, "too-many-inputs.txt")}`); +console.log("Success"); + +console.log("The success case of starknet-invoke test is temporarily disabled."); +console.log("To enable it back, uncomment the lines in its check.sh."); +// console.log("Testing success case"); +// exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} --inputs "10 20" 2>&1 \ +// | tail -n +2\ +// | head -n -5\ +// | diff - <(echo "Invoke transaction was sent.")`); +// console.log("Success"); diff --git a/test/general-tests/starknet-new-account/check.ts b/test/general-tests/starknet-new-account/check.ts new file mode 100644 index 00000000..0750825e --- /dev/null +++ b/test/general-tests/starknet-new-account/check.ts @@ -0,0 +1,30 @@ +import { readFileSync } from "fs"; +import path from "path"; +import shell from "shelljs"; +import { exec, extractAddress } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; +const HOME = process.env.HOME; + +const ACCOUNT_DIR = path.join(`${HOME}`, ".starknet_new_account_test"); +process.env.ACCOUNT_DIR = ACCOUNT_DIR; +const ACCOUNT_FILE_PATH = path.join(ACCOUNT_DIR, "starknet_open_zeppelin_accounts.json"); + +const output = exec(`npx hardhat starknet-new-account --wallet OpenZeppelin --starknet-network ${NETWORK}`); +const ACCOUNT_ADDRESS_FROM_STD = extractAddress(output.stdout, "Account address: "); + +// Read newly created account and grab the address +const ACCOUNT_FILE = readFileSync(ACCOUNT_FILE_PATH); +const ACCOUNT_ADDRESS_FROM_FILE = JSON.parse(ACCOUNT_FILE.toString())[`${NETWORK}`].OpenZeppelin.address; + +// Change hex to int +const addressOne = parseInt(ACCOUNT_ADDRESS_FROM_STD, 16); +const addressTwo = parseInt(ACCOUNT_ADDRESS_FROM_FILE, 16); + +// If address_one and address_two are equal then success +if (addressOne === addressTwo) { + console.log("Success"); +} else { + console.log("Failed"); + shell.exit(1); +} diff --git a/test/general-tests/starknet-plugin-version/check.ts b/test/general-tests/starknet-plugin-version/check.ts new file mode 100644 index 00000000..0e01ea0c --- /dev/null +++ b/test/general-tests/starknet-plugin-version/check.ts @@ -0,0 +1,3 @@ +import { exec } from "../../utils/utils"; + +exec("npx hardhat starknet-plugin-version"); diff --git a/test/general-tests/starknet-verify/check.ts b/test/general-tests/starknet-verify/check.ts new file mode 100644 index 00000000..c28db68b --- /dev/null +++ b/test/general-tests/starknet-verify/check.ts @@ -0,0 +1,32 @@ +import { exec, extractAddress } from "../../utils/utils"; +import shell from "shelljs"; + +console.log("The starknet-verify test is too flaky so it is temporarily suspended. Make sure it's working!"); +shell.exit(0); + +const NETWORK = process.env.NETWORK; + +const MAIN_CONTRACT = "contracts/contract.cairo"; +const UTIL_CONTRACT = "contracts/util.cairo"; + +exec(`npx hardhat starknet-compile ${MAIN_CONTRACT} ${UTIL_CONTRACT}`); + +console.log("Waiting for deployment to be accepted"); +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} contract --inputs 10 --wait`); +const address = extractAddress(output.stdout, "Contract address: "); +console.log("Verifying contract at $address"); + +console.log("Sleeping to allow Voyager to index the deployment"); +exec("sleep 1m"); + +exec(`npx hardhat starknet-verify --starknet-network ${NETWORK} --path ${MAIN_CONTRACT} ${UTIL_CONTRACT} --address ${address} --compiler-version 0.9.0 --license "No License (None)" --account-contract false`); +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("$0: Error: Not verified!"); + shell.exit(1); +} diff --git a/test/general-tests/wallet-test/check.ts b/test/general-tests/wallet-test/check.ts new file mode 100644 index 00000000..94aa7170 --- /dev/null +++ b/test/general-tests/wallet-test/check.ts @@ -0,0 +1,20 @@ +import path from "path"; +import { exec, extractAddress } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +const HOME = process.env.HOME; +const ACCOUNT_DIR = path.join(`${HOME}`, ".starknet_accounts_wallet_test"); +process.env.ACCOUNT_DIR = ACCOUNT_DIR; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); + +exec("bash ../scripts/deploy-funded-cli-account.sh"); + +exec("npx hardhat test --no-compile test/wallet-test.ts"); + +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +const ADDRESS = extractAddress(output.stdout, "Contract address: "); + +exec(`npx hardhat starknet-call --contract contract --function get_balance --address ${ADDRESS} --wallet OpenZeppelin --starknet-network ${NETWORK}`); +exec(`npx hardhat starknet-invoke --contract contract --function increase_balance --inputs "10 20" --address ${ADDRESS} --wallet OpenZeppelin --starknet-network ${NETWORK}`); diff --git a/test/integrated-devnet-tests/with-active-venv-args/check.ts b/test/integrated-devnet-tests/with-active-venv-args/check.ts new file mode 100644 index 00000000..72d50060 --- /dev/null +++ b/test/integrated-devnet-tests/with-active-venv-args/check.ts @@ -0,0 +1,6 @@ +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/integrated-devnet-args.test.ts"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-active-venv/check.ts b/test/integrated-devnet-tests/with-active-venv/check.ts index 8594a21e..64651257 100644 --- a/test/integrated-devnet-tests/with-active-venv/check.ts +++ b/test/integrated-devnet-tests/with-active-venv/check.ts @@ -1,4 +1,8 @@ -// import { exec } from "../../utils/utils"; +import path from "path"; +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; -// exec("npx hardhat starknet-compile contracts/contract.cairo"); -// exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); +exec(`bash ${path.join(__dirname, "venv.sh")}`); +checkDevnetIsNotRunning(); +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-active-venv/venv.sh b/test/integrated-devnet-tests/with-active-venv/venv.sh new file mode 100644 index 00000000..1b9b9269 --- /dev/null +++ b/test/integrated-devnet-tests/with-active-venv/venv.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +source ../my-venv/bin/activate diff --git a/test/integrated-devnet-tests/with-default/check.ts b/test/integrated-devnet-tests/with-default/check.ts new file mode 100644 index 00000000..31bd48fb --- /dev/null +++ b/test/integrated-devnet-tests/with-default/check.ts @@ -0,0 +1,6 @@ +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts new file mode 100644 index 00000000..687eae61 --- /dev/null +++ b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts @@ -0,0 +1,15 @@ +import { spawn } from "child_process"; +import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; + +exec("kill $(lsof -t -i:5050)"); + +checkDevnetIsNotRunning(); + +const cmd = "starknet-devnet --host 127.0.0.1 --port 5050 --accounts 0"; +const args = cmd.split(" ").slice(1); + +// run devnet which will cause integrated-devnet to fail +spawn("starknet-devnet", args, { detached: true }); +exec("npx hardhat starknet-compile contracts/contract.cairo"); + +contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "127.0.0.1:5050 already occupied."); diff --git a/test/integrated-devnet-tests/with-docker-args/check.ts b/test/integrated-devnet-tests/with-docker-args/check.ts new file mode 100644 index 00000000..72d50060 --- /dev/null +++ b/test/integrated-devnet-tests/with-docker-args/check.ts @@ -0,0 +1,6 @@ +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/integrated-devnet-args.test.ts"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts new file mode 100644 index 00000000..7adcf3cf --- /dev/null +++ b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts @@ -0,0 +1,7 @@ +import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); + +exec("npx hardhat starknet-compile contracts/contract.cairo"); + +contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); diff --git a/test/integrated-devnet-tests/with-docker/check.ts b/test/integrated-devnet-tests/with-docker/check.ts new file mode 100644 index 00000000..31bd48fb --- /dev/null +++ b/test/integrated-devnet-tests/with-docker/check.ts @@ -0,0 +1,6 @@ +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts new file mode 100644 index 00000000..0339ab26 --- /dev/null +++ b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts @@ -0,0 +1,26 @@ +import shell from "shelljs"; +import { existsSync, readFileSync } from "fs"; +import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); + + +const EXPECTED_STDOUT = "Account #0"; +const EXPECTED_WARNING = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", EXPECTED_WARNING); + +// 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(EXPECTED_STDOUT)) { + console.error(`Expected stderr to contain ${EXPECTED_STDOUT}`); + shell.exit(1); + } +} else { + console.log("Expected logs/stdout.log to exist"); +} + +console.log("Success"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts new file mode 100644 index 00000000..0c7b4dd7 --- /dev/null +++ b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts @@ -0,0 +1,6 @@ +import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); + +exec("npx hardhat starknet-compile contracts/contract.cairo"); +contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.ts b/test/integrated-devnet-tests/with-stderr-to-file/check.ts new file mode 100644 index 00000000..1e080f59 --- /dev/null +++ b/test/integrated-devnet-tests/with-stderr-to-file/check.ts @@ -0,0 +1,31 @@ +import shell from "shelljs"; +import { existsSync, readFileSync } from "fs"; +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); + +exec("npx hardhat starknet-compile contracts/contract.cairo"); + +const EXPECTED_STDOUT = "Account #0"; +const EXPECTED_WARNING = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; + +const output = exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); +// Checks if output contains the expected string from stdout +if (!output.includes(EXPECTED_STDOUT)) { + console.log(`Expected output to contain ${EXPECTED_STDOUT}`); + shell.exit(1); +} + +// 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(EXPECTED_WARNING)) { + console.error(`Expected stderr to contain ${EXPECTED_WARNING}`); + shell.exit(1); + } +} else { + console.log("Expected logs/stderr.log to exist"); +} + +console.log("Success"); +checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts new file mode 100644 index 00000000..8ea21bdd --- /dev/null +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts @@ -0,0 +1,14 @@ +import { spawn } from "child_process"; +import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; + +exec("kill $(lsof -t -i:5050)"); + +checkDevnetIsNotRunning(); + +const cmd = "starknet-devnet --host 127.0.0.1 --port 5050 --accounts 0"; +const args = cmd.split(" ").slice(1); + +spawn("starknet-devnet", args, { detached: true }); +exec("npx hardhat starknet-compile contracts/contract.cairo"); + +contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "127.0.0.1:5050 already occupied."); diff --git a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts new file mode 100644 index 00000000..7adcf3cf --- /dev/null +++ b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts @@ -0,0 +1,7 @@ +import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); + +exec("npx hardhat starknet-compile contracts/contract.cairo"); + +contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); diff --git a/test/integrated-devnet-tests/with-venv/check.ts b/test/integrated-devnet-tests/with-venv/check.ts new file mode 100644 index 00000000..31bd48fb --- /dev/null +++ b/test/integrated-devnet-tests/with-venv/check.ts @@ -0,0 +1,6 @@ +import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; + +checkDevnetIsNotRunning(); +exec("npx hardhat starknet-compile contracts/contract.cairo"); +exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); +checkDevnetIsNotRunning(); diff --git a/test/recompilation-tests/hardhat-run/check.ts b/test/recompilation-tests/hardhat-run/check.ts index b10c79c6..8dd49605 100644 --- a/test/recompilation-tests/hardhat-run/check.ts +++ b/test/recompilation-tests/hardhat-run/check.ts @@ -1,10 +1,11 @@ -import shell from "shelljs"; +import { rmSync } from "fs"; import { exec } from "../../utils/utils"; -shell.echo("should recompile with deleted artifact on hardhat run"); -shell.rm("-rf", "starknet-artifacts/contracts/contract.cairo"); +// Hardhat run command +console.log("should recompile with deleted artifact on hardhat run"); +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); exec("npx hardhat run scripts/deploy.ts"); -shell.echo("should recompile with cache file deleted on hardhat run"); -shell.rm("-rf", "cache/cairo-files-cache.json"); +console.log("should recompile with cache file deleted on hardhat run"); +rmSync("cache/cairo-files-cache.json", { recursive: true, force: true }); exec("npx hardhat run scripts/deploy.ts"); diff --git a/test/recompilation-tests/hardhat-test/check.ts b/test/recompilation-tests/hardhat-test/check.ts new file mode 100644 index 00000000..5893f96d --- /dev/null +++ b/test/recompilation-tests/hardhat-test/check.ts @@ -0,0 +1,58 @@ +import { rmSync, copyFileSync, readFileSync } from "fs"; +import path from "path"; +import shell from "shelljs"; +import { exec } from "../../utils/utils"; + +const PREFIX = path.join(__dirname); +const CONTRACT_NAME = "contract_test_cache.cairo"; +const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); + +const DEPENDENCY_NAME = "dependency.cairo"; +const DEPENDENCY_PATH = path.join("contracts", DEPENDENCY_NAME); + +rmSync(DEPENDENCY_PATH, { recursive: true, force: true }); +rmSync(CONTRACT_PATH, { recursive: true, force: true }); +// Hardhat test command +console.log("Testing Recompilation with new contract added"); +copyFileSync(path.join(PREFIX, CONTRACT_NAME), CONTRACT_PATH); +copyFileSync(path.join(PREFIX, DEPENDENCY_NAME), DEPENDENCY_PATH); + +exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); + +console.log("Testing Recompilation with artifacts deleted"); +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); +exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); + +console.log("Testing Recompilation with updated contract"); +// Appending a new function to the contract +exec(`cat ${path.join(PREFIX, "get_balance.cairo")} >> contracts/contract_test_cache.cairo`); +exec("npx hardhat test --no-compile test/recompilation/recompilation-update-test.ts"); + +console.log("Testing Recompilation with cache file deleted"); +rmSync("cache/cairo-files-cache.json", { recursive: true, force: true }); +exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); + +console.log("Testing Recompilation with dependency changed"); +exec(`echo "//" >> ${DEPENDENCY_PATH}`); +exec("npx hardhat test --no-compile test/recompilation/recompilation-dependency-test.ts"); + +console.log("Testing Recompilation with source deleted"); +copyFileSync("cache/cairo-files-cache.json", "cache-content-before.json"); +rmSync("contracts/contract_test_cache.cairo", { recursive: true, force: true }); +exec("npx hardhat test --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)) { + console.log("Cache file was not updated"); + shell.exit(1); +} + +console.log("Testing Recompilation one contract added another deleted"); +rmSync("contracts/contract_test_cache.cairo", { force: true }); +rmSync("contracts/dependency.cairo", { force: true }); + +const CONTRACT_WITH_NO_DEPENDENCY = "contract_test_cache_no_dependency.cairo"; +copyFileSync(path.join(PREFIX, CONTRACT_WITH_NO_DEPENDENCY), CONTRACT_PATH); + +exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); diff --git a/test/recompilation-tests/recompiler-default/check.ts b/test/recompilation-tests/recompiler-default/check.ts new file mode 100644 index 00000000..322f07ba --- /dev/null +++ b/test/recompilation-tests/recompiler-default/check.ts @@ -0,0 +1,8 @@ +import { rmSync } from "fs"; +import { contains } from "../../utils/utils"; + +const EXPECTED = "StarknetPluginError: Artifact expected to be at"; + +console.log("Testing with deleted artifact on recompiler option set to default (off)"); +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); +contains("npx hardhat run --no-compile scripts/deploy.ts", EXPECTED); diff --git a/test/recompilation-tests/recompiler-off/check.ts b/test/recompilation-tests/recompiler-off/check.ts new file mode 100644 index 00000000..78d32f49 --- /dev/null +++ b/test/recompilation-tests/recompiler-off/check.ts @@ -0,0 +1,9 @@ +import { rmSync } from "fs"; +import { contains } from "../../utils/utils"; + +const EXPECTED = "StarknetPluginError: Artifact expected to be at"; + +console.log("Testing with deleted artifact on recompiler option set to default (off)"); +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); +contains("npx hardhat run --no-compile scripts/deploy.ts", EXPECTED); +console.log("Success"); diff --git a/test/recompilation-tests/starknet-call/check.ts b/test/recompilation-tests/starknet-call/check.ts new file mode 100644 index 00000000..1fe0b178 --- /dev/null +++ b/test/recompilation-tests/starknet-call/check.ts @@ -0,0 +1,11 @@ +import { rmSync } from "fs"; +import { extractAddress, exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +console.log("Testing Recompilation with deleted artifact on starknet-call"); +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +const address = extractAddress(output.stdout, "Contract address: "); + +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); +exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`); diff --git a/test/recompilation-tests/starknet-deploy/check.ts b/test/recompilation-tests/starknet-deploy/check.ts new file mode 100644 index 00000000..1d8ce423 --- /dev/null +++ b/test/recompilation-tests/starknet-deploy/check.ts @@ -0,0 +1,9 @@ +import { rmSync } from "fs"; +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +// Hardhat starknet-deploy command +console.log("Testing Recompilation with deleted artifact on starknet-deploy"); +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); +exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); diff --git a/test/recompilation-tests/starknet-invoke/check.ts b/test/recompilation-tests/starknet-invoke/check.ts new file mode 100644 index 00000000..e56cea2b --- /dev/null +++ b/test/recompilation-tests/starknet-invoke/check.ts @@ -0,0 +1,26 @@ +import { rmSync } from "fs"; +import path from "path"; +import { exec, extractAddress } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +// Hardhat starknet-invoke command +console.log("Testing Recompilation with deleted artifact on hardhat starknet-invoke"); +const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +// Grab the output Contract address to a variable using parameter expansion +const address = extractAddress(output.stdout, "Contract address: "); +// Remove artifact contract to force recompilation +rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); +const HOME = process.env.HOME; +const ACCOUNT_DIR = path.join(`${HOME}`, ".starknet_accounts_recompile_test"); +process.env.ACCOUNT_DIR = ACCOUNT_DIR; + +exec("bash ../scripts/deploy-funded-cli-account.sh"); + +exec(`npx hardhat starknet-invoke \ + --starknet-network ${NETWORK} \ + --contract contract \ + --function increase_balance \ + --address ${address} \ + --inputs "10 20" \ + --wallet OpenZeppelin`); diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 6afb6597..b8fdf389 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -9,8 +9,18 @@ export function exec(cmd: string) { return result; } -export function contains(cmd: string, pattern: string) { - const res = shell.exec(cmd, { silent: true }).stderr; // Also needed for stdout +export function contains(cmd: string, pattern: string, responseType?: string) { + if (responseType === "stdout") { + const res = shell.exec(cmd, { silent: true }).stdout; + if (!res.includes(pattern)) { + console.error("Pattern not in input"); + console.error("Pattern:", pattern); + console.error("Input:", res); + shell.exit(1); + } + return; + } + const res = shell.exec(cmd, { silent: true }).stderr; if (!res.includes(pattern)) { console.error("Pattern not in input"); console.error("Pattern:", pattern); @@ -18,3 +28,23 @@ export function contains(cmd: string, pattern: string) { shell.exit(1); } } + +export function extractAddress(source: string, pattern: string) { + // Replaces all line breaks with a space + source = source.replace(/(\r\n|\n|\r)/gm, " "); + // Take the first word in source after the pattern + const res = source.split(pattern)[1].split(" ")[0]; + return res; +} + +export function checkDevnetIsNotRunning(): void { + const result = shell.exec("curl -s -o /dev/null -w \"%{http_code}\" http://127.0.0.1:5050/feeder_gateway/is_alive", { silent: true }); + if (result.code !== 0) { + shell.echo("Devnet is not running!", result); + } + + if (result.stdout !== "000") { + shell.echo("Devnet is running and responded with status", result); + shell.exit(1); + } +} diff --git a/test/venv-tests/with-venv-active/check.ts b/test/venv-tests/with-venv-active/check.ts new file mode 100644 index 00000000..dd0b586e --- /dev/null +++ b/test/venv-tests/with-venv-active/check.ts @@ -0,0 +1,10 @@ +import path from "path"; +import { exec } from "../../utils/utils"; + +const NETWORK = process.env.NETWORK; + +exec(`bash ${path.join(__dirname, "venv.sh")}`); +const INITIAL_VALUE = 10; + +exec("npx hardhat starknet-compile"); +exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network ${NETWORK} --inputs ${INITIAL_VALUE}`); diff --git a/test/venv-tests/with-venv-active/venv.sh b/test/venv-tests/with-venv-active/venv.sh new file mode 100644 index 00000000..1b9b9269 --- /dev/null +++ b/test/venv-tests/with-venv-active/venv.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +source ../my-venv/bin/activate From 2c56e9eaea6db7a87b1af5611381354d1e34f5b6 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Mon, 14 Nov 2022 14:31:52 +0300 Subject: [PATCH 07/41] Make venv files executable --- test/integrated-devnet-tests/with-active-venv/venv.sh | 0 test/venv-tests/with-venv-active/venv.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/integrated-devnet-tests/with-active-venv/venv.sh mode change 100644 => 100755 test/venv-tests/with-venv-active/venv.sh diff --git a/test/integrated-devnet-tests/with-active-venv/venv.sh b/test/integrated-devnet-tests/with-active-venv/venv.sh old mode 100644 new mode 100755 diff --git a/test/venv-tests/with-venv-active/venv.sh b/test/venv-tests/with-venv-active/venv.sh old mode 100644 new mode 100755 From a0cc8c176b6d466f09702aceea1bc700f22fab5f Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Mon, 14 Nov 2022 14:35:37 +0300 Subject: [PATCH 08/41] Update test call to mocha --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 548d86cd..596562bf 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -72,7 +72,7 @@ function iterate_dir() { # check if test_case/check.ts exists if [ -f "$test_case/check.ts" ]; then # run the test - NETWORK="$network" npx hardhat test --no-compile "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" + NETWORK="$network" npx mocha -r ts-node/register "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" fi # NETWORK="$network" "$test_case/check.sh" && success=$((success + 1)) || echo "Test failed!" From d11676006a68bc8b53c49d57b29e9667e9ab30f7 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 15 Nov 2022 10:36:32 +0300 Subject: [PATCH 09/41] Update test - Use spawn to detach bg process - add --no-compile flag --- test/configuration-tests/with-networks/check.ts | 7 +++---- test/general-tests/postman/check.ts | 14 +++++++++++--- .../with-docker-address-occupied/check.ts | 6 +++++- .../with-venv-address-occupied/check.ts | 6 +++++- test/recompilation-tests/hardhat-run/check.ts | 4 ++-- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/test/configuration-tests/with-networks/check.ts b/test/configuration-tests/with-networks/check.ts index b3f0a49a..f2065968 100644 --- a/test/configuration-tests/with-networks/check.ts +++ b/test/configuration-tests/with-networks/check.ts @@ -1,10 +1,11 @@ -import { exec } from "../../utils/utils"; +import { contains, exec } from "../../utils/utils"; import path from "path"; exec("npx hardhat starknet-compile contracts/contract.cairo"); const ARTIFACT_PATH = "starknet-artifacts/contracts/contract.cairo/"; const INVALID_NETWORK = "foo"; +const EXPECTED = "Error in plugin Starknet: Invalid network provided in starknet.network in hardhat.config: foo."; const PREFIX = path.join(__dirname); console.log("Testing no starknet network"); @@ -24,7 +25,5 @@ exec("NETWORK='' npx hardhat test --no-compile test/contract-factory-test.ts"); console.log("Success"); console.log("Testing invalid config network"); -exec(`NETWORK=${INVALID_NETWORK} npx hardhat test --no-compile test/contract-factory-test.ts 2>&1 \ -| tail -n +2 \ -| diff - ${path.join(PREFIX, "invalid-config-network.txt")}`); +contains(`NETWORK=${INVALID_NETWORK} npx hardhat test --no-compile test/contract-factory-test.ts`, EXPECTED); console.log("Success"); diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index 444ff872..d8f203dc 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -1,9 +1,17 @@ import { exec } from "../../utils/utils"; +import shell from "shelljs"; +import { spawn } from "child_process"; -exec("trap 'kill $(jobs -p)' EXIT"); +const res = shell.exec("lsof -t -i:8545"); +if (res.code === 0) { + exec("kill -9 $(lsof -t -i:8545)"); +} exec("npx hardhat starknet-compile contracts/l1l2.cairo"); -exec(`npx hardhat node & -sleep 1`); +const cmd = "npx hardhat node"; +const args = cmd.split(" ").slice(1); + +spawn("npx", args, { detached: true }); +exec("sleep 1"); exec("npx hardhat test --network localhost test/postman.test.ts"); diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts index 687eae61..982b0f9c 100644 --- a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts @@ -1,7 +1,11 @@ import { spawn } from "child_process"; import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; +import shell from "shelljs"; -exec("kill $(lsof -t -i:5050)"); +const res = shell.exec("lsof -t -i:5050"); +if (res.code === 0) { + exec("kill -9 $(lsof -t -i:5050)"); +} checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts index 8ea21bdd..b6c6c353 100644 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts @@ -1,7 +1,11 @@ import { spawn } from "child_process"; import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; +import shell from "shelljs"; -exec("kill $(lsof -t -i:5050)"); +const res = shell.exec("lsof -t -i:5050"); +if (res.code === 0) { + exec("kill -9 $(lsof -t -i:5050)"); +} checkDevnetIsNotRunning(); diff --git a/test/recompilation-tests/hardhat-run/check.ts b/test/recompilation-tests/hardhat-run/check.ts index 8dd49605..0940b600 100644 --- a/test/recompilation-tests/hardhat-run/check.ts +++ b/test/recompilation-tests/hardhat-run/check.ts @@ -4,8 +4,8 @@ import { exec } from "../../utils/utils"; // Hardhat run command console.log("should recompile with deleted artifact on hardhat run"); rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -exec("npx hardhat run scripts/deploy.ts"); +exec("npx hardhat run --no-compile scripts/deploy.ts"); console.log("should recompile with cache file deleted on hardhat run"); rmSync("cache/cairo-files-cache.json", { recursive: true, force: true }); -exec("npx hardhat run scripts/deploy.ts"); +exec("npx hardhat run --no-compile scripts/deploy.ts"); From 0e3bcbac72d3e2515826ba61d185eb8022bd7bb4 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 15 Nov 2022 10:56:02 +0300 Subject: [PATCH 10/41] Terminate detached processes --- test/general-tests/postman/check.ts | 1 + .../with-docker-address-occupied/check.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index d8f203dc..c2c8a7d6 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -15,3 +15,4 @@ spawn("npx", args, { detached: true }); exec("sleep 1"); exec("npx hardhat test --network localhost test/postman.test.ts"); +exec("kill -9 $(lsof -t -i:8545)"); diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts index 982b0f9c..7f89bba4 100644 --- a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts @@ -17,3 +17,4 @@ spawn("starknet-devnet", args, { detached: true }); exec("npx hardhat starknet-compile contracts/contract.cairo"); contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "127.0.0.1:5050 already occupied."); +exec("kill -9 $(lsof -t -i:5050)"); From 2ca78f05e21cc4500e70f5d76198147334bd05c2 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 15 Nov 2022 11:11:34 +0300 Subject: [PATCH 11/41] Terminate detached processes --- test/integrated-devnet-tests/with-venv-address-occupied/check.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts index b6c6c353..fbceaea2 100644 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts @@ -16,3 +16,4 @@ spawn("starknet-devnet", args, { detached: true }); exec("npx hardhat starknet-compile contracts/contract.cairo"); contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "127.0.0.1:5050 already occupied."); +exec("kill -9 $(lsof -t -i:5050)"); From c904bb9a71ca109bb510fd727ba2cf255c56ff49 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 15 Nov 2022 11:28:13 +0300 Subject: [PATCH 12/41] Update starknet-devnet version --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index e52ea855..a7f8ee28 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { "CAIRO_LANG": "0.10.1", - "STARKNET_DEVNET": "0.3.4" + "STARKNET_DEVNET": "0.3.5" } From 96def07a1e4f0cc929e8a6fb0872940f6e48bb1e Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 15 Nov 2022 14:37:12 +0300 Subject: [PATCH 13/41] Update dev docs [skip ci] --- README-dev.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README-dev.md b/README-dev.md index 055b0621..3e931043 100644 --- a/README-dev.md +++ b/README-dev.md @@ -38,11 +38,11 @@ If your IDE is reporting Typescript issues after compiling the plugin, you may w A test case is added by creating a directory in a subdirectory of a test group in the `test` directory. E.g. `declare-test` is a test case in the `general-tests` test group. A test case should contain: -- a `check.sh` script which does the testing logic +- a `check.ts` script which does the testing logic - a `network.json` file which specifies on which networks should the test case be run - a `hardhat.config.ts` file will be used -The main testing script is `scripts/test.sh`. It iterates over the test cases the test group specified by the `TEST_SUBDIR` environment variable. +The main testing script is `scripts/test.ts`. It iterates over the test cases the test group specified by the `TEST_SUBDIR` environment variable. ### Executing tests locally @@ -50,7 +50,7 @@ When running tests locally, you probably don't want to run the whole `test.sh` s - positioning yourself in your example repository - configuring the `hardhat.config.ts` -- executing the `check.sh` script (potentially modifying it to address path differences) +- executing the `check.ts` script (potentially modifying it to address path differences) To run all tests, you can use the `test-` scripts defined in `package.json`. For the tests to work, you may need to set the values from `config.json` as environment variables. You should also have the [`jq` CLI tool](https://stedolan.github.io/jq/) installed. From 6c2ef529c2597e0bbe2e06a8651aba54d9f44cdd Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 17 Nov 2022 10:48:41 +0300 Subject: [PATCH 14/41] Remove prev comment from test.sh --- scripts/test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 63e29d7d..36d37e8c 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -74,7 +74,6 @@ function iterate_dir() { # run the test NETWORK="$network" npx mocha -r ts-node/register "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!" fi - # NETWORK="$network" "$test_case/check.sh" && success=$((success + 1)) || echo "Test failed!" rm -rf starknet-artifacts git checkout --force From 90d81ba7ccb763ac3fcd5737e57973de68a0ce81 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 17 Nov 2022 10:51:53 +0300 Subject: [PATCH 15/41] Use path.join in place of concat --- .../with-account-compilation-option/check.ts | 2 +- .../with-disable-hint-compilation-option/check.ts | 2 +- test/general-tests/cairo-migrate/check.ts | 2 +- test/general-tests/expect-error-on-compile/check.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/configuration-tests/with-account-compilation-option/check.ts b/test/configuration-tests/with-account-compilation-option/check.ts index de532478..387a77c0 100644 --- a/test/configuration-tests/with-account-compilation-option/check.ts +++ b/test/configuration-tests/with-account-compilation-option/check.ts @@ -3,7 +3,7 @@ import path from "path"; import { contains, exec } from "../../utils/utils"; const CONTRACT_NAME = "dummy_account.cairo"; -const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); +const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); const EXPECTED = "Use the --account-contract flag to compile an account contract."; diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts index 41f413ad..e639ce5b 100644 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.ts +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -3,7 +3,7 @@ import path from "path"; import { contains, exec } from "../../utils/utils"; const CONTRACT_NAME = "contract_with_unwhitelisted_hints.cairo"; -const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); +const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); diff --git a/test/general-tests/cairo-migrate/check.ts b/test/general-tests/cairo-migrate/check.ts index 94fbd880..4628af32 100644 --- a/test/general-tests/cairo-migrate/check.ts +++ b/test/general-tests/cairo-migrate/check.ts @@ -3,7 +3,7 @@ import path from "path"; import { contains, exec } from "../../utils/utils"; const CONTRACT_NAME = "old_contract.cairo"; -const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); +const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); const NEW_COMMENT = "// Declare this file as a StarkNet contract."; copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); diff --git a/test/general-tests/expect-error-on-compile/check.ts b/test/general-tests/expect-error-on-compile/check.ts index ac9c8d93..18240574 100644 --- a/test/general-tests/expect-error-on-compile/check.ts +++ b/test/general-tests/expect-error-on-compile/check.ts @@ -4,7 +4,7 @@ import { contains } from "../../utils/utils"; const CONTRACT_NAME = "invalid_contract.cairo"; -const CONTRACT_PATH = "contracts/".concat(CONTRACT_NAME); +const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); From aa04ee4fa1a8d1345d89c467599009e1953400bb Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 16:08:35 +0300 Subject: [PATCH 16/41] Update utils - Remove shell.exit, shell.echo - Use axios inplace of curl - Update contains function --- test/utils/utils.ts | 50 ++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/test/utils/utils.ts b/test/utils/utils.ts index b8fdf389..5ed47509 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -1,31 +1,23 @@ +import axios from "axios"; +import { rmSync } from "fs"; import shell from "shelljs"; +import { StarknetPluginError } from "../../src/starknet-plugin-error"; export function exec(cmd: string) { const result = shell.exec(cmd); if (result.code !== 0) { - shell.exit(1); + throw new StarknetPluginError(`Command ${cmd} failed.\n${result.stderr}`); } return result; } -export function contains(cmd: string, pattern: string, responseType?: string) { - if (responseType === "stdout") { - const res = shell.exec(cmd, { silent: true }).stdout; - if (!res.includes(pattern)) { - console.error("Pattern not in input"); - console.error("Pattern:", pattern); - console.error("Input:", res); - shell.exit(1); - } - return; - } - const res = shell.exec(cmd, { silent: true }).stderr; - if (!res.includes(pattern)) { +export function contains(output: string, pattern: string) { + if (!output.includes(pattern)) { console.error("Pattern not in input"); console.error("Pattern:", pattern); - console.error("Input:", res); - shell.exit(1); + console.error("Input:", output); + throw new StarknetPluginError("Pattern not in input"); } } @@ -37,14 +29,26 @@ export function extractAddress(source: string, pattern: string) { return res; } -export function checkDevnetIsNotRunning(): void { - const result = shell.exec("curl -s -o /dev/null -w \"%{http_code}\" http://127.0.0.1:5050/feeder_gateway/is_alive", { silent: true }); - if (result.code !== 0) { - shell.echo("Devnet is not running!", result); +export async function checkDevnetIsNotRunning(url?: string): Promise { + url = url || "http://127.0.0.1:5050"; + try { + const res = await axios.get(`${url}/is_alive`); + console.log(`Devnet is running and responded with status ${res.status}`); + throw new StarknetPluginError(`Devnet is running and responded with status ${res.status}`); + } catch (err) { + if (err.toJSON().code == "ECONNREFUSED") { + console.log("Devnet is not running!"); + } } +} - if (result.stdout !== "000") { - shell.echo("Devnet is running and responded with status", result); - shell.exit(1); +export function ensureEnvVar(varName: string): string { + if (!process.env[varName]) { + throw new Error(`Env var ${varName} not set or empty`); } + return process.env[varName] as string; +} + +export function rmrfSync(path: string) { + rmSync(path, { recursive: true, force: true }); } From 58238d73851091a4cec407599d12c310da8e2656 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 16:09:29 +0300 Subject: [PATCH 17/41] Have create-fund-deploy script --- test/utils/deploy-funded-account.ts | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/utils/deploy-funded-account.ts diff --git a/test/utils/deploy-funded-account.ts b/test/utils/deploy-funded-account.ts new file mode 100644 index 00000000..bd5da8c9 --- /dev/null +++ b/test/utils/deploy-funded-account.ts @@ -0,0 +1,39 @@ +import axios from "axios"; +import { readFileSync } from "fs"; +import path from "path"; +import { StarknetPluginError } from "../../src/starknet-plugin-error"; +import { hardhatStarknetDeployAccount, hardhatStarknetNewAccount } from "./cli-functions"; +import { ensureEnvVar } from "./utils"; + +export async function deployFundedAccount(url?: string) { + const network = ensureEnvVar("NETWORK"); + const accountDir = ensureEnvVar("ACCOUNT_DIR"); + + if (network !== "devnet") { + throw new StarknetPluginError("only works with NETWORK set to devnet"); + } + + const args = [ + "--starknet-network", + network, + "--wallet", + "OpenZeppelin" + ]; + + // Creates new account + hardhatStarknetNewAccount(args); + + const accountFile = path.join(`${accountDir}`, "starknet_open_zeppelin_accounts.json"); + const accountAddress = JSON.parse(readFileSync(accountFile, "utf-8"))[`${network}`].OpenZeppelin.address; + + console.log(`Funding account ${accountAddress} on ${network}.`); + url = url || "http://127.0.0.1:5050"; + await axios.post(`${url}/mint`, { + address: accountAddress, + amount: 1000000000000000000n, + lite: true + }); + + // Deploying funded account on the network + hardhatStarknetDeployAccount(args); +} From 5ff203a6a77c84c1e2aff8788d2c229b316b193e Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 16:09:52 +0300 Subject: [PATCH 18/41] Add starknet cli helper functions --- test/utils/cli-functions.ts | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/utils/cli-functions.ts diff --git a/test/utils/cli-functions.ts b/test/utils/cli-functions.ts new file mode 100644 index 00000000..57cd333f --- /dev/null +++ b/test/utils/cli-functions.ts @@ -0,0 +1,50 @@ +import shell from "shelljs"; + +const exec = (cmd: string, silet?: boolean) => { + silet = silet || false; + return shell.exec(cmd, { silent: silet }); +}; + +export const hardhatStarknetCompile = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-compile ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetDeploy = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-deploy ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetInvoke = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-invoke ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetCall = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-call ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetEstimateFee = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-estimate-fee ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetNewAccount = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-new-account ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetDeployAccount = (args: Array, silet?: boolean) => { + return exec(`npx hardhat starknet-deploy-account ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetRun = (args: Array, silet?: boolean) => { + return exec(`npx hardhat run ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetTest = (args: Array, silet?: boolean) => { + return exec(`npx hardhat test ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetMigrate = (args: Array, silet?: boolean) => { + return exec(`npx hardhat migrate ${args.join(" ")}`, silet); +}; + +export const hardhatStarknetPluginVersion = () => { + return exec("npx hardhat starknet-plugin-version"); +}; From 7a6cc5aa067178a173242e2b7c0548817f790291 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 16:14:20 +0300 Subject: [PATCH 19/41] Update test based on comments --- .../with-account-compilation-option/check.ts | 17 +++--- .../with-artifacts-path/check.ts | 12 ++-- .../with-cairo-version/check.ts | 9 +-- .../with-cli-network/check.ts | 6 +- .../with-cli-paths/check.ts | 9 +-- .../with-deploy-inputs/check.ts | 15 ++--- .../with-deploy-path/check.ts | 11 ++-- .../check.ts | 16 ++--- .../with-networks/check.ts | 32 +++++----- .../with-networks/invalid-cli-network.txt | 2 - .../without-starknet-network.txt | 2 - .../with-sources-path/check.ts | 13 ++-- test/configuration-tests/with-wait/check.ts | 9 +-- test/general-tests/account-test/check.ts | 25 ++++---- test/general-tests/cairo-migrate/check.ts | 20 ++++--- test/general-tests/constructor-test/check.ts | 6 +- test/general-tests/declare-test/check.ts | 6 +- test/general-tests/decode-event-test/check.ts | 6 +- test/general-tests/devnet-block-time/check.ts | 4 +- .../devnet-create-block/check.ts | 4 +- .../devnet-dump-and-load/check.ts | 6 +- test/general-tests/devnet-restart/check.ts | 6 +- .../expect-error-on-compile/check.ts | 11 ++-- .../function-argument-number/check.ts | 6 +- .../general-tests/getContractFactory/check.ts | 6 +- test/general-tests/hardhat-run/check.ts | 7 ++- test/general-tests/plain/check.ts | 17 +++--- test/general-tests/postman/check.ts | 17 ++---- .../predeployed-accounts-test/check.ts | 4 +- test/general-tests/proxy-call/check.ts | 4 +- .../relative-artifact-test/check.ts | 5 +- test/general-tests/short-string-test/check.ts | 4 +- test/general-tests/starknet-call/check.ts | 36 +++++------ .../general-tests/starknet-call/no-inputs.txt | 3 - .../starknet-call/too-few-inputs.txt | 3 - .../starknet-call/too-many-inputs.txt | 3 - .../starknet-estimate-fee/check.ts | 35 +++++------ .../starknet-estimate-fee/no-inputs.txt | 3 - .../starknet-estimate-fee/too-few-inputs.txt | 3 - .../starknet-estimate-fee/too-many-inputs.txt | 3 - test/general-tests/starknet-invoke/check.ts | 35 +++++------ .../starknet-invoke/no-inputs.txt | 3 - .../starknet-invoke/too-few-inputs.txt | 3 - .../starknet-invoke/too-many-inputs.txt | 3 - .../starknet-new-account/check.ts | 32 +++++----- .../starknet-plugin-version/check.ts | 4 +- test/general-tests/starknet-verify/check.ts | 21 +++---- test/general-tests/wallet-test/check.ts | 29 +++++---- .../with-active-venv-args/check.ts | 13 ++-- .../with-active-venv/check.ts | 11 ++-- .../with-default/check.ts | 13 ++-- .../with-docker-address-occupied/check.ts | 28 ++++----- .../with-docker-args/check.ts | 13 ++-- .../with-docker-wrong-cli/check.ts | 15 +++-- .../with-docker/check.ts | 13 ++-- .../with-stderr-to-STDERR/check.ts | 40 +++++++------ .../with-stderr-to-STDOUT/check.ts | 13 ++-- .../with-stderr-to-file/check.ts | 48 +++++++-------- .../with-venv-address-occupied/check.ts | 26 ++++---- .../with-venv-wrong-cli/check.ts | 13 ++-- .../with-venv/check.ts | 13 ++-- test/recompilation-tests/hardhat-run/check.ts | 12 ++-- .../recompilation-tests/hardhat-test/check.ts | 60 +++++++++---------- .../recompiler-default/check.ts | 11 ++-- .../recompiler-off/check.ts | 11 ++-- .../starknet-call/check.ts | 12 ++-- .../starknet-deploy/check.ts | 10 ++-- .../starknet-invoke/check.ts | 32 +++++----- test/venv-tests/with-venv-active/check.ts | 11 ++-- test/venv-tests/with-venv/check.ts | 13 ++-- 70 files changed, 481 insertions(+), 486 deletions(-) diff --git a/test/configuration-tests/with-account-compilation-option/check.ts b/test/configuration-tests/with-account-compilation-option/check.ts index 387a77c0..30db2e57 100644 --- a/test/configuration-tests/with-account-compilation-option/check.ts +++ b/test/configuration-tests/with-account-compilation-option/check.ts @@ -1,15 +1,16 @@ import { copyFileSync } from "fs"; import path from "path"; -import { contains, exec } from "../../utils/utils"; +import { hardhatStarknetCompile } from "../../utils/cli-functions"; +import { contains } from "../../utils/utils"; -const CONTRACT_NAME = "dummy_account.cairo"; -const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); +const contractName = "dummy_account.cairo"; +const contractPath = path.join("contracts", contractName); -const EXPECTED = "Use the --account-contract flag to compile an account contract."; +const expected = "Use the --account-contract flag to compile an account contract."; console.log("Testing rejection of compilation without the account flag"); -copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); -contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); +copyFileSync(path.join(__dirname, contractName), contractPath); +const execution = hardhatStarknetCompile(contractPath.split(" "), true); +contains(execution.stderr, expected); console.log("Success"); - -exec(`npx hardhat starknet-compile ${CONTRACT_PATH} --account-contract`); +hardhatStarknetCompile(`${contractPath} --account-contract`.split(" ")); diff --git a/test/configuration-tests/with-artifacts-path/check.ts b/test/configuration-tests/with-artifacts-path/check.ts index ab4dcee7..bd555467 100644 --- a/test/configuration-tests/with-artifacts-path/check.ts +++ b/test/configuration-tests/with-artifacts-path/check.ts @@ -1,8 +1,8 @@ -import { rmSync } from "fs"; -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar, rmrfSync } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} my-starknet-artifacts/contracts/contract.cairo/ --inputs 10`); -rmSync("my-starknet-artifacts", { recursive: true, force: true }); +hardhatStarknetCompile("contracts/contract.cairo".split(" ")); +hardhatStarknetDeploy(`--starknet-network ${network} my-starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +rmrfSync("my-starknet-artifacts"); diff --git a/test/configuration-tests/with-cairo-version/check.ts b/test/configuration-tests/with-cairo-version/check.ts index de9f044b..d4b3b536 100644 --- a/test/configuration-tests/with-cairo-version/check.ts +++ b/test/configuration-tests/with-cairo-version/check.ts @@ -1,6 +1,7 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo --starknet-network ${NETWORK} --inputs 10`); +hardhatStarknetCompile("contracts/contract.cairo".split(" ")); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo --starknet-network ${network} --inputs 10`.split(" ")); diff --git a/test/configuration-tests/with-cli-network/check.ts b/test/configuration-tests/with-cli-network/check.ts index 9baad394..743d9775 100644 --- a/test/configuration-tests/with-cli-network/check.ts +++ b/test/configuration-tests/with-cli-network/check.ts @@ -1,9 +1,9 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetRun, hardhatStarknetTest } from "../../utils/cli-functions"; // Test how --starknet-network can be specified through CLI while at the same time // overriding hardhat.config specification. // It would be sufficient to run this test just once and not for both alpha and devnet. // Only tests if --starknet-network is accepted, not if the correct network is targeted. -exec("npx hardhat run --no-compile scripts/compile-contract.ts"); -exec("npx hardhat test --no-compile --starknet-network devnet test/quick-test.ts"); +hardhatStarknetRun("--no-compile scripts/compile-contract.ts".split(" ")); +hardhatStarknetTest("--no-compile --starknet-network devnet test/quick-test.ts".split(" ")); diff --git a/test/configuration-tests/with-cli-paths/check.ts b/test/configuration-tests/with-cli-paths/check.ts index 255c306c..da5878ec 100644 --- a/test/configuration-tests/with-cli-paths/check.ts +++ b/test/configuration-tests/with-cli-paths/check.ts @@ -1,6 +1,7 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +hardhatStarknetCompile("contracts/contract.cairo".split(" ")); +hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); diff --git a/test/configuration-tests/with-deploy-inputs/check.ts b/test/configuration-tests/with-deploy-inputs/check.ts index 20c733f5..9ea3ac53 100644 --- a/test/configuration-tests/with-deploy-inputs/check.ts +++ b/test/configuration-tests/with-deploy-inputs/check.ts @@ -1,11 +1,8 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec( - `npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK}` -); -exec( - `npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK} --salt 0x10` -); +hardhatStarknetCompile("contracts/contract.cairo".split(" ")); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network}`.split(" ")); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network} --salt 0x10`.split(" ")); diff --git a/test/configuration-tests/with-deploy-path/check.ts b/test/configuration-tests/with-deploy-path/check.ts index 2825959e..d95c0cf9 100644 --- a/test/configuration-tests/with-deploy-path/check.ts +++ b/test/configuration-tests/with-deploy-path/check.ts @@ -1,7 +1,8 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${NETWORK}`); -exec(`npx hardhat starknet-deploy contract --inputs "10" --starknet-network ${NETWORK}`); +hardhatStarknetCompile("contracts/contract.cairo".split(" ")); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network}`.split(" ")); +hardhatStarknetDeploy(`contract --inputs "10" --starknet-network ${network}`.split(" ")); diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts index e639ce5b..02c8ca73 100644 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.ts +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -1,17 +1,19 @@ import { copyFileSync } from "fs"; import path from "path"; -import { contains, exec } from "../../utils/utils"; +import { hardhatStarknetCompile } from "../../utils/cli-functions"; +import { contains } from "../../utils/utils"; -const CONTRACT_NAME = "contract_with_unwhitelisted_hints.cairo"; -const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); +const contractName = "contract_with_unwhitelisted_hints.cairo"; +const contractPath = path.join("contracts", contractName); -copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); +copyFileSync(path.join(__dirname, contractName), contractPath); -const EXPECTED = `Hint is not whitelisted. +const expected = `Hint is not whitelisted. This may indicate that this library function cannot be used in StarkNet contracts.`; console.log("Testing rejection of compilation without the --disable-hint-validation flag"); -contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, EXPECTED); +const execution = hardhatStarknetCompile([contractName], true); +contains(execution.stderr, expected); console.log("Success"); -exec(`npx hardhat starknet-compile ${CONTRACT_PATH} --disable-hint-validation`); +hardhatStarknetCompile(`${contractPath} --disable-hint-validation`.split(" ")); diff --git a/test/configuration-tests/with-networks/check.ts b/test/configuration-tests/with-networks/check.ts index f2065968..fb0a4128 100644 --- a/test/configuration-tests/with-networks/check.ts +++ b/test/configuration-tests/with-networks/check.ts @@ -1,29 +1,31 @@ -import { contains, exec } from "../../utils/utils"; +import { contains } from "../../utils/utils"; import path from "path"; +import { readFileSync } from "fs"; +import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; - -exec("npx hardhat starknet-compile contracts/contract.cairo"); -const ARTIFACT_PATH = "starknet-artifacts/contracts/contract.cairo/"; -const INVALID_NETWORK = "foo"; -const EXPECTED = "Error in plugin Starknet: Invalid network provided in starknet.network in hardhat.config: foo."; -const PREFIX = path.join(__dirname); +hardhatStarknetCompile(["contracts/contract.cairo"]); +const artifactsPath = "starknet-artifacts/contracts/contract.cairo/"; +const invalidNetwork = "foo"; +const expected = "Error in plugin Starknet: Invalid network provided in starknet.network in hardhat.config: foo."; +const prefix = path.join(__dirname); console.log("Testing no starknet network"); -exec(`npx hardhat starknet-deploy ${ARTIFACT_PATH} --inputs 10 2>&1 \ -| tail -n +2 \ -| diff - ${path.join(PREFIX, "without-starknet-network.txt")}`); +let execution = hardhatStarknetDeploy(`${artifactsPath} --inputs 10`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "without-starknet-network.txt")).toString()); console.log("Success"); console.log("Testing invalid CLI network"); -exec(`npx hardhat starknet-deploy --starknet-network ${INVALID_NETWORK} ${ARTIFACT_PATH} --inputs 10 2>&1 \ -| tail -n +2 \ -| diff - ${path.join(PREFIX, "invalid-cli-network.txt")}`); +execution = hardhatStarknetDeploy(`--starknet-network ${invalidNetwork} ${artifactsPath} --inputs 10`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "invalid-cli-network.txt")).toString()); console.log("Success"); console.log("Testing no mocha network"); -exec("NETWORK='' npx hardhat test --no-compile test/contract-factory-test.ts"); +process.env.NETWORK = ""; +hardhatStarknetTest("--no-compile test/contract-factory-test.ts".split(" ")); console.log("Success"); console.log("Testing invalid config network"); -contains(`NETWORK=${INVALID_NETWORK} npx hardhat test --no-compile test/contract-factory-test.ts`, EXPECTED); +process.env.NETWORK = invalidNetwork; +execution = hardhatStarknetTest("--no-compile test/contract-factory-test.ts".split(" "), true); +contains(execution.stderr, expected); console.log("Success"); diff --git a/test/configuration-tests/with-networks/invalid-cli-network.txt b/test/configuration-tests/with-networks/invalid-cli-network.txt index 0c683ad6..2c4b6baa 100644 --- a/test/configuration-tests/with-networks/invalid-cli-network.txt +++ b/test/configuration-tests/with-networks/invalid-cli-network.txt @@ -1,4 +1,2 @@ Error in plugin Starknet: Invalid network provided in starknet-network: foo. Valid hardhat networks: hardhat, localhost, devnet, alpha, alphaMainnet, integratedDevnet - -For more info run Hardhat with --show-stack-traces diff --git a/test/configuration-tests/with-networks/without-starknet-network.txt b/test/configuration-tests/with-networks/without-starknet-network.txt index 232c7046..997f7395 100644 --- a/test/configuration-tests/with-networks/without-starknet-network.txt +++ b/test/configuration-tests/with-networks/without-starknet-network.txt @@ -1,3 +1 @@ Error in plugin Starknet: No starknet-network or gateway-url provided. - -For more info run Hardhat with --show-stack-traces diff --git a/test/configuration-tests/with-sources-path/check.ts b/test/configuration-tests/with-sources-path/check.ts index 593f5d50..fc75cd6c 100644 --- a/test/configuration-tests/with-sources-path/check.ts +++ b/test/configuration-tests/with-sources-path/check.ts @@ -1,9 +1,10 @@ -import shell from "shelljs"; -import { exec } from "../../utils/utils"; +import { renameSync } from "fs"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -shell.mv("contracts", "my-starknet-sources"); +renameSync("contracts", "my-starknet-sources"); -exec("npx hardhat starknet-compile"); -exec(`npx hardhat starknet-deploy starknet-artifacts/my-starknet-sources/contract.cairo/ --starknet-network ${NETWORK} --inputs 10`); +hardhatStarknetCompile([]); +hardhatStarknetDeploy(`starknet-artifacts/my-starknet-sources/contract.cairo/ --starknet-network ${network} --inputs 10`.split(" ")); diff --git a/test/configuration-tests/with-wait/check.ts b/test/configuration-tests/with-wait/check.ts index 87ab9f8b..6ac81c86 100644 --- a/test/configuration-tests/with-wait/check.ts +++ b/test/configuration-tests/with-wait/check.ts @@ -1,6 +1,7 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/util.cairo"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/util.cairo/ --starknet-network ${NETWORK} --wait`); +hardhatStarknetCompile(["contracts/util.cairo"]); +hardhatStarknetDeploy(`starknet-artifacts/contracts/util.cairo/ --starknet-network ${network} --wait`.split(" ")); diff --git a/test/general-tests/account-test/check.ts b/test/general-tests/account-test/check.ts index 82c3324c..e9b9e4f7 100644 --- a/test/general-tests/account-test/check.ts +++ b/test/general-tests/account-test/check.ts @@ -1,19 +1,18 @@ -import { exec } from "../../utils/utils"; -import shell from "shelljs"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo"); -exec("npx hardhat test --no-compile test/oz-account-test.ts"); +hardhatStarknetCompile("contracts/contract.cairo contracts/util.cairo".split(" ")); +hardhatStarknetTest("--no-compile test/oz-account-test.ts".split(" ")); if (process.env.NETWORK === "devnet") { - exec("npx hardhat test --no-compile scripts/deploy-argent.ts"); + hardhatStarknetTest("--no-compile scripts/deploy-argent.ts".split(" ")); - shell.env.TOKEN_ADDRESS = "0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488"; - shell.env.SENDER_ADDRESS = process.env.OZ_ACCOUNT_ADDRESS; - shell.env.SENDER_PRIVATE_KEY = process.env.OZ_ACCOUNT_PRIVATE_KEY; - shell.env.SENDER_IMPLEMENTATION = "OpenZeppelin"; - shell.env.RECIPIENT_ADDRESS = process.env.ARGENT_ACCOUNT_ADDRESS; - shell.env.TRANSFER_AMOUNT = "1000000000000000000"; - exec("npx hardhat test --no-compile scripts/transfer-funds.ts"); + process.env.TOKEN_ADDRESS = "0x62230EA046A9A5FBC261AC77D03C8D41E5D442DB2284587570AB46455FD2488"; + process.env.SENDER_ADDRESS = process.env.OZ_ACCOUNT_ADDRESS; + process.env.SENDER_PRIVATE_KEY = process.env.OZ_ACCOUNT_PRIVATE_KEY; + process.env.SENDER_IMPLEMENTATION = "OpenZeppelin"; + process.env.RECIPIENT_ADDRESS = process.env.ARGENT_ACCOUNT_ADDRESS; + process.env.TRANSFER_AMOUNT = "1000000000000000000"; + hardhatStarknetTest("--no-compile scripts/transfer-funds.ts".split(" ")); } -exec("npx hardhat test --no-compile test/argent-account-test.ts"); +hardhatStarknetTest("--no-compile test/argent-account-test.ts".split(" ")); diff --git a/test/general-tests/cairo-migrate/check.ts b/test/general-tests/cairo-migrate/check.ts index 4628af32..11711842 100644 --- a/test/general-tests/cairo-migrate/check.ts +++ b/test/general-tests/cairo-migrate/check.ts @@ -1,19 +1,21 @@ -import { copyFileSync } from "fs"; +import { copyFileSync, readFileSync } from "fs"; import path from "path"; -import { contains, exec } from "../../utils/utils"; +import { hardhatStarknetMigrate } from "../../utils/cli-functions"; +import { contains } from "../../utils/utils"; -const CONTRACT_NAME = "old_contract.cairo"; -const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); -const NEW_COMMENT = "// Declare this file as a StarkNet contract."; +const contractName = "old_contract.cairo"; +const contractPath = path.join("contracts", contractName); +const newComment = "// Declare this file as a StarkNet contract."; -copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); +copyFileSync(path.join(__dirname, contractName), contractPath); console.log("Testing migration of old cairo contract to a new one"); // Migrate contract to new version. -contains(`npx hardhat migrate ${CONTRACT_PATH}`, NEW_COMMENT, "stdout"); +const execution = hardhatStarknetMigrate([contractPath], true); +contains(execution.stdout, newComment); // Migrate contract to new version with change content in place option. -exec(`npx hardhat migrate ${CONTRACT_PATH} --inplace`); -contains(`cat ${CONTRACT_PATH}`, NEW_COMMENT, "stdout"); +hardhatStarknetMigrate(`${contractPath} --inplace`.split(" ")); +contains(readFileSync(contractPath).toString(), newComment); console.log("Success"); diff --git a/test/general-tests/constructor-test/check.ts b/test/general-tests/constructor-test/check.ts index c9752f05..7ebb6ec8 100644 --- a/test/general-tests/constructor-test/check.ts +++ b/test/general-tests/constructor-test/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/contract.cairo contracts/simple_storage.cairo contracts/empty_constructor.cairo"); -exec("npx hardhat test --no-compile test/constructor.test.ts"); +hardhatStarknetCompile("contracts/contract.cairo contracts/simple_storage.cairo contracts/empty_constructor.cairo".split(" ")); +hardhatStarknetTest("--no-compile test/constructor.test.ts".split(" ")); diff --git a/test/general-tests/declare-test/check.ts b/test/general-tests/declare-test/check.ts index 15d3ddb2..c4a2d487 100644 --- a/test/general-tests/declare-test/check.ts +++ b/test/general-tests/declare-test/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/contract.cairo contracts/deployer.cairo"); -exec("npx hardhat test --no-compile test/declare-deploy.test.ts"); +hardhatStarknetCompile("contracts/contract.cairo contracts/deployer.cairo".split(" ")); +hardhatStarknetTest("--no-compile test/declare-deploy.test.ts".split(" ")); diff --git a/test/general-tests/decode-event-test/check.ts b/test/general-tests/decode-event-test/check.ts index 8166a8eb..7ce8a571 100644 --- a/test/general-tests/decode-event-test/check.ts +++ b/test/general-tests/decode-event-test/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/events.cairo"); -exec("npx hardhat test --no-compile test/decode-events.test.ts"); +hardhatStarknetCompile(["contracts/events.cairo"]); +hardhatStarknetTest("--no-compile test/decode-events.test.ts".split(" ")); diff --git a/test/general-tests/devnet-block-time/check.ts b/test/general-tests/devnet-block-time/check.ts index d188ded2..cac485e5 100644 --- a/test/general-tests/devnet-block-time/check.ts +++ b/test/general-tests/devnet-block-time/check.ts @@ -1,3 +1,3 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat test --no-compile test/devnet-time-test.ts"); +hardhatStarknetTest("--no-compile test/devnet-time-test.ts".split(" ")); diff --git a/test/general-tests/devnet-create-block/check.ts b/test/general-tests/devnet-create-block/check.ts index 29947da3..b0ec60a0 100644 --- a/test/general-tests/devnet-create-block/check.ts +++ b/test/general-tests/devnet-create-block/check.ts @@ -1,3 +1,3 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat test --no-compile test/devnet-create-block.test.ts"); +hardhatStarknetTest("--no-compile test/devnet-create-block.test.ts".split(" ")); diff --git a/test/general-tests/devnet-dump-and-load/check.ts b/test/general-tests/devnet-dump-and-load/check.ts index 43330543..049a0122 100644 --- a/test/general-tests/devnet-dump-and-load/check.ts +++ b/test/general-tests/devnet-dump-and-load/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/devnet-dump-and-load.test.ts"); +hardhatStarknetCompile(["contracts/contract.cairo"]); +hardhatStarknetTest("--no-compile test/devnet-dump-and-load.test.ts".split(" ")); diff --git a/test/general-tests/devnet-restart/check.ts b/test/general-tests/devnet-restart/check.ts index b044218f..4188b6ba 100644 --- a/test/general-tests/devnet-restart/check.ts +++ b/test/general-tests/devnet-restart/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/devnet-restart.test.ts"); +hardhatStarknetCompile(["contracts/contract.cairo"]); +hardhatStarknetTest("--no-compile test/devnet-restart.test.ts".split(" ")); diff --git a/test/general-tests/expect-error-on-compile/check.ts b/test/general-tests/expect-error-on-compile/check.ts index 18240574..c9b8d465 100644 --- a/test/general-tests/expect-error-on-compile/check.ts +++ b/test/general-tests/expect-error-on-compile/check.ts @@ -1,13 +1,14 @@ import { copyFileSync } from "fs"; import path from "path"; +import { hardhatStarknetCompile } from "../../utils/cli-functions"; import { contains } from "../../utils/utils"; +const contractName = "invalid_contract.cairo"; +const contractPath = path.join("contracts", contractName); -const CONTRACT_NAME = "invalid_contract.cairo"; -const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); - -copyFileSync(path.join(__dirname, CONTRACT_NAME), CONTRACT_PATH); +copyFileSync(path.join(__dirname, contractName), contractPath); console.log("Testing rejection of compilation with correct message"); -contains(`npx hardhat starknet-compile ${CONTRACT_PATH}`, "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'"); +const compileResult = hardhatStarknetCompile([contractPath], true); +contains(compileResult.stderr, "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'"); console.log("Success"); diff --git a/test/general-tests/function-argument-number/check.ts b/test/general-tests/function-argument-number/check.ts index ffb4538a..9cb60298 100644 --- a/test/general-tests/function-argument-number/check.ts +++ b/test/general-tests/function-argument-number/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/function-args-test.ts"); +hardhatStarknetCompile(["contracts/contract.cairo"]); +hardhatStarknetTest("--no-compile test/function-args-test.ts".split(" ")); diff --git a/test/general-tests/getContractFactory/check.ts b/test/general-tests/getContractFactory/check.ts index 3ac38b16..05eda6cf 100644 --- a/test/general-tests/getContractFactory/check.ts +++ b/test/general-tests/getContractFactory/check.ts @@ -1,4 +1,4 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat starknet-compile"); -exec("npx hardhat test --no-compile test/path-test.ts"); +hardhatStarknetCompile([]); +hardhatStarknetTest("--no-compile test/path-test.ts".split(" ")); diff --git a/test/general-tests/hardhat-run/check.ts b/test/general-tests/hardhat-run/check.ts index 782e5618..c6cfa2af 100644 --- a/test/general-tests/hardhat-run/check.ts +++ b/test/general-tests/hardhat-run/check.ts @@ -1,5 +1,8 @@ +// import { hardhatStarknetCompile, hardhatStarknetRun } from "../../utils/cli-functions"; +// import { ensureEnvVar } from "../../utils/utils"; console.log("$0: Testing hh run with --starknet-network is currently disabled"); +// const network = ensureEnvVar("NETWORK"); -// npx hardhat starknet-compile contracts/contract.cairo -// npx hardhat run --no-compile scripts/quick-script.ts --starknet-network "$NETWORK" +// hardhatStarknetCompile(["contracts/contract.cairo"]); +// hardhatStarknetRun(`--no-compile scripts/quick-script.ts --starknet-network ${network}`.split(" ")); diff --git a/test/general-tests/plain/check.ts b/test/general-tests/plain/check.ts index 8113749a..fb08c5fe 100644 --- a/test/general-tests/plain/check.ts +++ b/test/general-tests/plain/check.ts @@ -1,10 +1,11 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; -const INITIAL_VALUE = 10; -const PUBLIC_KEY = "1628448741648245036800002906075225705100596136133912895015035902954123957052"; +const network = ensureEnvVar("NETWORK"); +const initialValue = 10; +const publicKey = "1628448741648245036800002906075225705100596136133912895015035902954123957052"; -exec("npx hardhat starknet-compile"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network ${NETWORK} --inputs ${INITIAL_VALUE}`); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/auth_contract.cairo/ --inputs "${PUBLIC_KEY} ${INITIAL_VALUE}" --starknet-network ${NETWORK}`); -exec("npx hardhat test --no-compile test/sample-test.ts"); +hardhatStarknetCompile([]); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split(" ")); +hardhatStarknetDeploy(`starknet-artifacts/contracts/auth_contract.cairo/ --inputs "${publicKey} ${initialValue}" --starknet-network ${network}`.split(" ")); +hardhatStarknetTest("--no-compile test/sample-test.ts".split(" ")); diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index c2c8a7d6..f2193bda 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -1,18 +1,11 @@ import { exec } from "../../utils/utils"; -import shell from "shelljs"; import { spawn } from "child_process"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -const res = shell.exec("lsof -t -i:8545"); -if (res.code === 0) { - exec("kill -9 $(lsof -t -i:8545)"); -} +hardhatStarknetCompile(["contracts/l1l2.cairo"]); -exec("npx hardhat starknet-compile contracts/l1l2.cairo"); -const cmd = "npx hardhat node"; -const args = cmd.split(" ").slice(1); - -spawn("npx", args, { detached: true }); +const result = spawn("npx", ["hardhat", "node"], { detached: true }); exec("sleep 1"); -exec("npx hardhat test --network localhost test/postman.test.ts"); -exec("kill -9 $(lsof -t -i:8545)"); +hardhatStarknetTest("--network localhost test/postman.test.ts".split(" ")); +result.kill(); diff --git a/test/general-tests/predeployed-accounts-test/check.ts b/test/general-tests/predeployed-accounts-test/check.ts index ac99e475..b88e9ecf 100644 --- a/test/general-tests/predeployed-accounts-test/check.ts +++ b/test/general-tests/predeployed-accounts-test/check.ts @@ -1,3 +1,3 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat test --no-compile test/get-predeployed-accounts.test.ts"); +hardhatStarknetTest("--no-compile test/get-predeployed-accounts.test.ts".split(" ")); diff --git a/test/general-tests/proxy-call/check.ts b/test/general-tests/proxy-call/check.ts index 40b32950..240328c2 100644 --- a/test/general-tests/proxy-call/check.ts +++ b/test/general-tests/proxy-call/check.ts @@ -1,3 +1,3 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetTest } from "../../utils/cli-functions"; -exec("npx hardhat test --no-compile scripts/delegate-proxy.ts"); +hardhatStarknetTest("--no-compile scripts/delegate-proxy.ts".split(" ")); diff --git a/test/general-tests/relative-artifact-test/check.ts b/test/general-tests/relative-artifact-test/check.ts index 19cd122d..46680ce9 100644 --- a/test/general-tests/relative-artifact-test/check.ts +++ b/test/general-tests/relative-artifact-test/check.ts @@ -1,7 +1,8 @@ +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; import { exec } from "../../utils/utils"; -exec("npx hardhat starknet-compile contracts/contract.cairo contracts/util.cairo"); +hardhatStarknetCompile("contracts/contract.cairo contracts/util.cairo".split(" ")); exec("cp -a starknet-artifacts/contracts test/test-artifacts"); -exec("npx hardhat test --no-compile test/relative-artifacts.test.ts"); +hardhatStarknetTest("--no-compile test/relative-artifacts.test.ts".split(" ")); diff --git a/test/general-tests/short-string-test/check.ts b/test/general-tests/short-string-test/check.ts index 507f941f..ee90135c 100644 --- a/test/general-tests/short-string-test/check.ts +++ b/test/general-tests/short-string-test/check.ts @@ -1,7 +1,7 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetTest } from "../../utils/cli-functions"; process.chdir(".."); // The config file used for running mocha tests is the one in root -exec("npx hardhat test --no-compile test/general-tests/short-string-test/short-string-test.ts"); +hardhatStarknetTest("--no-compile test/general-tests/short-string-test/short-string-test.ts".split(" ")); diff --git a/test/general-tests/starknet-call/check.ts b/test/general-tests/starknet-call/check.ts index 05e4ca7d..3368a333 100644 --- a/test/general-tests/starknet-call/check.ts +++ b/test/general-tests/starknet-call/check.ts @@ -1,40 +1,36 @@ +import { readFileSync } from "fs"; import path from "path"; -import { exec, extractAddress } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetCall } from "../../utils/cli-functions"; +import { contains, ensureEnvVar, extractAddress } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +hardhatStarknetCompile(["contracts/contract.cairo"]); +const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" "), true); console.log(output.stdout); -const ADDRESS = extractAddress(output.stdout, "Contract address: "); -const PREFIX = path.join(__dirname); - +const address = extractAddress(output.stdout, "Contract address: "); +const prefix = path.join(__dirname); console.log("Testing no input argument"); -exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} 2>&1 \ -| tail -n +6 \ -| diff - ${path.join(PREFIX, "no-inputs.txt")}`); +let execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); -exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30" 2>&1 \ -| tail -n +6 \ -| diff - ${path.join(PREFIX, "too-few-inputs.txt")}`); +execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); -exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40 50" 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "too-many-inputs.txt")}`); +execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); console.log("The success case of starknet-call test is temporarily disabled."); console.log("To enable it back, uncomment the lines in its check.sh."); // console.log("Testing success case"); -// exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40" 2>&1 \ -// | tail -n +2 \ -// | head -n -3 \ -// | diff - <(echo "40 60")`); +// execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split(" "), true); +// contains(execution.stdout, "40 60"); // console.log("Success"); diff --git a/test/general-tests/starknet-call/no-inputs.txt b/test/general-tests/starknet-call/no-inputs.txt index 67093054..fb6b6ce5 100644 --- a/test/general-tests/starknet-call/no-inputs.txt +++ b/test/general-tests/starknet-call/no-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform call of sum_points_to_tuple: Error: AssertionError: Expected at least 4 inputs, got 0. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-call/too-few-inputs.txt b/test/general-tests/starknet-call/too-few-inputs.txt index 4c6be230..971373e1 100644 --- a/test/general-tests/starknet-call/too-few-inputs.txt +++ b/test/general-tests/starknet-call/too-few-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform call of sum_points_to_tuple: Error: AssertionError: Expected at least 4 inputs, got 3. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-call/too-many-inputs.txt b/test/general-tests/starknet-call/too-many-inputs.txt index 833a3546..bb147807 100644 --- a/test/general-tests/starknet-call/too-many-inputs.txt +++ b/test/general-tests/starknet-call/too-many-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform call of sum_points_to_tuple: Error: AssertionError: Wrong number of arguments. Expected 4, got 5. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-estimate-fee/check.ts b/test/general-tests/starknet-estimate-fee/check.ts index 7efd2095..a97234a2 100644 --- a/test/general-tests/starknet-estimate-fee/check.ts +++ b/test/general-tests/starknet-estimate-fee/check.ts @@ -1,37 +1,34 @@ +import { readFileSync } from "fs"; import path from "path"; -import { exec, extractAddress } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetEstimateFee } from "../../utils/cli-functions"; +import { contains, ensureEnvVar, extractAddress } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +hardhatStarknetCompile(["contracts/contract.cairo"]); +const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); -const ADDRESS = extractAddress(output.stdout, "Contract address: "); -const PREFIX = path.join(__dirname); +const address = extractAddress(output.stdout, "Contract address: "); +const prefix = path.join(__dirname); console.log("Testing no input argument"); -exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "no-inputs.txt")}`); +let execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); -exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30" 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "too-few-inputs.txt")}`); +execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); -exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40 50" 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "too-many-inputs.txt")}`); +execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); console.log("The success case of starknet-estimate-fee test is temporarily disabled."); console.log("To enable it back, uncomment the lines in its check.sh."); // console.log("Testing success case"); -// exec(`npx hardhat starknet-estimate-fee --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${ADDRESS} --inputs "10 20 30 40" 2>&1 \ -// | tail -n +2 \ -// | head -n -3 \ -// | diff - <(echo "40 60")`); +// execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split(" "), false); +// contains(execution.stdout, "40 60") // console.log("Success"); diff --git a/test/general-tests/starknet-estimate-fee/no-inputs.txt b/test/general-tests/starknet-estimate-fee/no-inputs.txt index 925b915d..a9e31505 100644 --- a/test/general-tests/starknet-estimate-fee/no-inputs.txt +++ b/test/general-tests/starknet-estimate-fee/no-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform estimateFee of sum_points_to_tuple: Error: AssertionError: Expected at least 4 inputs, got 0. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-estimate-fee/too-few-inputs.txt b/test/general-tests/starknet-estimate-fee/too-few-inputs.txt index e3fb1d05..802a4a3e 100644 --- a/test/general-tests/starknet-estimate-fee/too-few-inputs.txt +++ b/test/general-tests/starknet-estimate-fee/too-few-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform estimateFee of sum_points_to_tuple: Error: AssertionError: Expected at least 4 inputs, got 3. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-estimate-fee/too-many-inputs.txt b/test/general-tests/starknet-estimate-fee/too-many-inputs.txt index 937e8ea8..6e6d5332 100644 --- a/test/general-tests/starknet-estimate-fee/too-many-inputs.txt +++ b/test/general-tests/starknet-estimate-fee/too-many-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform estimateFee of sum_points_to_tuple: Error: AssertionError: Wrong number of arguments. Expected 4, got 5. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-invoke/check.ts b/test/general-tests/starknet-invoke/check.ts index ac935ded..919ae709 100644 --- a/test/general-tests/starknet-invoke/check.ts +++ b/test/general-tests/starknet-invoke/check.ts @@ -1,37 +1,34 @@ +import { readFileSync } from "fs"; import path from "path"; -import { exec, extractAddress } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetInvoke } from "../../utils/cli-functions"; +import { contains, ensureEnvVar, extractAddress } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +hardhatStarknetCompile(["contracts/contract.cairo"]); +const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); -const ADDRESS = extractAddress(output.stdout, "Contract address: "); -const PREFIX = path.join(__dirname); +const address = extractAddress(output.stdout, "Contract address: "); +const prefix = path.join(__dirname); console.log("Testing no input argument"); -exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "no-inputs.txt")}`); +let execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address}`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); -exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} --inputs 10 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "too-few-inputs.txt")}`); +execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs 10`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); -exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} --inputs "10 20 30" 2>&1 \ - | tail -n +6 \ - | diff - ${path.join(PREFIX, "too-many-inputs.txt")}`); +execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs "10 20 30"`.split(" "), true); +contains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); console.log("The success case of starknet-invoke test is temporarily disabled."); console.log("To enable it back, uncomment the lines in its check.sh."); // console.log("Testing success case"); -// exec(`npx hardhat starknet-invoke --starknet-network ${NETWORK} --contract contract --function increase_balance --address ${ADDRESS} --inputs "10 20" 2>&1 \ -// | tail -n +2\ -// | head -n -5\ -// | diff - <(echo "Invoke transaction was sent.")`); +// execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs "10 20"`.split(" "), true); +// contains(execution.stdout, "Invoke transaction was sent."); // console.log("Success"); diff --git a/test/general-tests/starknet-invoke/no-inputs.txt b/test/general-tests/starknet-invoke/no-inputs.txt index c88332c8..b3c48942 100644 --- a/test/general-tests/starknet-invoke/no-inputs.txt +++ b/test/general-tests/starknet-invoke/no-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform invoke of increase_balance: Error: AssertionError: Expected at least 1 inputs, got 0. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-invoke/too-few-inputs.txt b/test/general-tests/starknet-invoke/too-few-inputs.txt index 89215f24..9539dddb 100644 --- a/test/general-tests/starknet-invoke/too-few-inputs.txt +++ b/test/general-tests/starknet-invoke/too-few-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform invoke of increase_balance: Error: AssertionError: Expected at least 2 inputs, got 1. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-invoke/too-many-inputs.txt b/test/general-tests/starknet-invoke/too-many-inputs.txt index 3cef593f..c4f11c6e 100644 --- a/test/general-tests/starknet-invoke/too-many-inputs.txt +++ b/test/general-tests/starknet-invoke/too-many-inputs.txt @@ -1,5 +1,2 @@ Error in plugin Starknet: Could not perform invoke of increase_balance: Error: AssertionError: Wrong number of arguments. Expected 2, got 3. - - -For more info run Hardhat with --show-stack-traces diff --git a/test/general-tests/starknet-new-account/check.ts b/test/general-tests/starknet-new-account/check.ts index 0750825e..8d4dabd7 100644 --- a/test/general-tests/starknet-new-account/check.ts +++ b/test/general-tests/starknet-new-account/check.ts @@ -1,30 +1,30 @@ import { readFileSync } from "fs"; import path from "path"; -import shell from "shelljs"; -import { exec, extractAddress } from "../../utils/utils"; +import { StarknetPluginError } from "../../../src/starknet-plugin-error"; +import { hardhatStarknetNewAccount } from "../../utils/cli-functions"; +import { ensureEnvVar, extractAddress } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; -const HOME = process.env.HOME; +const network = ensureEnvVar("NETWORK"); +const home = ensureEnvVar("HOME"); -const ACCOUNT_DIR = path.join(`${HOME}`, ".starknet_new_account_test"); -process.env.ACCOUNT_DIR = ACCOUNT_DIR; -const ACCOUNT_FILE_PATH = path.join(ACCOUNT_DIR, "starknet_open_zeppelin_accounts.json"); +const accountDir = path.join(home, ".starknet_new_account_test"); +process.env.ACCOUNT_DIR = accountDir; +const accountFilePath = path.join(accountDir, "starknet_open_zeppelin_accounts.json"); -const output = exec(`npx hardhat starknet-new-account --wallet OpenZeppelin --starknet-network ${NETWORK}`); -const ACCOUNT_ADDRESS_FROM_STD = extractAddress(output.stdout, "Account address: "); +const output = hardhatStarknetNewAccount(`--wallet OpenZeppelin --starknet-network ${network}`.split(" ")); +const accountAddressStd = extractAddress(output.stdout, "Account address: "); // Read newly created account and grab the address -const ACCOUNT_FILE = readFileSync(ACCOUNT_FILE_PATH); -const ACCOUNT_ADDRESS_FROM_FILE = JSON.parse(ACCOUNT_FILE.toString())[`${NETWORK}`].OpenZeppelin.address; +const accountFile = readFileSync(accountFilePath); +const accountAddressFile = JSON.parse(accountFile.toString())[network].OpenZeppelin.address; // Change hex to int -const addressOne = parseInt(ACCOUNT_ADDRESS_FROM_STD, 16); -const addressTwo = parseInt(ACCOUNT_ADDRESS_FROM_FILE, 16); +const addressStd = parseInt(accountAddressStd, 16); +const addressFile = parseInt(accountAddressFile, 16); // If address_one and address_two are equal then success -if (addressOne === addressTwo) { +if (addressStd === addressFile) { console.log("Success"); } else { - console.log("Failed"); - shell.exit(1); + throw new StarknetPluginError("Addresses are not equal"); } diff --git a/test/general-tests/starknet-plugin-version/check.ts b/test/general-tests/starknet-plugin-version/check.ts index 0e01ea0c..ad011791 100644 --- a/test/general-tests/starknet-plugin-version/check.ts +++ b/test/general-tests/starknet-plugin-version/check.ts @@ -1,3 +1,3 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetPluginVersion } from "../../utils/cli-functions"; -exec("npx hardhat starknet-plugin-version"); +hardhatStarknetPluginVersion(); diff --git a/test/general-tests/starknet-verify/check.ts b/test/general-tests/starknet-verify/check.ts index c28db68b..9dd8f292 100644 --- a/test/general-tests/starknet-verify/check.ts +++ b/test/general-tests/starknet-verify/check.ts @@ -1,25 +1,26 @@ -import { exec, extractAddress } from "../../utils/utils"; -import shell from "shelljs"; +import { ensureEnvVar, exec, extractAddress } from "../../utils/utils"; +import { StarknetPluginError } from "../../../src/starknet-plugin-error"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; console.log("The starknet-verify test is too flaky so it is temporarily suspended. Make sure it's working!"); -shell.exit(0); +process.exit(0); -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); -const MAIN_CONTRACT = "contracts/contract.cairo"; -const UTIL_CONTRACT = "contracts/util.cairo"; +const mainContract = "contracts/contract.cairo"; +const utilContract = "contracts/util.cairo"; -exec(`npx hardhat starknet-compile ${MAIN_CONTRACT} ${UTIL_CONTRACT}`); +hardhatStarknetCompile(`${mainContract} ${utilContract}`.split(" ")); console.log("Waiting for deployment to be accepted"); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} contract --inputs 10 --wait`); +const output = hardhatStarknetDeploy(`--starknet-network ${network} contract --inputs 10 --wait`.split(" ")); const address = extractAddress(output.stdout, "Contract address: "); console.log("Verifying contract at $address"); console.log("Sleeping to allow Voyager to index the deployment"); exec("sleep 1m"); -exec(`npx hardhat starknet-verify --starknet-network ${NETWORK} --path ${MAIN_CONTRACT} ${UTIL_CONTRACT} --address ${address} --compiler-version 0.9.0 --license "No License (None)" --account-contract false`); +exec(`npx hardhat starknet-verify --starknet-network ${network} --path ${mainContract} ${utilContract} --address ${address} --compiler-version 0.9.0 --license "No License (None)" --account-contract false`); console.log("Sleeping to allow Voyager to register the verification"); exec("sleep 15s"); @@ -28,5 +29,5 @@ if (is_verified == "true") { console.log("Successfully verified!"); } else { console.log("$0: Error: Not verified!"); - shell.exit(1); + throw new StarknetPluginError("Error: Not verified!"); } diff --git a/test/general-tests/wallet-test/check.ts b/test/general-tests/wallet-test/check.ts index 94aa7170..f67572fa 100644 --- a/test/general-tests/wallet-test/check.ts +++ b/test/general-tests/wallet-test/check.ts @@ -1,20 +1,23 @@ import path from "path"; -import { exec, extractAddress } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest, hardhatStarknetDeploy, hardhatStarknetCall, hardhatStarknetInvoke } from "../../utils/cli-functions"; +import { deployFundedAccount } from "../../utils/deploy-funded-account"; +import { ensureEnvVar, extractAddress } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); +const home = ensureEnvVar("HOME"); -const HOME = process.env.HOME; -const ACCOUNT_DIR = path.join(`${HOME}`, ".starknet_accounts_wallet_test"); -process.env.ACCOUNT_DIR = ACCOUNT_DIR; +const accountDir = path.join(home, ".starknet_accounts_wallet_test"); +process.env.ACCOUNT_DIR = accountDir; -exec("npx hardhat starknet-compile contracts/contract.cairo"); +hardhatStarknetCompile(["contracts/contract.cairo"]); -exec("bash ../scripts/deploy-funded-cli-account.sh"); +(async () => { + await deployFundedAccount(); + hardhatStarknetTest("--no-compile test/wallet-test.ts".split(" ")); -exec("npx hardhat test --no-compile test/wallet-test.ts"); + const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); + const address = extractAddress(output.stdout, "Contract address: "); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); -const ADDRESS = extractAddress(output.stdout, "Contract address: "); - -exec(`npx hardhat starknet-call --contract contract --function get_balance --address ${ADDRESS} --wallet OpenZeppelin --starknet-network ${NETWORK}`); -exec(`npx hardhat starknet-invoke --contract contract --function increase_balance --inputs "10 20" --address ${ADDRESS} --wallet OpenZeppelin --starknet-network ${NETWORK}`); + hardhatStarknetCall(`--contract contract --function get_balance --address ${address} --wallet OpenZeppelin --starknet-network ${network}`.split(" ")); + hardhatStarknetInvoke(`--contract contract --function increase_balance --inputs "10 20" --address ${address} --wallet OpenZeppelin --starknet-network ${network}`.split(" ")); +})(); diff --git a/test/integrated-devnet-tests/with-active-venv-args/check.ts b/test/integrated-devnet-tests/with-active-venv-args/check.ts index 72d50060..05604214 100644 --- a/test/integrated-devnet-tests/with-active-venv-args/check.ts +++ b/test/integrated-devnet-tests/with-active-venv-args/check.ts @@ -1,6 +1,9 @@ -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; -checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/integrated-devnet-args.test.ts"); -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + hardhatStarknetTest("--no-compile test/integrated-devnet-args.test.ts".split(" ")); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-active-venv/check.ts b/test/integrated-devnet-tests/with-active-venv/check.ts index 64651257..b69e17d7 100644 --- a/test/integrated-devnet-tests/with-active-venv/check.ts +++ b/test/integrated-devnet-tests/with-active-venv/check.ts @@ -1,8 +1,11 @@ import path from "path"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; exec(`bash ${path.join(__dirname, "venv.sh")}`); -checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" ")); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-default/check.ts b/test/integrated-devnet-tests/with-default/check.ts index 31bd48fb..7fbc39ec 100644 --- a/test/integrated-devnet-tests/with-default/check.ts +++ b/test/integrated-devnet-tests/with-default/check.ts @@ -1,6 +1,9 @@ -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; -checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" ")); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts index 7f89bba4..c9629d2c 100644 --- a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts @@ -1,20 +1,16 @@ import { spawn } from "child_process"; -import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; -import shell from "shelljs"; +import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -const res = shell.exec("lsof -t -i:5050"); -if (res.code === 0) { - exec("kill -9 $(lsof -t -i:5050)"); -} +(async () => { + await checkDevnetIsNotRunning(); + // run devnet which will cause integrated-devnet to fail + const result = spawn("starknet-devnet", "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), { detached: true }); + hardhatStarknetCompile(["contracts/contract.cairo"]); -checkDevnetIsNotRunning(); + const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + contains(execution.stderr, "127.0.0.1:5050 already occupied."); + result.kill(); -const cmd = "starknet-devnet --host 127.0.0.1 --port 5050 --accounts 0"; -const args = cmd.split(" ").slice(1); - -// run devnet which will cause integrated-devnet to fail -spawn("starknet-devnet", args, { detached: true }); -exec("npx hardhat starknet-compile contracts/contract.cairo"); - -contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "127.0.0.1:5050 already occupied."); -exec("kill -9 $(lsof -t -i:5050)"); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-docker-args/check.ts b/test/integrated-devnet-tests/with-docker-args/check.ts index 72d50060..05604214 100644 --- a/test/integrated-devnet-tests/with-docker-args/check.ts +++ b/test/integrated-devnet-tests/with-docker-args/check.ts @@ -1,6 +1,9 @@ -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; -checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/integrated-devnet-args.test.ts"); -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + hardhatStarknetTest("--no-compile test/integrated-devnet-args.test.ts".split(" ")); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts index 7adcf3cf..1a09168d 100644 --- a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts +++ b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts @@ -1,7 +1,10 @@ -import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; -checkDevnetIsNotRunning(); - -exec("npx hardhat starknet-compile contracts/contract.cairo"); - -contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + contains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-docker/check.ts b/test/integrated-devnet-tests/with-docker/check.ts index 31bd48fb..7fbc39ec 100644 --- a/test/integrated-devnet-tests/with-docker/check.ts +++ b/test/integrated-devnet-tests/with-docker/check.ts @@ -1,6 +1,9 @@ -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; -checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" ")); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts index 0339ab26..4e7d7d81 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts @@ -1,26 +1,28 @@ -import shell from "shelljs"; import { existsSync, readFileSync } from "fs"; -import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; +import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { StarknetPluginError } from "../../../src/starknet-plugin-error"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + const expectedStdout = "Account #0"; + const expectedWarning = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; -const EXPECTED_STDOUT = "Account #0"; -const EXPECTED_WARNING = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; + hardhatStarknetCompile(["contracts/contract.cairo"]); + const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + contains(execution.stderr, expectedWarning); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", EXPECTED_WARNING); - -// 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(EXPECTED_STDOUT)) { - console.error(`Expected stderr to contain ${EXPECTED_STDOUT}`); - shell.exit(1); + // 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"); } -} else { - console.log("Expected logs/stdout.log to exist"); -} -console.log("Success"); -checkDevnetIsNotRunning(); + console.log("Success"); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts index 0c7b4dd7..6f689bbb 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts @@ -1,6 +1,11 @@ -import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + contains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.ts b/test/integrated-devnet-tests/with-stderr-to-file/check.ts index 1e080f59..adc9a181 100644 --- a/test/integrated-devnet-tests/with-stderr-to-file/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-file/check.ts @@ -1,31 +1,31 @@ -import shell from "shelljs"; import { existsSync, readFileSync } from "fs"; -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; +import { StarknetPluginError } from "../../../src/starknet-plugin-error"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); -exec("npx hardhat starknet-compile contracts/contract.cairo"); + const expectedStdout = "Account #0"; + const expectedWarning = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; -const EXPECTED_STDOUT = "Account #0"; -const EXPECTED_WARNING = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; - -const output = exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); -// Checks if output contains the expected string from stdout -if (!output.includes(EXPECTED_STDOUT)) { - console.log(`Expected output to contain ${EXPECTED_STDOUT}`); - shell.exit(1); -} + 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}`); + } -// 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(EXPECTED_WARNING)) { - console.error(`Expected stderr to contain ${EXPECTED_WARNING}`); - shell.exit(1); + // 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"); } -} else { - console.log("Expected logs/stderr.log to exist"); -} -console.log("Success"); -checkDevnetIsNotRunning(); + console.log("Success"); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts index fbceaea2..5cad04e5 100644 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts @@ -1,19 +1,15 @@ import { spawn } from "child_process"; -import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; -import shell from "shelljs"; +import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -const res = shell.exec("lsof -t -i:5050"); -if (res.code === 0) { - exec("kill -9 $(lsof -t -i:5050)"); -} +(async () => { + await checkDevnetIsNotRunning(); -checkDevnetIsNotRunning(); + const result = spawn("starknet-devnet", "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), { detached: true }); + hardhatStarknetCompile(["contracts/contract.cairo"]); + const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + contains(execution.stderr, "127.0.0.1:5050 already occupied."); + result.kill(); -const cmd = "starknet-devnet --host 127.0.0.1 --port 5050 --accounts 0"; -const args = cmd.split(" ").slice(1); - -spawn("starknet-devnet", args, { detached: true }); -exec("npx hardhat starknet-compile contracts/contract.cairo"); - -contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "127.0.0.1:5050 already occupied."); -exec("kill -9 $(lsof -t -i:5050)"); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts index 7adcf3cf..06b6b135 100644 --- a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts +++ b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts @@ -1,7 +1,12 @@ -import { checkDevnetIsNotRunning, contains, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); + hardhatStarknetCompile(["contracts/contract.cairo"]); + const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + contains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); -contains("npx hardhat test --no-compile test/integrated-devnet.test.ts", "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/integrated-devnet-tests/with-venv/check.ts b/test/integrated-devnet-tests/with-venv/check.ts index 31bd48fb..7fbc39ec 100644 --- a/test/integrated-devnet-tests/with-venv/check.ts +++ b/test/integrated-devnet-tests/with-venv/check.ts @@ -1,6 +1,9 @@ -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; -checkDevnetIsNotRunning(); -exec("npx hardhat starknet-compile contracts/contract.cairo"); -exec("npx hardhat test --no-compile test/integrated-devnet.test.ts"); -checkDevnetIsNotRunning(); +(async () => { + await checkDevnetIsNotRunning(); + hardhatStarknetCompile(["contracts/contract.cairo"]); + hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" ")); + await checkDevnetIsNotRunning(); +})(); diff --git a/test/recompilation-tests/hardhat-run/check.ts b/test/recompilation-tests/hardhat-run/check.ts index 0940b600..1aa83398 100644 --- a/test/recompilation-tests/hardhat-run/check.ts +++ b/test/recompilation-tests/hardhat-run/check.ts @@ -1,11 +1,11 @@ -import { rmSync } from "fs"; -import { exec } from "../../utils/utils"; +import { hardhatStarknetRun } from "../../utils/cli-functions"; +import { rmrfSync } from "../../utils/utils"; // Hardhat run command console.log("should recompile with deleted artifact on hardhat run"); -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -exec("npx hardhat run --no-compile scripts/deploy.ts"); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +hardhatStarknetRun("--no-compile scripts/deploy.ts".split(" ")); console.log("should recompile with cache file deleted on hardhat run"); -rmSync("cache/cairo-files-cache.json", { recursive: true, force: true }); -exec("npx hardhat run --no-compile scripts/deploy.ts"); +rmrfSync("cache/cairo-files-cache.json"); +hardhatStarknetRun("--no-compile scripts/deploy.ts".split(" ")); diff --git a/test/recompilation-tests/hardhat-test/check.ts b/test/recompilation-tests/hardhat-test/check.ts index 5893f96d..25d6893b 100644 --- a/test/recompilation-tests/hardhat-test/check.ts +++ b/test/recompilation-tests/hardhat-test/check.ts @@ -1,58 +1,58 @@ -import { rmSync, copyFileSync, readFileSync } from "fs"; +import { copyFileSync, readFileSync, appendFileSync } from "fs"; import path from "path"; -import shell from "shelljs"; -import { exec } from "../../utils/utils"; +import { StarknetPluginError } from "../../../src/starknet-plugin-error"; +import { hardhatStarknetTest } from "../../utils/cli-functions"; +import { rmrfSync } from "../../utils/utils"; -const PREFIX = path.join(__dirname); -const CONTRACT_NAME = "contract_test_cache.cairo"; -const CONTRACT_PATH = path.join("contracts", CONTRACT_NAME); +const prefix = path.join(__dirname); +const contractName = "contract_test_cache.cairo"; +const contractPath = path.join("contracts", contractName); -const DEPENDENCY_NAME = "dependency.cairo"; -const DEPENDENCY_PATH = path.join("contracts", DEPENDENCY_NAME); +const dependencyName = "dependency.cairo"; +const dependencyPath = path.join("contracts", dependencyName); -rmSync(DEPENDENCY_PATH, { recursive: true, force: true }); -rmSync(CONTRACT_PATH, { recursive: true, force: true }); +rmrfSync(dependencyPath); +rmrfSync(contractPath); // Hardhat test command console.log("Testing Recompilation with new contract added"); -copyFileSync(path.join(PREFIX, CONTRACT_NAME), CONTRACT_PATH); -copyFileSync(path.join(PREFIX, DEPENDENCY_NAME), DEPENDENCY_PATH); +copyFileSync(path.join(prefix, contractName), contractPath); +copyFileSync(path.join(prefix, dependencyName), dependencyPath); -exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts".split(" ")); console.log("Testing Recompilation with artifacts deleted"); -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts".split(" ")); console.log("Testing Recompilation with updated contract"); // Appending a new function to the contract -exec(`cat ${path.join(PREFIX, "get_balance.cairo")} >> contracts/contract_test_cache.cairo`); -exec("npx hardhat test --no-compile test/recompilation/recompilation-update-test.ts"); +appendFileSync("contracts/contract_test_cache.cairo", readFileSync(path.join(prefix, "get_balance.cairo")).toString()); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-update-test.ts".split(" ")); console.log("Testing Recompilation with cache file deleted"); -rmSync("cache/cairo-files-cache.json", { recursive: true, force: true }); -exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); +rmrfSync("cache/cairo-files-cache.json"); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts".split(" ")); console.log("Testing Recompilation with dependency changed"); -exec(`echo "//" >> ${DEPENDENCY_PATH}`); -exec("npx hardhat test --no-compile test/recompilation/recompilation-dependency-test.ts"); +appendFileSync(dependencyPath, "//"); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-dependency-test.ts".split(" ")); console.log("Testing Recompilation with source deleted"); copyFileSync("cache/cairo-files-cache.json", "cache-content-before.json"); -rmSync("contracts/contract_test_cache.cairo", { recursive: true, force: true }); -exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); +rmrfSync("contracts/contract_test_cache.cairo"); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts".split(" ")); // 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)) { - console.log("Cache file was not updated"); - shell.exit(1); + throw new StarknetPluginError("Cache file was not updated"); } console.log("Testing Recompilation one contract added another deleted"); -rmSync("contracts/contract_test_cache.cairo", { force: true }); -rmSync("contracts/dependency.cairo", { force: true }); +rmrfSync("contracts/contract_test_cache.cairo"); +rmrfSync("contracts/dependency.cairo"); -const CONTRACT_WITH_NO_DEPENDENCY = "contract_test_cache_no_dependency.cairo"; -copyFileSync(path.join(PREFIX, CONTRACT_WITH_NO_DEPENDENCY), CONTRACT_PATH); +const contractWithNoDependency = "contract_test_cache_no_dependency.cairo"; +copyFileSync(path.join(prefix, contractWithNoDependency), contractPath); -exec("npx hardhat test --no-compile test/recompilation/recompilation-main-test.ts"); +hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts".split(" ")); diff --git a/test/recompilation-tests/recompiler-default/check.ts b/test/recompilation-tests/recompiler-default/check.ts index 322f07ba..f40528f4 100644 --- a/test/recompilation-tests/recompiler-default/check.ts +++ b/test/recompilation-tests/recompiler-default/check.ts @@ -1,8 +1,9 @@ -import { rmSync } from "fs"; -import { contains } from "../../utils/utils"; +import { hardhatStarknetRun } from "../../utils/cli-functions"; +import { contains, rmrfSync } from "../../utils/utils"; -const EXPECTED = "StarknetPluginError: Artifact expected to be at"; +const expected = "StarknetPluginError: Artifact expected to be at"; console.log("Testing with deleted artifact on recompiler option set to default (off)"); -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -contains("npx hardhat run --no-compile scripts/deploy.ts", EXPECTED); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +const execution = hardhatStarknetRun("--no-compile scripts/deploy.ts".split(" "), true); +contains(execution.stderr, expected); diff --git a/test/recompilation-tests/recompiler-off/check.ts b/test/recompilation-tests/recompiler-off/check.ts index 78d32f49..769aaa2a 100644 --- a/test/recompilation-tests/recompiler-off/check.ts +++ b/test/recompilation-tests/recompiler-off/check.ts @@ -1,9 +1,10 @@ -import { rmSync } from "fs"; -import { contains } from "../../utils/utils"; +import { hardhatStarknetRun } from "../../utils/cli-functions"; +import { contains, rmrfSync } from "../../utils/utils"; -const EXPECTED = "StarknetPluginError: Artifact expected to be at"; +const expected = "StarknetPluginError: Artifact expected to be at"; console.log("Testing with deleted artifact on recompiler option set to default (off)"); -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -contains("npx hardhat run --no-compile scripts/deploy.ts", EXPECTED); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +const execution = hardhatStarknetRun("--no-compile scripts/deploy.ts".split(" "), true); +contains(execution.stderr, expected); console.log("Success"); diff --git a/test/recompilation-tests/starknet-call/check.ts b/test/recompilation-tests/starknet-call/check.ts index 1fe0b178..f237680d 100644 --- a/test/recompilation-tests/starknet-call/check.ts +++ b/test/recompilation-tests/starknet-call/check.ts @@ -1,11 +1,11 @@ -import { rmSync } from "fs"; -import { extractAddress, exec } from "../../utils/utils"; +import { hardhatStarknetDeploy, hardhatStarknetCall } from "../../utils/cli-functions"; +import { extractAddress, ensureEnvVar, rmrfSync } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); console.log("Testing Recompilation with deleted artifact on starknet-call"); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); const address = extractAddress(output.stdout, "Contract address: "); -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -exec(`npx hardhat starknet-call --starknet-network ${NETWORK} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split(" ")); diff --git a/test/recompilation-tests/starknet-deploy/check.ts b/test/recompilation-tests/starknet-deploy/check.ts index 1d8ce423..eb9463db 100644 --- a/test/recompilation-tests/starknet-deploy/check.ts +++ b/test/recompilation-tests/starknet-deploy/check.ts @@ -1,9 +1,9 @@ -import { rmSync } from "fs"; -import { exec } from "../../utils/utils"; +import { hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar, rmrfSync } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); // Hardhat starknet-deploy command console.log("Testing Recompilation with deleted artifact on starknet-deploy"); -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); diff --git a/test/recompilation-tests/starknet-invoke/check.ts b/test/recompilation-tests/starknet-invoke/check.ts index e56cea2b..1c169c00 100644 --- a/test/recompilation-tests/starknet-invoke/check.ts +++ b/test/recompilation-tests/starknet-invoke/check.ts @@ -1,26 +1,22 @@ -import { rmSync } from "fs"; import path from "path"; -import { exec, extractAddress } from "../../utils/utils"; - -const NETWORK = process.env.NETWORK; +import { hardhatStarknetDeploy, hardhatStarknetInvoke } from "../../utils/cli-functions"; +import { deployFundedAccount } from "../../utils/deploy-funded-account"; +import { ensureEnvVar, extractAddress, rmrfSync } from "../../utils/utils"; +const network = ensureEnvVar("NETWORK"); // Hardhat starknet-invoke command console.log("Testing Recompilation with deleted artifact on hardhat starknet-invoke"); -const output = exec(`npx hardhat starknet-deploy --starknet-network ${NETWORK} starknet-artifacts/contracts/contract.cairo/ --inputs 10`); +const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); // Grab the output Contract address to a variable using parameter expansion const address = extractAddress(output.stdout, "Contract address: "); // Remove artifact contract to force recompilation -rmSync("starknet-artifacts/contracts/contract.cairo", { recursive: true, force: true }); -const HOME = process.env.HOME; -const ACCOUNT_DIR = path.join(`${HOME}`, ".starknet_accounts_recompile_test"); -process.env.ACCOUNT_DIR = ACCOUNT_DIR; - -exec("bash ../scripts/deploy-funded-cli-account.sh"); +rmrfSync("starknet-artifacts/contracts/contract.cairo"); +const home = ensureEnvVar("HOME"); +const accountDir = path.join(home, ".starknet_accounts_recompile_test"); +process.env.ACCOUNT_DIR = accountDir; -exec(`npx hardhat starknet-invoke \ - --starknet-network ${NETWORK} \ - --contract contract \ - --function increase_balance \ - --address ${address} \ - --inputs "10 20" \ - --wallet OpenZeppelin`); +(async () => { + await deployFundedAccount(); + const args = `--starknet-network ${network} --contract contract --address ${address} --function increase_balance --inputs "10 20" --wallet OpenZeppelin`; + hardhatStarknetInvoke(args.split(" ")); +})(); diff --git a/test/venv-tests/with-venv-active/check.ts b/test/venv-tests/with-venv-active/check.ts index dd0b586e..b2eef50c 100644 --- a/test/venv-tests/with-venv-active/check.ts +++ b/test/venv-tests/with-venv-active/check.ts @@ -1,10 +1,11 @@ import path from "path"; -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; +import { ensureEnvVar, exec } from "../../utils/utils"; -const NETWORK = process.env.NETWORK; +const network = ensureEnvVar("NETWORK"); exec(`bash ${path.join(__dirname, "venv.sh")}`); -const INITIAL_VALUE = 10; +const initialValue = 10; -exec("npx hardhat starknet-compile"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network ${NETWORK} --inputs ${INITIAL_VALUE}`); +hardhatStarknetCompile([]); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split(" ")); diff --git a/test/venv-tests/with-venv/check.ts b/test/venv-tests/with-venv/check.ts index f9b86a41..2f5f08d0 100644 --- a/test/venv-tests/with-venv/check.ts +++ b/test/venv-tests/with-venv/check.ts @@ -1,8 +1,9 @@ -import { exec } from "../../utils/utils"; +import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; +import { ensureEnvVar } from "../../utils/utils"; -const INITIAL_VALUE = 10; -const NETWORK = process.env.NETWORK; +const initialValue = 10; +const network = ensureEnvVar("NETWORK"); -exec("npx hardhat starknet-compile"); -exec(`npx hardhat starknet-deploy starknet-artifacts/contracts/contract.cairo/ --starknet-network ${NETWORK} --inputs ${INITIAL_VALUE}`); -exec("npx hardhat test --no-compile test/quick-test.ts"); +hardhatStarknetCompile([]); +hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split(" ")); +hardhatStarknetTest("--no-compile test/quick-test.ts".split(" ")); From 1ae0f61a448ba11bfa176c6f349d1b1984612d0c Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 16:39:18 +0300 Subject: [PATCH 20/41] :fire: Remove unused scripts & update utils --- scripts/assert-contains.py | 22 ---------------------- scripts/check-devnet-is-not-running.sh | 12 ------------ scripts/deploy-funded-cli-account.sh | 21 --------------------- test/utils/utils.ts | 5 ++--- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100755 scripts/assert-contains.py delete mode 100755 scripts/check-devnet-is-not-running.sh delete mode 100755 scripts/deploy-funded-cli-account.sh diff --git a/scripts/assert-contains.py b/scripts/assert-contains.py deleted file mode 100755 index e39a3328..00000000 --- a/scripts/assert-contains.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/python3 - -""" -Asserts that stdin contains the provided as CLI argument. -""" - -import sys - -if len(sys.argv) != 2: - sys.exit(sys.argv[0] + " ") - -pattern = sys.argv[1] -input_content = sys.stdin.read() - -if pattern in input_content: - sys.exit(0) - -print("Pattern not in input", file=sys.stderr) -print("Pattern:", pattern, file=sys.stderr) -print("Input:", input_content, file=sys.stderr) - -sys.exit(1) diff --git a/scripts/check-devnet-is-not-running.sh b/scripts/check-devnet-is-not-running.sh deleted file mode 100755 index 7174d16f..00000000 --- a/scripts/check-devnet-is-not-running.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -check_devnet_is_not_running() { - local status - status=$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:5050/feeder_gateway/is_alive") || echo "Devnet is not running! $status" - - if [ "$status" != 000 ]; then - echo "Devnet is running and responded with status $status" - exit 1 - fi -} diff --git a/scripts/deploy-funded-cli-account.sh b/scripts/deploy-funded-cli-account.sh deleted file mode 100755 index 9a8d6849..00000000 --- a/scripts/deploy-funded-cli-account.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -eu - -if [[ "$NETWORK" != "devnet" ]]; then - echo "$0 only works with NETWORK set to devnet" - exit 1 -fi - -ACCOUNT_FILE="$ACCOUNT_DIR/starknet_open_zeppelin_accounts.json" - -npx hardhat starknet-new-account --starknet-network "$NETWORK" --wallet OpenZeppelin -ACCOUNT_ADDRESS=$(jq -r .$NETWORK.OpenZeppelin.address $ACCOUNT_FILE) - -echo "Funding $ACCOUNT_ADDRESS" -# assumes address, don't hardcode this in the future -curl 127.0.0.1:5050/mint \ - -H "Content-Type: application/json" \ - -d "{ \"address\": \"$ACCOUNT_ADDRESS\", \"amount\": 1000000000000000000, \"lite\": true }" - -npx hardhat starknet-deploy-account --starknet-network "$NETWORK" --wallet OpenZeppelin diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 5ed47509..dee91b86 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -36,12 +36,11 @@ export async function checkDevnetIsNotRunning(url?: string): Promise { console.log(`Devnet is running and responded with status ${res.status}`); throw new StarknetPluginError(`Devnet is running and responded with status ${res.status}`); } catch (err) { - if (err.toJSON().code == "ECONNREFUSED") { - console.log("Devnet is not running!"); - } + console.log("Devnet is not running!"); } } + export function ensureEnvVar(varName: string): string { if (!process.env[varName]) { throw new Error(`Env var ${varName} not set or empty`); From 9ea524d409a7bcad9468fa20b13dede0822d2cd6 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 16:41:31 +0300 Subject: [PATCH 21/41] Remove repetitive log [skip ci] --- test/utils/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/utils/utils.ts b/test/utils/utils.ts index dee91b86..2d8082d6 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -33,7 +33,6 @@ export async function checkDevnetIsNotRunning(url?: string): Promise { url = url || "http://127.0.0.1:5050"; try { const res = await axios.get(`${url}/is_alive`); - console.log(`Devnet is running and responded with status ${res.status}`); throw new StarknetPluginError(`Devnet is running and responded with status ${res.status}`); } catch (err) { console.log("Devnet is not running!"); From c949138538057e491be641ac3707eb3c9b770b5c Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Tue, 22 Nov 2022 20:59:47 +0300 Subject: [PATCH 22/41] Change branch --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 36d37e8c..2715a3f0 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,7 +9,7 @@ CONFIG_FILE_NAME="hardhat.config.ts" # setup example repo rm -rf starknet-hardhat-example -git clone -b plugin --single-branch git@github.com:Shard-Labs/starknet-hardhat-example.git +git clone -b resolveJsonModule --single-branch git@github.com:Shard-Labs/starknet-hardhat-example.git cd starknet-hardhat-example git log -n 1 npm ci From e0a32dd9a8eb72f9340a138d9254f7d6096a1df4 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 09:09:34 +0300 Subject: [PATCH 23/41] Kill with process.kill() & avoid silent execute --- .../with-disable-hint-compilation-option/check.ts | 2 +- test/general-tests/postman/check.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts index 02c8ca73..ddfcff85 100644 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.ts +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -12,7 +12,7 @@ const expected = `Hint is not whitelisted. This may indicate that this library function cannot be used in StarkNet contracts.`; console.log("Testing rejection of compilation without the --disable-hint-validation flag"); -const execution = hardhatStarknetCompile([contractName], true); +const execution = hardhatStarknetCompile([contractName]); contains(execution.stderr, expected); console.log("Success"); diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index f2193bda..747a8240 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -8,4 +8,4 @@ const result = spawn("npx", ["hardhat", "node"], { detached: true }); exec("sleep 1"); hardhatStarknetTest("--network localhost test/postman.test.ts".split(" ")); -result.kill(); +process.kill(result.pid as number); From 0ef112a68dea8b076bb683f073992e4dfac25ac9 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 09:18:35 +0300 Subject: [PATCH 24/41] Bug fix with contract path --- .../with-disable-hint-compilation-option/check.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts index ddfcff85..20b18f18 100644 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.ts +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -12,7 +12,7 @@ const expected = `Hint is not whitelisted. This may indicate that this library function cannot be used in StarkNet contracts.`; console.log("Testing rejection of compilation without the --disable-hint-validation flag"); -const execution = hardhatStarknetCompile([contractName]); +const execution = hardhatStarknetCompile([contractPath], true); contains(execution.stderr, expected); console.log("Success"); From ce0b6e91b3683b183d919d091d81cc284d9a1ac7 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 10:12:52 +0300 Subject: [PATCH 25/41] Use kill from shell --- test/general-tests/postman/check.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index 747a8240..8b3dfea3 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -8,4 +8,4 @@ const result = spawn("npx", ["hardhat", "node"], { detached: true }); exec("sleep 1"); hardhatStarknetTest("--network localhost test/postman.test.ts".split(" ")); -process.kill(result.pid as number); +exec("kill -9 $(lsof -t -i:8545)"); From 04c64f46df5bf109d3c3d5f734a8199043111664 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 10:24:49 +0300 Subject: [PATCH 26/41] Remove unused variable --- test/general-tests/postman/check.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index 8b3dfea3..e8d3e63f 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -4,7 +4,7 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun hardhatStarknetCompile(["contracts/l1l2.cairo"]); -const result = spawn("npx", ["hardhat", "node"], { detached: true }); +spawn("npx", ["hardhat", "node"], { detached: true }); exec("sleep 1"); hardhatStarknetTest("--network localhost test/postman.test.ts".split(" ")); From 26185a09c15061834cf20326f1663933dd0a2d7e Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 22:31:14 +0300 Subject: [PATCH 27/41] Fix typo --- test/utils/cli-functions.ts | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/utils/cli-functions.ts b/test/utils/cli-functions.ts index 57cd333f..0d64ec51 100644 --- a/test/utils/cli-functions.ts +++ b/test/utils/cli-functions.ts @@ -1,48 +1,48 @@ import shell from "shelljs"; -const exec = (cmd: string, silet?: boolean) => { - silet = silet || false; - return shell.exec(cmd, { silent: silet }); +const exec = (cmd: string, silent?: boolean) => { + silent = silent || false; + return shell.exec(cmd, { silent: silent }); }; -export const hardhatStarknetCompile = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-compile ${args.join(" ")}`, silet); +export const hardhatStarknetCompile = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-compile ${args.join(" ")}`, silent); }; -export const hardhatStarknetDeploy = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-deploy ${args.join(" ")}`, silet); +export const hardhatStarknetDeploy = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-deploy ${args.join(" ")}`, silent); }; -export const hardhatStarknetInvoke = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-invoke ${args.join(" ")}`, silet); +export const hardhatStarknetInvoke = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-invoke ${args.join(" ")}`, silent); }; -export const hardhatStarknetCall = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-call ${args.join(" ")}`, silet); +export const hardhatStarknetCall = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-call ${args.join(" ")}`, silent); }; -export const hardhatStarknetEstimateFee = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-estimate-fee ${args.join(" ")}`, silet); +export const hardhatStarknetEstimateFee = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-estimate-fee ${args.join(" ")}`, silent); }; -export const hardhatStarknetNewAccount = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-new-account ${args.join(" ")}`, silet); +export const hardhatStarknetNewAccount = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-new-account ${args.join(" ")}`, silent); }; -export const hardhatStarknetDeployAccount = (args: Array, silet?: boolean) => { - return exec(`npx hardhat starknet-deploy-account ${args.join(" ")}`, silet); +export const hardhatStarknetDeployAccount = (args: Array, silent?: boolean) => { + return exec(`npx hardhat starknet-deploy-account ${args.join(" ")}`, silent); }; -export const hardhatStarknetRun = (args: Array, silet?: boolean) => { - return exec(`npx hardhat run ${args.join(" ")}`, silet); +export const hardhatStarknetRun = (args: Array, silent?: boolean) => { + return exec(`npx hardhat run ${args.join(" ")}`, silent); }; -export const hardhatStarknetTest = (args: Array, silet?: boolean) => { - return exec(`npx hardhat test ${args.join(" ")}`, silet); +export const hardhatStarknetTest = (args: Array, silent?: boolean) => { + return exec(`npx hardhat test ${args.join(" ")}`, silent); }; -export const hardhatStarknetMigrate = (args: Array, silet?: boolean) => { - return exec(`npx hardhat migrate ${args.join(" ")}`, silet); +export const hardhatStarknetMigrate = (args: Array, silent?: boolean) => { + return exec(`npx hardhat migrate ${args.join(" ")}`, silent); }; export const hardhatStarknetPluginVersion = () => { From f053778ce3a76723ae6aa82cf34fc9b8a9623dc4 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 22:33:02 +0300 Subject: [PATCH 28/41] Avoid use of $0 in ts tests --- test/general-tests/hardhat-run/check.ts | 2 +- test/general-tests/starknet-verify/check.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/general-tests/hardhat-run/check.ts b/test/general-tests/hardhat-run/check.ts index c6cfa2af..84266d44 100644 --- a/test/general-tests/hardhat-run/check.ts +++ b/test/general-tests/hardhat-run/check.ts @@ -1,7 +1,7 @@ // import { hardhatStarknetCompile, hardhatStarknetRun } from "../../utils/cli-functions"; // import { ensureEnvVar } from "../../utils/utils"; -console.log("$0: Testing hh run with --starknet-network is currently disabled"); +console.log("Testing hh run with --starknet-network is currently disabled"); // const network = ensureEnvVar("NETWORK"); // hardhatStarknetCompile(["contracts/contract.cairo"]); diff --git a/test/general-tests/starknet-verify/check.ts b/test/general-tests/starknet-verify/check.ts index 9dd8f292..fa23dc6e 100644 --- a/test/general-tests/starknet-verify/check.ts +++ b/test/general-tests/starknet-verify/check.ts @@ -28,6 +28,6 @@ const is_verified = exec(`curl "https://goerli.voyager.online/api/contract/${add if (is_verified == "true") { console.log("Successfully verified!"); } else { - console.log("$0: Error: Not verified!"); + console.log("Error: Not verified!"); throw new StarknetPluginError("Error: Not verified!"); } From 7f1c800e7c95537e8cbd513b1a24751969ad4a8c Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Wed, 23 Nov 2022 22:33:38 +0300 Subject: [PATCH 29/41] Restore branch name --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 2715a3f0..36d37e8c 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,7 +9,7 @@ CONFIG_FILE_NAME="hardhat.config.ts" # setup example repo rm -rf starknet-hardhat-example -git clone -b resolveJsonModule --single-branch git@github.com:Shard-Labs/starknet-hardhat-example.git +git clone -b plugin --single-branch git@github.com:Shard-Labs/starknet-hardhat-example.git cd starknet-hardhat-example git log -n 1 npm ci From 3bd3c03639fc5b0e29ca5bd0c974eaec14b7b511 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 09:47:58 +0300 Subject: [PATCH 30/41] Use constants for default url --- test/constants/constants.ts | 5 +++++ test/utils/deploy-funded-account.ts | 4 ++-- test/utils/utils.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/constants/constants.ts diff --git a/test/constants/constants.ts b/test/constants/constants.ts new file mode 100644 index 00000000..13516e27 --- /dev/null +++ b/test/constants/constants.ts @@ -0,0 +1,5 @@ + +export const HOST = "127.0.0.1"; +export const PORT = "5050"; +export const NODE_PORT = "8545"; +export const DEVNET_URL = `http://${HOST}:${PORT}`; diff --git a/test/utils/deploy-funded-account.ts b/test/utils/deploy-funded-account.ts index bd5da8c9..637372f3 100644 --- a/test/utils/deploy-funded-account.ts +++ b/test/utils/deploy-funded-account.ts @@ -2,10 +2,11 @@ import axios from "axios"; import { readFileSync } from "fs"; import path from "path"; import { StarknetPluginError } from "../../src/starknet-plugin-error"; +import { DEVNET_URL } from "../constants/constants"; import { hardhatStarknetDeployAccount, hardhatStarknetNewAccount } from "./cli-functions"; import { ensureEnvVar } from "./utils"; -export async function deployFundedAccount(url?: string) { +export async function deployFundedAccount(url = DEVNET_URL) { const network = ensureEnvVar("NETWORK"); const accountDir = ensureEnvVar("ACCOUNT_DIR"); @@ -27,7 +28,6 @@ export async function deployFundedAccount(url?: string) { const accountAddress = JSON.parse(readFileSync(accountFile, "utf-8"))[`${network}`].OpenZeppelin.address; console.log(`Funding account ${accountAddress} on ${network}.`); - url = url || "http://127.0.0.1:5050"; await axios.post(`${url}/mint`, { address: accountAddress, amount: 1000000000000000000n, diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 2d8082d6..3fb3787f 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -2,6 +2,7 @@ import axios from "axios"; import { rmSync } from "fs"; import shell from "shelljs"; import { StarknetPluginError } from "../../src/starknet-plugin-error"; +import { DEVNET_URL } from "../constants/constants"; export function exec(cmd: string) { const result = shell.exec(cmd); @@ -29,8 +30,7 @@ export function extractAddress(source: string, pattern: string) { return res; } -export async function checkDevnetIsNotRunning(url?: string): Promise { - url = url || "http://127.0.0.1:5050"; +export async function checkDevnetIsNotRunning(url = DEVNET_URL): Promise { try { const res = await axios.get(`${url}/is_alive`); throw new StarknetPluginError(`Devnet is running and responded with status ${res.status}`); From fb0c77a8948621b6eb2c60c6a5b546d431c2a850 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 11:37:26 +0300 Subject: [PATCH 31/41] Read port from constant --- test/general-tests/postman/check.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/general-tests/postman/check.ts b/test/general-tests/postman/check.ts index e8d3e63f..79005f0a 100644 --- a/test/general-tests/postman/check.ts +++ b/test/general-tests/postman/check.ts @@ -1,11 +1,12 @@ import { exec } from "../../utils/utils"; import { spawn } from "child_process"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; +import { NODE_PORT } from "../../constants/constants"; hardhatStarknetCompile(["contracts/l1l2.cairo"]); -spawn("npx", ["hardhat", "node"], { detached: true }); +spawn("npx", ["hardhat", "node", "--port", NODE_PORT], { detached: true }); exec("sleep 1"); hardhatStarknetTest("--network localhost test/postman.test.ts".split(" ")); -exec("kill -9 $(lsof -t -i:8545)"); +exec(`kill -9 $(lsof -t -i:${NODE_PORT})`); From f4cedb1fa73c166f30b2f18cee83431714b1cafc Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 11:38:36 +0300 Subject: [PATCH 32/41] Replace StarknetPluginError with assertion --- .../starknet-new-account/check.ts | 11 +++-------- test/general-tests/starknet-verify/check.ts | 15 ++++++--------- .../with-stderr-to-STDERR/check.ts | 14 ++++---------- .../with-stderr-to-file/check.ts | 18 +++++------------- test/recompilation-tests/hardhat-test/check.ts | 7 ++----- 5 files changed, 20 insertions(+), 45 deletions(-) diff --git a/test/general-tests/starknet-new-account/check.ts b/test/general-tests/starknet-new-account/check.ts index 8d4dabd7..7acd513f 100644 --- a/test/general-tests/starknet-new-account/check.ts +++ b/test/general-tests/starknet-new-account/check.ts @@ -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"); @@ -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"); \ No newline at end of file diff --git a/test/general-tests/starknet-verify/check.ts b/test/general-tests/starknet-verify/check.ts index fa23dc6e..74ba2cc4 100644 --- a/test/general-tests/starknet-verify/check.ts +++ b/test/general-tests/starknet-verify/check.ts @@ -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); @@ -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"); +})(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts index 4e7d7d81..52b5c5fe 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts @@ -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 () => { @@ -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(); diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.ts b/test/integrated-devnet-tests/with-stderr-to-file/check.ts index adc9a181..f945f434 100644 --- a/test/integrated-devnet-tests/with-stderr-to-file/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-file/check.ts @@ -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 () => { @@ -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(); diff --git a/test/recompilation-tests/hardhat-test/check.ts b/test/recompilation-tests/hardhat-test/check.ts index 25d6893b..92ef49b8 100644 --- a/test/recompilation-tests/hardhat-test/check.ts +++ b/test/recompilation-tests/hardhat-test/check.ts @@ -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"; @@ -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"); From 7f9318d61ceb059d55995eabe73fa2560c0634de Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 11:39:07 +0300 Subject: [PATCH 33/41] Add new methods --- test/utils/deploy-funded-account.ts | 4 ++-- test/utils/utils.ts | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/test/utils/deploy-funded-account.ts b/test/utils/deploy-funded-account.ts index 637372f3..a0769a28 100644 --- a/test/utils/deploy-funded-account.ts +++ b/test/utils/deploy-funded-account.ts @@ -24,8 +24,8 @@ export async function deployFundedAccount(url = DEVNET_URL) { // Creates new account hardhatStarknetNewAccount(args); - const accountFile = path.join(`${accountDir}`, "starknet_open_zeppelin_accounts.json"); - const accountAddress = JSON.parse(readFileSync(accountFile, "utf-8"))[`${network}`].OpenZeppelin.address; + const accountFile = path.join(accountDir, "starknet_open_zeppelin_accounts.json"); + const accountAddress = JSON.parse(readFileSync(accountFile, "utf-8"))[network].OpenZeppelin.address; console.log(`Funding account ${accountAddress} on ${network}.`); await axios.post(`${url}/mint`, { diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 3fb3787f..a3173d61 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -1,5 +1,6 @@ import axios from "axios"; -import { rmSync } from "fs"; +import assert, { AssertionError } from "node:assert"; +import { existsSync, rmSync } from "fs"; import shell from "shelljs"; import { StarknetPluginError } from "../../src/starknet-plugin-error"; import { DEVNET_URL } from "../constants/constants"; @@ -50,3 +51,19 @@ export function ensureEnvVar(varName: string): string { export function rmrfSync(path: string) { rmSync(path, { recursive: true, force: true }); } + +export function assertEqual(val1: any, val2: any, msg?: string) { + assert.equal(val1, val2, msg); +} + +export function assertNotEqual(val1: any, val2: any, msg?: string) { + assert.notEqual(val1, val2, msg); +} + +export function assertExists(path: string, msg?: string) { + if(!existsSync(path)) { + throw new AssertionError({ + message: msg + }); + } +} From bcf5eec44d42f71b5616b34d39e8c0b262cde01e Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 11:41:05 +0300 Subject: [PATCH 34/41] Minor clean up --- test/general-tests/starknet-new-account/check.ts | 2 +- test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts | 2 +- test/integrated-devnet-tests/with-stderr-to-file/check.ts | 2 +- test/utils/utils.ts | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/general-tests/starknet-new-account/check.ts b/test/general-tests/starknet-new-account/check.ts index 7acd513f..516ac368 100644 --- a/test/general-tests/starknet-new-account/check.ts +++ b/test/general-tests/starknet-new-account/check.ts @@ -22,4 +22,4 @@ const addressStd = parseInt(accountAddressStd, 16); const addressFile = parseInt(accountAddressFile, 16); // If addressStd and addressFile are equal then success -assertEqual(addressStd, addressFile, "Account address mismatch"); \ No newline at end of file +assertEqual(addressStd, addressFile, "Account address mismatch"); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts index 52b5c5fe..cdd32fb1 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts @@ -1,4 +1,4 @@ -import { existsSync, readFileSync } from "fs"; +import { readFileSync } from "fs"; import { assertExists, checkDevnetIsNotRunning, contains } from "../../utils/utils"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.ts b/test/integrated-devnet-tests/with-stderr-to-file/check.ts index f945f434..a94fc212 100644 --- a/test/integrated-devnet-tests/with-stderr-to-file/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-file/check.ts @@ -1,4 +1,4 @@ -import { existsSync, readFileSync } from "fs"; +import { readFileSync } from "fs"; import { assertExists, checkDevnetIsNotRunning, contains } from "../../utils/utils"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; diff --git a/test/utils/utils.ts b/test/utils/utils.ts index a3173d61..1721b65a 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -52,16 +52,16 @@ export function rmrfSync(path: string) { rmSync(path, { recursive: true, force: true }); } -export function assertEqual(val1: any, val2: any, msg?: string) { +export function assertEqual(val1: unknown, val2: unknown, msg?: string) { assert.equal(val1, val2, msg); } -export function assertNotEqual(val1: any, val2: any, msg?: string) { +export function assertNotEqual(val1: unknown, val2: unknown, msg?: string) { assert.notEqual(val1, val2, msg); } export function assertExists(path: string, msg?: string) { - if(!existsSync(path)) { + if (!existsSync(path)) { throw new AssertionError({ message: msg }); From 7769e972dbb81e75245f83cf8a56dc55e7be63a3 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 11:53:41 +0300 Subject: [PATCH 35/41] Update import --- test/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 1721b65a..50cf7cbb 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -1,5 +1,5 @@ import axios from "axios"; -import assert, { AssertionError } from "node:assert"; +import assert, { AssertionError } from "assert"; import { existsSync, rmSync } from "fs"; import shell from "shelljs"; import { StarknetPluginError } from "../../src/starknet-plugin-error"; From f869821c5c5153f5e4b8878ca852a3fce03469ad Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 22:13:25 +0300 Subject: [PATCH 36/41] Update test - Use assertContains - Throw AssertionError --- .../with-account-compilation-option/check.ts | 4 ++-- .../with-disable-hint-compilation-option/check.ts | 4 ++-- test/configuration-tests/with-networks/check.ts | 8 ++++---- test/general-tests/cairo-migrate/check.ts | 6 +++--- test/general-tests/expect-error-on-compile/check.ts | 4 ++-- test/general-tests/starknet-call/check.ts | 10 +++++----- test/general-tests/starknet-estimate-fee/check.ts | 10 +++++----- test/general-tests/starknet-invoke/check.ts | 10 +++++----- .../with-docker-address-occupied/check.ts | 4 ++-- .../with-docker-wrong-cli/check.ts | 4 ++-- .../with-stderr-to-STDERR/check.ts | 6 +++--- .../with-stderr-to-STDOUT/check.ts | 4 ++-- .../with-stderr-to-file/check.ts | 6 +++--- .../with-venv-address-occupied/check.ts | 4 ++-- .../with-venv-wrong-cli/check.ts | 4 ++-- test/recompilation-tests/recompiler-default/check.ts | 4 ++-- test/recompilation-tests/recompiler-off/check.ts | 4 ++-- test/utils/deploy-funded-account.ts | 7 ++----- test/utils/utils.ts | 11 ++++------- 19 files changed, 54 insertions(+), 60 deletions(-) diff --git a/test/configuration-tests/with-account-compilation-option/check.ts b/test/configuration-tests/with-account-compilation-option/check.ts index 30db2e57..cf5f64c4 100644 --- a/test/configuration-tests/with-account-compilation-option/check.ts +++ b/test/configuration-tests/with-account-compilation-option/check.ts @@ -1,7 +1,7 @@ import { copyFileSync } from "fs"; import path from "path"; import { hardhatStarknetCompile } from "../../utils/cli-functions"; -import { contains } from "../../utils/utils"; +import { assertContains } from "../../utils/utils"; const contractName = "dummy_account.cairo"; const contractPath = path.join("contracts", contractName); @@ -11,6 +11,6 @@ const expected = "Use the --account-contract flag to compile an account contract console.log("Testing rejection of compilation without the account flag"); copyFileSync(path.join(__dirname, contractName), contractPath); const execution = hardhatStarknetCompile(contractPath.split(" "), true); -contains(execution.stderr, expected); +assertContains(execution.stderr, expected); console.log("Success"); hardhatStarknetCompile(`${contractPath} --account-contract`.split(" ")); diff --git a/test/configuration-tests/with-disable-hint-compilation-option/check.ts b/test/configuration-tests/with-disable-hint-compilation-option/check.ts index 20b18f18..12b7d689 100644 --- a/test/configuration-tests/with-disable-hint-compilation-option/check.ts +++ b/test/configuration-tests/with-disable-hint-compilation-option/check.ts @@ -1,7 +1,7 @@ import { copyFileSync } from "fs"; import path from "path"; import { hardhatStarknetCompile } from "../../utils/cli-functions"; -import { contains } from "../../utils/utils"; +import { assertContains } from "../../utils/utils"; const contractName = "contract_with_unwhitelisted_hints.cairo"; const contractPath = path.join("contracts", contractName); @@ -13,7 +13,7 @@ This may indicate that this library function cannot be used in StarkNet contract console.log("Testing rejection of compilation without the --disable-hint-validation flag"); const execution = hardhatStarknetCompile([contractPath], true); -contains(execution.stderr, expected); +assertContains(execution.stderr, expected); console.log("Success"); hardhatStarknetCompile(`${contractPath} --disable-hint-validation`.split(" ")); diff --git a/test/configuration-tests/with-networks/check.ts b/test/configuration-tests/with-networks/check.ts index fb0a4128..3edcee7b 100644 --- a/test/configuration-tests/with-networks/check.ts +++ b/test/configuration-tests/with-networks/check.ts @@ -1,4 +1,4 @@ -import { contains } from "../../utils/utils"; +import { assertContains } from "../../utils/utils"; import path from "path"; import { readFileSync } from "fs"; import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; @@ -11,12 +11,12 @@ const prefix = path.join(__dirname); console.log("Testing no starknet network"); let execution = hardhatStarknetDeploy(`${artifactsPath} --inputs 10`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "without-starknet-network.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "without-starknet-network.txt")).toString()); console.log("Success"); console.log("Testing invalid CLI network"); execution = hardhatStarknetDeploy(`--starknet-network ${invalidNetwork} ${artifactsPath} --inputs 10`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "invalid-cli-network.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "invalid-cli-network.txt")).toString()); console.log("Success"); console.log("Testing no mocha network"); @@ -27,5 +27,5 @@ console.log("Success"); console.log("Testing invalid config network"); process.env.NETWORK = invalidNetwork; execution = hardhatStarknetTest("--no-compile test/contract-factory-test.ts".split(" "), true); -contains(execution.stderr, expected); +assertContains(execution.stderr, expected); console.log("Success"); diff --git a/test/general-tests/cairo-migrate/check.ts b/test/general-tests/cairo-migrate/check.ts index 11711842..3db7faab 100644 --- a/test/general-tests/cairo-migrate/check.ts +++ b/test/general-tests/cairo-migrate/check.ts @@ -1,7 +1,7 @@ import { copyFileSync, readFileSync } from "fs"; import path from "path"; import { hardhatStarknetMigrate } from "../../utils/cli-functions"; -import { contains } from "../../utils/utils"; +import { assertContains } from "../../utils/utils"; const contractName = "old_contract.cairo"; const contractPath = path.join("contracts", contractName); @@ -12,10 +12,10 @@ copyFileSync(path.join(__dirname, contractName), contractPath); console.log("Testing migration of old cairo contract to a new one"); // Migrate contract to new version. const execution = hardhatStarknetMigrate([contractPath], true); -contains(execution.stdout, newComment); +assertContains(execution.stdout, newComment); // Migrate contract to new version with change content in place option. hardhatStarknetMigrate(`${contractPath} --inplace`.split(" ")); -contains(readFileSync(contractPath).toString(), newComment); +assertContains(readFileSync(contractPath).toString(), newComment); console.log("Success"); diff --git a/test/general-tests/expect-error-on-compile/check.ts b/test/general-tests/expect-error-on-compile/check.ts index c9b8d465..028bac77 100644 --- a/test/general-tests/expect-error-on-compile/check.ts +++ b/test/general-tests/expect-error-on-compile/check.ts @@ -1,7 +1,7 @@ import { copyFileSync } from "fs"; import path from "path"; import { hardhatStarknetCompile } from "../../utils/cli-functions"; -import { contains } from "../../utils/utils"; +import { assertContains } from "../../utils/utils"; const contractName = "invalid_contract.cairo"; const contractPath = path.join("contracts", contractName); @@ -10,5 +10,5 @@ copyFileSync(path.join(__dirname, contractName), contractPath); console.log("Testing rejection of compilation with correct message"); const compileResult = hardhatStarknetCompile([contractPath], true); -contains(compileResult.stderr, "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'"); +assertContains(compileResult.stderr, "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'"); console.log("Success"); diff --git a/test/general-tests/starknet-call/check.ts b/test/general-tests/starknet-call/check.ts index 3368a333..af5ef068 100644 --- a/test/general-tests/starknet-call/check.ts +++ b/test/general-tests/starknet-call/check.ts @@ -1,7 +1,7 @@ import { readFileSync } from "fs"; import path from "path"; import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetCall } from "../../utils/cli-functions"; -import { contains, ensureEnvVar, extractAddress } from "../../utils/utils"; +import { assertContains, ensureEnvVar, extractAddress } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); @@ -15,22 +15,22 @@ const prefix = path.join(__dirname); console.log("Testing no input argument"); let execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); console.log("The success case of starknet-call test is temporarily disabled."); console.log("To enable it back, uncomment the lines in its check.sh."); // console.log("Testing success case"); // execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split(" "), true); -// contains(execution.stdout, "40 60"); +// assertContains(execution.stdout, "40 60"); // console.log("Success"); diff --git a/test/general-tests/starknet-estimate-fee/check.ts b/test/general-tests/starknet-estimate-fee/check.ts index a97234a2..54985a5b 100644 --- a/test/general-tests/starknet-estimate-fee/check.ts +++ b/test/general-tests/starknet-estimate-fee/check.ts @@ -1,7 +1,7 @@ import { readFileSync } from "fs"; import path from "path"; import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetEstimateFee } from "../../utils/cli-functions"; -import { contains, ensureEnvVar, extractAddress } from "../../utils/utils"; +import { assertContains, ensureEnvVar, extractAddress } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); @@ -13,22 +13,22 @@ const prefix = path.join(__dirname); console.log("Testing no input argument"); let execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); console.log("The success case of starknet-estimate-fee test is temporarily disabled."); console.log("To enable it back, uncomment the lines in its check.sh."); // console.log("Testing success case"); // execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split(" "), false); -// contains(execution.stdout, "40 60") +// assertContains(execution.stdout, "40 60") // console.log("Success"); diff --git a/test/general-tests/starknet-invoke/check.ts b/test/general-tests/starknet-invoke/check.ts index 919ae709..19f894c9 100644 --- a/test/general-tests/starknet-invoke/check.ts +++ b/test/general-tests/starknet-invoke/check.ts @@ -1,7 +1,7 @@ import { readFileSync } from "fs"; import path from "path"; import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetInvoke } from "../../utils/cli-functions"; -import { contains, ensureEnvVar, extractAddress } from "../../utils/utils"; +import { assertContains, ensureEnvVar, extractAddress } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); @@ -13,22 +13,22 @@ const prefix = path.join(__dirname); console.log("Testing no input argument"); let execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address}`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs 10`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs "10 20 30"`.split(" "), true); -contains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); +assertContains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); console.log("The success case of starknet-invoke test is temporarily disabled."); console.log("To enable it back, uncomment the lines in its check.sh."); // console.log("Testing success case"); // execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs "10 20"`.split(" "), true); -// contains(execution.stdout, "Invoke transaction was sent."); +// assertContains(execution.stdout, "Invoke transaction was sent."); // console.log("Success"); diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts index c9629d2c..1e35747b 100644 --- a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts @@ -1,5 +1,5 @@ import { spawn } from "child_process"; -import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; (async () => { @@ -9,7 +9,7 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun hardhatStarknetCompile(["contracts/contract.cairo"]); const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - contains(execution.stderr, "127.0.0.1:5050 already occupied."); + assertContains(execution.stderr, "127.0.0.1:5050 already occupied."); result.kill(); await checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts index 1a09168d..24fe5119 100644 --- a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts +++ b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts @@ -1,10 +1,10 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - contains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + assertContains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); await checkDevnetIsNotRunning(); })(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts index cdd32fb1..c82dd7ca 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts @@ -1,5 +1,5 @@ import { readFileSync } from "fs"; -import { assertExists, checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { assertExists, checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; (async () => { @@ -10,12 +10,12 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun hardhatStarknetCompile(["contracts/contract.cairo"]); const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - contains(execution.stderr, expectedWarning); + assertContains(execution.stderr, expectedWarning); // Checks if file logs/stderr.log exists and contains the expected warning string assertExists("logs/stdout.log", "Expected logs/stdout.log to exist"); const stdout = readFileSync("logs/stdout.log", "utf-8"); - contains(stdout, expectedStdout); + assertContains(stdout, expectedStdout); console.log("Success"); await checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts index 6f689bbb..dd8d9f5a 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts @@ -1,11 +1,11 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - contains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + assertContains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); await checkDevnetIsNotRunning(); })(); diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.ts b/test/integrated-devnet-tests/with-stderr-to-file/check.ts index a94fc212..538070f9 100644 --- a/test/integrated-devnet-tests/with-stderr-to-file/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-file/check.ts @@ -1,5 +1,5 @@ import { readFileSync } from "fs"; -import { assertExists, checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { assertExists, checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; (async () => { @@ -11,12 +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 - contains(output.stdout, expectedStdout); + assertContains(output.stdout, expectedStdout); // Checks if file logs/stderr.log exists and contains the expected warning string assertExists("logs/stderr.log", "Expected logs/stderr.log to exist"); const stderr = readFileSync("logs/stderr.log", "utf-8"); - contains(stderr, expectedWarning); + assertContains(stderr, expectedWarning); console.log("Success"); await checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts index 5cad04e5..330be001 100644 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts @@ -1,5 +1,5 @@ import { spawn } from "child_process"; -import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; (async () => { @@ -8,7 +8,7 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun const result = spawn("starknet-devnet", "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), { detached: true }); hardhatStarknetCompile(["contracts/contract.cairo"]); const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - contains(execution.stderr, "127.0.0.1:5050 already occupied."); + assertContains(execution.stderr, "127.0.0.1:5050 already occupied."); result.kill(); await checkDevnetIsNotRunning(); diff --git a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts index 06b6b135..1264762b 100644 --- a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts +++ b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts @@ -1,12 +1,12 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -import { checkDevnetIsNotRunning, contains } from "../../utils/utils"; +import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - contains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + assertContains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); await checkDevnetIsNotRunning(); })(); diff --git a/test/recompilation-tests/recompiler-default/check.ts b/test/recompilation-tests/recompiler-default/check.ts index f40528f4..1389613b 100644 --- a/test/recompilation-tests/recompiler-default/check.ts +++ b/test/recompilation-tests/recompiler-default/check.ts @@ -1,9 +1,9 @@ import { hardhatStarknetRun } from "../../utils/cli-functions"; -import { contains, rmrfSync } from "../../utils/utils"; +import { assertContains, rmrfSync } from "../../utils/utils"; const expected = "StarknetPluginError: Artifact expected to be at"; console.log("Testing with deleted artifact on recompiler option set to default (off)"); rmrfSync("starknet-artifacts/contracts/contract.cairo"); const execution = hardhatStarknetRun("--no-compile scripts/deploy.ts".split(" "), true); -contains(execution.stderr, expected); +assertContains(execution.stderr, expected); diff --git a/test/recompilation-tests/recompiler-off/check.ts b/test/recompilation-tests/recompiler-off/check.ts index 769aaa2a..355b3f58 100644 --- a/test/recompilation-tests/recompiler-off/check.ts +++ b/test/recompilation-tests/recompiler-off/check.ts @@ -1,10 +1,10 @@ import { hardhatStarknetRun } from "../../utils/cli-functions"; -import { contains, rmrfSync } from "../../utils/utils"; +import { assertContains, rmrfSync } from "../../utils/utils"; const expected = "StarknetPluginError: Artifact expected to be at"; console.log("Testing with deleted artifact on recompiler option set to default (off)"); rmrfSync("starknet-artifacts/contracts/contract.cairo"); const execution = hardhatStarknetRun("--no-compile scripts/deploy.ts".split(" "), true); -contains(execution.stderr, expected); +assertContains(execution.stderr, expected); console.log("Success"); diff --git a/test/utils/deploy-funded-account.ts b/test/utils/deploy-funded-account.ts index a0769a28..b4ac21e2 100644 --- a/test/utils/deploy-funded-account.ts +++ b/test/utils/deploy-funded-account.ts @@ -1,18 +1,15 @@ import axios from "axios"; import { readFileSync } from "fs"; import path from "path"; -import { StarknetPluginError } from "../../src/starknet-plugin-error"; import { DEVNET_URL } from "../constants/constants"; import { hardhatStarknetDeployAccount, hardhatStarknetNewAccount } from "./cli-functions"; -import { ensureEnvVar } from "./utils"; +import { assertEqual, ensureEnvVar } from "./utils"; export async function deployFundedAccount(url = DEVNET_URL) { const network = ensureEnvVar("NETWORK"); const accountDir = ensureEnvVar("ACCOUNT_DIR"); - if (network !== "devnet") { - throw new StarknetPluginError("only works with NETWORK set to devnet"); - } + assertEqual(network, "devnet", "only works with NETWORK set to devnet"); const args = [ "--starknet-network", diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 50cf7cbb..2163aab1 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -2,24 +2,21 @@ import axios from "axios"; import assert, { AssertionError } from "assert"; import { existsSync, rmSync } from "fs"; import shell from "shelljs"; -import { StarknetPluginError } from "../../src/starknet-plugin-error"; import { DEVNET_URL } from "../constants/constants"; export function exec(cmd: string) { const result = shell.exec(cmd); - if (result.code !== 0) { - throw new StarknetPluginError(`Command ${cmd} failed.\n${result.stderr}`); - } + assertEqual(result.code, 0, `Command ${cmd} failed.\n${result.stderr}`); return result; } -export function contains(output: string, pattern: string) { +export function assertContains(output: string, pattern: string) { if (!output.includes(pattern)) { console.error("Pattern not in input"); console.error("Pattern:", pattern); console.error("Input:", output); - throw new StarknetPluginError("Pattern not in input"); + throw new AssertionError({ message: "Pattern not in input" }); } } @@ -34,7 +31,7 @@ export function extractAddress(source: string, pattern: string) { export async function checkDevnetIsNotRunning(url = DEVNET_URL): Promise { try { const res = await axios.get(`${url}/is_alive`); - throw new StarknetPluginError(`Devnet is running and responded with status ${res.status}`); + throw new AssertionError({ message: `Devnet is running and responded with status ${res.status}` }); } catch (err) { console.log("Devnet is not running!"); } From 4d34851208155284ea1c9cb482029ecfacfc7872 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 22:23:09 +0300 Subject: [PATCH 37/41] Silent venv activation --- test/integrated-devnet-tests/with-active-venv/check.ts | 2 +- test/venv-tests/with-venv-active/check.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integrated-devnet-tests/with-active-venv/check.ts b/test/integrated-devnet-tests/with-active-venv/check.ts index b69e17d7..320eccde 100644 --- a/test/integrated-devnet-tests/with-active-venv/check.ts +++ b/test/integrated-devnet-tests/with-active-venv/check.ts @@ -2,7 +2,7 @@ import path from "path"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; -exec(`bash ${path.join(__dirname, "venv.sh")}`); +// exec(`bash ${path.join(__dirname, "venv.sh")}`); (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); diff --git a/test/venv-tests/with-venv-active/check.ts b/test/venv-tests/with-venv-active/check.ts index b2eef50c..83ed4c00 100644 --- a/test/venv-tests/with-venv-active/check.ts +++ b/test/venv-tests/with-venv-active/check.ts @@ -4,7 +4,7 @@ import { ensureEnvVar, exec } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); -exec(`bash ${path.join(__dirname, "venv.sh")}`); +// exec(`bash ${path.join(__dirname, "venv.sh")}`); const initialValue = 10; hardhatStarknetCompile([]); From 5ef56b8f48311fd7362711b1debae12cb2b22e33 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 23:26:49 +0300 Subject: [PATCH 38/41] Remove unused imports --- test/integrated-devnet-tests/with-active-venv/check.ts | 3 +-- test/venv-tests/with-venv-active/check.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/integrated-devnet-tests/with-active-venv/check.ts b/test/integrated-devnet-tests/with-active-venv/check.ts index 320eccde..9a977054 100644 --- a/test/integrated-devnet-tests/with-active-venv/check.ts +++ b/test/integrated-devnet-tests/with-active-venv/check.ts @@ -1,6 +1,5 @@ -import path from "path"; import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -import { checkDevnetIsNotRunning, exec } from "../../utils/utils"; +import { checkDevnetIsNotRunning } from "../../utils/utils"; // exec(`bash ${path.join(__dirname, "venv.sh")}`); (async () => { diff --git a/test/venv-tests/with-venv-active/check.ts b/test/venv-tests/with-venv-active/check.ts index 83ed4c00..fd1f252f 100644 --- a/test/venv-tests/with-venv-active/check.ts +++ b/test/venv-tests/with-venv-active/check.ts @@ -1,6 +1,5 @@ -import path from "path"; import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions"; -import { ensureEnvVar, exec } from "../../utils/utils"; +import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); From 218c3e7d0bc75c0edc22f0dd59902403297fa04a Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Thu, 24 Nov 2022 23:45:00 +0300 Subject: [PATCH 39/41] Remove venv files [skip ci] --- test/integrated-devnet-tests/with-active-venv/check.ts | 1 - test/integrated-devnet-tests/with-active-venv/venv.sh | 4 ---- test/venv-tests/with-venv-active/check.ts | 1 - test/venv-tests/with-venv-active/venv.sh | 4 ---- 4 files changed, 10 deletions(-) delete mode 100755 test/integrated-devnet-tests/with-active-venv/venv.sh delete mode 100755 test/venv-tests/with-venv-active/venv.sh diff --git a/test/integrated-devnet-tests/with-active-venv/check.ts b/test/integrated-devnet-tests/with-active-venv/check.ts index 9a977054..7fbc39ec 100644 --- a/test/integrated-devnet-tests/with-active-venv/check.ts +++ b/test/integrated-devnet-tests/with-active-venv/check.ts @@ -1,7 +1,6 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; import { checkDevnetIsNotRunning } from "../../utils/utils"; -// exec(`bash ${path.join(__dirname, "venv.sh")}`); (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); diff --git a/test/integrated-devnet-tests/with-active-venv/venv.sh b/test/integrated-devnet-tests/with-active-venv/venv.sh deleted file mode 100755 index 1b9b9269..00000000 --- a/test/integrated-devnet-tests/with-active-venv/venv.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -source ../my-venv/bin/activate diff --git a/test/venv-tests/with-venv-active/check.ts b/test/venv-tests/with-venv-active/check.ts index fd1f252f..409fd4cb 100644 --- a/test/venv-tests/with-venv-active/check.ts +++ b/test/venv-tests/with-venv-active/check.ts @@ -3,7 +3,6 @@ import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); -// exec(`bash ${path.join(__dirname, "venv.sh")}`); const initialValue = 10; hardhatStarknetCompile([]); diff --git a/test/venv-tests/with-venv-active/venv.sh b/test/venv-tests/with-venv-active/venv.sh deleted file mode 100755 index 1b9b9269..00000000 --- a/test/venv-tests/with-venv-active/venv.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -source ../my-venv/bin/activate From 775582183719b1acdcaea8876f6a74151fdf2508 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Fri, 25 Nov 2022 11:38:49 +0300 Subject: [PATCH 40/41] Multiline string [skip ci] --- test/utils/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 2163aab1..6c4ccd6c 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -13,9 +13,9 @@ export function exec(cmd: string) { export function assertContains(output: string, pattern: string) { if (!output.includes(pattern)) { - console.error("Pattern not in input"); - console.error("Pattern:", pattern); - console.error("Input:", output); + console.error(`Pattern not in input +Pattern: ${pattern} +Input: ${output}`); throw new AssertionError({ message: "Pattern not in input" }); } } From a34e1106318964e889bb6e8e12a3829254a5a437 Mon Sep 17 00:00:00 2001 From: Nathan-SL Date: Fri, 25 Nov 2022 11:56:03 +0300 Subject: [PATCH 41/41] Format and use multiline error message [skip ci] --- .../with-artifacts-path/check.ts | 6 +++- .../with-cairo-version/check.ts | 6 +++- .../with-cli-paths/check.ts | 6 +++- .../with-deploy-inputs/check.ts | 12 +++++-- .../with-deploy-path/check.ts | 6 +++- .../with-networks/check.ts | 24 ++++++++++--- .../with-sources-path/check.ts | 6 +++- test/configuration-tests/with-wait/check.ts | 4 ++- test/constants/constants.ts | 1 - test/general-tests/constructor-test/check.ts | 6 +++- .../expect-error-on-compile/check.ts | 5 ++- test/general-tests/plain/check.ts | 18 ++++++++-- test/general-tests/short-string-test/check.ts | 4 ++- test/general-tests/starknet-call/check.ts | 35 +++++++++++++++---- .../starknet-estimate-fee/check.ts | 33 ++++++++++++++--- test/general-tests/starknet-invoke/check.ts | 33 ++++++++++++++--- .../starknet-new-account/check.ts | 4 ++- test/general-tests/starknet-verify/check.ts | 12 +++++-- test/general-tests/wallet-test/check.ts | 26 +++++++++++--- .../with-docker-address-occupied/check.ts | 11 ++++-- .../with-docker-wrong-cli/check.ts | 10 ++++-- .../with-stderr-to-STDERR/check.ts | 8 +++-- .../with-stderr-to-STDOUT/check.ts | 10 ++++-- .../with-stderr-to-file/check.ts | 3 +- .../with-venv-address-occupied/check.ts | 11 ++++-- .../with-venv-wrong-cli/check.ts | 10 ++++-- .../recompilation-tests/hardhat-test/check.ts | 5 ++- .../starknet-call/check.ts | 12 +++++-- .../starknet-deploy/check.ts | 6 +++- .../starknet-invoke/check.ts | 6 +++- test/utils/deploy-funded-account.ts | 10 ++---- test/utils/utils.ts | 12 +++---- test/venv-tests/with-venv-active/check.ts | 6 +++- test/venv-tests/with-venv/check.ts | 12 +++++-- 34 files changed, 301 insertions(+), 78 deletions(-) diff --git a/test/configuration-tests/with-artifacts-path/check.ts b/test/configuration-tests/with-artifacts-path/check.ts index bd555467..bceee3eb 100644 --- a/test/configuration-tests/with-artifacts-path/check.ts +++ b/test/configuration-tests/with-artifacts-path/check.ts @@ -4,5 +4,9 @@ import { ensureEnvVar, rmrfSync } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile("contracts/contract.cairo".split(" ")); -hardhatStarknetDeploy(`--starknet-network ${network} my-starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +hardhatStarknetDeploy( + `--starknet-network ${network} my-starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); rmrfSync("my-starknet-artifacts"); diff --git a/test/configuration-tests/with-cairo-version/check.ts b/test/configuration-tests/with-cairo-version/check.ts index d4b3b536..5b488721 100644 --- a/test/configuration-tests/with-cairo-version/check.ts +++ b/test/configuration-tests/with-cairo-version/check.ts @@ -4,4 +4,8 @@ import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile("contracts/contract.cairo".split(" ")); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo --starknet-network ${network} --inputs 10`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo --starknet-network ${network} --inputs 10`.split( + " " + ) +); diff --git a/test/configuration-tests/with-cli-paths/check.ts b/test/configuration-tests/with-cli-paths/check.ts index da5878ec..9d98d53e 100644 --- a/test/configuration-tests/with-cli-paths/check.ts +++ b/test/configuration-tests/with-cli-paths/check.ts @@ -4,4 +4,8 @@ import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile("contracts/contract.cairo".split(" ")); -hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); diff --git a/test/configuration-tests/with-deploy-inputs/check.ts b/test/configuration-tests/with-deploy-inputs/check.ts index 9ea3ac53..92a293bd 100644 --- a/test/configuration-tests/with-deploy-inputs/check.ts +++ b/test/configuration-tests/with-deploy-inputs/check.ts @@ -4,5 +4,13 @@ import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile("contracts/contract.cairo".split(" ")); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network}`.split(" ")); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network} --salt 0x10`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network}`.split( + " " + ) +); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network} --salt 0x10`.split( + " " + ) +); diff --git a/test/configuration-tests/with-deploy-path/check.ts b/test/configuration-tests/with-deploy-path/check.ts index d95c0cf9..4e611b9a 100644 --- a/test/configuration-tests/with-deploy-path/check.ts +++ b/test/configuration-tests/with-deploy-path/check.ts @@ -4,5 +4,9 @@ import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile("contracts/contract.cairo".split(" ")); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network}`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo/ --inputs "10" --starknet-network ${network}`.split( + " " + ) +); hardhatStarknetDeploy(`contract --inputs "10" --starknet-network ${network}`.split(" ")); diff --git a/test/configuration-tests/with-networks/check.ts b/test/configuration-tests/with-networks/check.ts index 3edcee7b..5843c040 100644 --- a/test/configuration-tests/with-networks/check.ts +++ b/test/configuration-tests/with-networks/check.ts @@ -1,22 +1,36 @@ import { assertContains } from "../../utils/utils"; import path from "path"; import { readFileSync } from "fs"; -import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetDeploy, + hardhatStarknetTest +} from "../../utils/cli-functions"; hardhatStarknetCompile(["contracts/contract.cairo"]); const artifactsPath = "starknet-artifacts/contracts/contract.cairo/"; const invalidNetwork = "foo"; -const expected = "Error in plugin Starknet: Invalid network provided in starknet.network in hardhat.config: foo."; +const expected = + "Error in plugin Starknet: Invalid network provided in starknet.network in hardhat.config: foo."; const prefix = path.join(__dirname); console.log("Testing no starknet network"); let execution = hardhatStarknetDeploy(`${artifactsPath} --inputs 10`.split(" "), true); -assertContains(execution.stderr, readFileSync(path.join(prefix, "without-starknet-network.txt")).toString()); +assertContains( + execution.stderr, + readFileSync(path.join(prefix, "without-starknet-network.txt")).toString() +); console.log("Success"); console.log("Testing invalid CLI network"); -execution = hardhatStarknetDeploy(`--starknet-network ${invalidNetwork} ${artifactsPath} --inputs 10`.split(" "), true); -assertContains(execution.stderr, readFileSync(path.join(prefix, "invalid-cli-network.txt")).toString()); +execution = hardhatStarknetDeploy( + `--starknet-network ${invalidNetwork} ${artifactsPath} --inputs 10`.split(" "), + true +); +assertContains( + execution.stderr, + readFileSync(path.join(prefix, "invalid-cli-network.txt")).toString() +); console.log("Success"); console.log("Testing no mocha network"); diff --git a/test/configuration-tests/with-sources-path/check.ts b/test/configuration-tests/with-sources-path/check.ts index fc75cd6c..a693d445 100644 --- a/test/configuration-tests/with-sources-path/check.ts +++ b/test/configuration-tests/with-sources-path/check.ts @@ -7,4 +7,8 @@ const network = ensureEnvVar("NETWORK"); renameSync("contracts", "my-starknet-sources"); hardhatStarknetCompile([]); -hardhatStarknetDeploy(`starknet-artifacts/my-starknet-sources/contract.cairo/ --starknet-network ${network} --inputs 10`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/my-starknet-sources/contract.cairo/ --starknet-network ${network} --inputs 10`.split( + " " + ) +); diff --git a/test/configuration-tests/with-wait/check.ts b/test/configuration-tests/with-wait/check.ts index 6ac81c86..e346d934 100644 --- a/test/configuration-tests/with-wait/check.ts +++ b/test/configuration-tests/with-wait/check.ts @@ -4,4 +4,6 @@ import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile(["contracts/util.cairo"]); -hardhatStarknetDeploy(`starknet-artifacts/contracts/util.cairo/ --starknet-network ${network} --wait`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/util.cairo/ --starknet-network ${network} --wait`.split(" ") +); diff --git a/test/constants/constants.ts b/test/constants/constants.ts index 13516e27..1bbf3610 100644 --- a/test/constants/constants.ts +++ b/test/constants/constants.ts @@ -1,4 +1,3 @@ - export const HOST = "127.0.0.1"; export const PORT = "5050"; export const NODE_PORT = "8545"; diff --git a/test/general-tests/constructor-test/check.ts b/test/general-tests/constructor-test/check.ts index 7ebb6ec8..c9c3afb5 100644 --- a/test/general-tests/constructor-test/check.ts +++ b/test/general-tests/constructor-test/check.ts @@ -1,4 +1,8 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-functions"; -hardhatStarknetCompile("contracts/contract.cairo contracts/simple_storage.cairo contracts/empty_constructor.cairo".split(" ")); +hardhatStarknetCompile( + "contracts/contract.cairo contracts/simple_storage.cairo contracts/empty_constructor.cairo".split( + " " + ) +); hardhatStarknetTest("--no-compile test/constructor.test.ts".split(" ")); diff --git a/test/general-tests/expect-error-on-compile/check.ts b/test/general-tests/expect-error-on-compile/check.ts index 028bac77..b4ff3c1c 100644 --- a/test/general-tests/expect-error-on-compile/check.ts +++ b/test/general-tests/expect-error-on-compile/check.ts @@ -10,5 +10,8 @@ copyFileSync(path.join(__dirname, contractName), contractPath); console.log("Testing rejection of compilation with correct message"); const compileResult = hardhatStarknetCompile([contractPath], true); -assertContains(compileResult.stderr, "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'"); +assertContains( + compileResult.stderr, + "Unknown identifier 'openzeppelin.token.erc721.library.ERC721.nonexistent_method'" +); console.log("Success"); diff --git a/test/general-tests/plain/check.ts b/test/general-tests/plain/check.ts index fb08c5fe..b1d2ea07 100644 --- a/test/general-tests/plain/check.ts +++ b/test/general-tests/plain/check.ts @@ -1,4 +1,8 @@ -import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetDeploy, + hardhatStarknetTest +} from "../../utils/cli-functions"; import { ensureEnvVar } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); @@ -6,6 +10,14 @@ const initialValue = 10; const publicKey = "1628448741648245036800002906075225705100596136133912895015035902954123957052"; hardhatStarknetCompile([]); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split(" ")); -hardhatStarknetDeploy(`starknet-artifacts/contracts/auth_contract.cairo/ --inputs "${publicKey} ${initialValue}" --starknet-network ${network}`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split( + " " + ) +); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/auth_contract.cairo/ --inputs "${publicKey} ${initialValue}" --starknet-network ${network}`.split( + " " + ) +); hardhatStarknetTest("--no-compile test/sample-test.ts".split(" ")); diff --git a/test/general-tests/short-string-test/check.ts b/test/general-tests/short-string-test/check.ts index ee90135c..9720961f 100644 --- a/test/general-tests/short-string-test/check.ts +++ b/test/general-tests/short-string-test/check.ts @@ -4,4 +4,6 @@ process.chdir(".."); // The config file used for running mocha tests is the one in root -hardhatStarknetTest("--no-compile test/general-tests/short-string-test/short-string-test.ts".split(" ")); +hardhatStarknetTest( + "--no-compile test/general-tests/short-string-test/short-string-test.ts".split(" ") +); diff --git a/test/general-tests/starknet-call/check.ts b/test/general-tests/starknet-call/check.ts index af5ef068..31532efb 100644 --- a/test/general-tests/starknet-call/check.ts +++ b/test/general-tests/starknet-call/check.ts @@ -1,30 +1,53 @@ import { readFileSync } from "fs"; import path from "path"; -import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetCall } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetDeploy, + hardhatStarknetCall +} from "../../utils/cli-functions"; import { assertContains, ensureEnvVar, extractAddress } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); - hardhatStarknetCompile(["contracts/contract.cairo"]); -const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" "), true); +const output = hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ), + true +); console.log(output.stdout); const address = extractAddress(output.stdout, "Contract address: "); const prefix = path.join(__dirname); console.log("Testing no input argument"); -let execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split(" "), true); +let execution = hardhatStarknetCall( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); -execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split(" "), true); +execution = hardhatStarknetCall( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); -execution = hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split(" "), true); +execution = hardhatStarknetCall( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); diff --git a/test/general-tests/starknet-estimate-fee/check.ts b/test/general-tests/starknet-estimate-fee/check.ts index 54985a5b..25228a09 100644 --- a/test/general-tests/starknet-estimate-fee/check.ts +++ b/test/general-tests/starknet-estimate-fee/check.ts @@ -1,28 +1,51 @@ import { readFileSync } from "fs"; import path from "path"; -import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetEstimateFee } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetDeploy, + hardhatStarknetEstimateFee +} from "../../utils/cli-functions"; import { assertContains, ensureEnvVar, extractAddress } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile(["contracts/contract.cairo"]); -const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +const output = hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); const address = extractAddress(output.stdout, "Contract address: "); const prefix = path.join(__dirname); console.log("Testing no input argument"); -let execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split(" "), true); +let execution = hardhatStarknetEstimateFee( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address}`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); -execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split(" "), true); +execution = hardhatStarknetEstimateFee( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30"`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); -execution = hardhatStarknetEstimateFee(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split(" "), true); +execution = hardhatStarknetEstimateFee( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40 50"`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); diff --git a/test/general-tests/starknet-invoke/check.ts b/test/general-tests/starknet-invoke/check.ts index 19f894c9..c67904a1 100644 --- a/test/general-tests/starknet-invoke/check.ts +++ b/test/general-tests/starknet-invoke/check.ts @@ -1,28 +1,51 @@ import { readFileSync } from "fs"; import path from "path"; -import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetInvoke } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetDeploy, + hardhatStarknetInvoke +} from "../../utils/cli-functions"; import { assertContains, ensureEnvVar, extractAddress } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile(["contracts/contract.cairo"]); -const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +const output = hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); const address = extractAddress(output.stdout, "Contract address: "); const prefix = path.join(__dirname); console.log("Testing no input argument"); -let execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address}`.split(" "), true); +let execution = hardhatStarknetInvoke( + `--starknet-network ${network} --contract contract --function increase_balance --address ${address}`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "no-inputs.txt")).toString()); console.log("Success"); console.log("Testing too few input arguments"); -execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs 10`.split(" "), true); +execution = hardhatStarknetInvoke( + `--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs 10`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "too-few-inputs.txt")).toString()); console.log("Success"); console.log("Testing too many input arguments"); -execution = hardhatStarknetInvoke(`--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs "10 20 30"`.split(" "), true); +execution = hardhatStarknetInvoke( + `--starknet-network ${network} --contract contract --function increase_balance --address ${address} --inputs "10 20 30"`.split( + " " + ), + true +); assertContains(execution.stderr, readFileSync(path.join(prefix, "too-many-inputs.txt")).toString()); console.log("Success"); diff --git a/test/general-tests/starknet-new-account/check.ts b/test/general-tests/starknet-new-account/check.ts index 516ac368..2b7246ea 100644 --- a/test/general-tests/starknet-new-account/check.ts +++ b/test/general-tests/starknet-new-account/check.ts @@ -10,7 +10,9 @@ const accountDir = path.join(home, ".starknet_new_account_test"); process.env.ACCOUNT_DIR = accountDir; const accountFilePath = path.join(accountDir, "starknet_open_zeppelin_accounts.json"); -const output = hardhatStarknetNewAccount(`--wallet OpenZeppelin --starknet-network ${network}`.split(" ")); +const output = hardhatStarknetNewAccount( + `--wallet OpenZeppelin --starknet-network ${network}`.split(" ") +); const accountAddressStd = extractAddress(output.stdout, "Account address: "); // Read newly created account and grab the address diff --git a/test/general-tests/starknet-verify/check.ts b/test/general-tests/starknet-verify/check.ts index 74ba2cc4..e878e007 100644 --- a/test/general-tests/starknet-verify/check.ts +++ b/test/general-tests/starknet-verify/check.ts @@ -2,7 +2,9 @@ import { assertEqual, ensureEnvVar, exec, extractAddress } from "../../utils/uti 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!"); +console.log( + "The starknet-verify test is too flaky so it is temporarily suspended. Make sure it's working!" +); process.exit(0); const network = ensureEnvVar("NETWORK"); @@ -13,14 +15,18 @@ const utilContract = "contracts/util.cairo"; hardhatStarknetCompile(`${mainContract} ${utilContract}`.split(" ")); console.log("Waiting for deployment to be accepted"); -const output = hardhatStarknetDeploy(`--starknet-network ${network} contract --inputs 10 --wait`.split(" ")); +const output = hardhatStarknetDeploy( + `--starknet-network ${network} contract --inputs 10 --wait`.split(" ") +); const address = extractAddress(output.stdout, "Contract address: "); console.log("Verifying contract at $address"); console.log("Sleeping to allow Voyager to index the deployment"); exec("sleep 1m"); -exec(`npx hardhat starknet-verify --starknet-network ${network} --path ${mainContract} ${utilContract} --address ${address} --compiler-version 0.9.0 --license "No License (None)" --account-contract false`); +exec( + `npx hardhat starknet-verify --starknet-network ${network} --path ${mainContract} ${utilContract} --address ${address} --compiler-version 0.9.0 --license "No License (None)" --account-contract false` +); console.log("Sleeping to allow Voyager to register the verification"); exec("sleep 15s"); diff --git a/test/general-tests/wallet-test/check.ts b/test/general-tests/wallet-test/check.ts index f67572fa..406d3965 100644 --- a/test/general-tests/wallet-test/check.ts +++ b/test/general-tests/wallet-test/check.ts @@ -1,5 +1,11 @@ import path from "path"; -import { hardhatStarknetCompile, hardhatStarknetTest, hardhatStarknetDeploy, hardhatStarknetCall, hardhatStarknetInvoke } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetTest, + hardhatStarknetDeploy, + hardhatStarknetCall, + hardhatStarknetInvoke +} from "../../utils/cli-functions"; import { deployFundedAccount } from "../../utils/deploy-funded-account"; import { ensureEnvVar, extractAddress } from "../../utils/utils"; @@ -15,9 +21,21 @@ hardhatStarknetCompile(["contracts/contract.cairo"]); await deployFundedAccount(); hardhatStarknetTest("--no-compile test/wallet-test.ts".split(" ")); - const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); + const output = hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) + ); const address = extractAddress(output.stdout, "Contract address: "); - hardhatStarknetCall(`--contract contract --function get_balance --address ${address} --wallet OpenZeppelin --starknet-network ${network}`.split(" ")); - hardhatStarknetInvoke(`--contract contract --function increase_balance --inputs "10 20" --address ${address} --wallet OpenZeppelin --starknet-network ${network}`.split(" ")); + hardhatStarknetCall( + `--contract contract --function get_balance --address ${address} --wallet OpenZeppelin --starknet-network ${network}`.split( + " " + ) + ); + hardhatStarknetInvoke( + `--contract contract --function increase_balance --inputs "10 20" --address ${address} --wallet OpenZeppelin --starknet-network ${network}`.split( + " " + ) + ); })(); diff --git a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts index 1e35747b..e730d529 100644 --- a/test/integrated-devnet-tests/with-docker-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-docker-address-occupied/check.ts @@ -5,10 +5,17 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun (async () => { await checkDevnetIsNotRunning(); // run devnet which will cause integrated-devnet to fail - const result = spawn("starknet-devnet", "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), { detached: true }); + const result = spawn( + "starknet-devnet", + "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), + { detached: true } + ); hardhatStarknetCompile(["contracts/contract.cairo"]); - const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + const execution = hardhatStarknetTest( + "--no-compile test/integrated-devnet.test.ts".split(" "), + true + ); assertContains(execution.stderr, "127.0.0.1:5050 already occupied."); result.kill(); diff --git a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts index 24fe5119..32d84be0 100644 --- a/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts +++ b/test/integrated-devnet-tests/with-docker-wrong-cli/check.ts @@ -4,7 +4,13 @@ import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); - const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - assertContains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + const execution = hardhatStarknetTest( + "--no-compile test/integrated-devnet.test.ts".split(" "), + true + ); + assertContains( + execution.stderr, + "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value." + ); await checkDevnetIsNotRunning(); })(); diff --git a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts index c82dd7ca..66262672 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDERR/check.ts @@ -6,10 +6,14 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun await checkDevnetIsNotRunning(); const expectedStdout = "Account #0"; - const expectedWarning = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; + const expectedWarning = + "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; hardhatStarknetCompile(["contracts/contract.cairo"]); - const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + const execution = hardhatStarknetTest( + "--no-compile test/integrated-devnet.test.ts".split(" "), + true + ); assertContains(execution.stderr, expectedWarning); // Checks if file logs/stderr.log exists and contains the expected warning string diff --git a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts index dd8d9f5a..2b5b6182 100644 --- a/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-STDOUT/check.ts @@ -4,8 +4,14 @@ import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; (async () => { await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); - const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - assertContains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + const execution = hardhatStarknetTest( + "--no-compile test/integrated-devnet.test.ts".split(" "), + true + ); + assertContains( + execution.stderr, + "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value." + ); await checkDevnetIsNotRunning(); })(); diff --git a/test/integrated-devnet-tests/with-stderr-to-file/check.ts b/test/integrated-devnet-tests/with-stderr-to-file/check.ts index 538070f9..827daf77 100644 --- a/test/integrated-devnet-tests/with-stderr-to-file/check.ts +++ b/test/integrated-devnet-tests/with-stderr-to-file/check.ts @@ -7,7 +7,8 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun hardhatStarknetCompile(["contracts/contract.cairo"]); const expectedStdout = "Account #0"; - const expectedWarning = "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; + const expectedWarning = + "WARNING: Use these accounts and their keys ONLY for local testing. DO NOT use them on mainnet or other live networks because you will LOSE FUNDS."; const output = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" ")); // Checks if output contains the expected string from stdout diff --git a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts index 330be001..ae83a92b 100644 --- a/test/integrated-devnet-tests/with-venv-address-occupied/check.ts +++ b/test/integrated-devnet-tests/with-venv-address-occupied/check.ts @@ -5,9 +5,16 @@ import { hardhatStarknetCompile, hardhatStarknetTest } from "../../utils/cli-fun (async () => { await checkDevnetIsNotRunning(); - const result = spawn("starknet-devnet", "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), { detached: true }); + const result = spawn( + "starknet-devnet", + "--host 127.0.0.1 --port 5050 --accounts 0".split(" "), + { detached: true } + ); hardhatStarknetCompile(["contracts/contract.cairo"]); - const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); + const execution = hardhatStarknetTest( + "--no-compile test/integrated-devnet.test.ts".split(" "), + true + ); assertContains(execution.stderr, "127.0.0.1:5050 already occupied."); result.kill(); diff --git a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts index 1264762b..69ec938f 100644 --- a/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts +++ b/test/integrated-devnet-tests/with-venv-wrong-cli/check.ts @@ -5,8 +5,14 @@ import { checkDevnetIsNotRunning, assertContains } from "../../utils/utils"; await checkDevnetIsNotRunning(); hardhatStarknetCompile(["contracts/contract.cairo"]); - const execution = hardhatStarknetTest("--no-compile test/integrated-devnet.test.ts".split(" "), true); - assertContains(execution.stderr, "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value."); + const execution = hardhatStarknetTest( + "--no-compile test/integrated-devnet.test.ts".split(" "), + true + ); + assertContains( + execution.stderr, + "starknet-devnet: error: --accounts must be a positive integer; got: invalid_value." + ); await checkDevnetIsNotRunning(); })(); diff --git a/test/recompilation-tests/hardhat-test/check.ts b/test/recompilation-tests/hardhat-test/check.ts index 92ef49b8..5e2c612a 100644 --- a/test/recompilation-tests/hardhat-test/check.ts +++ b/test/recompilation-tests/hardhat-test/check.ts @@ -25,7 +25,10 @@ hardhatStarknetTest("--no-compile test/recompilation/recompilation-main-test.ts" console.log("Testing Recompilation with updated contract"); // Appending a new function to the contract -appendFileSync("contracts/contract_test_cache.cairo", readFileSync(path.join(prefix, "get_balance.cairo")).toString()); +appendFileSync( + "contracts/contract_test_cache.cairo", + readFileSync(path.join(prefix, "get_balance.cairo")).toString() +); hardhatStarknetTest("--no-compile test/recompilation/recompilation-update-test.ts".split(" ")); console.log("Testing Recompilation with cache file deleted"); diff --git a/test/recompilation-tests/starknet-call/check.ts b/test/recompilation-tests/starknet-call/check.ts index f237680d..d26ad033 100644 --- a/test/recompilation-tests/starknet-call/check.ts +++ b/test/recompilation-tests/starknet-call/check.ts @@ -4,8 +4,16 @@ import { extractAddress, ensureEnvVar, rmrfSync } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); console.log("Testing Recompilation with deleted artifact on starknet-call"); -const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +const output = hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); const address = extractAddress(output.stdout, "Contract address: "); rmrfSync("starknet-artifacts/contracts/contract.cairo"); -hardhatStarknetCall(`--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split(" ")); +hardhatStarknetCall( + `--starknet-network ${network} --contract contract --function sum_points_to_tuple --address ${address} --inputs "10 20 30 40"`.split( + " " + ) +); diff --git a/test/recompilation-tests/starknet-deploy/check.ts b/test/recompilation-tests/starknet-deploy/check.ts index eb9463db..db397d17 100644 --- a/test/recompilation-tests/starknet-deploy/check.ts +++ b/test/recompilation-tests/starknet-deploy/check.ts @@ -6,4 +6,8 @@ const network = ensureEnvVar("NETWORK"); // Hardhat starknet-deploy command console.log("Testing Recompilation with deleted artifact on starknet-deploy"); rmrfSync("starknet-artifacts/contracts/contract.cairo"); -hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); diff --git a/test/recompilation-tests/starknet-invoke/check.ts b/test/recompilation-tests/starknet-invoke/check.ts index 1c169c00..4d950534 100644 --- a/test/recompilation-tests/starknet-invoke/check.ts +++ b/test/recompilation-tests/starknet-invoke/check.ts @@ -6,7 +6,11 @@ import { ensureEnvVar, extractAddress, rmrfSync } from "../../utils/utils"; const network = ensureEnvVar("NETWORK"); // Hardhat starknet-invoke command console.log("Testing Recompilation with deleted artifact on hardhat starknet-invoke"); -const output = hardhatStarknetDeploy(`--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split(" ")); +const output = hardhatStarknetDeploy( + `--starknet-network ${network} starknet-artifacts/contracts/contract.cairo/ --inputs 10`.split( + " " + ) +); // Grab the output Contract address to a variable using parameter expansion const address = extractAddress(output.stdout, "Contract address: "); // Remove artifact contract to force recompilation diff --git a/test/utils/deploy-funded-account.ts b/test/utils/deploy-funded-account.ts index b4ac21e2..4b7d02ec 100644 --- a/test/utils/deploy-funded-account.ts +++ b/test/utils/deploy-funded-account.ts @@ -11,18 +11,14 @@ export async function deployFundedAccount(url = DEVNET_URL) { assertEqual(network, "devnet", "only works with NETWORK set to devnet"); - const args = [ - "--starknet-network", - network, - "--wallet", - "OpenZeppelin" - ]; + const args = ["--starknet-network", network, "--wallet", "OpenZeppelin"]; // Creates new account hardhatStarknetNewAccount(args); const accountFile = path.join(accountDir, "starknet_open_zeppelin_accounts.json"); - const accountAddress = JSON.parse(readFileSync(accountFile, "utf-8"))[network].OpenZeppelin.address; + const accountAddress = JSON.parse(readFileSync(accountFile, "utf-8"))[network].OpenZeppelin + .address; console.log(`Funding account ${accountAddress} on ${network}.`); await axios.post(`${url}/mint`, { diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 6c4ccd6c..8a77eb99 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -13,10 +13,9 @@ export function exec(cmd: string) { export function assertContains(output: string, pattern: string) { if (!output.includes(pattern)) { - console.error(`Pattern not in input -Pattern: ${pattern} -Input: ${output}`); - throw new AssertionError({ message: "Pattern not in input" }); + throw new AssertionError({ + message: `Pattern not in input\nPattern: ${pattern}\nInput: ${output}` + }); } } @@ -31,13 +30,14 @@ export function extractAddress(source: string, pattern: string) { export async function checkDevnetIsNotRunning(url = DEVNET_URL): Promise { try { const res = await axios.get(`${url}/is_alive`); - throw new AssertionError({ message: `Devnet is running and responded with status ${res.status}` }); + throw new AssertionError({ + message: `Devnet is running and responded with status ${res.status}` + }); } catch (err) { console.log("Devnet is not running!"); } } - export function ensureEnvVar(varName: string): string { if (!process.env[varName]) { throw new Error(`Env var ${varName} not set or empty`); diff --git a/test/venv-tests/with-venv-active/check.ts b/test/venv-tests/with-venv-active/check.ts index 409fd4cb..de24dc78 100644 --- a/test/venv-tests/with-venv-active/check.ts +++ b/test/venv-tests/with-venv-active/check.ts @@ -6,4 +6,8 @@ const network = ensureEnvVar("NETWORK"); const initialValue = 10; hardhatStarknetCompile([]); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split( + " " + ) +); diff --git a/test/venv-tests/with-venv/check.ts b/test/venv-tests/with-venv/check.ts index 2f5f08d0..ff0d9061 100644 --- a/test/venv-tests/with-venv/check.ts +++ b/test/venv-tests/with-venv/check.ts @@ -1,9 +1,17 @@ -import { hardhatStarknetCompile, hardhatStarknetDeploy, hardhatStarknetTest } from "../../utils/cli-functions"; +import { + hardhatStarknetCompile, + hardhatStarknetDeploy, + hardhatStarknetTest +} from "../../utils/cli-functions"; import { ensureEnvVar } from "../../utils/utils"; const initialValue = 10; const network = ensureEnvVar("NETWORK"); hardhatStarknetCompile([]); -hardhatStarknetDeploy(`starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split(" ")); +hardhatStarknetDeploy( + `starknet-artifacts/contracts/contract.cairo/ --starknet-network ${network} --inputs ${initialValue}`.split( + " " + ) +); hardhatStarknetTest("--no-compile test/quick-test.ts".split(" "));