diff --git a/.circleci/config.yml b/.circleci/config.yml index dc5d0778..ae889851 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,9 @@ aliases: - &node-base steps: - checkout + - run: + name: Versions + command: ./scripts/versions.sh - run: name: Install command: npm install @@ -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 diff --git a/.gitignore b/.gitignore index de4d1f00..105d5f0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist node_modules +starknet-hardhat-example diff --git a/package.json b/package.json index 0b79b7b8..db6a6ebd 100644 --- a/package.json +++ b/package.json @@ -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 ." }, diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 00000000..8a6c1466 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +rm -rf starknet-hardhat-example +git clone git@github.com: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)) diff --git a/scripts/versions.sh b/scripts/versions.sh new file mode 100755 index 00000000..52bbbf9a --- /dev/null +++ b/scripts/versions.sh @@ -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 diff --git a/test/plain/check.sh b/test/plain/check.sh new file mode 100755 index 00000000..d0395ed7 --- /dev/null +++ b/test/plain/check.sh @@ -0,0 +1,4 @@ + npx hardhat starknet-compile + npx hardhat starknet-deploy --starknet-network alpha + npx hardhat test + \ No newline at end of file diff --git a/test/plain/hardhat.config.js b/test/plain/hardhat.config.js new file mode 100644 index 00000000..93b078a3 --- /dev/null +++ b/test/plain/hardhat.config.js @@ -0,0 +1,4 @@ +require("../dist/index.js"); + +module.exports = { +}; diff --git a/test/with-artifacts-path/check.sh b/test/with-artifacts-path/check.sh new file mode 100755 index 00000000..e38ed2d0 --- /dev/null +++ b/test/with-artifacts-path/check.sh @@ -0,0 +1,3 @@ + npx hardhat starknet-compile + npx hardhat starknet-deploy --starknet-network alpha + \ No newline at end of file diff --git a/test/with-artifacts-path/hardhat.config.js b/test/with-artifacts-path/hardhat.config.js new file mode 100644 index 00000000..0f9b042d --- /dev/null +++ b/test/with-artifacts-path/hardhat.config.js @@ -0,0 +1,7 @@ +require("../dist/index.js"); + +module.exports = { + paths: { + starknetArtifacts: "my-starknet-artifacts" + } +}; diff --git a/test/with-cairo-version/check.sh b/test/with-cairo-version/check.sh new file mode 100755 index 00000000..e38ed2d0 --- /dev/null +++ b/test/with-cairo-version/check.sh @@ -0,0 +1,3 @@ + npx hardhat starknet-compile + npx hardhat starknet-deploy --starknet-network alpha + \ No newline at end of file diff --git a/test/with-cairo-version/hardhat.config.js b/test/with-cairo-version/hardhat.config.js new file mode 100644 index 00000000..fccbdf6c --- /dev/null +++ b/test/with-cairo-version/hardhat.config.js @@ -0,0 +1,7 @@ +require("../dist/index.js"); + +module.exports = { + cairo: { + version: "0.4.1" + } +}; diff --git a/test/with-sources-path/check.sh b/test/with-sources-path/check.sh new file mode 100755 index 00000000..e38ed2d0 --- /dev/null +++ b/test/with-sources-path/check.sh @@ -0,0 +1,3 @@ + npx hardhat starknet-compile + npx hardhat starknet-deploy --starknet-network alpha + \ No newline at end of file diff --git a/test/with-sources-path/hardhat.config.js b/test/with-sources-path/hardhat.config.js new file mode 100644 index 00000000..c6c481f7 --- /dev/null +++ b/test/with-sources-path/hardhat.config.js @@ -0,0 +1,7 @@ +require("../dist/index.js"); + +module.exports = { + paths: { + starknetSources: "my-starknet-sources" + } +}; diff --git a/test/with-sources-path/init.sh b/test/with-sources-path/init.sh new file mode 100755 index 00000000..ccf9b56a --- /dev/null +++ b/test/with-sources-path/init.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# consider `source`ing the script (caveat: affecting subsequent tests) +mv contracts my-starknet-sources