Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
remove hasHappened function (#220)
Browse files Browse the repository at this point in the history
* remove hasHappened function

* remove constant, go back to zero being special value
  • Loading branch information
Brendan Chou authored Apr 8, 2019
1 parent 609edd9 commit 67077b1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
12 changes: 0 additions & 12 deletions __tests__/Library.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,6 @@ describe('Library', () => {
expect(new BigNumber(time2).toNumber()).toBeGreaterThanOrEqual(block2.timestamp);
expect(block2.timestamp).toBeGreaterThanOrEqual(block1.timestamp + 15);
});

it('hasHappened', async () => {
const block = await solo.web3.eth.getBlock('latest');
const results = await Promise.all([
solo.contracts.testLib.methods.TimeHasHappened(0).call(),
solo.contracts.testLib.methods.TimeHasHappened(1).call(),
solo.contracts.testLib.methods.TimeHasHappened(block.timestamp - 10).call(),
solo.contracts.testLib.methods.TimeHasHappened(block.timestamp).call(),
solo.contracts.testLib.methods.TimeHasHappened(block.timestamp + 10).call(),
]);
expect(results).toEqual([false, true, true, true, false]);
});
});

describe('Token', () => {
Expand Down
14 changes: 13 additions & 1 deletion contracts/external/traders/Expiry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract Expiry is

// expiry time validation
Require.that(
Time.hasHappened(getExpiry(makerAccount, inputMarketId)),
hasExpired(makerAccount, inputMarketId),
FILE,
"Loan not yet expired"
);
Expand Down Expand Up @@ -195,6 +195,18 @@ contract Expiry is
);
}

function hasExpired(
Account.Info memory account,
uint256 marketId
)
private
view
returns (bool)
{
uint32 expiry = getExpiry(account, marketId);
return expiry != 0 && expiry <= Time.currentTime();
}

function inputWeiToOutput(
Types.Wei memory inputWei,
uint256 inputMarketId,
Expand Down
10 changes: 0 additions & 10 deletions contracts/protocol/lib/Time.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,4 @@ library Time {
{
return Math.to32(block.timestamp);
}

function hasHappened(
uint32 time
)
internal
view
returns (bool)
{
return (time != 0) && (time <= currentTime());
}
}
10 changes: 0 additions & 10 deletions contracts/testing/TestLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,6 @@ contract TestLib {
return Time.currentTime();
}

function TimeHasHappened(
uint32 time
)
external
view
returns (bool)
{
return Time.hasHappened(time);
}

// ============ Token Functions ============

function TokenBalanceOf(
Expand Down

0 comments on commit 67077b1

Please sign in to comment.