Skip to content
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ build/
dist/
chains/
**/_build
__pycache__
.env
.history
.hypothesis/
reports/
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions contracts/DateTime.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.16;
pragma solidity ^0.8.0;

contract DateTime {
/*
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions contracts/api.sol → interfaces/api.sol
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pytz==2015.6
populus==0.5.1
eth-brownie==1.17.0
6 changes: 6 additions & 0 deletions tests/datetime/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest
from brownie import accounts, DateTime

@pytest.fixture(scope="session")
def crontab():
return accounts[0].deploy(DateTime)
3 changes: 1 addition & 2 deletions tests/datetime/test_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions tests/datetime/test_hour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions tests/datetime/test_isLeapYear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions tests/datetime/test_minute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import pytest

@pytest.mark.parametrize(
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions tests/datetime/test_month.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tests/datetime/test_second.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions tests/datetime/test_to_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions tests/datetime/test_weekday.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions tests/datetime/test_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -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