Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Replace bash test to TS using shelljs #251

Merged
merged 42 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c6fe5ca
WIP: Replace bash test to TS using shelljs
Nathan-SL Nov 8, 2022
b43adda
Add no-compile flag to test
Nathan-SL Nov 8, 2022
701a9a2
Put no-compile after the task name
Nathan-SL Nov 8, 2022
46201c4
Update suits for configuration test set
Nathan-SL Nov 9, 2022
189a496
Remove check.sh files
Nathan-SL Nov 14, 2022
77f9a40
Replace check.sh with check.ts
Nathan-SL Nov 14, 2022
2c56e9e
Make venv files executable
Nathan-SL Nov 14, 2022
a0cc8c1
Update test call to mocha
Nathan-SL Nov 14, 2022
d116760
Update test
Nathan-SL Nov 15, 2022
0e3bcba
Terminate detached processes
Nathan-SL Nov 15, 2022
2ca78f0
Terminate detached processes
Nathan-SL Nov 15, 2022
c904bb9
Update starknet-devnet version
Nathan-SL Nov 15, 2022
f4472c9
Merge branch 'master' into replace-bash-to-shelljs
Nathan-SL Nov 15, 2022
96def07
Update dev docs [skip ci]
Nathan-SL Nov 15, 2022
6c2ef52
Remove prev comment from test.sh
Nathan-SL Nov 17, 2022
90d81ba
Use path.join in place of concat
Nathan-SL Nov 17, 2022
aa04ee4
Update utils
Nathan-SL Nov 22, 2022
58238d7
Have create-fund-deploy script
Nathan-SL Nov 22, 2022
5ff203a
Add starknet cli helper functions
Nathan-SL Nov 22, 2022
7a6cc5a
Update test based on comments
Nathan-SL Nov 22, 2022
1ae0f61
:fire: Remove unused scripts & update utils
Nathan-SL Nov 22, 2022
9ea524d
Remove repetitive log [skip ci]
Nathan-SL Nov 22, 2022
c949138
Change branch
Nathan-SL Nov 22, 2022
e0a32dd
Kill with process.kill() & avoid silent execute
Nathan-SL Nov 23, 2022
0ef112a
Bug fix with contract path
Nathan-SL Nov 23, 2022
ce0b6e9
Use kill from shell
Nathan-SL Nov 23, 2022
04c64f4
Remove unused variable
Nathan-SL Nov 23, 2022
26185a0
Fix typo
Nathan-SL Nov 23, 2022
f053778
Avoid use of $0 in ts tests
Nathan-SL Nov 23, 2022
7f1c800
Restore branch name
Nathan-SL Nov 23, 2022
3bd3c03
Use constants for default url
Nathan-SL Nov 24, 2022
fb0c77a
Read port from constant
Nathan-SL Nov 24, 2022
f4cedb1
Replace StarknetPluginError with assertion
Nathan-SL Nov 24, 2022
7f9318d
Add new methods
Nathan-SL Nov 24, 2022
bcf5eec
Minor clean up
Nathan-SL Nov 24, 2022
7769e97
Update import
Nathan-SL Nov 24, 2022
f869821
Update test
Nathan-SL Nov 24, 2022
4d34851
Silent venv activation
Nathan-SL Nov 24, 2022
5ef56b8
Remove unused imports
Nathan-SL Nov 24, 2022
218c3e7
Remove venv files [skip ci]
Nathan-SL Nov 24, 2022
7755821
Multiline string [skip ci]
Nathan-SL Nov 25, 2022
a34e110
Format and use multiline error message [skip ci]
Nathan-SL Nov 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

8 changes: 6 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CONFIG_FILE_NAME="hardhat.config.ts"

# setup example repo
rm -rf starknet-hardhat-example
git clone -b plugin --single-branch [email protected]:Shard-Labs/starknet-hardhat-example.git
git clone -b resolveJsonModule --single-branch [email protected]:Shard-Labs/starknet-hardhat-example.git
FabijanC marked this conversation as resolved.
Show resolved Hide resolved
cd starknet-hardhat-example
git log -n 1
npm ci
Expand Down 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 { contains } 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);
contains(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.

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

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

Loading