Skip to content

Commit

Permalink
Add testing (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabijanC authored Sep 29, 2021
1 parent 3a51f40 commit 2ecc499
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 5 deletions.
11 changes: 7 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ aliases:
- &node-base
steps:
- checkout
- run:
name: Versions
command: ./scripts/versions.sh
- run:
name: Install
command: npm install
Expand All @@ -17,12 +20,12 @@ aliases:
jobs:
test_node_v12:
<<: *node-base
docker:
- image: circleci/node:12
machine:
image: ubuntu-2004:202010-01
test_node_v14:
<<: *node-base
docker:
- image: circleci/node:14
machine:
image: ubuntu-2004:202107-02
npm_publish:
docker:
- image: circleci/node:14
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
starknet-hardhat-example
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Plugin for using Starknet tools within Hardhat projects",
"main": "dist/index.js",
"scripts": {
"test": "echo \"No tests yet. Add them!\"",
"test": "./scripts/test.sh",
"build": "rm -rf dist && tsc",
"build-image": "docker build -t shardlabs/cairo-cli --build-arg CAIRO_VERSION=$CAIRO_VERSION ."
},
Expand Down
26 changes: 26 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

rm -rf starknet-hardhat-example
git clone [email protected]:Shard-Labs/starknet-hardhat-example.git
cd starknet-hardhat-example
npm install

TOTAL=0
SUCCESS=0
for TEST_CASE in ../test/*; do
TOTAL=$((TOTAL + 1))
echo "Test $TOTAL) $TEST_CASE"
cp "$TEST_CASE/hardhat.config.js" hardhat.config.js

INIT_SCRIPT="$TEST_CASE/init.sh"
if [ -f "$INIT_SCRIPT" ]; then
$INIT_SCRIPT
fi

"$TEST_CASE/check.sh" && SUCCESS=$((SUCCESS + 1)) || echo "Test failed!"
git checkout --force
done

echo "Tests passing: $SUCCESS / $TOTAL"
exit $((TOTAL - SUCCESS))
9 changes: 9 additions & 0 deletions scripts/versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

node --version
npm --version

#these two commands may return different versions (e.g. if using circleci/node and remote docker)
docker --version
docker version
4 changes: 4 additions & 0 deletions test/plain/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
npx hardhat starknet-compile
npx hardhat starknet-deploy --starknet-network alpha
npx hardhat test

4 changes: 4 additions & 0 deletions test/plain/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require("../dist/index.js");

module.exports = {
};
3 changes: 3 additions & 0 deletions test/with-artifacts-path/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npx hardhat starknet-compile
npx hardhat starknet-deploy --starknet-network alpha

7 changes: 7 additions & 0 deletions test/with-artifacts-path/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require("../dist/index.js");

module.exports = {
paths: {
starknetArtifacts: "my-starknet-artifacts"
}
};
3 changes: 3 additions & 0 deletions test/with-cairo-version/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npx hardhat starknet-compile
npx hardhat starknet-deploy --starknet-network alpha

7 changes: 7 additions & 0 deletions test/with-cairo-version/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require("../dist/index.js");

module.exports = {
cairo: {
version: "0.4.1"
}
};
3 changes: 3 additions & 0 deletions test/with-sources-path/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npx hardhat starknet-compile
npx hardhat starknet-deploy --starknet-network alpha

7 changes: 7 additions & 0 deletions test/with-sources-path/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require("../dist/index.js");

module.exports = {
paths: {
starknetSources: "my-starknet-sources"
}
};
4 changes: 4 additions & 0 deletions test/with-sources-path/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# consider `source`ing the script (caveat: affecting subsequent tests)
mv contracts my-starknet-sources

0 comments on commit 2ecc499

Please sign in to comment.