diff --git a/.github/workflows/contracts-testing.yml b/.github/workflows/contracts-testing.yml new file mode 100644 index 000000000..3736f753d --- /dev/null +++ b/.github/workflows/contracts-testing.yml @@ -0,0 +1,60 @@ +name: Contracts Testing + +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + branches: + - "*" + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Setup Node.js environment + uses: actions/setup-node@v2.5.1 + with: + node-version: 16.x + + - uses: actions/checkout@v2.4.0 + + - name: Cache node modules + uses: actions/cache@v2.1.7 + env: + cache-name: cache-node-modules + with: + path: | + ~/.npm + **/node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + #- name: Install parent dependencies + # run: | + # echo "current dir: $PWD" + # yarn install + + - name: Install contracts dependencies + run: | + yarn workspace @kleros/kleros-v2-contracts install + + - name: Compile + run: | + npx hardhat compile + working-directory: contracts + + - name: Test with coverage + run: | + npx hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"./test/**/*.ts\" + working-directory: contracts + + - name: Upload a build artifact + uses: actions/upload-artifact@v2.3.1 + with: + name: code-coverage-report + path: contracts/coverage diff --git a/README.md b/README.md index dd8d06cfa..49090207d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@
+
diff --git a/contracts/.gitignore b/contracts/.gitignore
index 1d29ae4ea..18aa4922d 100644
--- a/contracts/.gitignore
+++ b/contracts/.gitignore
@@ -1,6 +1,7 @@
# Hardhat files
cache
artifacts
+coverage.json
## Hardhat typechain bindings/types
typechain
diff --git a/contracts/.solcover.js b/contracts/.solcover.js
new file mode 100644
index 000000000..43bd929a3
--- /dev/null
+++ b/contracts/.solcover.js
@@ -0,0 +1,19 @@
+/* eslint-disable node/no-extraneous-require */
+
+const shell = require("shelljs");
+
+// The environment variables are loaded in hardhat.config.ts
+
+module.exports = {
+ istanbulReporter: ["html"],
+ onCompileComplete: async function (_config) {
+ await run("typechain");
+ },
+ onIstanbulComplete: async function (_config) {
+ // We need to do this because solcover generates bespoke artifacts.
+ shell.rm("-rf", "./artifacts");
+ shell.rm("-rf", "./typechain");
+ },
+ providerOptions: {},
+ skipFiles: ["mocks", "test"],
+};
diff --git a/contracts/coverage.json b/contracts/coverage.json
deleted file mode 100644
index 75bd461c7..000000000
--- a/contracts/coverage.json
+++ /dev/null
@@ -1,122 +0,0 @@
-{
- "src/Greeter.sol": {
- "l": {
- "10": 3,
- "11": 3,
- "15": 2,
- "19": 1,
- "20": 1
- },
- "path": "/Users/jaybee/project/kleros/kleros-v2/contracts/src/Greeter.sol",
- "s": {
- "1": 3,
- "2": 3,
- "3": 2,
- "4": 1,
- "5": 1
- },
- "b": {},
- "f": {
- "1": 3,
- "2": 2,
- "3": 1
- },
- "fnMap": {
- "1": {
- "name": "constructor",
- "line": 9,
- "loc": {
- "start": {
- "line": 9,
- "column": 4
- },
- "end": {
- "line": 12,
- "column": 4
- }
- }
- },
- "2": {
- "name": "greet",
- "line": 14,
- "loc": {
- "start": {
- "line": 14,
- "column": 4
- },
- "end": {
- "line": 16,
- "column": 4
- }
- }
- },
- "3": {
- "name": "setGreeting",
- "line": 18,
- "loc": {
- "start": {
- "line": 18,
- "column": 4
- },
- "end": {
- "line": 21,
- "column": 4
- }
- }
- }
- },
- "statementMap": {
- "1": {
- "start": {
- "line": 10,
- "column": 8
- },
- "end": {
- "line": 10,
- "column": 67
- }
- },
- "2": {
- "start": {
- "line": 11,
- "column": 8
- },
- "end": {
- "line": 11,
- "column": 27
- }
- },
- "3": {
- "start": {
- "line": 15,
- "column": 8
- },
- "end": {
- "line": 15,
- "column": 23
- }
- },
- "4": {
- "start": {
- "line": 19,
- "column": 8
- },
- "end": {
- "line": 19,
- "column": 78
- }
- },
- "5": {
- "start": {
- "line": 20,
- "column": 8
- },
- "end": {
- "line": 20,
- "column": 27
- }
- }
- },
- "branchMap": {}
- }
-}