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

Connect tests to CI #18

Merged
merged 18 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
"parser": "@typescript-eslint/parser",
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
"parserOptions": { "ecmaVersion": 2022, "sourceType": "module" },
"plugins": ["no-only-tests"],
"plugins": ["no-only-tests", "simple-import-sort"],
"rules": {
"@typescript-eslint/no-explicit-any": ["warn"],
"@typescript-eslint/no-unused-vars": ["warn"],
// prevents committing `describe.only` and `it.only` tests
"no-only-tests/no-only-tests": "warn"
"no-only-tests/no-only-tests": "warn",
"simple-import-sort/imports": ["error",{
"groups": [
["^node:"],
["^\\u0000"],
["^[^@]\\w"],
["^@\\w"],
["^typechain-types"],
["^lib"],
["^test"],
["^../"],
["^./"],
["^"]
]
}]
},
"overrides": [
{
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Code Analysis

#on:
# push:
# branches: [master, develop]
# pull_request:
# branches: [master, develop]
#
#jobs:
# slither:
# name: Solidity code analysis
# runs-on: ubuntu-latest
#
# permissions:
# contents: read
# security-events: write
#
# steps:
# - uses: actions/checkout@v4
# with:
# persist-credentials: false
#
# - run: corepack enable
#
# - uses: actions/setup-node@v4
# with:
# node-version: 20
# cache: 'pnpm'
#
# - name: Install dependencies
# run: pnpm install
#
# # REVIEW: here and below steps taken from official guide
# # https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
# - name: Install poetry
# run: >
# pipx install poetry
#
# # REVIEW:
# # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-adding-a-system-path
# - name: Add poetry to $GITHUB_PATH
# run: >
# echo "$HOME/.local/bin" >> $GITHUB_PATH
#
# - uses: actions/setup-python@v5
# with:
# python-version: '3.12'
# cache: 'poetry'
#
# - name: Install dependencies
# run: poetry install --no-root
#
# - name: Run slither
# run: >
# poetry run slither . --sarif results.sarif --no-fail-pedantic
#
# - name: Check results.sarif presence
# id: results
# if: always()
# shell: bash
# run: >
# test -f results.sarif &&
# echo 'value=present' >> $GITHUB_OUTPUT ||
# echo 'value=not' >> $GITHUB_OUTPUT
#
# - name: Upload results.sarif file
# uses: github/codeql-action/upload-sarif@main
# if: ${{ always() && steps.results.outputs.value == 'present' }}
# with:
# sarif_file: results.sarif
54 changes: 54 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Linters

on: [push]

jobs:
lint:
name: Solidity and TypeScript linters
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run Solidity linters
run: pnpm lint:sol

- name: Run TS linters
run: pnpm lint:ts

types:
name: TypeScript types check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Generate typechain types
run: pnpm hardhat compile

- name: Run TypeScript types check
run: pnpm type:check
62 changes: 62 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Tests

on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

jobs:
test:
name: Solidity tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run Hardhat Solidity tests
run: pnpm test

coverage:
name: Solidity coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run Solidity coverage
run: pnpm test:coverage

- name: Produce the coverage report
uses: insightsengineering/coverage-action@v2
with:
path: ./coverage/cobertura-coverage.xml
publish: true
diff: true
diff-branch: master
diff-storage: _core_coverage_reports
coverage-summary-title: "Code Coverage Summary"
17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
node_modules
.env
coverage
/.idea

/node_modules
/coverage
coverage.json
typechain
typechain-types

/typechain
/typechain-types

# Hardhat files
cache
artifacts
/cache
/artifacts

.env
16 changes: 16 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
istanbulReporter: ['html', 'text', 'cobertura'],
// NOTE: those is are all relative paths to the `contracts` directory and does not support regex
// https://github.com/sc-forks/solidity-coverage/issues/632#issuecomment-1736629543
skipFiles: [
'0.4.24/template',
'0.4.24/test_helpers',
'0.6.11/deposit_contract.sol',
'0.6.12/interfaces',
'0.6.12/mocks',
'0.8.9/interfaces',
'0.8.9/test_helpers',
'common/interfaces',
'common/test_helpers',
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.trimTrailingWhitespace": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pnpm test
- eslint
- prettier
- solhint
- slither

## Todos

- anvil
- slither
- readme

## Conventions
Expand Down
8 changes: 5 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import path from "node:path";

import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox";
import "@typechain/hardhat";

import "solidity-coverage";
import "tsconfig-paths/register";
import { globSync } from "glob";
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import { HardhatUserConfig, subtask } from "hardhat/config";
import path from "path";
import "solidity-coverage";
import "tsconfig-paths/register";

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
Expand Down
1 change: 1 addition & 0 deletions lib/address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Wallet } from "ethers";

import { streccak } from "./keccak";

export function randomAddress() {
Expand Down
7 changes: 5 additions & 2 deletions lib/aragon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { BaseContract } from "ethers";

import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";

import {
ACL__factory,
DAOFactory__factory,
Expand All @@ -8,10 +11,10 @@ import {
Kernel__factory,
Lido__factory,
} from "typechain-types";

import { dummyLocator } from "./dummy";
import { findEvents } from "./event";
import { streccak } from "./keccak";
import { BaseContract } from "ethers";
import { dummyLocator } from "./dummy";
import { ether } from "./units";

export async function createAragonDao(rootAccount: HardhatEthersSigner) {
Expand Down
7 changes: 5 additions & 2 deletions lib/dsm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { sign, toEip2098 } from "./ec";
import { solidityPackedKeccak256 } from "ethers";

import { DepositSecurityModule } from "typechain-types";

import { sign, toEip2098 } from "./ec";

class DSMMessage {
static MESSAGE_PREFIX: string;

Expand All @@ -9,7 +12,7 @@ class DSMMessage {
}

get messagePrefix(): string {
const messagePrefix = this.constructor.MESSAGE_PREFIX;
const messagePrefix = (this.constructor as typeof DSMMessage).MESSAGE_PREFIX;
if (messagePrefix === undefined) {
throw new Error(`MESSAGE_PREFIX isn't set`);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/dummy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
import { ethers } from "hardhat";

import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";

import { LidoLocator, LidoLocator__factory } from "typechain-types";

import { certainAddress } from ".";

export async function dummyLocator(config?: Partial<LidoLocator.ConfigStruct>, deployer?: HardhatEthersSigner) {
Expand Down
9 changes: 5 additions & 4 deletions lib/ec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
ECDSASignature,
bufferToHex,
toBuffer,
ECDSASignature,
ecrecover,
ecsign,
pubToAddress,
toBuffer,
toChecksumAddress,
} from "ethereumjs-util";

import { de0x } from "./string";

export function sign(message: string, privateKey: string) {
Expand All @@ -19,11 +20,11 @@ export function recover(messageHash: string, { v, r, s }: ECDSASignature) {
}

// Converts a ECDSA signature to the format provided in https://eips.ethereum.org/EIPS/eip-2098.
export function toEip2098({ v, r, s }) {
export function toEip2098({ v, r, s }: ECDSASignature) {
const vs = toBuffer(s);
if (vs[0] >> 7 === 1) {
throw new Error(`invalid signature 's' value`);
}
vs[0] |= v % 27 << 7; // set the first bit of vs to the v parity bit
return [r, bufferToHex(vs)];
return { r, vs: bufferToHex(vs) };
}
4 changes: 3 additions & 1 deletion lib/eip712.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { toBuffer } from "ethereumjs-util";
import { AbiCoder, HDNodeWallet, keccak256, solidityPackedKeccak256 } from "ethers";
import { network } from "hardhat";

import { OwnerWithEip712PermitSignature } from "typechain-types";

import { sign } from "./ec";
import { streccak } from "./keccak";
import { de0x } from "./string";
import { toBuffer } from "ethereumjs-util";

interface DeriveDomainSeparatorArgs {
type: string;
Expand Down
Loading
Loading