name: Test

on:
  push:
    branches:
    - master
    - develop
  pull_request:

jobs:
  functional:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1

    - name: Cache Compiler Installations
      uses: actions/cache@v2
      with:
        path: |
          ~/.solcx
          ~/.vvm
        key: compiler-cache

    - name: Cache compiler installations
      uses: actions/cache@v2
      with:
        path: |
          ~/.solcx
          ~/.vvm
        key: ${{ runner.os }}-compiler-cache

    - name: Setup node.js
      uses: actions/setup-node@v1
      with:
        node-version: '12.x'

    - name: Install ganache
      run: npm install -g ganache-cli@6.12.1

    - name: Set up python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8

    - name: Set pip cache directory path
      id: pip-cache-dir-path
      run: |
        echo "::set-output name=dir::$(pip cache dir)"

    - name: Restore pip cache
      uses: actions/cache@v2
      id: pip-cache
      with:
        path: |
          ${{ steps.pip-cache-dir-path.outputs.dir }}
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
          ${{ runner.os }}-pip-

    - name: Install python dependencies
      run: pip install -r requirements-dev.txt

    - name: Compile Code
      run: brownie compile --size

    - name: Run Tests
      run: brownie test tests/functional/ --gas --coverage --revert-tb

  integration:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1

    - name: Cache Compiler Installations
      uses: actions/cache@v2
      with:
        path: |
          ~/.solcx
          ~/.vvm
        key: compiler-cache

    - name: Cache compiler installations
      uses: actions/cache@v2
      with:
        path: |
          ~/.solcx
          ~/.vvm
        key: ${{ runner.os }}-compiler-cache

    - name: Setup node.js
      uses: actions/setup-node@v1
      with:
        node-version: '12.x'

    - name: Install ganache
      run: npm install -g ganache-cli@6.12.1

    - name: Set up python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8

    - name: Set pip cache directory path
      id: pip-cache-dir-path
      run: |
        echo "::set-output name=dir::$(pip cache dir)"

    - name: Restore pip cache
      uses: actions/cache@v2
      id: pip-cache
      with:
        path: |
          ${{ steps.pip-cache-dir-path.outputs.dir }}
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}
          ${{ runner.os }}-pip-

    - name: Install python dependencies
      run: pip install -r requirements-dev.txt

    - name: Run Tests
      run: brownie test tests/integration/ -s --revert-tb
