Skip to content

Commit

Permalink
Replace bash test to TS using shelljs (#251)
Browse files Browse the repository at this point in the history
* [skip ci]
  • Loading branch information
Nathan-SL committed Nov 25, 2022
1 parent adbf6d7 commit 3183645
Show file tree
Hide file tree
Showing 140 changed files with 1,234 additions and 866 deletions.
6 changes: 3 additions & 3 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ 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

When running tests locally, you probably don't want to run the whole `test.sh` script as it may alter your development environment. However, you can run individual tests by:

- 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.

Expand Down
88 changes: 82 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
22 changes: 0 additions & 22 deletions scripts/assert-contains.py

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/check-devnet-is-not-running.sh

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/deploy-funded-cli-account.sh

This file was deleted.

6 changes: 5 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ function iterate_dir() {

[ "$network" == "devnet" ] && ../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 mocha -r ts-node/register "$test_case/check.ts" && success=$((success + 1)) || echo "Test failed!"
fi

rm -rf starknet-artifacts
git checkout --force
Expand Down
16 changes: 0 additions & 16 deletions test/configuration-tests/with-account-compilation-option/check.sh

This file was deleted.

16 changes: 16 additions & 0 deletions test/configuration-tests/with-account-compilation-option/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { copyFileSync } from "fs";
import path from "path";
import { hardhatStarknetCompile } from "../../utils/cli-functions";
import { assertContains } from "../../utils/utils";

const contractName = "dummy_account.cairo";
const contractPath = path.join("contracts", contractName);

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);
assertContains(execution.stderr, expected);
console.log("Success");
hardhatStarknetCompile(`${contractPath} --account-contract`.split(" "));
6 changes: 0 additions & 6 deletions test/configuration-tests/with-artifacts-path/check.sh

This file was deleted.

12 changes: 12 additions & 0 deletions test/configuration-tests/with-artifacts-path/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions";
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(
" "
)
);
rmrfSync("my-starknet-artifacts");
5 changes: 0 additions & 5 deletions test/configuration-tests/with-cairo-version/check.sh

This file was deleted.

11 changes: 11 additions & 0 deletions test/configuration-tests/with-cairo-version/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { hardhatStarknetCompile, hardhatStarknetDeploy } from "../../utils/cli-functions";
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(
" "
)
);
10 changes: 0 additions & 10 deletions test/configuration-tests/with-cli-network/check.sh

This file was deleted.

9 changes: 9 additions & 0 deletions test/configuration-tests/with-cli-network/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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.

hardhatStarknetRun("--no-compile scripts/compile-contract.ts".split(" "));
hardhatStarknetTest("--no-compile --starknet-network devnet test/quick-test.ts".split(" "));
5 changes: 0 additions & 5 deletions test/configuration-tests/with-cli-paths/check.sh

This file was deleted.

0 comments on commit 3183645

Please sign in to comment.