From 67077b1dc5ad4d60e4690cc82f5b6bae2033a84a Mon Sep 17 00:00:00 2001 From: Brendan Chou Date: Mon, 8 Apr 2019 10:59:14 -0700 Subject: [PATCH] remove hasHappened function (#220) * remove hasHappened function * remove constant, go back to zero being special value --- __tests__/Library.test.ts | 12 ------------ contracts/external/traders/Expiry.sol | 14 +++++++++++++- contracts/protocol/lib/Time.sol | 10 ---------- contracts/testing/TestLib.sol | 10 ---------- 4 files changed, 13 insertions(+), 33 deletions(-) diff --git a/__tests__/Library.test.ts b/__tests__/Library.test.ts index 2ba84976..e30d3ab2 100644 --- a/__tests__/Library.test.ts +++ b/__tests__/Library.test.ts @@ -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', () => { diff --git a/contracts/external/traders/Expiry.sol b/contracts/external/traders/Expiry.sol index 51566ac3..6d03ff3c 100644 --- a/contracts/external/traders/Expiry.sol +++ b/contracts/external/traders/Expiry.sol @@ -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" ); @@ -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, diff --git a/contracts/protocol/lib/Time.sol b/contracts/protocol/lib/Time.sol index 10002d8d..982c5bab 100644 --- a/contracts/protocol/lib/Time.sol +++ b/contracts/protocol/lib/Time.sol @@ -38,14 +38,4 @@ library Time { { return Math.to32(block.timestamp); } - - function hasHappened( - uint32 time - ) - internal - view - returns (bool) - { - return (time != 0) && (time <= currentTime()); - } } diff --git a/contracts/testing/TestLib.sol b/contracts/testing/TestLib.sol index 3ef134d4..2aee0bd9 100644 --- a/contracts/testing/TestLib.sol +++ b/contracts/testing/TestLib.sol @@ -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(