From 26ee44b8e2b8acecfb4189db6255ffc7ab298a87 Mon Sep 17 00:00:00 2001 From: Ryan Hall Date: Fri, 15 Oct 2021 15:54:59 -0400 Subject: [PATCH 1/3] convert project to use brownie --- .gitignore | 5 +++++ {contracts => interfaces}/api.sol | 6 ++++-- requirements-dev.txt | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) rename {contracts => interfaces}/api.sol (90%) diff --git a/.gitignore b/.gitignore index 2514e6c..ad6622c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ build/ dist/ chains/ **/_build +__pycache__ +.env +.history +.hypothesis/ +reports/ diff --git a/contracts/api.sol b/interfaces/api.sol similarity index 90% rename from contracts/api.sol rename to interfaces/api.sol index 892a40e..3659af1 100644 --- a/contracts/api.sol +++ b/interfaces/api.sol @@ -1,6 +1,8 @@ -contract DateTimeAPI { +pragma solidity ^0.4.16; + +interface DateTimeAPI { /* - * Abstract contract for interfacing with the DateTime contract. + * Interface for interfacing with the DateTime contract. * */ function isLeapYear(uint16 year) constant returns (bool); diff --git a/requirements-dev.txt b/requirements-dev.txt index d5684b7..87205f7 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,2 @@ pytz==2015.6 -populus==0.5.1 +eth-brownie==1.17.0 From fe72954c9cb766717f84a6e2d846f5f13cbdb5eb Mon Sep 17 00:00:00 2001 From: Ryan Hall Date: Fri, 15 Oct 2021 16:15:07 -0400 Subject: [PATCH 2/3] update to sol 0.8, refactor tests --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ README.md | 17 ++++++++++++++++- contracts/DateTime.sol | 4 ++-- tests/datetime/conftest.py | 6 ++++++ tests/datetime/test_day.py | 3 +-- tests/datetime/test_hour.py | 3 +-- tests/datetime/test_isLeapYear.py | 3 +-- tests/datetime/test_minute.py | 4 +--- tests/datetime/test_month.py | 3 +-- tests/datetime/test_second.py | 3 +-- tests/datetime/test_to_timestamp.py | 3 +-- tests/datetime/test_weekday.py | 3 +-- tests/datetime/test_year.py | 3 +-- 13 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/datetime/conftest.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..eddf908 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: "CI" +on: + push: +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: '3.x' + - uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Install Dependencies + run: pip install -r requirements-dev.txt + - name: Install Ganache + run: npm install -g ganache-cli + - name: Run Tests + run: brownie test diff --git a/README.md b/README.md index 8243abc..98f839c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Contract which implements utilities for working with datetime values in ethereum. -Contract Deployments: +Contract Deployments: - Mainnet: [`0x1a6184CD4C5Bea62B0116de7962EE7315B7bcBce`](https://etherscan.io/address/0x1a6184cd4c5bea62b0116de7962ee7315b7bcbce) - Rinkeby: [`0x92482Ba45A4D2186DafB486b322C6d0B88410FE7`](https://rinkeby.etherscan.io/address/0x92482ba45a4d2186dafb486b322c6d0b88410fe7) @@ -84,3 +84,18 @@ Given a unix timestamp, returns the `DateTime.weekday` value for the timestamp. * `toTimestamp(uint16 year, uint8 month, uint8 day) constant returns (uint timestamp)` Returns the unix timestamp representation for the given date and time values. + +### Running Tests + +First, install dependencies + +```bash +pip install -r requirements-dev.txt +npm install -g ganache-cli +``` + +Then, run tests with + +```bash +brownie test +``` diff --git a/contracts/DateTime.sol b/contracts/DateTime.sol index 75eaf1a..3156cf7 100644 --- a/contracts/DateTime.sol +++ b/contracts/DateTime.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.16; +pragma solidity ^0.8.0; contract DateTime { /* @@ -57,7 +57,7 @@ contract DateTime { } } - function parseTimestamp(uint timestamp) internal pure returns (_DateTime dt) { + function parseTimestamp(uint timestamp) internal pure returns (_DateTime memory dt) { uint secondsAccountedFor = 0; uint buf; uint8 i; diff --git a/tests/datetime/conftest.py b/tests/datetime/conftest.py new file mode 100644 index 0000000..eb1f1d4 --- /dev/null +++ b/tests/datetime/conftest.py @@ -0,0 +1,6 @@ +import pytest +from brownie import accounts, DateTime + +@pytest.fixture(scope="session") +def crontab(): + return accounts[0].deploy(DateTime) diff --git a/tests/datetime/test_day.py b/tests/datetime/test_day.py index 8922f7b..17464a4 100644 --- a/tests/datetime/test_day.py +++ b/tests/datetime/test_day.py @@ -59,6 +59,5 @@ (94694400, 1), # Jan 1 1972 ), ) -def test_get_day_from_timestamp(deployed_contracts, timestamp, day): - crontab = deployed_contracts.DateTime +def test_get_day_from_timestamp(crontab, timestamp, day): assert crontab.getDay(timestamp) == day diff --git a/tests/datetime/test_hour.py b/tests/datetime/test_hour.py index 8189993..b94e788 100644 --- a/tests/datetime/test_hour.py +++ b/tests/datetime/test_hour.py @@ -54,6 +54,5 @@ (63158400, 0), ), ) -def test_get_hour_from_timestamp(deployed_contracts, timestamp, hour): - crontab = deployed_contracts.DateTime +def test_get_minute_from_timestamp(crontab, timestamp, hour): assert crontab.getHour(timestamp) == hour diff --git a/tests/datetime/test_isLeapYear.py b/tests/datetime/test_isLeapYear.py index 305b822..fa793ff 100644 --- a/tests/datetime/test_isLeapYear.py +++ b/tests/datetime/test_isLeapYear.py @@ -16,8 +16,7 @@ @pytest.mark.parametrize( 'year', range(1970, 2401), ) -def test_is_leap_year(deployed_contracts, year): - crontab = deployed_contracts.DateTime +def test_is_leap_year(crontab, year): if year in LEAP_YEARS: assert crontab.isLeapYear(year) is True else: diff --git a/tests/datetime/test_minute.py b/tests/datetime/test_minute.py index e9565f6..594d001 100644 --- a/tests/datetime/test_minute.py +++ b/tests/datetime/test_minute.py @@ -1,4 +1,3 @@ - import pytest @pytest.mark.parametrize( @@ -128,6 +127,5 @@ (63075600, 0), ), ) -def test_get_minute_from_timestamp(deployed_contracts, timestamp, minute): - crontab = deployed_contracts.DateTime +def test_get_minute_from_timestamp(crontab, timestamp, minute): assert crontab.getMinute(timestamp) == minute diff --git a/tests/datetime/test_month.py b/tests/datetime/test_month.py index 4fbcf76..9edebe6 100644 --- a/tests/datetime/test_month.py +++ b/tests/datetime/test_month.py @@ -61,7 +61,6 @@ (94694400, 1), ), ) -def test_get_month_from_timestamp(deployed_contracts, timestamp, month): - crontab = deployed_contracts.DateTime +def test_get_month_from_timestamp(crontab, timestamp, month): assert crontab.getMonth(timestamp) == month diff --git a/tests/datetime/test_second.py b/tests/datetime/test_second.py index e084001..e4c3af5 100644 --- a/tests/datetime/test_second.py +++ b/tests/datetime/test_second.py @@ -67,6 +67,5 @@ (63072060, 0), ), ) -def test_get_second_from_timestamp(deployed_contracts, timestamp, second): - crontab = deployed_contracts.DateTime +def test_get_second_from_timestamp(crontab, timestamp, second): assert crontab.getSecond(timestamp) == second diff --git a/tests/datetime/test_to_timestamp.py b/tests/datetime/test_to_timestamp.py index c95e480..c4c347c 100644 --- a/tests/datetime/test_to_timestamp.py +++ b/tests/datetime/test_to_timestamp.py @@ -13,6 +13,5 @@ (datetime.datetime(2016, 3, 1), 1456790400), ), ) -def test_dt_to_timestamp(deployed_contracts, dt, timestamp): - crontab = deployed_contracts.DateTime +def test_dt_to_timestamp(crontab, dt, timestamp): assert crontab.toTimestamp(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second) == timestamp diff --git a/tests/datetime/test_weekday.py b/tests/datetime/test_weekday.py index 8911eb9..d61d8a7 100644 --- a/tests/datetime/test_weekday.py +++ b/tests/datetime/test_weekday.py @@ -21,7 +21,6 @@ (68342400, 4), ), ) -def test_get_weekday_from_timestamp(deployed_contracts, timestamp, weekday): - crontab = deployed_contracts.DateTime +def test_get_weekday_from_timestamp(crontab, timestamp, weekday): assert crontab.getWeekday(timestamp) == weekday diff --git a/tests/datetime/test_year.py b/tests/datetime/test_year.py index 3e40249..95a6509 100644 --- a/tests/datetime/test_year.py +++ b/tests/datetime/test_year.py @@ -866,6 +866,5 @@ (13537929599, 2398), ) ) -def test_get_year_from_timestamp(deployed_contracts, timestamp, year): - crontab = deployed_contracts.DateTime +def test_get_year_from_timestamp(crontab, timestamp, year): assert crontab.getYear(timestamp) == year From 9de64680ef8db69d5331ec054318d1c91680cd38 Mon Sep 17 00:00:00 2001 From: Ryan Hall Date: Mon, 25 Oct 2021 11:07:51 -0400 Subject: [PATCH 3/3] fix workflow typo --- .github/workflows/ci.yml | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eddf908..45b68af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,20 +1,19 @@ name: "CI" -on: - push: +on: [push] jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - uses: actions/setup-node@v2 - with: - node-version: '14' - - name: Install Dependencies - run: pip install -r requirements-dev.txt - - name: Install Ganache - run: npm install -g ganache-cli - - name: Run Tests - run: brownie test + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: "3.8.10" + - uses: actions/setup-node@v2 + with: + node-version: "14" + - name: Install Dependencies + run: pip install -r requirements-dev.txt + - name: Install Ganache + run: npm install -g ganache-cli + - name: Run Tests + run: brownie test