From 14b91c90a342e975b031305b506c6cce69d46952 Mon Sep 17 00:00:00 2001 From: David Disu Date: Fri, 2 Sep 2022 15:25:15 +0100 Subject: [PATCH] Add workflow for running solidity unit tests --- .github/workflows/run-sut.yml | 20 +++++++++++++ .../remix-ide/contracts/tests/Ballot_test.sol | 28 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/run-sut.yml create mode 100644 apps/remix-ide/contracts/tests/Ballot_test.sol diff --git a/.github/workflows/run-sut.yml b/.github/workflows/run-sut.yml new file mode 100644 index 0000000000..e6b8d98221 --- /dev/null +++ b/.github/workflows/run-sut.yml @@ -0,0 +1,20 @@ + +name: Running Solidity Unit Tests +on: [push] + +jobs: + run_sol_contracts_job: + runs-on: ubuntu-latest + name: A job to run solidity unit tests on github actions CI + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Environment Setup + uses: actions/setup-node@v3 + with: + node-version: 14.17.6 + - name: Run SUT Action + uses: EthereumRemix/sol-test@v1 + with: + test-path: 'apps/remix-ide/contracts/tests' + compiler-version: '0.8.15' \ No newline at end of file diff --git a/apps/remix-ide/contracts/tests/Ballot_test.sol b/apps/remix-ide/contracts/tests/Ballot_test.sol new file mode 100644 index 0000000000..452a5433b4 --- /dev/null +++ b/apps/remix-ide/contracts/tests/Ballot_test.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; +import "remix_tests.sol"; // this import is automatically injected by Remix. +import "hardhat/console.sol"; +import "../ballot.sol"; + +contract BallotTest { + + bytes32[] proposalNames; + + Ballot ballotToTest; + function beforeAll () public { + proposalNames.push(bytes32("candidate1")); + ballotToTest = new Ballot(proposalNames); + } + + function checkWinningProposal () public { + console.log("Running checkWinningProposal"); + ballotToTest.vote(0); + Assert.equal(ballotToTest.winningProposal(), uint(0), "proposal at index 0 should be the winning proposal"); + Assert.equal(ballotToTest.winnerName(), bytes32("candidate1"), "candidate1 should be the winner name"); + } + + function checkWinninProposalWithReturnValue () public view returns (bool) { + return ballotToTest.winningProposal() == 0; + } +} \ No newline at end of file